Set focus on a textbox control in UserControl in wpf

前端 未结 7 877
孤独总比滥情好
孤独总比滥情好 2020-12-05 07:46

I have created an UserControl which is loaded in a View (Window) in WPF. In my user control I have put a TextBox. I am unable to set focus on this

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 08:45

    This is similar to Sheridan's answer but does not require focus to be set to the control first. It fires as soon as the control is made visible and is based on the parent grid rather than the textbox itself.

    In the 'Resources' section:

        
    

    In my grid definition:

    
    

提交回复
热议问题