It depends on if you want to be able to change themes (because in essence this is what you want to do) on the fly (I 'm assuming you do).
I haven't done this myself, but I think it should go like this:
- Use a
ContentTemplate
or a DataTemplate
for every piece of UI that you want to make themable
- Refer to these templates using
{DynamicResource}
- Have the resources be pulled from your application resources; your will place them there as
ResourceDictionary
objects, one per "theme", using ResourceDictionary.MergedDictionaries
- Whenever you want to change "theme", programmatically remove all current merged dictionaries and add the one corresponding to the desired "theme"
To illustrate, your Application
would use a default dictionary like this:
<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 'm describing: Can WPF themes be used to include multiple skins for an application that can be changed at runtime?