[英]how To Type Uppercase String in windows phone TextBox Wpf c#
如何在Windows Phone TextBox Wpf c#中鍵入大寫字符串。
我在KeyDown事件上嘗試過。
void TxtPanno_KeyDown(object sender, KeyEventArgs e)
{
TxtPanno.Text = TxtPanno.Text.ToUpper(); //1 code.
TxtPanno.Text= CultureInfo.CurrentCulture.TextInfo.ToUpper(TxtPanno.Text); //2 code
TxtPanno.Text=Regex.Replace(TxtPanno.Text, "^[A-Z]", m => m.Value.ToUpper()); //3 code.
}
但是問題在於。
光標總是移到左側。
嘗試做:
TxtPanno.Text = TxtPanno.Text.ToUpper();
TxtPanno.SelectionStart = TxtPanno.Text.Length;
TxtPanno.SelectionLength = 0;
它使文本變為大寫,將光標移到末尾,並且什么也沒有選擇。
您不應該嘗試替換文本,而應該應用這樣的樣式
<Style TargetType="{x:Type TextBox}">
<Setter Property="CharacterCasing" Value="Upper"/>
</Style>
上面的樣式將使所有文本框都變為大寫,您可以將其更改為僅適用於這樣的特定教科書
<TextBox CharacterCasing="Upper" />
然后在使用輸入的文本時將其大寫。
最終,我嘗試了這段代碼,它成功了。
void TxtPanno_TextChanged(object sender, TextChangedEventArgs e)
{
TxtPanno.Text = TxtPanno.Text.ToUpper();
TxtPanno.SelectionStart = TxtPanno.Text.Length;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.