Skip to main content
 首页 » 编程设计

c#之将格式 xxxxxxxxxx 更改为 xxx-xxx-xxxx

2024年02月06日14grandyang

我在 WPF 中有一个文本框,我需要以 xxx-xxx-xxxx 格式显示文本。

<TextBox FontSize="30" Text="{Binding MyString,UpdateSourceTrigger=PropertyChanged}" Grid.Row="3" MaxLength="10"></TextBox> 

MyString 只是将 TextBox 中的值设置到其中以用于其他一些逻辑的属性。我可以使用 StringFormat 在 XAML 本身中完成吗?

请您参考如下方法:

您可以尝试使用 MaskedTextBox指定输入的格式。

示例:

<wpfx:MaskedTextBox Mask="000-000-0000" /> 

尝试 this tutorial还有。