0
내 ItemsControl에 Validation.Errors를 표시하는 데 문제가 있습니다. Validation.Errors에는 아무것도 포함되어 있지 않습니다. 나는 BindingGroup을 사용하지 않지만 내 자신의 사용자 정의 TextBoxes를 사용합니다. 나는 ItemsControl에 바인딩 할 때 Validation.Errors 아무것도 포함하지 않는 이유WPF Validation.Errors Contains Nothing
<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에 코드는?
답장을 보내 주셔서 감사합니다.하지만 질문에 대해 오해 하셨을 것입니다! TextBox에 아무 것도 넣지 않아도 유효성 검사를 실행하는 Custom TextBox를 만들었습니다. 그러나 ItemsControl에 바인딩 된 Validation.Errors 속성은 Window가 유효하지 않은 경우에도 null을 반환합니다. – azamsharp
찾고있는 오류를 만들기 위해 무엇을 사용하고 있습니까? 내 코드 숨김 클래스에는 "NameRequiredRule"이라는 유효성 검사기 클래스가 있습니다. 유효성 검사 오류가있는 경우 오류 객체를 추가합니다. – Jay