DataGridCell Validation.ErrorTemplate被忽略 [英] DataGridCell Validation.ErrorTemplate ignored

查看:410
本文介绍了DataGridCell Validation.ErrorTemplate被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to set the Validation.ErrorTemplate of the DataGridCells, here's 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>

,而数据网格单元格的背景成功地使用绿色(与任何验证结果无关)使用的验证。 ErrorTemplate仍然是默认的,即红色边框。

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

我知道在stackoverflow中有类似的问题,例如
造型DataGridCell错误模板
但他们并没有真正解决我的问题

I know there have been similar issues here in stackoverflow, e.g. Styling DataGridCell Error Template but they do not really solve my problem.

任何帮助不胜感激

Frank

推荐答案

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

I believe that I'm experiencing the same issue.

当使用 DataGridTemplateColumn 时,内容将显示一个 ContentPresenter 。此内容演示者使用默认错误模板。

When using a DataGridTemplateColumn the content is presented with a ContentPresenter. This content presenter uses the default error template.

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

I can't find a direct way to remove this template for an individual DataGridTemplateColumn but you can remove it for all content presenters in the DataGrid by adding a style to the DataGrid's resources.

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

这篇关于DataGridCell Validation.ErrorTemplate被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆