I have several several styles and templates for both standard WPF controls and custom controls in an external custom control libary project. For each control, there's a ResourceDictionary
in my \\Themes
folder, along with a Generic.xaml
which contains a merged dictionary of all the other XAML files.
I made sure that:
Generic.xaml
is in the Themes\\
folder within the root of my project Generic.xaml
has a Build Action of Page
. Generic.xaml
uses the custom tool flag MSBuild:Compile
. [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
What I tried:
Source="MyControl.xaml"
Source="/MyLibrary;component/Themes/MyControl.xaml"
Source="/MyLibrary;component/Themes/MyControl.xaml"
Source="/pack://application:,,,/Themes/MyControl.xaml"
Source="/pack://application:,,,/MyLibrary;component/Themes/MyControl.xaml"
Generic.xaml
in my application with all possible source declarations However, nothing works. The application stays completely unthemed, even though I can see that all dictionaries have been loaded when accessing Application.Current.Resources
.
It's also worth noting that most of my control themes contain additional dynamic resources (for colors etc.), which are loaded manually when the application starts.
It seems that I'm facing the exact same unanswered problem as the OP in this question here , however they state that manually referencing the Generic.xaml
works for them.
Do you defined following code in static constructor?
DefaultStyleKeyProperty.OverrideMetadata (typeof (YourCustomClass),new FrameworkPropertyMetadata (typeof (YourCustomClass)));
don't use x:key ="style_name" in resource dictionary
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.