此XAML标记不起作用:
<Label Content="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
在此XAML代码中:
<Style x:Key="textBoxStyle" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Red"/>
<!--<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />-->
<Setter Property="ToolTip">
<Setter.Value>
<StackPanel Orientation="Vertical">
<Label Background="AliceBlue" Content="Input Error"/>
<Label Content="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
</StackPanel>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
我想在ToolTip属性中的Label中传递(Validation.Errors)[0]。ErrorContent数据。
答案 0 :(得分:0)
在RelativeSource Self
上使用Label
会将标签作为来源,而您需要TextBox
。试试RelativeSource FindAncestor
:
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TextBox}}, Path=(Validation.Errors)[0].ErrorContent}" />