Validation Template without Binding Errors
WPF guru Josh Smith has just put up a great post here about how to access the validation errors on a WPF control without getting lots of binding debug output. Most samples (including MSDN documentation) suggest you should use Validation.Errors[0] which generate debug output for a binding failure whenever there are no errors (since Errors[0] doesn’t exist).
The format of the template that I commonly use (which also avoids the Errors[0] issue in almost exactly the same way) is as follows:
<ControlTemplate x:Key="DefaultErrorTemplate"> <DockPanel DataContext="{Binding ElementName=adorner,
Path=AdornedElement.(Validation.Errors)/ErrorContent}"> <Ellipse x:Name="Ellipse"
DockPanel.Dock="Right"
Margin="2,0,2,0"
Width="14" Height="14"
VerticalAlignment="Center" Stroke="#40000000" StrokeThickness="2" Fill="Red"> <Ellipse.ToolTip> <Border MaxWidth="350"> <ContentControl FontSize="14" Content="{Binding}"/> </Border> </Ellipse.ToolTip> </Ellipse> <Border BorderBrush="#40FFAF00" BorderThickness="2" IsHitTestVisible="False"> <Border.Background> <SolidColorBrush Color="Red" Opacity="0.2"/> </Border.Background> <AdornedElementPlaceholder Margin="-2" Name="adorner"/> </Border> </DockPanel> </ControlTemplate>
Normally instead of hard coding the colours I would use a colour converter that maps the severity of the error (through a custom property) to the relevant colour, e.g. error=red, warning=orange etc.
My equivalent of Josh’s sample project is here.




I came here accidentally. and got great information. i would say a nice share. Thanks