【发布时间】:2012-03-15 14:34:49
【问题描述】:
我正在尝试设置 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>
虽然 datagridcells 的背景成功地被着色为绿色(独立于任何验证结果),但使用的 Validation.ErrorTemplate 仍然是默认的,即红色边框。
我知道在 stackoverflow 中也有类似的问题,例如 Styling DataGridCell Error Template 但他们并没有真正解决我的问题。
感谢任何帮助
弗兰克
【问题讨论】:
-
感谢您的反馈,但我不确定我是否理解。在我的场景中,数据网格单元不是由用户编辑(因此没有编辑控件),而是由后台进程编辑。我还是想用 IDataErrorInfo 来突出那些值有问题的字段。
-
当他们说“编辑控件”时,(我认为)他们的意思是“嵌入在每个
DataGridCell中的控件”。换句话说,模板可能会应用于单元格,但在创建内部控件时会被覆盖。这就是为什么您可能必须在创建 Row 时捕获,并循环遍历每个单元格以设置您自己的值..
标签: wpf validation datagrid idataerrorinfo