hello, I am not sure if I am posting in the right forum. I am working on a WPF project using MVVM and am running into an issue. The exact error is "Method Private Sub LoginExecute does not have a signature compatible with delegate Sub Action(Of Object)(obj As Object)". I will post the code below:
The above code generates the error and is in my class constructor for the LoginViewModel. The class it is calling is below:Code:LoginCommand = New RelayCommand(AddressOf LoginExecute, AddressOf CanLoginExecute)
*Edit as Sitten Spynne said, I did not include the 2 methods being passed in. Please note the bolded changes in my post and see below for missing code:Code:Public Class RelayCommand Implements ICommand Private ReadOnly _execute As Action(Of Object) Private ReadOnly _canExecute As Predicate(Of Object) Public Sub New(ByVal execute As Action(Of Object)) Me.New(execute, Nothing) End Sub Public Sub New(ByVal execute As Action(Of Object), ByVal canExecute As Predicate(Of Object)) If execute Is Nothing Then Throw New ArgumentNullException("execute") End If _execute = execute _canExecute = canExecute End Sub <DebuggerStepThrough()> _ Public Function CanExecute(ByVal parameter As Object) As Boolean Implements ICommand.CanExecute Return If(_canExecute Is Nothing, True, _canExecute(parameter)) End Function Public Custom Event CanExecuteChanged As EventHandler Implements ICommand.CanExecuteChanged AddHandler(ByVal value As EventHandler) AddHandler CommandManager.RequerySuggested, value End AddHandler RemoveHandler(ByVal value As EventHandler) RemoveHandler CommandManager.RequerySuggested, value End RemoveHandler RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) End RaiseEvent End Event Public Sub Execute(ByVal parameter As Object) Implements ICommand.Execute _execute(parameter) End Sub End Class Public Class RelayCommand(Of T) Implements ICommand Private ReadOnly _execute As Action(Of T) Private ReadOnly _canExecute As Predicate(Of T) Public Sub New(ByVal execute As Action(Of T)) Me.New(execute, Nothing) End Sub Public Sub New(ByVal execute As Action(Of T), ByVal canExecute As Predicate(Of T)) If execute Is Nothing Then Throw New ArgumentNullException("execute") End If _execute = execute _canExecute = canExecute End Sub <DebuggerStepThrough()> _ Public Function CanExecute(ByVal parameter As Object) As Boolean Implements ICommand.CanExecute Return If(_canExecute Is Nothing, True, _canExecute(CType(parameter, T))) End Function Public Custom Event CanExecuteChanged As EventHandler Implements ICommand.CanExecuteChanged AddHandler(ByVal value As EventHandler) AddHandler CommandManager.RequerySuggested, value End AddHandler RemoveHandler(ByVal value As EventHandler) RemoveHandler CommandManager.RequerySuggested, value End RemoveHandler RaiseEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) End RaiseEvent End Event Public Sub Execute(ByVal parameter As Object) Implements ICommand.Execute _execute(CType(parameter, T)) End Sub End Class
I have tried to add parameters, add a new delegate, and more. Rather than keep banging my head, I thought I would ask.Code:Private Sub LoginExecute() Dim paramLoginID = LoginID Dim paramPassword = Password Try If _userAccess.Login(paramLoginID, paramPassword) Then _loginSuccess = True LoginMessage = "You are logged in!" End If Catch ex As Exception LoginMessage = ex.Message End Try End Sub Private Function CanLoginExecute(ByVal param As Object) As Boolean Return (Not String.IsNullOrEmpty(LoginID)) AndAlso (Not String.IsNullOrEmpty(Password)) End Function
Thanks in Advance!




Reply With Quote
