Notify Property Changed on a Dictionary

前端 未结 5 1829
余生分开走
余生分开走 2020-12-09 23:11

I have a WPF / XAML form data-bound to a property in a dictionary, similar to this:


<

5条回答
  •  天涯浪人
    2020-12-09 23:44

    Dr. WPF has created an ObservableDictionary at this link: http://drwpf.com/blog/2007/09/16/can-i-bind-my-itemscontrol-to-a-dictionary/

    Update: The comment made by Dr. WPF in the following link says that he has fixed this problem himself so the following change should no longer be required

    Also, an addition was made at this link: http://10rem.net/blog/2010/03/08/binding-to-a-dictionary-in-wpf-and-silverlight

    The small change was

    // old version
    public TValue this[TKey key]
    {
        get { return (TValue)_keyedEntryCollection[key].Value; }
        set { DoSetEntry(key, value);}
    }
    
    // new version
    public TValue this[TKey key]
    {
        get { return (TValue)_keyedEntryCollection[key].Value; }
        set
        {
            DoSetEntry(key, value);
            OnPropertyChanged(Binding.IndexerName);
        }
    }
    

提交回复
热议问题