How Do I Give a Textbox Focus in Silverlight?

前端 未结 15 1707
無奈伤痛
無奈伤痛 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:26

    Indeed an annoying beheviour. I found a simple straightforward solution:

    (VB code)

        Me.Focus()
        Me.UpdateLayout()
    
        Me.tbx_user_num.Focus()
        Me.tbx_user_num.UpdateLayout()
    

    Each element here is essential, as per my project at least (VB2010 SL4 OutOfBrowser).

    Credit to : http://www.dotnetspark.com/kb/1792-set-focus-to-textbox-silverlight-3.aspx

    0 讨论(0)
  • 2020-12-01 08:30

    I would try adding a DispatcherTimer on the UserLoaded event that executes the Focus method a few milliseconds after the whole control has loaded; maybe the problem is there.

    0 讨论(0)
  • 2020-12-01 08:30

    My profile is not good enough to comment on @Jim B-G's answer but what worked for me was to add a handler for the Loaded event on the RichTextBox and inside that handler add

    System.Windows.Browser.HtmlPage.Plugin.Focus();
    <YourTextBox>.UpdateLayout()
    <YourTextBox>.Focus();
    

    However, it only worked on IE and FF. To get it work on Chrome and Safari, scroll to the bottom of this

    0 讨论(0)
提交回复
热议问题