【C#】实现INotifyPropertyChanged的3种方法 - YoMe - 博客园

复制代码; "复制代码")

class StudentItemViewModel:INotifyPropertyChanged

{ public event PropertyChangedEventHandler PropertyChanged; public Student Student { get; set; } private bool _isSelected; public bool IsSelected
    { get { return _isSelected; } set {
            _isSelected = value; this.PropertyChanged(this,new PropertyChangedEventArgs("IsSelected")); //NotifyPropertyChanged("IsSelected");

}

    } private void NotifyPropertyChanged(string Name)
    { if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(Name));
        }
    }


} class NotifyCationObject : INotifyPropertyChanged
{ private string GetPropertyName<T>(Expression<Func<T>> action)
    { var expression = (MemberExpression)action.Body; return expression.Member.Name;
    } protected void NotifyPropertyChanged<T>(Expression<Func<T>> action)
    { string name = GetPropertyName<T>(action);
        NotifyPropertyChanged(name);
    } private event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string Name)
    { if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(Name));
        }
    }
}

复制代码; "复制代码")


原网址: 访问
创建于: 2024-06-19 19:19:51
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论