I have a WPF application with a theme (ShinyRed.xaml) and I want to have a button that when clicked changes the theme to ShinyBlue.xaml
I load in the theme initially in App.xaml:
<Application.Resources> <ResourceDictionary Source="/Themes/ShinyBlue.xaml"/> </Application.Resources>
How might I do this?
In your mobile, in the display settings, there is an option to set your whole mobile themes like a light blue color theme, red color theme or any other. This will set your full mobile functionality with this theme setting.
To change default themes go to File and click on Settings. A new Settings dialog will appear, like this. Under the Appearance & Behaviour -> Appearance, you will find Theme. Choose the right theme from the drop-down and click on Apply and then Ok.
In the Project pane select Android, go to app > res > values > themes > themes.
This week, the Android 12 starts to be released by Google. With the update comes the new Dynamic Theme feature, which lets you use the colors of the wallpaper to customize the look of the system and other apps with support for Material You.
How you could do it:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary x:Name="ThemeDictionary"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Themes/ShinyRed.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> <!-- ... -->
public partial class App : Application { public ResourceDictionary ThemeDictionary { // You could probably get it via its name with some query logic as well. get { return Resources.MergedDictionaries[0]; } } public void ChangeTheme(Uri uri) { ThemeDictionary.MergedDictionaries.Clear(); ThemeDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = uri }); } //... }
In your change method:
var app = (App)Application.Current; app.ChangeTheme(new Uri("New Uri here"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With