2014-12-10 7 views
0
궁금

, 다음 내가 할 가정 :바인딩이 제공되는지 여부를 확인하는 방법은 무엇입니까?

<Some element Command="{Binding FileButton1}" Content="Load into File1" /> 
... 
<Some element Command="{Binding FileButton2}" Content="Load into File2" /> 

두 버튼은 기본적으로 그냥 File1File2 변수로 일부 파일을로드합니다. action 릴레이 기능 구현을 위해 어떤 버튼이 호출되는지 인식하려면 어떻게해야합니까?

FileAddButton1 = new RelayCommand(action, always_true); 

FileAddButton2 = new RelayCommand(action, always_true); 

다음과 같은 버튼을 호출 할 수있는 방법을 확인할 수 있습니까?

미리 감사드립니다.

답변

1

CommandParameter를 사용하여 View에서 Viewmodel로 인수를 보낼 수 있습니다.

<Some element Command="{Binding FileButton1}" 
       CommandParameter="MyArgument" Content="Load into File1" /> 

More information on CommandParameter. 그래서 모양을 명령에 해당하는 대리자,

public void OnCommandExecuted(object argument) 
{ 
    // argument is the parameter passed from view. 
} 
+0

실제로 I 수, 같은 이름이나 뭔가를 얻을? 이것은 실제로 추가 매개 변수의 필요성을 제거합니다. 실제로는 액션 메서드에서 보낸 사람 개체를 얻습니다. – Snowflake

관련 문제