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

后端 未结 3 1009
[愿得一人]
[愿得一人] 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:45

    I ran into the same issue. I followed up on the focus issue. I found that when I set my focus to a button inside of my form, the commands started working. If my focus item gets deleted and not redirected (such as deleting the last item from a listbox), then none of my commands work.

    I manually reset my keyboard focus to a default item in the cases that were leaving my focus ina weird state causing my commands to break. In my case, that was the page loaded event and the delete command (when there were no more items in my list box).

提交回复
热议问题