wpf - 在 DataGridCell 工具提示中显示验证错误

标签 wpf datagrid

我有一个 WPF DataGrid,它显示实现 IDataErrorInfo 的类型。正如预期的那样,当验证失败时,该行会显示红色感叹号,无效单元格会显示红色突出显示。 enter image description here

这一切都很好;但是,我希望验证错误消息显示在无效单元格的工具提示中,以便用户了解错误所在。我目前有:

<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/

相关文章:

wpf - 使用 XAML 添加控件,但使用代码隐藏进行实例化

c# - C# 使用和 Java 导入之间的区别

c# - 在 View 模型中实现 IDataErrorInfo

C# + WPF : text mode equivalent of old DOS libraries or curses

c# - 如何在 DataGrid WPF 中显示 SortedDictionary?

c# - 如何从 WPF 中的基类型集合中为子类型集合自动生成 DataGrid 列?

C# WPF DataTemplate 在属性上设置背景颜色

c# - WPF DataGrid AutoGeneratingColumn 未可靠触发

c# - 将 DataGrid 绑定(bind)到 List<T>,但仅显示 T 属性的选择

c# - wpf excel 喜欢网格编辑吗?