Can't set focus to a child of UserControl

后端 未结 18 620
耶瑟儿~
耶瑟儿~ 2020-12-04 21:55

I have a UserControl which contains a TextBox. When my main window loads I want to set the focus to this textbox so I added Focusable=\"True

18条回答
  •  囚心锁ツ
    2020-12-04 22:24

    Assuming you want to set focus for Username textbox, thus user can type in directly every time it shows up.

    In Constructor of your control:

    this.Loaded += (sender, e) => Keyboard.Focus(txtUsername);
    

提交回复
热议问题