dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

In windows and ios the RequestedThemeChanged event only fires the first time. #25864

Closed JPfahl closed 6 days ago

JPfahl commented 1 week ago

Description

Works in Android but in windows and ios you only ever get the event once, you have to restart the app to get it to fire again.

Steps to Reproduce

The following code in App.xaml.cs demonstrates the issue in a new default maui project:

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new AppShell();

        RequestedThemeChanged += App_RequestedThemeChanged;
    }

    private void App_RequestedThemeChanged(object? sender, AppThemeChangedEventArgs e)
    {
        UserAppTheme = e.RequestedTheme;
    }
}

Link to public reproduction project repository

No response

Version with bug

8.0.93 SR9.3

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

No response

Affected platforms

iOS, Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

similar-issues-ai[bot] commented 1 week ago

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

drasticactions commented 6 days ago

@JPfahl https://github.com/dotnet/maui/issues/15350#issuecomment-1596523882

I believe this is your issue: By setting UserAppTheme, you're saying, "I will handle theme updates from now on," so that event won't be raised again.

kevinxufei commented 6 days ago

This issue can be reproduced at Windows platform on the latest 17.13 Preview 1(8.0.93 &8.0.92).

JPfahl commented 6 days ago

When I wrote this code originally the app would not switch themes without setting UserAppTheme from the event. It must have been fixed along the way. Thanks for the info.