Ali Shan
Ali Shan

Reputation: 527

how to change the theme of application dynamically in app.xaml.cs file

I have two resource dictionaries

  1. DarkTheme.xaml
  2. LightTheme.xaml

I load the LightTheme by default when the application starts in app.xaml file using the following code

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Themes/LightTheme.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

</Application.Resources>

I want to give an option to user that he can change the theme of application as he likes problem is that how can i load the DarkTheme.xaml file when user chooses that theme and load LightTheme.xaml file when it is chosen.

Upvotes: 1

Views: 770

Answers (1)

AnjumSKhan
AnjumSKhan

Reputation: 9827

Application.Current.Resources.MergedDictionaries[0] = 
    new ResourceDictionary() { Source = new Uri("Themes/LightTheme.xaml", UriKind.Relative) };

Upvotes: 2

Related Questions