Access Validation.Errors from ErrorTemplate

I have a BindingGroup in a grid:

<Grid x:Name="" DataContext="{Binding Source={StaticResource }}" Grid.RowSpan="1" Grid.Row="1" HorizontalAlignment="Center"> <Grid.BindingGroup> <BindingGroup NotifyOnValidationError="True"> <BindingGroup.ValidationRules> <: ValidationStep="ConvertedProposedValue" /> </BindingGroup.ValidationRules> </BindingGroup> </Grid.BindingGroup> <Grid.Style> <Style> <Setter Property="Validation.ErrorTemplate" Value="{StaticResource BindingGroup}" /> </Style> </Grid.Style> ... 

And I have an ErrorTemplate for my grid:

 <ControlTemplate x:Key="BindingGroup"> <Border BorderBrush="Blue" BorderThickness="2"> <StackPanel> <Label Content="My BindingGroup Error should be here!"></Label> <AdornedElementPlaceholder /> </StackPanel> </Border> </ControlTemplate> 

I want to access Validation.Errors [0] .ErrorContent from my ControlTemplate to display it in my label. Is it possible? Could you help me?

+4
source share
1 answer

Try

 <ControlTemplate x:Key="BindingGroup"> <Border BorderBrush="Blue" BorderThickness="2"> <StackPanel> <Label Content="{Binding Path=[0].ErrorContent}"></Label> <AdornedElementPlaceholder /> </StackPanel> </Border> </ControlTemplate> 
+3
source

Source: https://habr.com/ru/post/1483687/


All Articles