Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display IDataErrorInfo's error in tooltip on DataGridTextColumn?

Tags:

wpf

datagrid

With textbox, it works well when I put the following xml in App.xml :

    <Style TargetType="{x:Type TextBox}" x:Key="TextBoxValidationStyle">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip"
            Value="{Binding RelativeSource={RelativeSource Self}, 
                   Path=(Validation.Errors)[0].ErrorContent}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

But it only works for textbox, how to do a similar thing with DataGridTextColumn ?

like image 548
JatSing Avatar asked Nov 08 '11 04:11

JatSing


1 Answers

Simply use DataGridTextColumn.ElementStyle and/or DataGridTextColumn.EditingElementStyle, for example:

<DataGridTextColumn MinWidth="80" ...>
    <DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip"
                Value="{Binding RelativeSource={RelativeSource Self}, 
                       Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
like image 137
surfen Avatar answered Oct 16 '22 04:10

surfen