uno.extensions icon indicating copy to clipboard operation
uno.extensions copied to clipboard

[MVUX/CSM] Resources don't update after changing Fluent Theme manually

Open morning4coffe-dev opened this issue 7 months ago • 2 comments

Changing the theme manually with a ToggleSwitch inside the app results in the app not updating its background on Windows and on other platforms, the color is too dark when in DarkTheme.

Tested on my side on "Uno.Sdk": "5.2.175"

Repro with my notes: https://github.com/morning4coffe-dev/uno-platform-testing/tree/bug/mvux-csm-fluent-theme-resource-update

Then testing the same case in XAML+MVVM project, I am not able to repro this issue.

Originally posted by @kucint in https://github.com/unoplatform/uno/discussions/17487:

Changing Theme to dark and back to light works fine on Desktop. On Windows, controls seem to react correctly on change, except the main frame background which stays always light.

    public MainPage() => this
        .DataContext(new BindableMainPageModel(), (page, vm) => page
        .Background(ThemeResource.Get<Brush>("ApplicationPageBackgroundThemeBrush"))   // -> does not work on windows
        .Content(
            new ToggleSwitch()
            .OnContent("Dark mode")
            .OffContent("Light mode")
            .Name(out ToggleSwitch c, c => c.Toggled += (s, e) =>
            {
                FrameworkElement? content = XamlRoot?.Content as FrameworkElement;
                if (content is not null)
                    content.RequestedTheme = content.RequestedTheme == ElementTheme.Dark ? ElementTheme.Light : ElementTheme.Dark;
            })
            .IsOn(x => x.Binding(() => vm.IsAppInDarkMode).TwoWay())
        ));

Model:

internal partial record MainPageModel
{
    public IState<bool> IsAppInDarkMode => State<bool>.Value(this, () => false);
}

image

image

[!NOTE] Latest dev branch used: "Uno.Sdk": "5.4.0-dev.99"

morning4coffe-dev avatar Jul 12 '24 09:07 morning4coffe-dev