WPF 输入异常提示

<TextBox Grid.Column="0"  Style="{StaticResource TextBoxStyle}" Height="30" Text="{Binding CodeBinding, Mode=TwoWay, ValidatesOnExceptions=True}"  Validation.ErrorTemplate="{StaticResource errorTemplateStyle}"></TextBox>
public string CodeBinding
{
    get
    {
        return code;
    }
    set
    {              
        SetProperty(ref code, value, () => CodeBinding);
        if (value==null)
        {
            return;
        }
        string sql = "";
        //读取数据库,看看编码是否重复
        var model=......;
 
        if (model!=null)
        {
            //编码重复,抛出异常
            throw new Exception("人员编码重复"); 
        }
    }
}

调试会报错,运行会显示错误警告"人员编码重复"

原文地址:https://www.cnblogs.com/Lulus/p/8158364.html