Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / WPF

Wpf ErrorProvider - Integrating IDataErrorInfo, WPF, and the Validation Application Block (VAB)

Rate me:
Please Sign up or sign in to vote.
2.14/5 (5 votes)
22 Sep 2008CPOL6 min read 63.9K   2.8K   26  
A WPF validation control integrated with VAB and IDataErrorInfo.
<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	>

	<!--
	<remarks>
	Copyright (c) 2008, Rahul Singla (See License.txt)
	</remarks>
	-->
	<ControlTemplate x:Key="RedBorderErrorTemplate" TargetType="{x:Type Control}">

		<StackPanel Orientation="Horizontal">
			<Border BorderBrush="Red" BorderThickness="3">
				<AdornedElementPlaceholder Name="MyAdorner" />
			</Border>

			<Image Name="imgError" Margin="15,0,0,0" Stretch="None" Source="pack://application:,,,/ErrorProvider;component/Images/ErrorImage.gif"
				ToolTip="{Binding ElementName=MyAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
				ToolTipService.InitialShowDelay="0" ToolTipService.ShowDuration="60000"/>

			<!--<TextBlock Name="txtError" Foreground="Orange" Margin="5" 
				FontSize="12pt"
				Text="{Binding ElementName=MyAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
			</TextBlock>-->
		</StackPanel>
		
	</ControlTemplate>

	<ControlTemplate x:Key="BorderLessErrorTemplate" TargetType="{x:Type Control}">

		<StackPanel Orientation="Horizontal">
			<AdornedElementPlaceholder Name="MyAdorner" />

			<Image Name="imgError" Margin="15,0,0,0" Stretch="None" Source="pack://application:,,,/ErrorProvider;component/Images/ErrorImage.gif"
				ToolTip="{Binding ElementName=MyAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
				ToolTipService.InitialShowDelay="0" ToolTipService.ShowDuration="60000"/>

		</StackPanel>

	</ControlTemplate>
</ResourceDictionary>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions