Brandon Moore
Brandon Moore

Reputation: 8780

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

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>

Upvotes: 6

Views: 6921

Answers (1)

Fede
Fede

Reputation: 44038

<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.

Upvotes: 10

Related Questions