WPF验证。错误不包含任何内容

WPF验证。错误不包含任何内容,wpf,validation,Wpf,Validation,我的ItemsControl中显示验证时遇到问题。错误。Validation.Errors不包含任何内容。我没有使用BindingGroup,但我使用自己的自定义文本框。以下是ItemsControl代码: <ItemsControl x:Name="errorList" ItemsSource="{Binding Path = (Validation.Errors), ElementName=gvAddCustomer}" > <It

我的ItemsControl中显示验证时遇到问题。错误。Validation.Errors不包含任何内容。我没有使用BindingGroup,但我使用自己的自定义文本框。以下是ItemsControl代码:

     <ItemsControl x:Name="errorList" ItemsSource="{Binding Path = (Validation.Errors), ElementName=gvAddCustomer}" >
                <ItemsControl.ItemTemplate>
                    <DataTemplate>                        
                                <TextBlock FontSize="18" Text="{Binding Path=ErrorContent}" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

My TextBox uses the ErrorTemplate to display the errors beside the TextBox control and it displays correctly with the error message. Here is the style: 

 <Style x:Key="TextBoxStyle" TargetType="TextBox">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right"
                        Foreground="Orange"
                        FontSize="12pt"
                        Text="{Binding ElementName=MyAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
                            </TextBlock>
                            <Border BorderBrush="Red" BorderThickness="2">
                                <AdornedElementPlaceholder Name="MyAdorner" />
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

有人能解释一下为什么绑定到ItemsControl时Validation.Errors不包含任何内容吗?

我的验证过程非常类似:

<TextBox
    Style="{StaticResource TextBoxValidationError}"
    Name="PatientFirstName" TabIndex="0">
    <TextBox.Text>
        <Binding Path="Patient.PatientFirstName" UpdateSourceTrigger="PropertyChanged">
            <Binding.ValidationRules>
                <bs:NameRequiredRule />
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
</TextBox>

谢谢你的回答,但我认为你误解了这个问题!我已经创建了一个自定义文本框,即使您没有在文本框中放入任何内容,它也会触发验证。但是绑定到ItemsControl的Validation.Errors属性即使在窗口无效时也返回null。您使用什么来创建要查找的错误?在我的代码隐藏类中,我有一个名为NameRequiredRule的验证器类。如果存在验证错误,它会添加一个错误对象。
System.Windows.Data.BindingExpression be;
DependencyProperty txtProp = System.Windows.Controls.TextBox.TextProperty;
be = PatientFirstName.GetBindingExpression(txtProp);
be.UpdateSource();