views:

61

answers:

2

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?

A: 

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...

Rodney
A: 

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

chadbr
Hmm, so you don't get the design-time error with that code?
Rodney
Oh no... but I gave up on the designers in VS and Blend about 2 weeks after I started writing cross-compiled code. They simply do not work.
chadbr
If I want to use the designers, I use a separate WPF or Silverlight only project, do my design work, then bring it to my "real" project and figure out how to get it to cross-compile. Getting the design to load in the designer after that is close to impossible.I have open an open connect issue which is being worked by MS, but it isn’t really going anywhere.
chadbr