2010-08-19 7 views
0

Silverlight 응용 프로그램에 MVVM 패턴을 사용하려고합니다.Silverlight에서 ViewModel 클래스에 두 개의 매개 변수를 전달하는 방법은 무엇입니까?

다음 코드는 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" /> 

그리고 다음 코드는 뷰 모델 클래스에서이다 : 어떻게 내가 두 개의 매개 변수를 전달해야

public ICommand GetCustomersCommand 
{ 
    get { return new RelayCommand(GetCustomers) { IsEnabled = true }; } 
} 

public void GetCustomers(string name, string id) 
{ 
    // call server service (WCF service) 
} 

하지만, 찾을 수 없습니다 ViewModel 클래스에 두 개의 매개 변수 (id 및 name)를 전달합니다.

코드 숨김이 아닌 xaml 코드에서 가능한지 알고 싶습니다. 사전

답변

1

그것을 할 수있는 쉬운 방법이 없습니다에

감사합니다.

<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" /> 
+0

가 답장을 보내 주셔서 감사

C#을

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"); } } 

XAML 대신, 나는 당신의 ViewModel의 속성에 텍스트 상자를 매개 변수없이 명령을 제안하고, 바인드 상자 , 내 문제를 해결하지만 Silverlight에서는 다중 바인딩 기능이 필요합니다. – Ray

+0

멀티 바인딩? 왜 ? 한 번에 하나의 속성에만 바인딩되므로 간단한 바인딩이 잘 작동합니다. –

+0

여전히 두 개 이상의 매개 변수를 보낼 수 있을지 궁금한가요? –

관련 문제