DataGridCell Validation.ErrorTemplate被忽略

Fra*_*nkE 6 validation wpf datagrid idataerrorinfo

我正在尝试设置DataGridCells的Validation.ErrorTemplate,这是xaml代码:

<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>
Run Code Online (Sandbox Code Playgroud)

当datagridcells的背景成功地变为绿色(与任何验证结果无关)时,使用的Validation.ErrorTemplate仍然是默认值,即红色边框。

我知道在stackoverflow中也有类似的问题,例如,设置 DataGridCell错误模板的样式, 但它们并不能真正解决我的问题。

任何帮助表示赞赏

坦率

Ter*_*nce 6

我相信我也遇到了同样的问题。

使用时DataGridTemplateColumn,内容会带有ContentPresenter。该内容演示者使用默认错误模板。

我找不到为个人删除此模板的直接方法,DataGridTemplateColumn但是您可以通过向DataGrid的资源中添加样式来为DataGrid中的所有内容呈现者删除它。

<DataGrid.Resources>
    <Style TargetType="ContentPresenter">
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
    </Style>
</DataGrid.Resources>
Run Code Online (Sandbox Code Playgroud)