我有一个 WPF DataGrid,它显示实现 IDataErrorInfo 的类型。正如预期的那样,当验证失败时,该行会显示红色感叹号,无效单元格会显示红色突出显示。
这一切都很好;但是,我希望验证错误消息显示在无效单元格的工具提示中,以便用户了解错误所在。我目前有:
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors[0].ErrorContent}"/>
</Style>
</DataGrid.CellStyle>
此方法适用于 TextBox
,但不适用于 DataGridCell
。有什么区别?
最佳答案
我现在正在做的一个项目中有类似的东西,它是这样的:
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="DataGridCell.ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Style>
</DataGridTextColumn.ElementStyle>
关于wpf - 在 DataGridCell 工具提示中显示验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7504408/