How to move cursor to next field auto without hit

2019-08-09 03:11发布

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条回答
看我几分像从前
2楼-- · 2019-08-09 03:31

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()
    }
}
查看更多
登录 后发表回答