0
votes

I'm using on xamarin forms and on Android and iOS, and both when phone is using dark theme, it changes in order to use the same theme. But When I run app on UWP, xamarin forms work with Light theme, always. Could you tell me how to force to use dark theme? I have tried to set manually the dark theme on constructor of App.cs (UWP) as I do on native UWP apps, but it is setted but Xamarin forms continue working with Light theme. Any idea?

Steps to reproduce it.

  • Create a MasterDetail template
  • On constructor of App.cs of UWP, added the following line: "RequestedTheme = Windows.UI.Xaml.ApplicationTheme.Dark;"

  • Execute app and: iOS menu and status bar is dark. Android 10, menu and status bar is dark (tried on realme). Windows 10, menu is White.

Thank you

1
Please, share your code and what have you tried - Pavel Anikhouski
check this possible duplicate stackoverflow.com/questions/41685125/… - W0RT4
Added steps to reproduce my situation. - cansado2930
Have you tried to remove RequestedTheme and then change system theme. Will your app react on that ? - W0RT4
Yes, I tried it, and.... Android & iOS work correctly, but UWP continue with Light Theme - cansado2930

1 Answers

1
votes

If you want to set uwp theme manually, please call the following method in uwp client project.

public static class ThemeSelectorService
{

    public static async Task SetRequestedThemeAsync(ElementTheme Theme)
    {
        foreach (var view in CoreApplication.Views)
        {
            await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (Window.Current.Content is FrameworkElement frameworkElement)
                {
                    frameworkElement.RequestedTheme = Theme;
                }
            });
        }
    }


}

Usage

ThemeSelectorService.SetRequestedThemeAsync(ElementTheme.Dark);