Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DictionaryKeyProperty attribute does not appear to be usable.

$
0
0
I'm trying to add a special class to be used in a ResourceDictionary. It's using a custom key, and as per the WPF documentation I  am using the DictionaryKeyPropertyAttribute on my new class type to specify a custom key property.

Here is the code:
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Windows.Markup;  
 
namespace DictionaryKeyPropertyBug  
{  
    [DictionaryKeyProperty("Property1")]  
    public class DictionaryKeyPropertyTestClass  
    {  
        public object Property1 { get; set; }  
    }  
}  
 


And the XAML:
<Window x:Class="DictionaryKeyPropertyBug.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:local="clr-namespace:DictionaryKeyPropertyBug" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">  
    <Window.Resources> 
        <local:DictionaryKeyPropertyTestClass Property1="foo"/>  
    </Window.Resources> 
</Window> 


And here is the error I get:
Error 1 All objects added to an IDictionary must have a Key attribute or some other type of key associated with them. Line 6 Position 10. Window1.xaml 6 10 DictionaryKeyPropertyBug

It's telling me I need a key (e.g. x:Key="..."), but I shouldn't because the purpose of the DictionaryKeyPropertyAttribute to define what property the key represents. In this case Property1 is the key.

Anyone know what is going on here?

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>