Can't set focus to a child of UserControl

后端 未结 18 589
耶瑟儿~
耶瑟儿~ 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:20

    What did the trick for me was the FocusManager.FocusedElement attribute. I first tried to set it on the UserControl, but it didn't work.

    So I tried putting it on the UserControl's first child instead:

    
    
        
    
    

    ... and it worked! :)

提交回复
热议问题