如何在 Xamarin 中以编程方式更改导航栏的背景颜色? [英] How to change background Color of Navigationbar programmatically in Xamarin?

查看:41
本文介绍了如何在 Xamarin 中以编程方式更改导航栏的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xamarin 上的 UWP 项目中创建了一个导航栏.

I created a navigationbar in UWP project on Xamarin.

App.xaml.cs
...
public app()
{
  InitializeComponent();
  MainPage = new NavigationPage(new LoginPage()){
    BarBackgroundColor = Color.Black;
  }
}

所以如果我在设置页面,我需要以编程方式更改导航栏的颜色.

So If I am in Setting Page, I need to change the color of Navigationbar programmatically.

SettingPage.xaml.cs

...
private void clicked_btn(sender, e) {
  ...
  // how can I get the handle of navigationbar and then change the attribute of one???
}

这可能吗?

有什么办法吗?

推荐答案

最好不要这样做,或者通过自定义渲染器进行.但以下是表单方法:

Its better not do it, or do it via custom renderers. But below is the forms approach :

var navigationPage = Application.Current.MainPage as NavigationPage;
navigationPage.BarBackgroundColor = Color.Black;

这篇关于如何在 Xamarin 中以编程方式更改导航栏的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆