我有模特班员工:
public class Employee
{
public string Id { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
}
和 View Model 类EmployeeViewModel
,其中包含一个Employee Object
public class EmployeeViewModel : INotifyPropertyChanged
{
public EmployeeViewModel()
{
}
private Employee currentEmployee;
public Employee CurrentEmployee
{
get { return this.currentEmployee; }
set
{
this.currentEmployee = value;
this.NotifyPropertyChanged("CurrentEmployee");
}
}
//Some code .....
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
现在视图(WPF)将使用Employee
视图模型中的对象ItemSource
来显示员工数据
现在的问题是:我在视图上有更新按钮,当我更改Employee
视图中的属性时(通过文本框)我想更新模型(所以之后我可以更新数据库),如何从视图更新这个模型.