1 新建WPF 应用程序WPFMVVMExample
程序结构如下图所示。
2 Model实现
在Model文件夹下新建业务类StudentModel(类文件StudentModel.cs),类的详细代码如下所示。
[csharp]
using System.ComponentModel;
namespace WPFMVVMExample.Model
{
public class StudentModel : INotifyPropertyChanged
{
/// <summary>
/// 学号
/// </summary>
private int studentId;
public int StudentId
{
get
{
return studentId;
}
set
{
studentId = value;
NotifyPropertyChanged("StudentId");
}
}
/// <summary>
/// 姓名
/// </summary>
private string studentName;
public string StudentName
{
get
{
return studentName;
}
set
{
studentName = value;
NotifyPropertyChanged("StudentName");
}
}
/// <summary>
/// 年龄
/// </summary>
private int studentAge;
public int StudentAge
{
get
{
return studentAge;
}
set
{
studentAge = value;
NotifyPropertyChanged("StudentAge");
}
}
/// <summary>
/// </summary>
private string studentEmail;
public string StudentEmail
{
get
{
return studentEmail;
}
set
{
studentEmail = value;
NotifyPropertyChanged("StudentEmail");
}
}
/// <summary>
/// 性别
/// </summary>
private string studentSex;
public string StudentSex
{
get
{
return studentSex;
}
set
{
studentSex = value;
NotifyPropertyChanged("StudentSex");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{