C# UWP Assign从DependencyProperty回调中继承的文本值引发异常

C# UWP Assign从DependencyProperty回调中继承的文本值引发异常,c#,uwp,dependency-properties,C#,Uwp,Dependency Properties,我正在使用从TextBox继承的自定义输入控件,该控件将用于输入社会保险号码。最终目标是使用掩码并显示项目符号字符,而不是实际数字,同时将实际值存储在名为ActualValue的依赖项属性中 我正在尝试将TextBox.Text值设置为实际值(稍后将替换为格式化的隐藏字符),如果我在TextChanging事件上有一个事件处理程序并绑定该值,我将在内核级别收到一个异常(如果设置为托管和本机调试,则没有可用的符号) 无文本更改事件处理程序-无异常 不在回调中设置文本-无异常 在标记中使用文字(例

我正在使用从TextBox继承的自定义输入控件,该控件将用于输入社会保险号码。最终目标是使用掩码并显示项目符号字符,而不是实际数字,同时将实际值存储在名为ActualValue的依赖项属性中

我正在尝试将TextBox.Text值设置为实际值(稍后将替换为格式化的隐藏字符),如果我在TextChanging事件上有一个事件处理程序并绑定该值,我将在内核级别收到一个异常(如果设置为托管和本机调试,则没有可用的符号)

  • 无文本更改事件处理程序-无异常
  • 不在回调中设置文本-无异常
  • 在标记中使用文字(例如123456)而不是绑定-无例外
我以前使用过这种模式(甚至在UWP应用程序中),但我在这个示例中看到的唯一区别是,它在新项目中,最低版本和目标版本都设置为周年更新版本。。。我不确定这是否与此有关

我不是在寻找最终目标的解决方案。。。请帮我解释一下为什么会抛出异常

下面是课堂:

public class SSNInputBox : TextBox
{
    private static readonly string SSNMask = "___-__-____";

    public SSNInputBox()
    {
        DefaultStyleKey = typeof(TextBox);
        TextChanging += OnTextChanging;
    }

    #region Properties

    private void OnTextChanging(TextBox sender, TextBoxTextChangingEventArgs args)
    {

    }

    public string ActualValue
    {
        get { return (string)GetValue(ActualValueProperty); }
        set { SetValue(ActualValueProperty, value); }
    }

    // Using a DependencyProperty as the backing store for ActualValue.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ActualValueProperty =
        DependencyProperty.Register("ActualValue", typeof(string), typeof(SSNInputBox), new PropertyMetadata(string.Empty, onActualValueChanged));

    private static void onActualValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ((SSNInputBox)d).OnActualValueChanged(e);
    }

    protected virtual void OnActualValueChanged(DependencyPropertyChangedEventArgs e)
    {
        Text = e.NewValue.ToString();
    }

    #endregion
}
以下是标记:

<local:SSNInputBox ActualValue="{Binding Path=CurrentApplicant.SSN, Mode=TwoWay}" />

只是想知道,从
密码箱继承会不会就这么简单?谢谢,贾斯汀。。。我已经考虑过了。但是,PasswordBox是密封的,您不能从中继承。
public class Applicant : INotifyPropertyChanged
{
    private string _ssn;
    public string SSN
    {
        get { return _ssn; }
        set { Set(ref _ssn, value); }
    }

    #region INotifyPropertyChanged

    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    protected bool Set<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
    {
        if (Equals(storage, value)) return false;

        storage = value;
        this.RaisePropertyChanged(propertyName);
        return true;
    }

    protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
    {
        this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    #endregion

}
public class MainViewModel : ViewModelBase
{
    private Applicant _currentApplicant = new Applicant();
    public Applicant CurrentApplicant
    {
        get { return _currentApplicant; }
        set { Set(ref _currentApplicant, value); }
    }

    private string _ssn = "123-45-6789";
    public string SSN
    {
        get { return _ssn; }
        set { Set(ref _ssn, value); }
    }

    public void LoadApplicant()
    {
        CurrentApplicant.SSN = "123-45-6789";
    }

    public void ChangeSSN()
    {
        CurrentApplicant.SSN = SSN = "987-65-4321";
    }
}