I am just learning Silverlight and looking at MVVM and Commanding.
So, I saw the basic implementation of RelayCommand:
public class RelayCommand : ICommand { private readonly Action _handler; private bool _isEnabled; public RelayCommand(Action handler) { _handler = handler; } public bool IsEnabled { get { return _isEnabled; } set { if (value != _isEnabled) { _isEnabled = value; if (CanExecuteChanged != null) { CanExecuteChanged(this, EventArgs.Empty); } } } } public bool CanExecute(object parameter) { return IsEnabled; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { _handler(); } }
How to pass parameter with command using this command?
I saw that you can pass CommandParameter as follows:
<Button Command="{Binding SomeCommand}" CommandParameter="{Binding SomeCommandParameter}" ... />
In my ViewModel, I need to create a command, but RelayCommand expects an Action delegate. Can I implement RelayCommand<T> with Action<T> - if so, how to do it and how to use it?
Can someone give me practical examples in CommandParameters with MVVM that are not related to using third-party libraries (like MVVM Light), since I want to fully understand it before using existing libraries.
Thanks.
source share