2012-05-25 3 views
1

AutoCommit = "False"인 DataForm과 Command SaveCommand에 바인딩 된 외부 저장 버튼이 있습니다.데이터 폼 및 외부 저장 버튼 사용

ViewModel을 사용중인 데이터 변경 사항이 보류 중일 때 저장 명령을 사용하지 않으려면 SaveCommand.RaiseECanExecuteChanges()를 언제 실행해야합니까?

답변

1

저는 일반적으로 RaisePropertyChanged를 오버라이드하고 ViewModel이 더티인지 아닌지에 대해 CanExecute 술어를 설정합니다.

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(); 
    } 
} 

희망이 있습니다.