How Do I Give a Textbox Focus in Silverlight?

前端 未结 15 1754
無奈伤痛
無奈伤痛 2020-12-01 07:49

In my Silverlight application, I can\'t seem to bring focus to a TextBox control. On the recommendation of various posts, I\'ve set the IsTabStop property to True and I\'m

15条回答
  •  醉梦人生
    2020-12-01 08:12

    You code to set the focus is correct since if you add a button that calls the same code it works perfectly:

    
        
        
    
    

    So I'm assuming this is something to do with Focus() requiring some kind of user interaction. I couldn't get it to work with a MouseMove event on the UserControl, but putting a KeyDown event to set the focus works (although the template doesn't update to the focused template).

    Width="400" Height="300" Loaded="UserControl_Loaded" KeyDown="UserControl_KeyDown">
    

    Seems like a bug to me....

提交回复
热议问题