我在 Xamarin 上的 UWP 项目中创建了一个导航栏。
App.xaml.cs
...
public app()
{
InitializeComponent();
MainPage = new NavigationPage(new LoginPage()){
BarBackgroundColor = Color.Black;
}
}
因此,如果我在设置页面,我需要以编程方式更改导航栏的颜色。
SettingPage.xaml.cs
...
private void clicked_btn(sender, e) {
...
// how can I get the handle of navigationbar and then change the attribute of one???
}
这可能吗?
有什么办法吗?
最佳答案
最好不要这样做,或者通过自定义渲染器来完成。 但下面是表单方法:
var navigationPage = Application.Current.MainPage as NavigationPage;
navigationPage.BarBackgroundColor = Color.Black;
关于xamarin - 如何在 Xamarin 中以编程方式更改导航栏的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40799154/