【发布时间】:2014-03-30 01:42:45
【问题描述】:
我正在使用通用 RelayCommand 类的版本并尝试传递命令参数但没有成功。我收到以下错误:
Error 29 Method 'Private Sub KeyPadPressExecute(param As Object)' does not have a signature compatible with delegate 'Delegate Sub Action()'.
我查看了许多在命令中使用参数的示例,但我无法理解它们。我不明白我应该从哪里获取参数,该参数将被传递给KeyPadPressExecute()。
以下是相关代码:
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
我的 XAML 是什么样子的:
<Button Command="{Binding KeyPadPress}" CommandParameter="1" Width="84"></Button>
我正在使用 VS 2012 并针对 .NET 4.5。
注意:我原来的帖子说我使用的是 MicroMVVM。对该项目的仔细检查表明,名为 MicroMVVM 的程序集与托管在 codeplex 的 MicroMVVM 框架无关。这个项目是别人发起的,所以很混乱。
【问题讨论】:
-
我将代码更改为
Return New RelayCommand(Of String)(AddressOf KeyPadPressExecute...,现在可以正常使用了。
标签: wpf vb.net mvvm command .net-4.5