按 Tab 键时使用 Control.Focus() 跳转 Tab 键顺序 (.net 3.5)
我有三个文本框:
<TextBox Name="textBox1" LostFocus="textBox1_LostFocus" />
<TextBox Name="textBox2" />
<TextBox Name="textBox3" />
通过此事件:
private void textBox1_LostFocus(object sender, RoutedEventArgs e)
{
if (textBox1.Text.Equals("some value"))
textBox3.Focus();
}
当我在 textBox1 上按下 TAB 键时,焦点将转到 textBox2,与 textBox3.Focus() 无关。 我怎样才能真正将焦点集中在textBox3上?
I have three text boxes:
<TextBox Name="textBox1" LostFocus="textBox1_LostFocus" />
<TextBox Name="textBox2" />
<TextBox Name="textBox3" />
With this event:
private void textBox1_LostFocus(object sender, RoutedEventArgs e)
{
if (textBox1.Text.Equals("some value"))
textBox3.Focus();
}
When I press TAB key with focus on textBox1, the focus goes to textBox2, independently of textBox3.Focus().
How could I really set focus on textBox3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一些测试,我发现您当前捕获了错误的事件。将 XAML 代码的第一行更改为以下内容
并实现以下方法,
窗口中的焦点将正确设置为所需的控件。
After some testing I found that you are currently catching the wrong event. Changing the first line of your XAML code into the following
and implementing the following method
the focus in the window is correctly set to the desired control.