I don't know if there's a difference between Josh Smith's and Laurent Bugnion's implementations of RelayCommand or not, but everywhere I've looked, it sounds like the Execute portion of RelayCommand can take 0 or 1 parameters. I've only been able to get it to work with 0. When I try something like:
public class Test
{
public RelayCommand MyCommand { get; set; }
public Test()
{
MyCommand = new RelayCommand((param) => SomeFunc(param));
}
private void SomeFunc( object param)
{
}
}
I get the error: Delegate 'System.Action' does not take '1' arguments
. Just to make sure I am not insane, I went to the definition of RelayCommand to make sure I didn't have some rogue implementation in my solution somewhere, but sure enough, it was just Action, and not Action<>.
What on earth am I missing here?
The non-generic implementation of RelayCommand
(in MVVM Light) does not accept a parameter. Use RelayCommand<Object>
instead, or (even better) RelayCommand<YourCustomType>
so the parameter to SomeFunc
is strongly typed.
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