MAUI NavigationPage BarBackgroundColor
ISIMobile
1
Reputation point
In a Navigation Page in MAUI on Android the NavigationPage BarBackGroundColor does not change when set, but on iOS it does work.
The code is as follows: We set a binding on a Property in our ViewModel, when the property value change, it should change the BarBackgroundColor, it does not change the color in Android.
Any ideas for a workaround or fix?
The current workaround idea is to pop the page when the property change and then reload the page, but that is not ideal and it is slow.
protected override void OnAppearing()
{
base.OnAppearing();
if (App.RootPage.Detail is NavigationPage page)
{
page.BindingContext = ViewModel;
page.SetBinding(NavigationPage.BarBackgroundColorProperty, new Binding("IsOffline", BindingMode.OneWay, PageIsOfflineToColorConverter.Instance));
}
}
// our convertor code
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
if (value != null && bool.TryParse(value.ToString(), out var result) && result)
{
return (Color)Application.Current.Resources["OfflineColor"];
}
}
catch { }
return (Color)Application.Current.Resources["Primary"];
}
Sign in to answer