C#/ WPF:对的PropertyChanged视图模型中的所有属性? [英] C#/WPF: PropertyChanged for all Properties in ViewModel?

查看:308
本文介绍了C#/ WPF:对的PropertyChanged视图模型中的所有属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个类:

public class PersonViewModel : ViewModelBase //Here is the INotifyPropertyChanged Stuff
{
    public PersonViewModel(Person person)
    {
        PersonEntity = person;
    }

    public Person PersonEntity { 
        get { return PersonEntity.Name; }
        private set { PersonEntity.Name = value; RaisePropertyChanged("PersonEntity");
    }

    public string Name { 
        get { return PersonEntity.Name; }
        set { PersonEntity.Name = value; RaisePropertyChanged("Name");
    } 
    public int Age{ 
        get { return PersonEntity.Age; }
        set { PersonEntity.Age= value; RaisePropertyChanged("Age");
    } 

    public void ChangePerson(Person newPerson)
    {
        //Some Validation..
        PersonEntity = newPerson;
    }



我的文本框绑定到名称和视图模型的时代。
。如果我更改视图模型的_person对象,我必须再次呼吁为每个属性一个RaisePropertyChanged还是有办法做到这一点全自动(在我的混凝土比如我有大约15属性..)?

My TextBoxes are bound to Name and Age of the ViewModel. If I change the _person object in the ViewModel, do I have to call for each Property a RaisePropertyChanged again or is there a way to do this automaticly (in my concret example I have about 15 Properties..)?

感谢您的帮助。

干杯
约瑟夫

推荐答案

您可以指示所有属性都使用的String.Empty 的属性名称 PropertyChangedEventArgs 。这是在文档中提到的PropertyChanged

You can indicate all properties have changed by using null or string.Empty for the property name in PropertyChangedEventArgs. This is mentioned in the documentation for PropertyChanged.

这篇关于C#/ WPF:对的PropertyChanged视图模型中的所有属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆