How to move cursor to next field auto without hit Tab Key in Silverlight?

Deadly 提交于 2019-12-11 13:37:14

问题


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()
    }
}


来源:https://stackoverflow.com/questions/8221872/how-to-move-cursor-to-next-field-auto-without-hit-tab-key-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!