WPF INotifyErrorInfo验证。未引发错误事件

WPF INotifyErrorInfo验证。未引发错误事件,wpf,vb.net,validation,Wpf,Vb.net,Validation,我遇到了一个奇怪的问题。尽管所有设置都正确,但不会触发Validation.Error 详情如下: <DataTemplate x:Key="dtLateComers"> <TextBox Text="{Binding ParticipantTag, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, NotifyOnSource

我遇到了一个奇怪的问题。尽管所有设置都正确,但不会触发Validation.Error

详情如下:

<DataTemplate x:Key="dtLateComers">
     <TextBox  Text="{Binding ParticipantTag, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, NotifyOnSourceUpdated=True}" Validation.Error="Validation_Error" >
</DataTemplate>
_迟到者视图模型是(参与者视图模型的)可观察集合

ParticipantViewMode的实现:

Public Class ParticipantViewModel
Implements INotifyPropertyChanged, IDataErrorInfo

 Private _ParticipantTag As String = ""

Public Property ParticipantTag() As String
    Get
        Return _ParticipantTag
    End Get
    Set(ByVal value As String)
        _ParticipantTag = value
        _ParticipantTag= _ParticipantTag.ToUpper      

        NotifyPropertyChanged("ParticipantTag")
    End Set
End Property

 Public ReadOnly Property Item(byVal columnName As String) As String Implements IDataErrorInfo.Item
    Get
        Dim errorString As String = String.Empty

        If columnName.Equals("ParticipantTag") Then

            If not ParticipantValidationManager.IsValidKeypadTag(_ParticipantTag, True) then
                errorString = "Incorrect entry. Please try again."
            End If
        End If

        Return errorString
    End Get
End Property

Public ReadOnly Property [Error] As String Implements IDataErrorInfo.Error
    Get
        Throw New NotImplementedException()
    End Get
End Property

End Class
问题 当我设置ItemSource属性(如代码中所述)时,调用Item index的次数与_LaterComersViewModels中的项数相同。验证工作正常,因此我在文本框旁边得到了一个红色圆圈。然而,在我开始在文本框中输入之前,验证错误永远不会被触发。在TextBox中键入会更改绑定到它的属性并对其进行验证。基于验证。引发错误事件,并由应用程序处理。在该事件处理程序中,我维护错误计数

所以问题是,在初始数据绑定期间,当一个或多个项在验证规则上失败时,为什么不会引发Validation.Error?虽然在文本框中键入属性更改后,它确实会被引发

请随意分享任何想法、假设或解决方案。任何形式的帮助都将不胜感激。谢谢


旁注:我有一个简单的C#应用程序,它不使用数据模板。在该应用程序中,Validation.Error事件在启动和属性更改时完全引发。尽管在该应用程序中,模型绑定到网格的DataContext属性。

因为Validation.Error是附加的事件,您可以在HeaderEditMsControl上连接事件处理程序:

hicLateComers.ItemsSource = _LateComersViewModels
<HeaderedItemsControl x:Name="hicLateComers" ItemTemplate="{StaticResource dtLateComers}" Validation.Error="Validation_Error" />
Private Sub Validation_Error(sender As Object, e As ValidationErrorEventArgs)
    Dim textBox = CType(e.OriginalSource, TextBox)
    Dim participant = CType(textBox.DataContext, ParticipantViewModel)

    '...
End Sub