반응형
WPF 를 사용하다보면 마우스나 키보드를 이용하여 상호작용을 해야할 때가 있다.
이럴때 컨트롤에 InputBindings을 이용하여 MVVM으로 바인딩하는 방법이 있다.
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding Path=DataContext.ListDoubleClickCommand, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"/>
</Grid.InputBindings>
</Grid>
</ListView.ItemTemplate>
</ListView>
MouseBinding 할때 Gesture를 이용해도 되고, MouseAction을 사용해도 된다.
보통은 저렇게 쓸때 자동완성기능에 없는데 MouseBinding의 경우 아래의 URL가서 MouseAction 관련 Enum을 확인하면된다.
MouseBinding 클래스 (System.Windows.Input)
MouseGesture를 RoutedCommand 또는 다른 ICommand 구현에 바인딩합니다.
docs.microsoft.com
마찬가지로 KeyBinding도 똑같다.
https://docs.microsoft.com/ko-kr/dotnet/api/system.windows.input.keybinding?view=windowsdesktop-6.0
KeyBinding 클래스 (System.Windows.Input)
KeyGesture를 RoutedCommand(또는 다른 ICommand 구현)에 바인딩합니다.
docs.microsoft.com
반응형
'프로그래밍 > WPF' 카테고리의 다른 글
[WPF] Usercontrol 사용 시, 디자이너 Exception 문제 (0) | 2022.08.04 |
---|---|
[WPF] TabControl header Content Binding (0) | 2022.08.03 |
[WPF] TreeView MVVM IsSelected & IsExpanded Binding (0) | 2022.08.03 |
[WPF] DispatcherUnhandledException (0) | 2022.06.22 |
[WPF] Binding 시, 자기 자신의 Property를 바인딩 하는 법 (0) | 2022.04.15 |