时,我已经有了一个TextBox
风格展现一个校验错误消息如下:在Expander
WPF扩展仍然显示验证错误装饰器缩水
<Style 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}"/>
</Trigger>
</Style.Triggers>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<Border BorderBrush="{Binding Path=ErrorContent,
Converter={StaticResource ValidationErrorToBrushConverter}}" BorderThickness="2">
<AdornedElementPlaceholder />
</Border>
<Image Name="image1" Height="14" Width="14" Stretch="Fill" Margin="1,1,1,1"
Source="{Binding Path=ErrorContent,
Converter={StaticResource ValidationErrorToImageSourceConverter}}"
ToolTip="{Binding Path=ErrorContent}"/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
的TextBox
生活。当我打开Expander时,TextBox
允许输入,但如果输入是NullorEmpty
或包含特殊字符,则验证失败。
我的问题是,当我触发验证错误时,TextBox
以红色点亮并显示一个图标,并显示消息作为工具提示。迄今为止都很好。但是当我没有通过验证关闭Expander
时,带有工具提示的红色轮廓和图标仍然存在!即使与Expander
缩小!只是漂浮在那里......这不是好行为。
关于如何让验证内容隐藏以及Expander
中所有其他控件的任何想法?此外,用于验证的样式在UserControl的资源中声明,而不是在Expander
本身中。
检查[这个答案](http://stackoverflow.com/questions/1471451/wpf-error解决同样的问题-template-red-box-still-visible-on-collapse-of-an-expander/1471733#1471733)或[this answer](http://stackoverflow.com/questions/321327/how-do-i-get (当我的wpf-binding-validation-has-failed-a/321987#321987)的可能解决方案。这两个中的任何一个都适合你。 – 2009-10-19 10:23:29