我正在使用 IDataErrorInfo 在 WPF 中的表单中验证我的数据。我在我的演示者中实施了验证。
实际验证正在发生,但应该更新 UI 和设置样式的 XAML 没有发生。
这里是:
<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
问题是我的绑定不Validation.Errors
包含数据。如何从 Presenter 类中获取这些数据并将其传递给此 XAML 以更新 UI 元素?
编辑:
文本框:
<TextBox Style="{StaticResource textBoxInError}" Name="txtAge" Height="23" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Width="150">
<TextBox.Text>
<Binding Path="StrAge" Mode="TwoWay"
ValidatesOnDataErrors="True"
UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
验证发生,但数据无效时应用的样式没有发生。