Each Dictionary entry must have an associated key attribute - c#

I am programming w Windows 8.1 App using C# and the MVVM-Light Toolkit from GalaSoft.
All I have is the code below:
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resource Dictionaries/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
The error "Each Dictionary entry must have an associated key attribute" occurs and only disappears when I either remove
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resource Dictionaries/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
or
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />
Can anyone tell me what the problem here is?

Note that Application.Resources requires an instance of ResourceDictionary, so you have to do something like this:
<Application.Resources>
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resource Dictionaries/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
So it's not strange at all, it's also not a bug. If you want your ResourceDictionary to be treated as a resource, you of course have to provide some Key for it, however in this case you really want to assign an instance of ResourceDictionary to the Application.Resources

Related

Use Material Design and Caliburn.Micro simalteniously

I use WPF, and C#. I want to use both :MaterialDesign and Caliburn.Micro v4.0173 in one solution in Visual Studio. I have tried to add both of them to App.xaml, but materialDesign does not work. So the view of controls is the same as if I don't installed materialDesign.
<Application x:Class="WPFUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFUI">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<local:Bootstrapper x:Key="Bootstrapper"/>
<ResourceDictionary x:Key="MD1" Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary x:Key="MD2" Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary x:Key="MD3" Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.BlueGrey.xaml" />
<ResourceDictionary x:Key="MD4" Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
<ResourceDictionary x:Key="MD5" Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.DataGrid.ComboBox.xaml" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

Application a style to all page xaml wpf

I have a style file "dark.xaml" that I will use to style all xaml pages, so I place it in "application.xaml". But why my xaml page can't to access the style of "dark.xml"?
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/rtwin;component/style/Dark.xaml">
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
From your ResourceDictionary source it seems that you are adding style from an assembly (correct if I'm wrong).
Well, in that case, you need to add pack://application:,,, so that your final App.xaml should look like this,
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/rtwin;component/style/Dark.xaml">
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Resource dictionary not found in WPF prism user control

I have the following project structure:
When I tried to add Resoucse dictionary inside my user control FloorplanHierarchy I am getting file not found error:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=".../UserControls/UserControlResources/LookUpEditTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
LookUpEditTemplate.xaml is inside the folder UserControlResources. Please help.
Remove UserControls in the source because UserControlResources and FloorplanHierarchy both are in the same folder.
So changing this:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=".../UserControls/UserControlResources/LookUpEditTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
To this:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../UserControlResources/LookUpEditTemplate.xaml"/>
</ResourceDictionary.MergedDictionaries>
Should works.

MergedDictionaries nightmare

I'm trying to use a WPF Template and I'm supposed to include this in my App.xaml, but I get "Nested properties are not supported: ResourceDictionaries.MergedDictionaries" error and "The attachable property "MergedDictionaries" was not found in type "ResourceDictionary".
<Application x:Class="Unico.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary.MergedDictionaries>
<!-- Set default skin -->
<ResourceDictionary Source="\ExpressionDark.xaml"/>
<ResourceDictionary Source="\WindowStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type Rectangle}" />
</Application.Resources>
</Application>
I've tried everything but still can't fix this. Any idea? Thanks.
MergedDictionaries is a property of ResourceDictionary.
Change to:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
...
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type Rectangle}" />
</ResourceDictionary>
</Application.Resources>

Can i store string in <Application.Resources> and bind to it?

I'm using Microsoft's AdControl on several pages... but in order to simplify it i would like to store ApplicationId once and read it as a resource.
Could it be possible to use in the App.xaml and then in the control set the binding to it? But how?
Use "{StaticResource name}" just like you would with <Page.Resources>
To store the resource, create a new <ResourceDictionary> in <ResourceDictionary.MergedDictionaries> and place your resource in that.
For example:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
<ResourceDictionary>
<x:String x:Key="Foo">Bar</x:String>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Categories

Resources