2017-12-26 69 views
0

MVVM 라이트를 사용하여 코드를 수정합니다. 내 오래된 코드는 다음과 같습니다.MVVM에서 명령을 사용하여 그리드에서 RoutedEvent를 처리하는 방법 light wpf

<Grid x:Name="root" ButtonBase.Click="LayoutRoot_Click"> 

LayoutRoot_Click은 하위 컨트롤의 모든 RoutedEvent를 처리합니다. 그리드 this-

public class SomeViewModel : ViewModelBase 
{ 
    public SomeViewModel() 
    { 
     InputCommand = new RelayCommand(InputCode); 
    } 

    public ICommand InputCommand { get; set; } 

    private void InputCode() 
    { 
     string input = string.Empty; 
    } 
} 

처럼 뷰 모델이

<Grid x:Name="root" ButtonBase.Click="LayoutRoot_Click"> 
<i:Interaction.Triggers> 
    <i:EventTrigger EventName="ButtonBase.Click"> 
     <mvvm:EventToCommand Command="{Binding InputCommand}" CommandParameter="{Binding ElementName=button1}" /> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

같은 어떤 명령 인터페이스, 그래서 새로운 코드가없는 그러나이 작동하지 않기 때문에. 명령이 RoutedEvent를 얻지 못했습니다.

답변

0

를 추가해보십시오 PassEventArgsToCommand 바인딩 명령에 = "진정한"

<Grid x:Name="root" ButtonBase.Click="LayoutRoot_Click"> 
<i:Interaction.Triggers> 
    <i:EventTrigger EventName="ButtonBase.Click"> 
     <mvvm:EventToCommand Command="{Binding InputCommand}" CommandParameter="{Binding ElementName=button1}" PassEventArgsToCommand="True"/> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

귀하의 명령은 다음 내가 생각하는 올바른 유형의 매개 변수를해야 할 것입니다 RoutedEventArgs

public RelayCommand<RoutedEventArgs> SomeCommand { get; private set; } 
    private void SomeCode(RoutedEvent routedEvent) 
    { 
     //Do something with the routed event 
    }