C# to VB.NET Delegate command translation

1.3k Views Asked by At

Could one of you gurus help with a bit of translation?

Argument not specified for 'userList' of 'Private Sub OpenUserDetail(userList as Model.UserList)'. It works in the C# version just not sure about the C# to VB translation. Any help would be greatly appreciated. :)

Original declaration in C#:

private readonly DelegateCommand<EmailDocument> openMessageCommand;

this.openMessageCommand = new DelegateCommand<EmailDocument>(this.OpenMessage);

private void OpenMessage(EmailDocument document) {
    // Do stuff
}

VB Translation:

Private ReadOnly openUserCommand As DelegateCommand(Of UserList)

Me.openUserCommand = New DelegateCommand(Of UserList)(Me.OpenUserDetail)

Private Sub OpenUserDetail(userList As UserList)
    ' Do stuff
End Sub

Notes:

VB version - UserList is a class instance
C# Version - EmailDocument is a class instance

########### EDIT

Adding more details:

XAML calling code:

<UserControl.Resources>
    <command:ObservableCommand x:Name="OpenUserCommand" Value="{Binding OpenUserCommand}"/>
</UserControl.Resources>

        <sdk:DataGrid.Columns>
            <sdk:DataGridTemplateColumn Header="Name" Width="150*" MinWidth="150">
                <sdk:DataGridTemplateColumn.HeaderStyle>
                    <Style TargetType="sdk:DataGridColumnHeader">
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <ComboBox Name="cboNameFormat" 
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch"
                                        Height="Auto"
                                        Width="180" SelectedValuePath="Tag" >
                                        <ComboBoxItem Tag="%0 %1" IsSelected="True">First Name Last Name</ComboBoxItem>
                                        <ComboBoxItem Tag="%1, %0">Last Name, First Name</ComboBoxItem>
                                    </ComboBox>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </sdk:DataGridTemplateColumn.HeaderStyle>
                <sdk:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <HyperlinkButton x:Name="hbtnName" 
                            **Command="{Binding Value, Source={StaticResource OpenUserCommand}}"**
                            CommandParameter="{Binding}"
                            VerticalAlignment="Center" 
                            AutomationProperties.AutomationId="OpenMailHyperLink" 
                            Content="{Binding Name}">
                            <!--<HyperlinkButton.Content>
                                <mvc:MultiBinding Source1="FirstName" Source2="LastName" StringFormat="{Binding SelectedValue, ElementName=cboNameFormat}" >
                                    <mvc:BindingCollection>
                                        <Binding Path="FirstName" />
                                        <Binding Path="LastName" />
                                    </mvc:BindingCollection>
                                </mvc:MultiBinding>
                            </HyperlinkButton.Content>-->
                        </HyperlinkButton>
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellTemplate>
            </sdk:DataGridTemplateColumn>
            <sdk:DataGridTextColumn Header="Role" MinWidth="150" Binding="{Binding   Role, StringFormat=g}" CanUserSort="True"/>
            <sdk:DataGridTextColumn Header="Company" MinWidth="150" Binding="{Binding Company, StringFormat=g}" CanUserSort="False"/>
            <sdk:DataGridTextColumn Header="Phone" MinWidth="150" Binding="{Binding Phone, Converter={StaticResource stringToPhoneNumberConverter}}" CanUserSort="False"/>
            <sdk:DataGridTextColumn Header="Phone" MinWidth="150" Binding="{Binding Email, StringFormat=g}" CanUserSort="False"/>
            <sdk:DataGridTextColumn Header="Phone" MinWidth="150" Binding="{Binding Address, StringFormat=g}" CanUserSort="False"/>
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>

VB.NET Property:

Private ReadOnly openUserCommand As DelegateCommand(Of UserList)

    <ImportingConstructor()> _
    Public Sub New(userService As IUserService, regionManager As IRegionManager)
        Me.openUserCommand = New DelegateCommand(Of UserList)(Me.OpenUserDetail)
    End Sub

#Region "OpenUserCommand"
    Public ReadOnly Property OpenUserCmd() As ICommand
        Get
            Return Me.openUserCommand
        End Get
    End Property

    Private Function OpenUserDetail(userList As UserList)
        ' This view initiates navigation using the RegionManager.
        ' The RegionManager will find the region and delegate the
        ' navigation request to the region specified.
        '
        ' This navigation request also includes additional navigation context, an 'EmailId', to
        ' allow the Email view to orient to the right item.  The navigation request and context
        ' is built using a UriQuery that helps build the request.
        If userList Is Nothing Then Return Nothing
        Dim builder = New StringBuilder()
        builder.Append(UserViewKey)
        Dim query = New UriQuery()
        query.Add(UserId, userList.ID.ToString)
        builder.Append(query)
        Me.regionManager.RequestNavigate(RegionNames.MainContentRegion, New Uri(builder.ToString(), UriKind.Relative))
        Return Nothing
    End Function
#End Region
1

There are 1 best solutions below

0
On BEST ANSWER

Been a long while since I looked at VB.NET. I think you need to use the AddressOf keyword

Me.openUserCommand = New DelegateCommand(Of UserList)(AddressOf Me.OpenUserDetail)

http://msdn.microsoft.com/en-us/library/74wy9422%28v=vs.90%29.aspx