I'm sure I'm struggling with something very basic, missing a very simple point... But I just keep hitting the wall, so please help.
The problem is as follows.
If I define a certain style in the <Window.Resources>
of the same Window where I apply it to controls - everything works just fine.
But since I want to reuse this style in a different window of my application, I tried to move the style out to some common location... And here the things stopped working.
If I put the style in Themes\Generic.开发者_C百科xaml, the style doesn't get applied.
When I try to reference it from the original window by explicitly applying Style="{DynamicResource MyStyle}"
on the corresponding control (where "MyStyle" is the x:Key of the style) - I get an error
The resource 'MyStyle' could not be resolved
If I put the style in a separate XAML file, and try to add it to MergedDictionaries in my App.xaml, I get a different problem: "'Resources' property has already been set on 'App'". This is how I try to define it:
<Application.Resources>
<ResourceDictionary x:Key="MergedDictionaries">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/MyStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<Application.Resources>
You should not set the x:Key
on the dictionary, otherwise it will be added as a resource which is not what you want, it should set the Application.Resources
property instead.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Merged dictionaries -->
</ResourceDictionary.MergedDictionaries>
<!-- Other Resources -->
</ResourceDictionary>
</Application.Resources>
精彩评论