在DataGridCell工具提示中显示验证错误 [英] Display validation error in DataGridCell tooltip
问题描述
一切都好,好但是,我想要验证错误消息显示在无效单元格的工具提示中,因此用户有一些错误的指示。我目前有:
< 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屋!