У меня есть DataGrid, содержащий несколько столбцов.всякий раз, когда пользователь вводит недопустимые данные (например, недопустимые символы или не цифры в столбце целых чисел, ...), строка должна быть помечена как ошибочная в целом, но особенно в ошибочной ячейке.Точнее, «!» Должен отображаться в ControlTemplate, вся строка должна иметь красную границу размером 1 пиксель, а ошибочная ячейка должна получить красный фон с белым текстом дополнительно.
При использовании следующего стиля всеячейки строки получают красный фон:
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontFamily" Value="ArialMT"/>
<Setter Property="Height" Value="24"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="ValidationErrorTemplate">
<Setter.Value>
<ControlTemplate>
<Grid>
<Ellipse Width="12" Height="12" Fill="Red" Stroke="Black" StrokeThickness="0.5"/>
<TextBlock FontWeight="Bold" Padding="4,0,0,0" Margin="0" VerticalAlignment="Top" Foreground="White" Text="!" />
<!--<ToolTip {Binding RelativeSource={RelativeSourceSelf}, Path=(Validation.Errors)[0].ErrorContent}"/>-->
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<!--<DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridRow}}" Value="true" >-->
<!--<DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource Self}}" Value="true" >-->
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="IsEnabled" Value="True" />
</Trigger>
<Trigger Property="Validation.HasError" Value="false">
<!--<DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridRow}}" Value="false" >-->
<!--<DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource Self}}" Value="false" >-->
<Setter Property="ToolTip" Value="{x:Null}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="IsEnabled" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="textBlockErrStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridRow}}" Value="false" >
<Setter Property="ToolTip" Value="{x:Null}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=(Validation.HasError), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridRow}}" Value="true" >
<Setter Property="Background" Value="Red" />
<Setter Property="Foreground" Value="White" />
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
<!--<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/>-->
</DataTrigger>
</Style.Triggers>
</Style>
Вот код XAML:
<Grid>
<ct_ctrls:CTDataGrid x:Name="tagsGrid" ItemsSource="{Binding}" GridLinesVisibility="None" AlternatingRowBackground="#C3DDE5" AutoGenerateColumns="False" CanUserAddRows="True" IsReadOnly="False"
SelectionUnit="Cell" SelectionMode="Extended" BorderThickness="3" CellEditEnding="CellEditEnding" >
<!--<DataGrid.RowValidationErrorTemplate>
<ControlTemplate
</DataGrid.RowValidationErrorTemplate>-->
<DataGrid.RowValidationRules>
<!--<local:StringToIntValidationRule ValidationStep="UpdatedValue" />-->
</DataGrid.RowValidationRules>
<DataGrid.Columns>
<DataGridTextColumn x:Name="TagName" Header="Tag name" Width="*"
Binding="{Binding Mode=TwoWay, Path=RawTag.TagName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
ElementStyle="{StaticResource ResourceKey=textBlockErrStyle}" />
<DataGridTextColumn x:Name="TagCycle" Header="Cycle"
Binding="{Binding Mode=TwoWay, Path=RawTag.Cycle, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
ElementStyle="{StaticResource ResourceKey=textBlockErrStyle}">
</DataGridTextColumn>
<DataGridTextColumn x:Name="TagSource" Header="Source" Width="*"
Binding="{Binding Mode=TwoWay, Path=RawTag.Source, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
ElementStyle="{StaticResource ResourceKey=textBlockErrStyle}"/>
<DataGridTextColumn x:Name="Unassigned" Header="unassigned" Width="*"
Binding="{Binding Mode=OneWay, Path=RawTag.Unassigned, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=False, NotifyOnValidationError=False}"
ElementStyle="{StaticResource ResourceKey=textBlockUnassignedStyle}"/>
<DataGridTemplateColumn x:Name="editTagColumn" Header="" CanUserResize="True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<WrapPanel>
<Button x:Name="btnTagDelete" Click="BtnTagDelete_Click" CommandParameter="{Binding}" Height="15" Width="15" Margin="2">
<Button.Content>
<Image Source="../Resources/delete.png"></Image>
</Button.Content>
</Button>
</WrapPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</ct_ctrls:CTDataGrid>
</Grid>
Как мне изменить стиль?