我正在尝试设置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>虽然数据网格单元的背景成功地着色为绿色(独立于任何验证结果),但使用的Validation.ErrorTemplate仍然是默认的,即红色边框。
我知道在stackoverflow中也有类似的问题,例如Styling DataGridCell Error Template,但它们并没有真正解决我的问题。
任何帮助我们都将不胜感激
弗兰克
发布于 2013-02-21 07:12:18
我相信我也遇到了同样的问题。
当使用DataGridTemplateColumn时,内容用ContentPresenter表示。此内容演示者使用默认错误模板。
我无法找到直接删除单个DataGridTemplateColumn的模板的方法,但是您可以通过向数据网格的资源添加样式来为DataGrid中的所有内容呈现者删除该模板。
<DataGrid.Resources>
<Style TargetType="ContentPresenter">
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
</Style>
</DataGrid.Resources>发布于 2014-09-17 19:29:51
通过使用下面的TextBlock样式,我幸运地删除了恼人的红色边框。
<Style TargetType="TextBlock">
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
</Style>https://stackoverflow.com/questions/9721960
复制相似问题