Windows phone 8 如何在windows phone 8中屏蔽phonetextbox中的文本?
在windows phone 8中,如果我选择了phone文本框并在其中输入了一些文本,我想屏蔽此文本,如何实现此目的?我解决了此代码的问题: 在xaml中:Windows phone 8 如何在windows phone 8中屏蔽phonetextbox中的文本?,windows-phone-8,Windows Phone 8,在windows phone 8中,如果我选择了phone文本框并在其中输入了一些文本,我想屏蔽此文本,如何实现此目的?我解决了此代码的问题: 在xaml中: <toolkit:PhoneTextBox Margin="-20,48,0,0" InputScope="TelephoneAreaCode" Style="{
<toolkit:PhoneTextBox Margin="-20,48,0,0"
InputScope="TelephoneAreaCode"
Style="{StaticResource PhoneTextBoxStyleGreen}"
x:Name="PhoneNumber" Height="72" VerticalAlignment="Top" Width="200" MaxLength="10" Hint="Ceular"/>
我的面具:如果8个号码:8888-8888
如果.XAML文件中有9个数字:00000-0000,请在文本框中添加TextChanged事件
<TextBox Name="tvCelular" TextChanged="OnTextCelularChanged" MaxLength="14" InputScope="Number"/>
像密码输入框吗?你是说你想格式化你的输入?like电话号码应该只有数字,并且可能被格式化为:123-456-7890格式?@PaulAnnetts:在asp.net中,我们可以使用textbox.mask来屏蔽我们的文本框,就像那样@sunil5715:不,我不想格式化,我想屏蔽它。我不是说任何验证。简单的解决方案是“”,或者在这里看到另一种方法:希望这有帮助。如果是,请将此标记为答案。
<TextBox Name="tvCelular" TextChanged="OnTextCelularChanged" MaxLength="14" InputScope="Number"/>
/// <summary>
/// created by MAYCON CARDOSO
/// </summary>
public class Mask {
private bool isUpdating = false;
private string old = "";
public String unmask(String s) {
return s.Replace(".", "").Replace("-", "")
.Replace("/", "").Replace("(", "")
.Replace(")", "");
}
public void performFilter(string mask, TextBox ediTxt) {
string s = ediTxt.Text;
String str = unmask(s);
String mascara = "";
if (isUpdating) {
old = str;
isUpdating = false;
return;
}
int i = 0;
foreach(char m in mask.ToCharArray()) {
if (m != '#' && str.Length != old.Length) {
mascara += m;
continue;
}
try {
mascara += str[i];
}
catch (Exception e) {
break;
}
i++;
}
isUpdating = true;
ediTxt.Text = mascara;
ediTxt.SelectionStart = mascara.Length;
}
}
private void OnTextCelularChanged(object sender, TextChangedEventArgs e) {
mCelularMask.performFilter("(##)####-#####",tvCelular);
}