2016-08-16 64 views
1
<DataGridCheckBoxColumn Binding="{Binding Value, ValidatesOnDataErrors=True}" 
    Validation.ErrorTemplate="{x:Null}"/> 

我试图从单元格中移除红框。这里的errortemplate = null不会改变任何东西。DataGridCheckBoxColumn上的错误模板装饰器不能被覆盖

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

这也没有做任何事情。我试过DataGridCell,DataGridRow,ContentTemplate,复选框样式。没有任何东西能够从单元格中移除丑陋的红色框。

我探听了它,发现一个装饰器正在被自动创建,未命名和模板化。它连接到复选框。

我得到它的唯一方法是更改​​为DataGridTemplateColumn并直接在数据模板中创建复选框。然而,这是一个迂回的并且撤消了我做过的很多其他样式模板。有没有办法让模板栏像复选框一样不显示红色的错误验证边框?

这里的关键是我想要错误验证。我只是不想要它做的装饰者。

+0

您是否尝试将CheckBox样式作为资源添加到您的列中,并将复选框上的ValidationErrorTemplate设置为null? – lokusking

+0

是的。与使用OP作为DataGridCell,DataGridRow,ContentTemplate和Checkbox提到的样式TargetType相同。没有影响。 – user99999991

回答

1

可能的解决方案可能是像这样对ElementStyle进行造型。

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

注意

摆脱对左边的红色exclamationmark的做到这一点:

RowValidationErrorTemplate="{x:Null}" 

DataGrid

+0

所以这个工作,但我遗憾地失去了我的复选框列的所有我的方式,即使我使用BasedOn。我有一个只读datagridcheckboxcolumsn的样式,以及datagridcheckbox列上isreadonly为false时的样式。 我想我可以很聪明,并在datagridcolumn上做一个datatrigger,将样式切换为静态资源,具体取决于IsReadOnly是true还是false,但是失败。我希望这更容易。 – user99999991