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