显示 Phone 指定格式的数字 XAML
Showing Phone Number in specified format XAML
我在 WPF 中有一个文本框。
<TextBox Grid.Row="3" FontSize="30"></TextBox>
我只需要输入 10 位数字 phone 即可。显示格式应为 xxx-xxx-xxxx
。
是否可以在不借助任何代码的情况下从 XAML 本身处理这种情况? 如果否,如何在代码的帮助下做到这一点?
使用这个功能
public string phoneformat(string phnumber)
{
String phone=phnumber;
string countrycode = phone.Substring(0, 3);
string Areacode = phone.Substring(3, 3);
string number = phone.Substring(6,phone.Length);
phnumber="("+countrycode+")" +Areacode+"-" +number ;
return phnumber;
}
尝试使用
<TextBox Grid.Row="3" MaxLength="10(or your limit)" FontSize="30"></TextBox>
您可以在 xaml 以及视图模型或代码隐藏文件中设置限制。
我在 WPF 中有一个文本框。
<TextBox Grid.Row="3" FontSize="30"></TextBox>
我只需要输入 10 位数字 phone 即可。显示格式应为 xxx-xxx-xxxx
。
是否可以在不借助任何代码的情况下从 XAML 本身处理这种情况? 如果否,如何在代码的帮助下做到这一点?
使用这个功能
public string phoneformat(string phnumber)
{
String phone=phnumber;
string countrycode = phone.Substring(0, 3);
string Areacode = phone.Substring(3, 3);
string number = phone.Substring(6,phone.Length);
phnumber="("+countrycode+")" +Areacode+"-" +number ;
return phnumber;
}
尝试使用
<TextBox Grid.Row="3" MaxLength="10(or your limit)" FontSize="30"></TextBox>
您可以在 xaml 以及视图模型或代码隐藏文件中设置限制。