我有一个包含行的数据网格,其中验证取决于他的兄弟姐妹。到目前为止,我正在使用 BindingGroups 和自定义 ValidationRule 同时验证多行。但我不知道如何更改无效行条目的外观。我返回一个 ValidationResult,我的网格出现红色边框,但我的样式被忽略。
到目前为止我的 xaml 样式代码:
<Style TargetType="{x:Type dg:DataGridRow}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="BorderThickness" Value="10"/>
<Setter Property="BorderBrush" Value="Green"/>
<Setter Property="Background" Value="#F6B39E"/>
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
编辑:也许我应该发布更多的代码
目前我有这个验证声明:
<dg:DataGrid.RowValidationRules>
<viewModel:StreamGridValidationRules />
</dg:DataGrid.RowValidationRules>
使用此代码,我上面的样式设置正确,但一次只能验证一行。由于我需要验证所有兄弟姐妹及其父母,因此我将代码更改为:
<dg:DataGrid.BindingGroup>
<BindingGroup Name="BindingGroup">
<BindingGroup.ValidationRules>
<viewModel:StreamGridValidationRules />
</BindingGroup.ValidationRules>
</BindingGroup>
</dg:DataGrid.BindingGroup>
这样,我在 BindingGroup 中获得了多个项目,但我的样式被完全忽略,并且网格仅获得标准的 1px 红色边框。
预先感谢您的任何提示和提示!
tS!
如果删除 x:Key="RowStyle" 会发生什么,它会起作用吗?
如果我很明显,但没有看到你的其余代码,请原谅我,我无法告诉。如果您正在命名一种样式,除非您明确将其设置为使用,否则它不会被使用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)