Reputation: 339
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.
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
Upvotes: 0
Views: 892
Reputation: 32785
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);
Upvotes: 1