DelegateCommand
Implementation of ICommand where the Execute and CanExecute callbacks are handled by delegates.
1 2 3 4 5 6 7 8 9 10 11
| public IDelegateCommand AddItems { get; }
public TestViewModel() { AddItems = DelegateCommand.Create(OnAddItems); }
private void AddItemsImpl() { Debug.WriteLine("Hello"); }
|
DelegateCommand With Parameter and CanExecute
1 2 3 4 5 6 7 8 9 10 11 12 13
| private IDelegateCommand CommandWithCanExecute { get; } CommandWithCanExecute = DelegateCommand.Create(OnSimpleCommand, CanExecuteCommandWithCanExecute);
private bool CanExecuteCommandWithCanExecute() { return true; }
private void OnSimpleCommand() { }
|
Command with Paramter
1 2 3 4 5 6 7 8 9 10 11 12 13
| private IDelegateCommand CommandWithParameter { get; } CommandWithParameter = DelegateCommand.Create(OnCommandWithParameter, CanExecuteCommandWithParameter);
private bool CanExecuteCommandWithParameter(object? parameter) { return true; }
private void OnCommandWithParameter(object? parameter) { }
|
you can use IDelegateCommand Instead of ICommand

Demo
you can run demo and see this feature.