adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
595 stars 49 forks source link

SetAppThemeColor not found #89

Closed MattePozzy closed 1 year ago

MattePozzy commented 1 year ago

Hi, I'm trying to uset the method SetAppThemeColor from here https://learn.microsoft.com/en-us/dotnet/maui/user-interface/system-theme-changes#extension-methods but the control from MauiReactor doesn't have it.

image

it's possible to implement it or there is a way to use this method?

Thank you.

adospace commented 1 year ago

SetAppThemeColor works on native MAUI Controls so you can't call it on MauiReactor label (that is wrapper around MauiControls.Label): you need a reference to the nativecontrol first:

new MauiReactor(labelRef => labelRef?.SetAppThemeColor(...))

BUT it's not recommended even in classic Maui app. You should instead use a xaml resource dictionary like this:

<Setter Property="Label.TextColor"
        Value="{AppThemeBinding 
            Light={StaticResource LightGray}, 
            Dark={StaticResource Background_Mid}}" />

See https://github.com/adospace/reactorui-maui/tree/main/samples/MauiReactor.WeatherTwentyOne

Said that in MauiReactor the recommended approach is something like this:

public static bool IsDarkTheme => MauiControls.Application.Current?.UserAppTheme == Microsoft.Maui.ApplicationModel.AppTheme.Dark;

new MauiReactor.Label()
.TextColor(IsDarkTheme ? Colors.White : Colors.Black)
MattePozzy commented 1 year ago

SetAppThemeColor works on native MAUI Controls so you can't call it on MauiReactor label (that is wrapper around MauiControls.Label): you need a reference to the nativecontrol first:

new MauiReactor(labelRef => labelRef?.SetAppThemeColor(...))

BUT it's not recommended even in classic Maui app. You should instead use a xaml resource dictionary like this:

<Setter Property="Label.TextColor"
        Value="{AppThemeBinding 
            Light={StaticResource LightGray}, 
            Dark={StaticResource Background_Mid}}" />

See https://github.com/adospace/reactorui-maui/tree/main/samples/MauiReactor.WeatherTwentyOne

Said that in MauiReactor the recommended approach is something like this:

public static bool IsDarkTheme => MauiControls.Application.Current?.UserAppTheme == Microsoft.Maui.ApplicationModel.AppTheme.Dark;

new MauiReactor.Label()
.TextColor(IsDarkTheme ? Colors.White : Colors.Black)

Thank you, I have solved using this code: lblTitolo.TextColor(Utility.GetResources<Color>(Utility.IsDarkTheme() ? "White" : "Black"));