移除对第一个文本框的关注 [英] Remove focus on first textbox

查看:32
本文介绍了移除对第一个文本框的关注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的 Windows Store 应用程序中,我们有一个文本框,当应用程序启动时,这个文本框总是会获得焦点.在桌面场景中没问题,但在平板设备上这个焦点会直接打开屏幕键盘,这不是我们想要的场景.

In our Windows Store app we have a textbox, and when the application starts this textbox always get focus. In a desktop scenario that's no problem, but on a tablet device this focus will directly open the onscreen keyboard which is not a scenario that we want.

我们尝试使用 .Focus(FocusState) 方法将焦点设置在另一个编程控件上,但不知何故焦点被设置回文本框.我们都在 LoadState 或 OnNavigatedTo 方法中设置了焦点.

We tried to set the focus on another control programmatic with the .Focus(FocusState) method, but somehow the focus is set back to the textbox. We have both set the focus in the LoadState or the OnNavigatedTo method.

只有当我们有计时器时,我们才能成功地将焦点设置到另一个控件上.任何人都知道如何将焦点设置到另一个控件上,或者最好将根本不焦点设置到一个控件上?

Only when we have timer we have set the focus succesfully to another control. Anyone has ideas how to set the focus to another control, or preferably set not focus at all to an control?

推荐答案

通常您可以通过 TextBox.Focus() 将焦点设置在任何元素上.但是,当您将 TextBox 放入 ScrollViewer 或 FlyOut 时,我发现了相同的行为(启动时自动对焦).然后你必须设置 IsTabStop 在父元素上:

Normally you can set the Focus on any element by TextBox.Focus(). However I discovered the same behaviors (autofocus on start) when you place your TextBox inside a ScrollViewer or a FlyOut. Then you have to set the IsTabStop on the parent-element:

<ScrollViewer IsTabStop="true">
   <TextBox />
</ScrollViewer>

这篇关于移除对第一个文本框的关注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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