How to move cursor to next field auto without hit

2019-08-09 03:10发布

问题:

Suppose I set MaxLength=3 for a textbox, when user input 3 char in this field, I want to the cursor move to next item.

It's default is user must hit Tab or use mouse to move the cursor to next field.

How to implement this request?

回答1:

There may be a more clever way but at first glance I would say a simple way would be to you add a TextChanged event to your TextBox and then when the number of characters hits the 3 you mention then set the focus to what you want.

So if this is in your xaml:

<TextBox x:Name="MyText1" TextChanged="txtChanged"/>
<TextBox x:Name="MyText2" />

Then in your code something like:

private void txtChanged(object sender, TextChangedEventArgs e)
{
    if (MyText1.Text.Length == 3)
    {
         MyText2.Focus()
    }
}