xamarin-docs
xamarin-docs copied to clipboard
Setting a default theme in App.xaml can cause issues on new pages
If, as suggested a 'default theme' is defined in App.xaml, any new pages created will use this 'theme' and not the current theme that has been 'merged'. for example. a simple 2 page app MainPage - containing a page link to SettingsPage SettingsPage - contains a switch that toggles between dark and light themes and a 'back button'
if you: Navigate to Settings page. Toggle the theme from light (the default theme in App.xaml) to dark using the 'merge method' shown - observe the page correctly change theme. Navigate back to MainPage - observe theme is correct. Navigate to the SettingsPage once again - observe the theme has reverted to 'Light' without reaching any code that merges the light theme into the resource dictionary.
To Fix: Remove the default theme from App.xaml In App.xaml.cs App constuctor: Merge in the default theme OR Determine the previously saved theme and merge that.
It may be worth noting this effect on the page so others aren't caught by it.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 3f353ff4-2d18-218c-f0d5-b3110e476c4d
- Version Independent ID: a1cec8f2-969c-23c5-a252-b417afcacff6
- Content: Theme a Xamarin.Forms Application - Xamarin
- Content Source: docs/xamarin-forms/user-interface/theming/theming.md
- Product: xamarin
- Technology: xamarin-forms
- GitHub Login: @davidbritch
- Microsoft Alias: dabritch