I am new to WPF MVVM and I need to develop a new application (which will replace an old app written in WinForms with SQL Server database). I would like to know what would be the best way to change styles programatically - e.g. from a default style to a 'dark theme'.
I am not sure if my approach is correct but for now I've setup a 'default style' which consists of two XAML files which I reference in the App.xaml as follows:
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApp"
StartupUri="/AppGeneral/MainWindowView.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Default style -->
<ResourceDictionary Source="/Framework/Resources/Styles/Default/AppStyle.xaml"/>
<ResourceDictionary Source="/Framework/Resources/Styles/Default/CommonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
The first file defines styles for the overall look of the application, and the second file contains common styles applied too all views. This simple implementation works for me so far, but I would like to add another style, such as a 'DarkTheme' for example:
<!-- Dark theme -->
<ResourceDictionary Source="/Framework/Resources/Styles/DarkTheme/AppStyle.xaml"/>
<ResourceDictionary Source="/Framework/Resources/Styles/DarkTheme/CommonStyle.xaml"/>
And I am not sure how to go about doing it so that I can change in between the styles programatically (i.e. allow the user to change the style). Any help is greatly appreciated.