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

后端 未结 3 1036
[愿得一人]
[愿得一人] 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-14 00:01

    I'm not sure if this fully answers your question, but most of my keybinding / focus questions are solved by setting Focusable=True on your user control, and then in the code behind, call Focus() on the view's load event.

        
    
        private void Act_Loaded(object sender, RoutedEventArgs e)
        {
            Focus();
        }
    

提交回复
热议问题