Bind a keyboard shortcut to a command in the view model in WPF

前端 未结 2 1026
情歌与酒
情歌与酒 2021-01-18 05:24

I have an application where I have a UserControl with a toolbar in it. This toolbar has a button Execute which in turn has its command bound to an

相关标签:
2条回答
  • 2021-01-18 05:45

    There was another answer that disappeared for some reason. This worked fine:

    <UserControl.InputBindings>
      <KeyBinding Key="F5" Command="{Binding ExecuteCommand}" />
    </UserControl.InputBindings>
    

    I'd like to give credit to that guy if possible. Please appear again :)

    0 讨论(0)
  • 2021-01-18 05:47

    Afaik, there isn't a way to directly bind to a keypress, but there are some work arounds. It looks like others have had this problem as well, have you seen this post? My other suggestion is to look into attached commands.

    0 讨论(0)
提交回复
热议问题