1
我有一個DataForm與AutoCommit =「False」和一個外部保存按鈕綁定到一個Command SaveCommand。使用DataForm和外部保存按鈕
如果我希望禁用保存命令時沒有更改數據(我使用ViewModel)掛起,我什麼時候必須執行SaveCommand.RaiseECanExecuteChanges()?
我有一個DataForm與AutoCommit =「False」和一個外部保存按鈕綁定到一個Command SaveCommand。使用DataForm和外部保存按鈕
如果我希望禁用保存命令時沒有更改數據(我使用ViewModel)掛起,我什麼時候必須執行SaveCommand.RaiseECanExecuteChanges()?
我通常重寫RaisePropertyChanged並將我的CanExecute謂詞設置爲ViewModel是否髒。
class ViewModel : ViewModelBase
{
public DelegateCommand SaveCommand { get; set; }
private bool _isDirty;
public ViewModel()
{
SaveCommand = new DelegateCommand(() => OnExecuteSave(),() => CanExecuteSave());
}
private void CanExecuteSave()
{
// do your saving
}
private bool CanExecuteSave()
{
return !_isDirty;
}
protected override void RaisePropertyChanged(string propertyName)
{
base.RaisePropertyChanged(propertyName);
_isDirty == true;
SaveCommand.RaiseCanExecuteChanged();
}
}
希望有所幫助。