本文介绍了如何在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的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!