[assembly: ThemeInfo(
ResourceDictionaryLocation.SourceAssembly,
// Where theme-specific resource dictionaries are located.
// (Used if a resource is not found in the page,
// or application resource dictionaries.)
ResourceDictionaryLocation.SourceAssembly
// Where the generic resource dictionary is located.
// (Used if a resource is not found in the page,
// app, or any theme specific resource dictionaries.)
)]
<!-- Aero.NormalColor.xaml: -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/MyAssemblyName;component/Themes/MyControl.Aero.NormalColor.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- generic.xaml: -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/MyAssemblyName;component/Themes/UnthemedControl.generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
// Register the default style for MyControl.
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl),
new FrameworkPropertyMetadata(typeof(MyControl)));
ResourceDictionary dict = Application.LoadComponent(
new Uri("MyAssemblyName;component/Themes/NewDefaultStyle.xaml", UriKind.Relative))
as ResourceDictionary;
Application.Current.Resources.MergedDictionaries.Add(dict);
...and that's it! That should cover everything you need to do
to get your resources picking up their styles from the correct place.
Download Full Source Code
3 comments:
I am having this problem as well. Unfortunately I am a novice at WPF and cannot get you example to compile and run. Do you have the as complete example code instead of snippets. Thanks.
I've added an example solution to the post.
Thanks
Thank you very much!! I wasted hours trying to figure this out on my own, your article was a great help.
Post a Comment