Eri*_*han 4 xamarin xamarin.forms
我在 Xamarin 的 UWP 项目中创建了一个导航栏。
App.xaml.cs
...
public app()
{
InitializeComponent();
MainPage = new NavigationPage(new LoginPage()){
BarBackgroundColor = Color.Black;
}
}
Run Code Online (Sandbox Code Playgroud)
所以如果我在设置页面,我需要以编程方式更改导航栏的颜色。
SettingPage.xaml.cs
...
private void clicked_btn(sender, e) {
...
// how can I get the handle of navigationbar and then change the attribute of one???
}
Run Code Online (Sandbox Code Playgroud)
那可能吗?
我有办法吗?
从类定义中,您可以设置条形背景颜色。像这样。
namespace ProyectName
{
public class MainPage
{
public MainPage()
{
BarBackgroundColor = Color.FromHex("#484559");
BarTextColor = Color.White;
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者从你的 App.xml 添加一个 ResourceDictionary
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="StockIt.App">
<Application.Resources>
<ResourceDictionary>
<Color x:Key="Primary">#484559</Color>
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="BarTextColor" Value="White" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)
最好不要这样做,或者通过自定义渲染器进行。但下面是表格方法:
var navigationPage = Application.Current.MainPage as NavigationPage;
navigationPage.BarBackgroundColor = Color.Black;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14795 次 |
| 最近记录: |