0

Small problem I got. In my project I want to use key shortcuts for my buttons. There are about 5 buttons, where I want to use shortcuts. Like F1, F2, F3.

My code:

<UserControl.InputBindings>
    <KeyBinding Key="F1" Command="{Binding DataContext.ZeroScaleRequestCmd, RelativeSource={RelativeSource AncestorType=weightDisplay:UCScalexWeightDisplay}}" />
    <KeyBinding Key="F2" Command="{Binding TradeWeighingRequestCmd}" />
    <KeyBinding Key="F3" Command="{Binding PairWeighingRequestCmd}" />
</UserControl.InputBindings>

Main problem is, these key bindings don´t react. When i click F1 it doesn´t jump inside breakpoint, or window dont open. I tried to set

Focusable = true

but it doesn´t work also. I don´t know where is mistake. If i press button by click on mouse, it work perfectly. But shortcuts not. Any ideas?

Daniel Capek
  • 131
  • 8
  • 1
    Do the bindings work? What control is focused when you press the keys? – mm8 Jul 18 '18 at 08:53
  • Yes the bindings work perfectly. Problem is with shortcuts. :) Just F1, F2, etc. That´s a good question what control is focused, i try figured it out which one is focused :) – Daniel Capek Jul 18 '18 at 09:39
  • 1
    Have you seen this post? => https://stackoverflow.com/questions/21347666/usercontrol-inputbindings-only-working-after-pressing-a-button-first – Mikitori Jul 18 '18 at 12:26
  • @Mikitori Hello. Thanks for your comment. No, I didn´t see this post, but i checked it and it helped me a lot! This two rows of code helped me through. Thanks! :) – Daniel Capek Jul 18 '18 at 12:35

0 Answers0