我错过了什么吗?
1- Style
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Validation.HasError}" Value="true">
<Setter Property="BorderBrush" Value="Blue" />
</DataTrigger>
</Style.Triggers>
<Setter Property="MinWidth" Value="160" />
<Setter Property="Margin" Value="0 7 0 0"/>
</Style>
2 - Viewmodel实现IDataErrorInfo 视图中的3- textBox
<TextBox x:Name="FirstName" Text="{Binding Person.FirstName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true}"></TextBox>
3 - 我使用Caliburn MVVM
我得到“BindingExpression路径错误:'验证'属性未找到'对象'''PersonWindowViewModel'(HashCode = 38783181)'。BindingExpression:Path = Validation.HasError; DataItem ='PersonWindowViewModel'(HashCode = 38783181); target元素是'TextBox'(Name ='FirstName'); target属性是'NoTarget'(类型'Object')“S
答案 0 :(得分:14)
查看Beth Massi关于实施验证的文章here
基本上,您使用了DataTrigger
,只需要Trigger
所以:
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter ... />
</Trigger>
</Style.Triggers>