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???
}
Is that possible?
Is there a way I can do?
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;
From class definition you can set the bar background color. Like this.
namespace ProyectName
{
public class MainPage
{
public MainPage()
{
BarBackgroundColor = Color.FromHex("#484559");
BarTextColor = Color.White;
}
}
}
Or from your App.xml add a 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With