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

血红的双手。 提交于 2019-12-08 15:00:55

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/2695849/can-you-define-a-resourcedictionary-mergeddictionary-together-with-other-local

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!