Change NavigationPage Backbutton color from DynamicResource

133 Views Asked by At

Found this for change to change the color of the backbutton .

NavigationPage.SetIconColor(this, Color.FromHex("#FFFF00"));

The backgroudcolor of the page i change with DynamicResource.

Invul.xaml.cs

  App.Current.Resources["defaultBackgroundColor"] = Preferences.Get("BackgroundColor", "#1D252D");

For the Backcolor of the backbutton i tryed this but not working because Color.FromHex i think ,can i change the FromHex part in to ?

  NavigationPage.SetIconColor(this, Color.FromHex("{DynamicResource defaultBackgroundColor}"));
1

There are 1 best solutions below

0
Jessie Zhang -MSFT On BEST ANSWER

If you want to use color from ResourceDictionary , you can access it first and pass the result color to the second parameter of method NavigationPage.SetIconColor.

Please refer to the following code:

        Color color = (Color)Application.Current.Resources["defaultBackgroundColor"];
        NavigationPage.SetIconColor(this, color);

The defaultBackgroundColor is a color in Application.Resources:

   <Application.Resources>
    <ResourceDictionary>
        <!-- Colors -->
        <Color x:Key="defaultBackgroundColor">Red</Color>
        <Color x:Key="Yellow">#ffd966</Color>
    </ResourceDictionary>
</Application.Resources>