Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The "Key" attribute can only be used on an element that is contained in "IDictionary"

Tags:

wpf

xaml

I'm getting the squiggly line under the 6th line of code below giving me the error stated in the title. I just migrated to VS 2012 and everything was working fine in VS 2010. I feel like maybe the problem is really elsewhere... can someone tell me if there is actually 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>
like image 275
Brandon Moore Avatar asked Feb 16 '13 06:02

Brandon Moore


1 Answers

<ResourceDictionary x:Key="rd"> is invalid. Remove the x:Key from there.

Also.. that's 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>

Only use Merged Dictionaries if you have resources defined in another XAML file and you want to import them here.

like image 96
Federico Berasategui Avatar answered Sep 19 '22 02:09

Federico Berasategui