In a Xamarin.Forms program, how to dynamically change the BarBackgroundColor? I already changed the app.xaml file like this:
<Application.Resources>
<ResourceDictionary>
<!--Global Styles-->
<Color x:Key="NavigationPrimary">#2196F3</Color>
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="DarkOliveGreen" />
<Setter Property="BarTextColor" Value="White" />
</Style>
</ResourceDictionary>
</Application.Resources>
But the color changes are not dynamic: they are read when the app is started, then can no longer be modified.
This works by making the following changes in the app.xaml.cs file:
DB_ParametreList = dbparametre.GetAllParametre();
parametres = DB_ParametreList[0];
if (parametres.WallpaperName == "wallpapers_4.png")
{
MainPage = new NavigationPage(new ListeAchatsPage())
{
BarBackgroundColor = Color.FromHex("#705502"),
BarTextColor = Color.White,
};
}
else if (parametres.WallpaperName == "wallpapers_3.png")
{
MainPage = new NavigationPage(new ListeAchatsPage())
{
BarBackgroundColor = Color.FromHex("#09506B"),
BarTextColor = Color.White,
};
}
else
{
MainPage = new NavigationPage(new ListeAchatsPage())
{
BarBackgroundColor = Color.DarkOliveGreen,
BarTextColor = Color.White,
};
}
The problem comes from the MainPage which cannot be a NavigationPage because I have to display the icon of a Hambuger menu. Please help me to resolve this issue.