在加载 Windows Phone 7 应用程序时将焦点设置到文本框 [英] Setting focus to a textbox on load of Windows Phone 7 app

查看:24
本文介绍了在加载 Windows Phone 7 应用程序时将焦点设置到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有一个 TwoWay 数据绑定文本框.我想做一些非常简单的事情,但我一生都无法弄清楚如何去做.当页面加载时,如果文本框中没有任何文本,我想将焦点设置在文本框上.

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.

克里斯

推荐答案

从页面 Loaded 事件中执行此操作是否符合您的要求?

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

它会从那里工作.

这篇关于在加载 Windows Phone 7 应用程序时将焦点设置到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆