Two Way Data Binding With a Dictionary in WPF

前端 未结 5 1406
天涯浪人
天涯浪人 2020-12-05 07:37

I\'d like to bind a Dictionary to a ListView in WPF. I\'d like to do this in such a way that the Values in the

5条回答
  •  情话喂你
    2020-12-05 08:01

    Just posting what I derived from the above. You can place the below in a ObservableCollection>

    Made the Key read-only as they key probably shouldn't be changed. This needs Prism to work - or you can implement your own version of INotifyPropertyChanged instead

    public class ObservableKvp : BindableBase
    {
        public K Key { get; }
    
        private V _value;
        public V Value
        {
            get { return _value; }
            set { SetProperty(ref _value, value); }
        }
    
        public ObservableKvp(K key, V value)
        {
            Key = key;
            Value = value;
        }
    }
    

提交回复
热议问题