0

你们哪位大师可以帮忙翻译一下吗?

未为“Private Sub OpenUserDetail(userList as Model.UserList)”的“userList”指定参数。它适用于 C# 版本,只是不确定 C# 到 VB 的转换。任何帮助将不胜感激。:)

C# 中的原始声明:

private readonly DelegateCommand<EmailDocument> openMessageCommand;

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

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

VB翻译:

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

笔记:

VB版本——UserList是类实例
C#版本——EmailDocument是类实例

########### 编辑

添加更多细节:

XAML 调用代码:

<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 属性:

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
4

1 回答 1

2

很久没看VB.NET了。我认为您需要使用 AddressOf 关键字

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

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

于 2012-01-27T01:17:31.217 回答