WPF and initial focus

后端 未结 12 2189
鱼传尺愫
鱼传尺愫 2020-11-29 15:59

It seems that when a WPF application starts, nothing has focus.

This is really weird. Every other framework I\'ve used does just what you\'d expect: puts initial foc

12条回答
  •  孤城傲影
    2020-11-29 16:44

    Had same problem solved it with simple solution: In the main window:

      
    

    In the user control:

    private void UserControl_GotFocus_1(object sender, RoutedEventArgs e)
            {
                targetcontrol.Focus();
                this.GotFocus -= UserControl_GotFocus_1;  // to set focus only once
            }
    

提交回复
热议问题