Mvvm 如何在Silverlight中将两个参数传递给ViewModel类?

Mvvm 如何在Silverlight中将两个参数传递给ViewModel类?,mvvm,silverlight-4.0,Mvvm,Silverlight 4.0,我正在学习在Silverlight应用程序中使用MVVM模式 以下代码来自xaml UI代码: <Button Width="30" Margin="10" Content="Find" Command="{Binding Path=GetCustomersCommand, Source={StaticResource customerVM}}" CommandParameter="{Binding Path=Text,

我正在学习在Silverlight应用程序中使用MVVM模式

以下代码来自xaml UI代码:

<Button Width="30" 
        Margin="10" 
        Content="Find"
        Command="{Binding Path=GetCustomersCommand, Source={StaticResource customerVM}}"
        CommandParameter="{Binding Path=Text, ElementName=tbName}"/>

<TextBox x:Name="tbName" 
         Width="50" />

<TextBox x:Name="tbID" 
         Width="50" />
我需要传递两个参数,但是,无法找到如何将两个参数(id和名称)传递给ViewModel类

我想知道是否可以在xaml代码中而不是在codebehind中实现


提前感谢

没有简单的方法可以做到这一点。相反,我建议您使用不带参数的命令,并将框文本框绑定到ViewModel的属性:

C#

XAML

<Button Width="30" 
        Margin="10" 
        Content="Find"
        Command="{Binding Path=GetCustomersCommand, Source={StaticResource customerVM}}"/>

<TextBox x:Name="tbName"
         Text="{Binding Path=Name, Source={StaticResource customerVM}, Mode=TwoWay}"
         Width="50" />

<TextBox x:Name="tbID" 
         Text="{Binding Path=ID, Source={StaticResource customerVM}, Mode=TwoWay}"
         Width="50" />


感谢您的回复,它解决了我的问题,但是Silverlight似乎需要多绑定功能。多绑定?为什么?一次只能绑定一个属性,所以简单的绑定就可以了
public void GetCustomers()
{
    GetCustomers(_id, _name);
}

private int _id;
public int ID
{
    get { return _id; }
    set
    {
        _id = value;
        OnPropertyChanged("ID");
    }
}

private string _name;
public string Name
{
    get { return _name; }
    set
    {
        _name = value;
        OnPropertyChanged("Name");
    }
}
<Button Width="30" 
        Margin="10" 
        Content="Find"
        Command="{Binding Path=GetCustomersCommand, Source={StaticResource customerVM}}"/>

<TextBox x:Name="tbName"
         Text="{Binding Path=Name, Source={StaticResource customerVM}, Mode=TwoWay}"
         Width="50" />

<TextBox x:Name="tbID" 
         Text="{Binding Path=ID, Source={StaticResource customerVM}, Mode=TwoWay}"
         Width="50" />