With textbox, it works well when I put the following xml in App.xml :
使用文本框,当我将以下xml放在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 ?
但它只适用于文本框,如何使用DataGridTextColumn做类似的事情?
1 个解决方案
#1
14
Simply use DataGridTextColumn.ElementStyle
and/or DataGridTextColumn.EditingElementStyle
, for example:
只需使用DataGridTextColumn.ElementStyle和/或DataGridTextColumn.EditingElementStyle,例如:
<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>
#1
14
Simply use DataGridTextColumn.ElementStyle
and/or DataGridTextColumn.EditingElementStyle
, for example:
只需使用DataGridTextColumn.ElementStyle和/或DataGridTextColumn.EditingElementStyle,例如:
<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>