[英]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.