Having different buttons on a view, how could I control the IsEnabled state of the buttons when a command is being executed?
If I execute this command:
public ICommand DoSomethingCommand
{
get
{
if (doSomethingCommand == null)
{
doSomethingCommand = new RelayCommand(
(parameter) =>
{
this.IsBusy = true;
this.someService.DoSomething(
(b, m) =>
{
this.IsBusy = false;
}
);
},
(parameter) => !this.IsBusy);
}
return this.doSomethingCommand ;
}
}
I set the IsBusy property which fires the OnPropertyChanged event. All the other buttons check this property in their command’s CanExecute. But the buttons do not get disabled, when the above command is executed.
How do I do this right?
CanExecuteChanged needs to fire in order for the Command Source to know to invoke CanExecute.
A simple way to do this is to invoke
CommandManager.InvalidateRequerySuggested().