1
나는 유효성 검사 오류를 표시하기위한 컨트롤 템플릿을 정의한 다음과 같이 난 뒤에 코드에서 유효성 검사를 설정하고WPF 유효성 검사 오류가 표시되지 않는 이유는 무엇입니까?
<TextBox Text="{Binding Text}" PreviewTextInput="textBox1_PreviewTextInput"
Validation.ErrorTemplate="{StaticResource validationTemplate}" />
을 : 다음과 같이
<ControlTemplate x:Key="validationTemplate">
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Right"
Background="Red"
TextWrapping="Wrap">
<TextBlock.Text>
<Binding Path="(Validation.Errors)[0].ErrorContent"
RelativeSource="{x:Static RelativeSource.Self}">
</Binding>
</TextBlock.Text>
</TextBlock>
<AdornedElementPlaceholder ></AdornedElementPlaceholder>
</DockPanel>
</ControlTemplate>
나는 텍스트 상자를 정의
private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
TextBox txtBox = (TextBox)sender;
....
....
ValidationError validationError = new ValidationError(new DummyValidator(),
txtBox.GetBindingExpression(TextBox.TextProperty));
Validation.MarkInvalid(txtBox.GetBindingExpression(TextBox.TextProperty), validationError);
validationError.ErrorContent = "This is wrong input";
e.Handled = true;
}
이제 문제는 유효성 검사가 실행되고 빨간색 스트립이 표시되지만 그 안에 오류 메시지가 표시되지 않습니다 !! 내가이
그것은 (경계 예외에서 인덱스) 콘솔에서 몇 가지 예외를 던지고 문제입니다 수 있음
<Binding Path="(Validation.Errors)[0].ErrorContent"
RelativeSource="{x:Static RelativeSource.Self}">
어디 잘못 갈거야 관한 나를 인도하세요? 내가 너무 빨리 입력 - -
내가 대신 – Gishu
예 기간의 공간은 {RelativeSource 자체}을 믿고 잘못 바로 –
가 여전히 작동하지 않는 것! :( – GuruC