Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Validation.Errors from an 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 please help me?

like image 317
Anatoly U Avatar asked Oct 03 '22 23:10

Anatoly U


1 Answers

Try

<ControlTemplate x:Key="BindingGroupШаблОш">
  <Border BorderBrush="Blue" BorderThickness="2">
    <StackPanel>
      <Label Content="{Binding Path=[0].ErrorContent}"></Label>
      <AdornedElementPlaceholder />
    </StackPanel>
  </Border>
</ControlTemplate>
like image 68
Viv Avatar answered Oct 13 '22 12:10

Viv