Click here to Skip to main content
15,896,557 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 64K   2.8K   26  
A WPF validation control integrated with VAB and IDataErrorInfo.
Namespace Wpf.Controls

	''<remarks>
	'' Copyright (c) 2008, Rahul Singla (See License.txt)
	'' </remarks>

	''' <summary>
	''' Defines the type used by the BindingOverrideProperty in the ErrorProvider.
	''' </summary>
	Public Class BindingOverride
		Private _ownerType As Type
		Private _path As String
		Private _overrideRelativeSource As RelativeSourceMode = RelativeSourceMode.Self

		Public Property ownerType() As Type
			Get
				Return (Me._ownerType)
			End Get
			Set(ByVal value As Type)
				Me._ownerType = value
			End Set
		End Property

		Public Property path() As String
			Get
				Return (Me._path)
			End Get
			Set(ByVal value As String)
				Me._path = value
			End Set
		End Property

		Public Property overrideRelativeSource() As RelativeSourceMode
			Get
				Return (Me._overrideRelativeSource)
			End Get
			Set(ByVal value As RelativeSourceMode)
				Select Case value
					Case RelativeSourceMode.PreviousData, RelativeSourceMode.Self
						Me._overrideRelativeSource = value

					Case Else
						Throw New Exception("Only PreviousData and Self are supported as overrideRelativesource")
				End Select
			End Set
		End Property
	End Class


	''' <summary>
	''' A MarkupExtension for the BindingOverride used in the ErrorProvider.
	''' </summary>
	Public Class BindingOverrideExtension
		Inherits Markup.MarkupExtension

		Private _bindingOverride As New BindingOverride

		Public Property ownerType() As Type
			Get
				Return (Me._bindingOverride.ownerType)
			End Get
			Set(ByVal value As Type)
				Me._bindingOverride.ownerType = value
			End Set
		End Property

		Public Property path() As String
			Get
				Return (Me._bindingOverride.path)
			End Get
			Set(ByVal value As String)
				Me._bindingOverride.path = value
			End Set
		End Property

		Public Property overrideRelativeSource() As RelativeSourceMode
			Get
				Return (Me._bindingOverride.overrideRelativeSource)
			End Get
			Set(ByVal value As RelativeSourceMode)
				Me._bindingOverride.overrideRelativeSource = value
			End Set
		End Property

		Public Overrides Function ProvideValue(ByVal serviceProvider As System.IServiceProvider) As Object
			Return (Me._bindingOverride)
		End Function
	End Class
End Namespace

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