0

I'm using a version of the common RelayCommand class and trying to pass a command parameter but not having success. I get the following error:

Error 29 Method 'Private Sub KeyPadPressExecute(param As Object)' does not have a signature compatible with delegate 'Delegate Sub Action()'.

I've looked at the many examples of using parameters with commands, but I can't make sense out of them. I don't understand where I'm supposed to get the parameter from that will be passed on to KeyPadPressExecute().

Here's the relevant code:

Private Sub KeyPadPressExecute(param As Object)
    Debug.Print(param.ToString)
End Sub
Private Function CanKeyPadPressExecute() As Boolean
    Return True
End Function
Public ReadOnly Property KeyPadPress() As ICommand
    Get 'Error occurs on next line
        Return New RelayCommand(AddressOf KeyPadPressExecute, AddressOf CanKeyPadPressExecute)
    End Get
End Property

What my XAML looks like:

<Button Command="{Binding KeyPadPress}" CommandParameter="1" Width="84"></Button>

I'm using VS 2012 and targeting .NET 4.5.

Note: My original post said I was using MicroMVVM. Closer inspect of the project indicates that the assembly named MicroMVVM is not related to the MicroMVVM framework hosted at codeplex. This project was started by someone else, thus the confusion.

1
  • I changed my code to Return New RelayCommand(Of String)(AddressOf KeyPadPressExecute... and now it's working. Commented Mar 4, 2014 at 22:02

1 Answer 1

2

From a RelayCommand implementation seen at GitHub, one can tell that the class effectively hides and swallows the command parameter. Perhaps you should try to use the generic version of the class instead: RelayCommand(Of T). The run-time exception is pretty clear: there's a mismatch between the MicroMVVM class's constructor, taking only a blunt Sub Action() delegate; and your command's execute handler, taking an object argument.

NB: Please forgive my bad VB, it's not my mother tongue.

Update: I see that MicroMVVM is hosted at CodePlex, but there's no RelayCommand class in there (apparently replaced by the smarter DelegateCommand class). The link to the probably unrelated project at GitHub still serves its purpose as an example and source of information. Comments are welcome.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.