Is the parameter passed to the CanExecute method of bound commands the CommandParameter specified in the binding control? If not, where does it come from?
A parameter can be passed through the "CommandParameter" property. Once the button is clicked the selected address value is passed to the ICommand. Execute method. The CommandParameter is sent to both CanExecute and Execute events.
The command is the action to be executed. The command source is the object which invokes the command. The command target is the object that the command is being executed on. The command binding is the object which maps the command logic to the command.
ICommand is an interface between the Presentation & the BusinessLogic layer. Whenever any button is pressed on the screen, XAML has its code-behind ButtonClick event. But in MVVM architecture, there is no room for code-behind to keep the application loosely coupled, so ICommand was introduced.
The ICommand interface is the code contract for commands that are written in . NET for Windows Runtime apps. These commands provide the commanding behavior for UI elements such as a Windows Runtime XAML Button and in particular an AppBarButton .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With