WPF MVVM KeyBinding not being recognized right away and not always working

后端 未结 3 1011
[愿得一人]
[愿得一人] 2021-01-13 23:32

For whatever reason, the KeyBindings for my UserControl aren\'t working as soon as my WPF Application loads. They do work after I press a button on the form but not when I s

3条回答
  •  爱一瞬间的悲伤
    2021-01-13 23:54

    Have you verified that the control actually has focus when it loads by using Mole? It could be that whatever your parent control is keeps focus until your buttons are selected manually. As for the Enter keys, it sounds as if they are probably selecting the last clicked button since it would still have focus instead of firing your commands.

    You may need to look at your commands as I'm not sure the declarations are set up correctly. For KeyBindings, your command should be referenced in XAML as a CommandReference, like this article describes.

提交回复
热议问题