Reputation: 41
I am trying to display tool tip to a stack panel based on property HasValidationError.
<Style TargetType="StackPanel" x:Key="stackstyle">
<Style.Triggers>
<DataTrigger Binding="{Binding HasValidationError}" Value="True">
<Setter Property="ToolTip">
<Setter.Value>
<Binding Path="DisplayError"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
The code works fine. But it displays the tooltip under yellow background ( as normal tooltip). I need to customize it to change and include image. For that,
<Style TargetType="StackPanel" x:Key="stackstyle">
<Style.Triggers>
<DataTrigger Binding="{Binding HasValidationError}" Value="True">
<Setter Property="ToolTip">
<Setter.Value>
<StackPanel>
<!-- Have to add image and other decorations here -->
<TextBlock Text = "{Binding DisplayError}"/>
</StackPanel>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
It shows error when adding StackPanel to the . Please help me in solving.
Upvotes: 4
Views: 10169
Reputation: 59139
I don't know why that fails, but you can work around it by making the ToolTip a resource:
<StackPanel x:Key="ToolTipContents">
<!-- Have to add image and other decorations here -->
<TextBlock Text = "{Binding DisplayError}"/>
</StackPanel>
<Style TargetType="StackPanel" x:Key="stackstyle">
<Style.Triggers>
<DataTrigger Binding="{Binding HasValidationError}" Value="True">
<Setter Property="ToolTip" Value="{StaticResource ToolTipContents}"/>
</DataTrigger>
</Style.Triggers>
</Style>
or
<ToolTip x:Key="ToolTipContents">
<StackPanel>
<!-- Have to add image and other decorations here -->
<TextBlock Text = "{Binding DisplayError}"/>
</StackPanel>
</ToolTip>
<!-- etc -->
Also, the code you have will work as written in .NET 4, so the bug has been fixed.
Upvotes: 6