C #> VB Conversion, RelayCommand behaves differently

    [Visual C#]
    public ICommand MyCommand
    {
        get
        {
            if (this.myCommand == null)
            {
                this.myCommand = new RelayCommand(this.ShowMyCommand);
            }

            return this.myCommand;
        }
    }

    private void ShowMyCommand(object param)
    {
        ...
    }

This code works fine, but when I convert it to Visual Basic:

[Visual Basic]
Private _myCommand As RelayCommand
Public ReadOnly Property MyCommand As ICommand
    Get
        If Me._myCommand Is Nothing Then
            Me._myCommand = New RelayCommand(Me.ShowMyCommand)
        End If

        Return Me._myCommand
    End Get
End Property

Private Sub ShowMyCommand(ByVal param As Object)

    ...

End Sub

I get an error message:

Error 3 An argument not specified for the 'param' of 'Private Sub ShowMyCommand (param as Object)' parameter.

Any ideas? I'm just doing a blind conversion, so I don’t understand what the project is doing, I just convert it.

+3
source share
1 answer

I'm a bit on thin ice when it comes to VB, but according to what I know, you need a method name prefix with a keyword AddressOfso that it can be used as a group of methods for an event.

Next line:

Me._myCommand = New RelayCommand(Me.ShowMyCommand)

Need to write like:

Me._myCommand = New RelayCommand(AddressOf Me.ShowMyCommand)

, , , .

+5

Source: https://habr.com/ru/post/1741751/


All Articles