NotificationObject中有一个此方法的重载:
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression);
我们在以下方式写入属性的设置:
RaisePropertyChanged(() => PropertyVariable);
解决方法
表达< TDelegate>表示lambda表达式的抽象语法树.所以你只需要分析这个语法树来找出属性名称:
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression) { var memberExpr = propertyExpression.Body as MemberExpression; if (memberExpr == null) throw new ArgumentException("propertyExpression should represent access to a member"); string memberName = memberExpr.Member.Name; RaisePropertyChanged(memberName); }