我在
Windows Phone 8.1应用程序中使用TextBox控件进行用户输入.
如何在用户输入时隐藏字符?
如何在用户输入时隐藏字符?
我没有使用PasswordBox,因为定义的InputScope是“Number”,这在PasswordBox中是不可能的.
在互联网上搜索解决方案时,我找到了在UserControl的帮助下自定义TextBox的唯一方法.
有没有更简单的方法来创建任何UserControl?
以下是我的代码段:
在XAML页面中:
<TextBox Text="{Binding CardNo,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" MaxLength="17" x:Name="CardNoTextBox" InputScope="Number" Margin="70,5" PlaceholderText="Enter Your Card Number" TextChanged="CardNoTextBox_TextChanged" BorderBrush="Gray" BorderThickness="2" FontSize="20"/>
在后面的代码(xaml.cs)中:
private void CardNoTextBox_TextChanged(object sender,RoutedEventArgs routedEventArgs) { if (IsTextAllowed(CardNoTextBox.Text)) { if (CardNoTextBox.Text.Length == 5) { if (CardNoTextBox.Text[4] != ' ') { string text = CardNoTextBox.Text.Insert(4," "); CardNoTextBox.Text = text; CardNoTextBox.Select(CardNoTextBox.Text.Length,0); } } if (CardNoTextBox.Text.Length == 12) { if (CardNoTextBox.Text[11] != ' ') { string text = CardNoTextBox.Text.Insert(11,0); } } } else { CardNoTextBox.Text = ""; } }