Setting focus to a textbox on load of Windows Phone 7 app

自作多情 提交于 2019-12-23 12:46:31

问题


I have a TwoWay data-bound textbox inside my page. I want to do something pretty simple, but I can't for the life of me work out how to do it. When the page loads, I want to set the focus to the textbox if it doesn't have any text in it.

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    if (tbSearch.Text == "")
        tbSearch.Focus();
}

This doesn't work. It doesn't fail, it just doesn't do anything. Am I doing something strange wrong? I've also tried putting this in the constructor, to no avail.

Chris


回答1:


Does doing this from the pages Loaded event work for your requirements?

It will work from there.



来源:https://stackoverflow.com/questions/4513222/setting-focus-to-a-textbox-on-load-of-windows-phone-7-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!