Support for AppThemeBindings
HobDev opened this issue · 1 comments
Discussed in #75
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.
@HobDev It doesn't look like the Discussion in #75 is complete.
Please propose an API design and example of the new features usage in #75.
Once the feature has been fully fleshed out, you will open a New Feature Proposal.
For more information see the instructions for Submitting A New Feature in the README: https://github.com/CommunityToolkit/Maui.Markup#submitting-a-new-feature