c# - 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; }
}
解决方案
推荐阅读
- nuxt.js - 我如何从生产中阻止页面但在 nuxt 的开发中显示?
- sql - 无法识别日期“% {syslog_timestamp}”
- unity3d - 如何让物体只碰撞一次?
- python - 获取前 n 列并忽略 NaN
- scala - Scala,创建一个二维数组来管理用户
- sql - 最长公共子串、BigQuery、SQL
- scala - 如何读取 csv 文件并将值分配给 spark scala 中的变量
- wordpress - Woocommerce:当前类别的产品类别小部件
- javascript - 使用 document.cookie 在不同的子域上创建 cookie
- javascript - 将对象存储在数组中