It depends on whether you want to change topics (because in essence this is what you want to do) on the fly (I assume that you do it).
I did not do this myself, but I think it should look like this:
- Use a
ContentTemplate or DataTemplate for each fragment of the user interface that you want to make available {DynamicResource} these patterns with {DynamicResource}- Extract resources from application resources; you will place them there as
ResourceDictionary objects, one per theme using ResourceDictionary.MergedDictionaries - Whenever you want to change the "theme", programmatically delete all current merged dictionaries and add the appropriate one corresponding to the desired theme
To illustrate, your Application will use the default dictionary:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="themes\default.theme.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
And you would add / remove dictionaries with something like
ResourceDictionary theme = (ResourceDictionary)Application.LoadComponent(themeUri); Resources.MergedDictionaries.Add(theme);
Update: I searched a bit and found a more complete example of what I am describing: Can I use WPF themes to include multiple skins for an application that can be changed at runtime?
source share