Reputation: 1548
We display our Errors via an Validation.ValidationAdornerSite in the StatusBar. With the usage of the ValidationAdornerSite, it seems that wpf disables the Validation.ErrorTemplate.
What can I do to achieve both the display of the ErrorTemplate? We currently have a compromise where we only display stuff at the ValidationAdornersite by setting it on MouseOver via Trigger, so that the ErrorTemplate is displayed as long as the mouse is outside the control.
<Style x:Key="ValidationStyle">
<Setter Property="Validation.ErrorTemplate"
Value="{StaticResource Default_ErrorTemplate}" />
<Style.Triggers>
<Trigger Property="UIElement.IsMouseOver"
Value="True">
<Setter Property="Validation.ValidationAdornerSite"
Value="{Binding ValidationAdornerSite,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
</Trigger>
<Trigger Property="Validation.HasError"
Value="true">
<Setter Property="FrameworkElement.ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors)[0].ErrorContent}" />
</Trigger>
</Style.Triggers>
</Style>
Upvotes: 3
Views: 2260
Reputation: 1548
After looking with ILSpy how the Validation has been implemented, I have come to the conclusion that this behavior cannot be altered.
It is much easier to do something similar like ValidationAdornerSite and ValidationAdornerSiteFor does. Define two attached dependency props with similar behaviour. Then you use it instead of the standard adonersite props:
<Setter Property="gw:FormValidation.ValidationSite"
Value="{Binding ValidationAdornerSite,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
...............................
<TextBlock x:Name="PART_ValidationAdornerSite"
HorizontalAlignment="Center"
Text="{Binding RelativeSource={RelativeSource Self}, Path=(gw:FormValidation.ValidationSiteFor).(Validation.Errors)[0].ErrorContent, NotifyOnTargetUpdated=True}"
TargetUpdated="PART_ValidationAdornerSite_TargetUpdated"
TextBlock.Foreground="Red"/>
...............................
this.ValidationAdornerSite = this.PART_ValidationAdornerSite;
this is a Window holding a dp "ValidationAdornerSite". Beware that this solution can be simplified, but it fits my need because my validated controls are within modules (PRISM) that aren't aware of the window (the shell).
Upvotes: 1