Imports System.ComponentModel Module ValidationGroup Public Delegate Function ValidationDelegate(propertyName As String) As String Public Delegate Sub PropertyChangedDelegate(propertyName As String) _ Public Sub AddValidationGroup(Of T As {INotifyPropertyChanged, INotifyPropertyChanging})(obj As T, validationGroup As List(Of String), validationFlag As Boolean, validationDelegate As ValidationDelegate, propertyChangedDelegate As PropertyChangedDelegate) ' This delegate runs before a PropertyChanged event. If the property ' being changed exists within the Validation Group, check for validation ' errors on the other fields in the group. If there is an error with one ' of them, set a flag to true. AddHandler obj.PropertyChanging, Sub(sender As Object, e As PropertyChangingEventArgs) If validationGroup.Contains(e.PropertyName) Then For Each [property] As String In validationGroup If validationDelegate([property]) IsNot Nothing Then validationFlag = True Exit For End If Next End If End Sub ' After the Property gets changed, if another field in this group was ' invalid prior to the change, then raise the PropertyChanged event for ' all other fields in the Validation Group to update them. ' Also turn flag off so it doesn't get stuck in an infinite loop AddHandler obj.PropertyChanged, Sub(sender As Object, e As PropertyChangedEventArgs) If validationGroup.Contains(e.PropertyName) Then If validationFlag AndAlso validationDelegate(e.PropertyName) Is Nothing Then validationFlag = False For Each [property] As String In validationGroup propertyChangedDelegate([property]) Next End If End If End Sub End Sub End Module