MAUI NavigationPage BarBackgroundColor

ISIMobile 1 Reputation point
2024-03-13T08:30:59.56+00:00

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"];
        }

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
{count} votes