How Do I Give a Textbox Focus in Silverlight?

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

    It works for me in SL4 and IE7 and Firefox 3.6.12

    Final missing "piece" which made focus to work (for me) was setting .TabIndex property

            System.Windows.Browser.HtmlPage.Plugin.Focus();
            txtUserName.IsTabStop = true;
            txtPassword.IsTabStop = true;
    
            if (txtUserName.Text.Trim().Length != 0)
            {
                txtPassword.UpdateLayout();
                txtPassword.Focus();
                txtPassword.TabIndex = 0;
            }
            else
            {
                txtUserName.UpdateLayout();
                txtUserName.Focus();
                txtUserName.TabIndex = 0;
            }
    

提交回复
热议问题