我目前正在使用MVVM和实体框架代码优先模型的项目。所以我在我的模型类中实现了IDataErrorInfo和INotifyPropertyChanged。现在,在我的viewmodel中,我实现了一个SaveCommand和一个CanSave布尔方法,我的问题是如何为整个实体提高canexecutechanged而不是单独的属性?因为我的属性已经在模型中实现了InotifyPropertyChanged。使用实体框架MVVM验证
这是我的模型类
public class Guest:ValidatableBindableClass
{
//my properties here
//implement InotifyPropertyChanged and IDataErrorInfo
}
这是我ViewModelClass:
public class AddEditGuestViewModel:BindableClass
{
private Hospede guest;
public RelayCommand SaveCommand { get; set; }
private readonly Hmsdb.HMS context = new Hmsdb.HMS();
public Hospede Guest
{
get { return guest; }
set { SetProperty(ref guest, value, propertyName: "Guest"); }
}
private void OnSave()
{
context.Hospedes.Add(Guest);
context.SaveChanges();
}
private bool CanSave()
{
return context.Entry(Guest)
.GetValidationResult().IsValid;
}
}
请勿发布代码图片。将相关代码复制到相应的问题和格式中。只是发布图像会降低问题的可搜索性。 – Lithium