C# 如何替换文本框插入符号

C# 如何替换文本框插入符号,c#,wpf,C#,Wpf,我有一个绑定了手机号码的文本框,每3个字符后面都有一个字符。假设手机号码的最大字符数为10,在3个字符a后面将显示一个字符(例如我有1234567890)(此手机号码将替换为123-456-7890) 我的问题是我需要从文本框中删除-并使其为空。有人能帮我吗?这都是用C语言完成的# 这是我尝试过的代码 这是我设置的关联属性 public static readonly DependencyProperty AssociatedElementProperty = DependencyPropert

我有一个绑定了手机号码的文本框,每3个字符后面都有一个字符。假设手机号码的最大字符数为10,在3个字符a后面将显示一个字符(例如我有1234567890)(此手机号码将替换为123-456-7890)

我的问题是我需要从文本框中删除-并使其为空。有人能帮我吗?这都是用C语言完成的# 这是我尝试过的代码

这是我设置的关联属性

public static readonly DependencyProperty AssociatedElementProperty = DependencyProperty.Register("AssociatedElement", typeof(FrameworkElement), typeof(NumericKeyBoard), null);

this.caretPosition = associatedTextBox.SelectionStart;
if (associatedTextBox.Tag.ToString() == "mobile" && associatedTextBox.Text.Substring(this.caretPosition - 1, 1) == "-")
{
     associatedTextBox.Text = associatedTextBox.Text.Remove(this.caretPosition - 1, 1);
     this.caretPosition--;
}  

考虑使用修改后的文本框控件,如

,这是无法更改的。应使用上述相同的代码完成此操作。这只是猜测,但请查看System.ComponentModel命名空间()中的MaskedTextProvider,也许您可以隔离屏蔽函数