WPF Datagrid cell with validation error style

I am trying to change the default style for a DataGridCell (in the WPF Toolkit DataGrid) when there is a validation error. By default, a red frame is used. How can I post my own template?

Thanks.

+5
source share
2 answers

Try the following:

<!-- Cell Style --> <Style x:Key="CellErrorStyle" TargetType="{x:Type TextBlock}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> <Setter Property="Background" Value="Yellow"/> </Trigger> </Style.Triggers> </Style> 

And use it:

  <DataGrid.Columns> <DataGridTextColumn ElementStyle="{StaticResource CellErrorStyle}"> </DataGridTextColumn> </DataGrid.Columns> 
+9
source

There's a good tutorial from Diederik Krols that does exactly what you ask for in the WPF Toolkit DataGrid.

+2
source

All Articles