WPF command binding: CanExecute parameter
Is the parameter passed to the CanExecute method of bound commands the CommandParameter specified in the binding control? If not, wher开发者_Go百科e does it come from?
The CommandParameter
is sent to both the CanExecute
and Execute(d)
events.
Alex Curtis is right:
public bool CanExecute(object parameter)
public void Execute(object parameter)
Use both the object that was set as CommandParameter
for the command.
This is also good to know when calling ICommand's OnCanExecuteChanged(EventArgs e)
because this method won't let you pass any parameter. So CanExecute must use the CommandParameter previously set.
精彩评论