1

Keyで可能なように、カスタム クラス内でにバインドすることは可能Dictionaryですか?

このバインディングでにバインドできますDictionary:

"Binding MyDictionary[MyKey]" 

Dictionaryしかし、私は次のようなカスタムクラスを使用したくありません:

public class DataGridField :  INotifyPropertyChanged
{
    [Required]
    [Key]
    public string Key { get; set; }

    private object value;
    public object Value
    {
        get
        {
            return this.value;
        }
        set
        {
            this.value = value;
            this.OnPropertyChanged("Value");
        }
    }
}

ObservableCollectionで行うのと同じ方法で、このクラスのオブジェクトにアクセスしたいと思いますDictionary。これを達成する方法はありますか?

4

1 に答える 1

4

できますが、インデクサー プロパティを実装する必要があります。

public class DataGridField
{
    public string this[string index]
    {
        get { return this.Key; }
        set
        {
            this.Key = index;
        }
     }
 }

編集:

しかし、INotifyProperty/CollectionChange 実装を備えた Dictionary を持つことに興味がある場合は、ObservableDictionaryを使用できます。

于 2013-04-05T10:41:23.790 に答える