使用textbox,当我将以下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>
但它只适用于文本框,如何使用DataGridTextColumn做类似的事情?
答案 0 :(得分:14)
只需使用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>