<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>
虽然数据网格单元格的背景颜色成功变为绿色(与任何验证结果无关),但使用的Validation.ErrorTemplate仍然是默认的红色边框。
我知道在stackoverflow上有类似的问题,例如Styling DataGridCell Error Template,但它们并没有真正解决我的问题。
感谢您的帮助。
Frank
DataGridCell
中的控件”。换句话说,模板可能会应用于单元格,但在创建内部控件时被覆盖。这就是为什么您可能需要捕获行创建的时间,并循环遍历每个单元格以设置自己的值的原因。 - Jake Berger