Jeremy Holt
Jeremy Holt

Reputation: 325

Can you define a ResourceDictionary.MergedDictionary together with other (local) resources in <Windows.Resources>?

I would like to refer to a MergedDictionary together with locally declared resources in my Windows.Resources. However, I'm getting this error:

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

Is it possible to mix local resources together with imported resources in the same Window.Resources?

The XAML is:

 <Window.Resources>
    <CollectionViewSource x:Key="cvsData" Source="{Binding Path=Data}">
        <CollectionViewSource.GroupDescriptions>
            <PropertyGroupDescription PropertyName="Country"/>
        </CollectionViewSource.GroupDescriptions>           
    </CollectionViewSource>

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary x:Name="images" Source="pack://application:,,,/CoreWpfControls;component/Images.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

Thanks Jeremy

Upvotes: 13

Views: 7248

Answers (1)

Josh
Josh

Reputation: 69282

Yes, it's actually very simple. You just need to move the additional resources inside of the ResourceDictionary element.

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/CoreWpfControls;component/Images.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <CollectionViewSource x:Key="cvsData" Source="{Binding Path=Data}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Country"/>
            </CollectionViewSource.GroupDescriptions>           
        </CollectionViewSource>
    </ResourceDictionary>
</Window.Resources>

Upvotes: 34

Related Questions