gpt4 book ai didi

wpf DataGrid.RowValidationErrorTemplate - 如何实际更改行外观而不是标题行?

转载 作者:行者123 更新时间:2023-12-01 09:56:09 29 4
gpt4 key购买 nike

我目前正在为我的数据网格使用行验证。当行无效时,我正在尝试更改行的外观。到目前为止,我的代码在视觉报告错误方面:

<DataGrid.RowValidationErrorTemplate>
<ControlTemplate>
<Grid Margin="0,-2,0,-2" Background="Red" HorizontalAlignment="Stretch"
ToolTip="{Binding RelativeSource={RelativeSource
FindAncestor, AncestorType={x:Type DataGridRow}},
Path=(Validation.Errors)[0].ErrorContent}">
<TextBlock Text="!" FontSize="{TemplateBinding FontSize}"
FontWeight="Bold" Foreground="White"
HorizontalAlignment="Center" />
</Grid>
</ControlTemplate>
</DataGrid.RowValidationErrorTemplate>

这似乎只会影响我的标题行。有没有办法可以处理这个 RowValidationErrorTemplate 来修改行外观?我想让整行的背景变成红色或类似的颜色。

有什么想法吗?如果我需要为这个特定问题提供更多代码,请告诉我。提前致谢!

最佳答案

您可以更新 DataGridRow 类型的样式,并尝试根据行的验证标志设置错误背景。

这样的……

    <DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}"
BasedOn="{StaticResource (x:Type DataGridRow)}"> <!--BasedOn is optional-->
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>

如果这有帮助,请告诉我。

关于wpf DataGrid.RowValidationErrorTemplate - 如何实际更改行外观而不是标题行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6875116/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com