Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
morning4coffe-dev opened this issue Jul 12, 2024 · 5 comments
Assignees

Comments

@morning4coffe-dev
Copy link
Member

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 unoplatform/uno#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 morning4coffe-dev transferred this issue from unoplatform/uno Jul 12, 2024
@agneszitte
Copy link
Contributor

@kazo0 to verify if it is a duplicate: https://github.com/unoplatform/uno.csharpmarkup/issues/716

@kazo0
Copy link
Contributor

kazo0 commented Aug 1, 2024

@agneszitte yes this is the same issue as https://github.com/unoplatform/uno.csharpmarkup/issues/716

@MartinZikmund
Copy link
Member

To work around this issue, you can create a Style targeting Page, with a setter for the Background (using ThemeResource in the Setter) - theme resources should be correctly applied and observed when part of Style, and this should work across all targets including WinUI

@MartinZikmund
Copy link
Member

Workaround similar to microsoft/microsoft-ui-xaml#9464 (comment)

@MartinZikmund
Copy link
Member

Created microsoft/microsoft-ui-xaml#10029

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants