1.Exception
<TextBox Width="120" Text="{Binding Name,ValidatesOnExceptions=True,UpdateSourceTrigger=PropertyChanged}"
ToolTip="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}">
</TextBox>
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
if (name.Length > 10)
{
throw new ArgumentException("输入超长!");
}
}
}
2.ValidationRule
3.IDataErrorInfo
4.INotifyDataErrorInfo
5. 代码直接验证(直接用 MessageBox 弹出消息,Windows 的老传统)
标签:Errors,name,验证,Self,RelativeSource,string From: https://www.cnblogs.com/xiuju/p/17775359.html