You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by HobDev June 23, 2022
The docs have the SetAppThemeColor() and SetAppTheme(). This way I have to declare the colors on each UI element. There should be some better way to share style among the UI elements in C#. C# markup must support to declare the style once and use it throughout the app.
static Color darkThemeTextColor = Color.FromArgb("#FFFFFF");
static Color lightThemeTextColor = Color.FromArgb("#000000");
static Style<Label> cSharpLabelStyle;
public static Style<Label> CSharpLabelStyle => cSharpLabelStyle ?? (cSharpLabelStyle = new Style<Label>(
(Label.TextColorProperty, new AppThemeBindingExtension { Dark = darkThemeTextColor, Light = lightThemeTextColor }),
(Label.FontFamilyProperty, "OpenSansRegular"),
(Label.FontSizeProperty, 14)
));
Finally use the style in UI :
new Label{Text = "Hello World" , HorizontalOptions=LayoutOptions.Center, VerticalOptions=LayoutOptions.Center}.Style(AppStyles.CSharpLabelStyle),
In the attached sample the color of the XAML Label changes with the change of mode. But the C# Label does not change color until the app restarts. Unable to check the change of device theme due to this bug.
Discussed in #75
Originally posted by HobDev June 23, 2022
The docs have the
SetAppThemeColor()
andSetAppTheme()
. This way I have to declare the colors on each UI element. There should be some better way to share style among the UI elements in C#. C# markup must support to declare the style once and use it throughout the app.Finally use the style in UI :
new Label{Text = "Hello World" , HorizontalOptions=LayoutOptions.Center, VerticalOptions=LayoutOptions.Center}.Style(AppStyles.CSharpLabelStyle),
In the attached sample the color of the XAML Label changes with the change of mode. But the C# Label does not change color until the app restarts. Unable to check the change of device theme due to this bug.
MauiApp1.zip
The text was updated successfully, but these errors were encountered: