在DataGridCell工具提示中显示验证错误 [英] Display validation error in DataGridCell tooltip

查看:145
本文介绍了在DataGridCell工具提示中显示验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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>


I have a WPF DataGrid which displays types that implement IDataErrorInfo. As expected when the validation fails the row gets the red exclamation mark and the invalid cell gets the red highlight.

This is all well and good; however, I want the validation error message to display in the tooltip of the invalid cell so the user has some indication of what is wrong. I presently have:

<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Setter Property="ToolTip"
                Value="{Binding RelativeSource={RelativeSource Self},
                                                Path=(Validation.Errors[0].ErrorContent}"/>
     </Style>
</DataGrid.CellStyle>

This approach works for TextBox but not for DataGridCell. What is the difference?

解决方案

I have something similiar in a project I'm working on right now, and it goes something like this:

<DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
        <Setter Property="DataGridCell.ToolTip"
                Value="{Binding RelativeSource={RelativeSource Self},
                                                Path=(Validation.Errors)[0].ErrorContent}"/>
     </Style>
</DataGridTextColumn.ElementStyle>

这篇关于在DataGridCell工具提示中显示验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆