user999999928 user999999928 - 1 year ago 67
C# Question

Error Template Adorner on DataGridCheckBoxColumn Can't Be Overridden

<DataGridCheckBoxColumn Binding="{Binding Value, ValidatesOnDataErrors=True}"

I'm trying to remove the red box from the cell. The errortemplate=null in this doesn't change anything.

<Style TargetType="{x:Type DataGridCheckBoxColumn}" >
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>

That too doesn't do anything. I've tried DataGridCell, DataGridRow, ContentTemplate, Checkbox styles. Nothing removes the ugly looking red box from the cell.

I snooped it and found that an adorner is being made automatically, unnamed and templated. It's attached to the checkbox.

The only way I've gotten around it is to change to a DataGridTemplateColumn and make a Checkbox directly in a data template. However, this is roundabout and undo's a lot of other style templates I've done. Is there any way to make the Template columns, like Checkbox, not display the red error validation border around it?

The key here is that I want error validation. I just dont want the adorner it makes.

Answer Source

A possible solution might be styling the ElementStyle like this.

<DataGrid ItemsSource="{Binding Datas}" AutoGenerateColumns="False">
            <DataGridCheckBoxColumn Binding="{Binding Invalid, ValidatesOnDataErrors=True}" Header="Invalid" >
                    <Style TargetType="{x:Type CheckBox}">
                        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"></Setter>


To get rid of the red exclamationmark on the left do this:


on your DataGrid.