2013-05-14 2 views
1

CanExecute 조건이 변경되면 RaiseCanExecuteChanged를 원합니다. 예컨대 :RaiseCanExecuteChanged more convenience

public class ViewModel 
{ 
public viewModel() 
{ 
    Command = new RelayCommand(action,condition); 
} 

private bool condition() 
{ 
    return this.Condition1&&this.Condition2&&this.Condition3; 
} 

public bool Condition1 
{ 
    get{...} 
    set{.... **command.RaiseCanExecuteChanged();}** 
} 
public bool Condition2 
{ 
    get{...} 
    set{.... command.**RaiseCanExecuteChanged();}** 
} 
public bool Condition3 
{ 
    get{...} 
    set{.... **command.RaiseCanExecuteChanged();}** 
} 

}

잘 작동

. 하지만 많은 수의 RaiseCanExecuteChanged를 쓰고 싶지는 않습니다.이 변경 사항을 자동으로 설정하고 싶습니다. RelayCommand에서 예 ,

public void RaiseChanged(XXXXXX XXX, params string[] propertyNames) 
    { 
     // for each property in propertyNames, 
    // RaiseCanExecuteChanged(); 
    } 

내가 매개 변수로 뷰 모델 VM을 넣어 RaiseChanged라는 새로운 방법을 만들고, vm.PropertyChanged + = (S, E) => {} 사용하지만 나는 생각하지 않는다 이것을하는 좋은 방법.

다른 아이디어가 있습니까?

C#보기 모델 : 나는 그렇게 할 수있는

답변

0

나는 내 솔루션을 개발

public bool CanExecuteMethod(object sender) 
     { 
     } 
public void ButtonExecuteMethod(object sender) 
     { 
     } 

public event Action EventNotifyCanExecuteChanged; 

private Action _DelegateNotifyCanExecuteChanged; 
public Action DelegateNotifyCanExecuteChanged 
    { 
     get { return _DelegateNotifyCanExecuteChanged; } 
     set { _DelegateNotifyCanExecuteChanged = value; } 
    } 

public void CanExecuteFlag 
     { 
    if (EventNotifyCanExecuteChanged != null) { EventNotifyCanExecuteChanged(); } 
    if (_DelegateNotifyCanExecuteChanged != null) { _DelegateNotifyCanExecuteChanged();} 
     } 

XAML :

< Button Content="Button Cmd-ExCeCh" HorizontalAlignment="Left" Margin="27,231,0,0" 
     VerticalAlignment="Top" Width="120" 
     Command="{mark:BindCommandResource MainWindowViewModel, 
     ExecuteMethodName=ButtonExecuteMethod, 
     CanExecuteMethodName=CanExecuteMethod, 
     EventToInvokeCanExecuteChanged=EventNotifyCanExecuteChanged, 
     PropertyActionCanExecuteChanged=DelegateNotifyCanExecuteChanged}" /> 

내 오픈 소스 프로젝트에/주에게이 솔루션을 넣어 MVVM-WPF XAML 마크 업 바인딩 확장 - http://wpfmvvmbindingext.codeplex.com