简体   繁体   English

按下Tab键(.net 3.5)时使用Control.Focus()跳转制表符顺序

[英]Jumping tab order using Control.Focus() when pressing Tab key (.net 3.5)

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(). 当我按TAB键并将焦点放在textBox1上时,焦点将移到textBox2上,而独立于textBox3.Focus()。 How could I really set focus on textBox3? 我怎样才能真正专注于textBox3?

After some testing I found that you are currently catching the wrong event. 经过一些测试,我发现您当前正在捕获错误的事件。 Changing the first line of your XAML code into the following 将XAML代码的第一行更改为以下内容

<TextBox Name="textBox1" LostKeyboardFocus="textBox1_LostKeyboardFocus" />

and implementing the following method 并实现以下方法

private void textBox1_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) {

    if (textBox1.Text.Equals("some value")) {
        Keyboard.Focus(textBox3);
    }
}

the focus in the window is correctly set to the desired control. 窗口中的焦点已正确设置为所需的控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM