1

Is there a way to change dark/light theme in Xamarin Forms without defining a custom theme?

For example, when I go into the iPhone simulator and toggle Settings -> Developer -> Dark Appearance, my app will change appearance. However, the code below by itself does not do this.

Application.Current.UserAppTheme = OSAppTheme.Dark;

I'd rather avoid reinventing both the system light and dark themes for every control in my app and stick to overriding system styles as needed.

Any way to do this?

dalchri
  • 97
  • 8
  • I tested this, and can confirm that it doesn't work as it should. I even tried setting in App.xaml.cs constructor, before MainPage is set. The default colors did not change. Tested on iOS and Android. Verified that UserAppTheme is still set when page is laid out (to make sure system theme wasn't re-asserting itself). Unfortunately you'll have to do what you said you don't want to do. [Define theme colors](https://stackoverflow.com/q/61156276/199364). Or [use AppThemeBinding in styles](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/theming/system-theme-changes). – ToolmakerSteve Dec 24 '21 at 20:56
  • If anyone knowledgeable wants to test this, or attempt some work-around, in [ToolmakerSteve - repo XFormsSOAnswers](https://github.com/ToolmakerSteve/XFormsSOAnswers), see `StartPage`. OR in `App.xaml.cs`, uncomment call to `ForceLightTheme`. Set your device to Dark theme, then run app. You'll see that the app theme is set, but the default colors don't change on the next page loaded. This contradicts the docs, which state this this is all you need to do. NOTE: Referring to DEFAULT system colors, NOT to AppThemeBinding (which probably works, though I did not test). – ToolmakerSteve Dec 24 '21 at 21:21

0 Answers0