Reputation: 545
I want the main button to be of a color derived from the windows theme. for example if the windows theme is red my buttons are the same color Thank you
Upvotes: 1
Views: 1663
Reputation: 14475
UISettings Class could be used to get current system color in windows platform , the point is how to convert Windows.UI.Color
to Microsoft.Maui.Graphics.Color
.
#if WINDOWS
var uiSettings = new Windows.UI.ViewManagement.UISettings();
var color = uiSettings.GetColorValue(UIColorType.Accent);
//change button color with system theme color
button.BackgroundColor = Microsoft.Maui.Graphics.Color.Parse(color.ToString());
#endif
And if you want to change the color dynamically according to system theme, take a look at Application.Current.RequestedThemeChanged event ,it is used to to detect the change of system theme .
Notice: The following event is only triggered when switching between light/dark theme .
Application.Current.RequestedThemeChanged += (s, a) =>
{
#if WINDOWS
var uiSettings = new Windows.UI.ViewManagement.UISettings();
var color = uiSettings.GetColorValue(UIColorType.Accent);
//change button color with system theme color
button.BackgroundColor = Microsoft.Maui.Graphics.Color.Parse(color.ToString());
#endif
};
Upvotes: 1