xamarin - 如何在 Xamarin 中以编程方式更改导航栏的背景颜色?

标签 xamarin xamarin.forms

我在 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/

相关文章:

xamarin - MVVMCross 中的常量程序集重新映射

xamarin - 将 OnAppearing 传递给 Xamarin Forms MVVM 中的 ViewModel?

c# - Xamarin.Forms。 XAML Label IsVisible 条件未按预期进行评估

c# - 在 xamarin 中启用 ARC

c# - 用信息填充表

android - Xamarin Android fragment 库

asp.net - 如何从android模拟器访问本地主机?

c# - 未找到方法 'Android.Support.CustomTabs.CustomTabsIntent.LaunchUrl'

VS2015 update 2 中的 Xamarin 项目模板似乎与 Microsoft 电子书不一致

c# - 检索项目 : No resource found that matches the given name 'ThemeOverlay.AppCompat.Light' 的父项时出错