The Key attribute can only be used for an element contained in an IDictionary,

I get a squiggly line under the 6th line of code below, giving me the error indicated in the title. I just switched to VS 2012, and everything worked perfectly in VS 2010. I feel that maybe the problem is really in another place ... can someone tell me if there is something wrong with this xaml?

<Application x:Class="SageWpf.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SageWpf"> <Application.Resources> <ResourceDictionary x:Key="rd"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary> <local:AppBootStrapper x:Key="bootstrapper"/> <local:EffectConverter x:Key="effectConverter"/> <local:VisibilityConverter x:Key="visibilityConverter"/> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> 
+6
source share
1 answer

<ResourceDictionary x:Key="rd"> not valid. Remove x:Key from there.

Also .. this is a bad way to structure your resources. Change it to:

 <Application.Resources> <ResourceDictionary> <local:AppBootStrapper x:Key="bootstrapper"/> <local:EffectConverter x:Key="effectConverter"/> <local:VisibilityConverter x:Key="visibilityConverter"/> </ResourceDictionary> </Application.Resources> 

Use only merged dictionaries if you have resources defined in another XAML file and you want to import them here.

+10
source

All Articles