Error DataGridCell Validation.ErrorTemplate

I am trying to set the Validation.ErrorTemplate template from DataGridCells, here is the xaml code:

<Style x:Key="{x:Type DataGridCell}" x:Uid="dataGridCellErrorTemplate" TargetType="{x:Type DataGridCell}"> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate > <Border BorderBrush="Green" BorderThickness="2" ToolTip="Heidenei"></Border> </ControlTemplate> </Setter.Value> </Setter> <!-- following line only for demonstration that the setter is working ... --> <Setter Property="Background" Value="Aquamarine"></Setter> </Style> 

while the datagridcells background is successfully colored green (regardless of any validation result), the used Validation.ErrorTemplate template is still the default, i.e. a red border.

I know that stackoverflow had similar problems, for example. DataGridCell modeling error pattern but they really don't solve my problem.

Any help is appreciated

Franc

+4
source share
2 answers

I think I have the same problem.

When using a DataGridTemplateColumn content is ContentPresenter using ContentPresenter . This content presenter uses the default error pattern.

I cannot find a direct way to remove this template for a single DataGridTemplateColumn , but you can remove it for all content presenters in a DataGrid by adding a style to the DataGrid resources.

 <DataGrid.Resources> <Style TargetType="ContentPresenter"> <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/> </Style> </DataGrid.Resources> 
+4
source

I was lucky to remove the annoying red border using the following TextBlock style.

 <Style TargetType="TextBlock"> <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/> </Style> 
0
source

Source: https://habr.com/ru/post/1401620/


All Articles