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
In Extensible Application Markup Language (XAML), the ResourceDictionary class is typically an implicit collection element that is the object element value of several Resources properties, when given in property element syntax. For details on implicit collections in XAML, see XAML Syntax Terminology.
A resource dictionary is a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve them in XAML using the {StaticResource} markup extension and {ThemeResource} markup extension s. You can also access resources with code, but that is less common.
To add a merged dictionary through code, you obtain a reference to the desired primary ResourceDictionary , get its MergedDictionaries property value, and call Add on the generic Collection that's contained in MergedDictionaries . The object you add must be a new ResourceDictionary .
Tip You can create a resource dictionary file in Microsoft Visual Studio by using the Add > New Item… > Resource Dictionary option from the Project menu. Here, you define a resource dictionary in a separate XAML file called Dictionary1.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With