WPF compile error "IDictionary must have a Key attribute"

Posted by the empirical programmer on Stack Overflow See other posts from Stack Overflow or by the empirical programmer
Published on 2010-05-28T19:17:36Z Indexed on 2010/05/28 19:22 UTC
Read the original article Hit count: 397

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about wpf

Related posts about styles