Wpf – Display validation error in DataGridCell tooltip

datagridwpf

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.
enter image description here

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?

Best Answer

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>
Related Topic