ObservableCollection <t>的Notifychange属性

时间:2019-05-22 13:35:49

标签: c# wpf binding observablecollection inotifypropertychanged

我为简单的MVVM模式实现了INotifyPropertyChanged。我的模型中有一个类,未在视图模型中实现INotifyPropertyChanged和ObservableCollection<class>

当不同的column(cell)值更改时,我需要运行不同的方法。如果不是绝对必要,我真的不想对模型实现INotifyPropertyChanged

我尝试了这个ObservableCollection not noticing when Item in it changes (even with INotifyPropertyChanged)解决方案,但无法解决。

//ViewModel
public class LimitsViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

ObservableCollection<SingleLimit> _limitsclone= new ObservableCollection<SingleLimit>();
        public ObservableCollection<SingleLimit> LimitClone
        {
            get { return _limitsclone; }
            set
            {
                if (_limitsclone != value)
                    _limitsclone = value;
                OnPropertyChanged();
            }
        }
    }
//Model
public class SingleLimit
    {
        public string frstr{ get; set; }
        public double X{ get; set; }
        public double MaxP{ get; set; }
        public double MaxM{ get; set; }
    }

0 个答案:

没有答案