我在网格中有一个BindingGroup:
<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>
...
我的网格有一个ErrorTemplate:
<ControlTemplate x:Key="BindingGroupШаблОш">
<Border BorderBrush="Blue" BorderThickness="2">
<StackPanel>
<Label Content="My BindingGroup Error should be here!"></Label>
<AdornedElementPlaceholder />
</StackPanel>
</Border>
</ControlTemplate>
我想从我的ControlTemplate访问Validation.Errors [0] .ErrorContent以在我的Label中显示它。可能吗?你能帮我吗?
答案 0 :(得分:4)
尝试
<ControlTemplate x:Key="BindingGroupШаблОш">
<Border BorderBrush="Blue" BorderThickness="2">
<StackPanel>
<Label Content="{Binding Path=[0].ErrorContent}"></Label>
<AdornedElementPlaceholder />
</StackPanel>
</Border>
</ControlTemplate>