如何在DataGridTextColumn的工具提示中显示IDataErrorInfo的错误? [英] How to display IDataErrorInfo's error in tooltip on DataGridTextColumn?

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

问题描述

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

但它只适用于文本框,如何使用DataGridTextColumn做类似的事?

解决方案

只需使用 DataGridTextColumn.ElementStyle 和/或 DataGridTextColumn.EditingElementStyle ,例如:

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


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 ?

解决方案

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>

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

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