Tas*_*iha 5 wpf xaml textbox passwordbox windows-phone-8.1
我TextBox在 Windows Phone 8.1 应用程序中使用用户输入控件。
如何在用户输入时隐藏字符?
我没有使用 aPasswordBox因为定义的InputScopeis"Number"在 a 中是不可能的PasswordBox。
在互联网上搜索解决方案时,我找到了唯一的方法,即TextBox在UserControl.
有没有更简单的方法来做到这一点而不创建任何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"/>
Run Code Online (Sandbox Code Playgroud)
在后面的代码(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, " ");
CardNoTextBox.Text = text;
CardNoTextBox.Select(CardNoTextBox.Text.Length, 0);
}
}
}
else
{
CardNoTextBox.Text = "";
}
}
Run Code Online (Sandbox Code Playgroud)
经过几个小时寻找更简单的方法后,我得到了一个惊人的解决方案。希望这对其他人也有帮助。
我只是将以下值添加到FontFamily我的控件的属性中TextBox:
FontFamily="ms-appx:///Assets/PassDot.ttf#PassDot"
Run Code Online (Sandbox Code Playgroud)
并给出了字体大小35,
FontSize="35"
Run Code Online (Sandbox Code Playgroud)
这对我的项目来说效果很好。
| 归档时间: |
|
| 查看次数: |
2195 次 |
| 最近记录: |