首页 > 解决方案 > ObservableCollection 的 Notifychange 属性

问题描述

我实现INotifyPropertyChanged了一个简单的 MVVM 模式。我在模型中有一个类没有实现 INotifyPropertyChanged 并且ObservableCollection<class>在我的视图模型中。

当不同的列(单元格)值发生变化时,我需要运行不同的方法。INotifyPropertyChanged如果不是绝对必要的话,我真的不想实现模型。

我尝试了这个ObservableCollection,没有注意到其中的项目何时发生变化(即使使用 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; }
    }

标签: c#wpfbindingobservablecollectioninotifypropertychanged

解决方案


推荐阅读