This is probably a really stupid question but I can't figure this out.
I have a page with a MergeDictionary defined:
<navigation:Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Assets/TourneySetupStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</navigation:Page.Resources>
and I reference the styles in TourneySetupStyles.xaml in my XAML like this with no problem:
<TextBlock Text="Tourney Name:" Style="{StaticResource TourneySetupTextStyle}" />
However, now I need to add another page resource like this:
But the designer now throws a warning: "The designer does not support loading dictionaries that mix 'ResourceDictionary' items without a key and other items in the same collection. Please ensure that the 'Resources' property does not contain 'ResourceDictionary' items without a key, or that the 'ResourceDictionary' item is the only element in the collection."
So I add a key to my ResourceDictionary like this:
<navigation:Page.Resources>
<local:Tournament x:Key="tournament" />
<ResourceDictionary x:Key="whatever">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Assets/TourneySetupStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</navigation:Page.Resources>
and the warning goes away. BUT now my reference to the style in TourneySetupStyles no longer works:
"Cannot find a Resource with the Name/Key TourneySetupTextStyle"
So I guess the question is: How do I access the style now that the ResourceDictionary is keyed?
I just ran into this today -- I'm cross compiling to WPF / Silverlight. Put the local resource inside the ResourceDictionary node, don't put a x:Key on the ResourceDictionary node.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/mydll;component/folder/MyResDict.xaml" />
</ResourceDictionary.MergedDictionaries>
<LinearGradientBrush x:Key="OrangeGradient"
EndPoint="0.5,1"
MappingMode="RelativeToBoundingBox"
StartPoint="0.5,0">
<LinearGradientBrush.RelativeTransform>
<RotateTransform CenterY="0.5"
CenterX="0.5" />
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="#FFF3801E" />
<GradientStop Color="#FFEDB17E"
Offset="0.5" />
<GradientStop Color="#FFF3801E"
Offset="1" />
</LinearGradientBrush>
</ResourceDictionary>
</UserControl.Resources>
I can't explain why - but I know it works...
hth
sigh it seems that the order of the declarations is important, as soon as I move the first resource down it now works:
<navigation:Page.Resources>
<ResourceDictionary x:Key="TourneySetupStyles">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Assets/TourneySetupStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<local:Tournament x:Key="tourneySetupViewModel" />
</navigation:Page.Resources>
If anyone can explain why it would be great for future reference...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With