[英]How to set the caret to the end of the text in TextBox (WP8)?
我需要编写用相同的字符替换第一个字符的算法,但大写。 所以,我写了这段代码:
private void RegionFilter_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox tb = (sender as TextBox);
var initialText = tb.Text;
if (initialText != "")
{
var firstChar = initialText.Substring(0, 1).ToUpper();
var restOfString = initialText.Substring(1, initialText.Length - 1);
tb.Text = firstChar + restOfString;
}
}
但是有一个问题:更换文本后,插入符号没有移动到最后,它仍然在开头。
重要的是要说Windows Phone 8中的TextBox中没有CaretIndex属性。我该如何解决这个问题?
但是,您可以使用文本框的选择方法,如我在此处所示:
myTextBox.Select(tbPositionCursor.Text.Length, 0);
你可以在这里找到更多相关信息:: http://msdn.microsoft.com/en-us/library/ms752349(v=vs.110).aspx
您还可以通过设置TextBox
TextBox.SelectionStart来更改插入符的位置。 在算法结束时添加:
yourTextBox.SelectionStart = yourTextBox.Text.Length;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.