windows商店应用程序(通过命令参数传递两个字段)



我正在开发一个windows商店应用程序。我希望能够在点击一个按钮时将两个参数传递到另一个页面。我可以像下面的线路一样方便地通过一个

       CommandParameter="{Binding  CustomerServiceRepresentativeId}"

如何传递一个额外的字段,如下面的字段,使两个字段传递到目标页面。

       Binding CustomerServiceRepresentativeName

我没能通过这两项考试。

                <GridView x:Name="GVCSRList" Grid.Column="2" Grid.Row="2" ItemsSource="{Binding}" SelectionMode="None" ItemContainerStyle="{StaticResource GridViewItemStyle1}" Width="Auto" Margin="40,0,0,0">                           
                    <GridView.ItemTemplate>
                        <DataTemplate >
                        <Button Style="{StaticResource CSRProfile}" Margin="0,0,10,0" Click="ButtonBase_OnClick"  CommandParameter="{Binding  CustomerServiceRepresentativeId}">
                        <StackPanel Width="290" Height="45" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0">
                        <TextBlock Tag="CSRListName"  Text="{Binding CustomerServiceRepresentativeName}" Style="{StaticResource CntMedTextBlockStyleBold}" HorizontalAlignment="Left" VerticalAlignment="Center"  Margin="10,15"/> 
                        </StackPanel>
                        </Button>
                        </DataTemplate>
                    </GridView.ItemTemplate> 
                </GridView>

                        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
                                {
                                    try
                                    {
                                        var commandParameter = ((Button)sender).CommandParameter;
                                        if (commandParameter != null)
                                            this.Frame.Navigate(typeof(CSRProfile), commandParameter.ToString());
                                    }
                                    catch (Exception ex)
                                    {
                                        throw ex;
                                    }
                                }

绑定到一个同时具有两个成员的新属性:

例如,现在您有:

class MyClass 
{
    public int CustomerServiceRepresentativeId { get; set; }
    public string CustomerServiceRepresentativeName { get; set; }
}

将它们放在一个单独的类中,并将该类型的属性添加到类中。例如:

class IdNameCombo
{
    public int CustomerServiceRepresentativeId { get; set; }
    public string CustomerServiceRepresentativeName { get; set; }
}
class MyClass 
{
    public IdNameCombo IdName { get; set; }
}

然后,您绑定到新属性:

CommandParameter="{Binding IdName}"

要设置或获取id名称,您需要再键入一点:

MyClass myClass;
myClass.IdName.CustomerServiceRepresentativeId = 1;
myClass.IdName.CustomerServiceRepresentativeName = "Bob";

最新更新