[UWP]如何在每次文本更改后将光标放在文本框的末尾? textbox.Select似乎不起作用。 [英] [UWP]How to place cursor at the end of a textbox after every text change? textbox.Select doesnt seem to work.

查看:87
本文介绍了[UWP]如何在每次文本更改后将光标放在文本框的末尾? textbox.Select似乎不起作用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void MyTextBox_TextChanging(TextBox sender, TextBoxTextChangingEventArgs args)
        {
            sender.Select(sender.Text.Length, 0);
        }




如果用户复制并粘贴某些内容或使用语音输入字符,我无法使用关键事件。我希望每次文本更改时都会触发它。更具体的是,如果我在单词的中间选择或按左箭头将
光标移动到文本框的中间,我可以自由键入并填写单词的中间,但我想只能输入一个字符然后被踢回到文本的末尾



I can't use on key events becuase what if the user copies and pastes something or uses speech to input a character. I want it to fire every time the text changes. To be more specific if I select in the middle of the word or press the left arrow to move the cursor to the middle of the textbox I can type freely and fill in the middle of the word, but I would like to only be able to enter one character and then be kicked back to the end of the text

推荐答案

您只需要稍微改变一下即可实现目标。最好使用  TextBox.TextChanged Event  而不是  TextChanging。  TextBox.TextChanged
事件
 触发文字更改后,文字更改时触发TextChanging。 

You just need to change a little bit to reach your goal. It will be better to use TextBox.TextChanged Event instead of TextChanging. TextBox.TextChanged Event triggers when the text is changed and TextChanging triggers when the text is changing. 

喜欢这样:

 private void MyTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            
            MyTextBox.Select(MyTextBox.Text.Length, 0);
        }


您的要求将被实施。

And your requirement will be implemented.

祝你好运,

Roy


这篇关于[UWP]如何在每次文本更改后将光标放在文本框的末尾? textbox.Select似乎不起作用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆