tags:

views:

274

answers:

1

I've created control styles I want to use among multiple xaml pages in my WPF app. To do this I created a Resources.xaml and added the styles there.

Then in my pages I add this code

<Grid.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/SampleEventTask;component/Resources.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Grid.Resources>

On two pages this works fine, but on the 3rd page I get a compile error that says:

All objects added to an IDictionary must have a Key attribute or some other type of key associated with them.

If I add a key to this, as such ResourceDictionary x:Key="x", then the compile error goes but on running the app it errors finding the style.

I can make the compile error go away and have the app run by just moving original (no key specified) "ResourceDictionary" xaml from the top level Grid into a contained Grid on that page.

But I don't understand what is going on here. Any suggestions as to what the problem is, I'm just missing something or doing something incorrectly. Is there a better way to share styles?

thanks

A: 

Are there any other resources defined other than the merged ResourceDictionary in that Page?

For example, here's a snippet from a Window I created.

<Window x:Class="SelectionPagePrototype.SelectionPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SelectionPagePrototype"
    Title="SelectionPage" MinHeight="600" MinWidth="800" Loaded="OnLoaded">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ImageResourceDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <local:QuickPickCheckedConverter x:Key="quickPickConverter" />
            <local:BoolToCaptionConverter x:Key="captionConverter" />
            <local:ProductAndImageTypeConverter x:Key="imageConverter" />
        </ResourceDictionary>
    </Window.Resources>
    <Grid> ...

The merged dictionary did not require a key, but the other resources for that Window do.

Eric