I'm trying to set the enable state of a button depending on the validation result of the items in an ItemsControl (The user should not be able to save if any validation errors exist).
I've done this successfully with other input fields like so:
<Style x:Key="SaveButtonStyle" TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MinValueTextBox, Path=(Validation.HasError)}" Value="True">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
However now I also have an ItemsControl bound to a collection which I wish to validate in the same manner. The collection objects implement IDataErrorInfo.
How would I do this since I can't specify ElementName in the DataTrigger of the button style?
I want to disable the save button if not all input fields of all the collection items are valid.
Here is the ItemsControl code with DataTemplate:
<ItemsControl ItemsSource="{Binding FeedTypes}" ItemTemplate="{StaticResource FeedTypeDataTemplate}"/>
<DataTemplate x:Key="FeedTypeDataTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Label Content="{x:Static p:Resources.FeedTypeNameLabel}"/>
<TextBox Name="FeedTypeNameTxtBox" Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Name,
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Grid.Column="1"/>
<Label Content="{x:Static p:Resources.KgPerLitreLabel}" Grid.Column="2"/>
<TextBox x:Name="FeedTypeKgPerLitreTxtBox" Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=KgPerLitre,
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Grid.Column="3"/>
</Grid>
</DataTemplate>
regards!