views:

267

answers:

1

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?

+3  A: 

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.

Matt Hamilton
Thanks, Matt, I *finally* also found that info on a somewhat related post (slaps forehead) -- http://stackoverflow.com/questions/2306063/canexecute-on-relaycommandt-not-working. I was going to delete my question, but you were way too fast with your answer. :) I will accept this as soon as the system allows it! Thank you.
Dave
I'll vote to close this one as a duplicate. We'll see which happens first. :)
Matt Hamilton
I think I won? haha
Dave
Hee hee. We both won, in a way! :)
Matt Hamilton