WPF Styles and Tooltips Question
- by A.R.
I have a style that I am using to make dynamic tooltips on certain text boxes like so.
<Style TargetType="{x:Type TextBox}">
<Setter Property="MinWidth" Value="100"/>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<!-- item of interest -->
<Setter Property="ToolTip">
<Setter.Value>
<MultiBinding Converter="{StaticResource ErrorMessageConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="Tag"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
This works very well, but if I want to use a more complex tooltip I can't figure out how to bind to 'Tag' anymore for the converter value. For example;
...
<Setter Property="ToolTip">
<Setter.Value>
<StackPanel>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ErrorMessageConverter}">
<!-- item of interest -->
<Binding RelativeSource=" what goes here?? "/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<Image/>
</StackPanel>
</Setter.Value>
</Setter>
...
I have tried several flavors of 'FindAncestor' and what not for the relative source, but I can't get anything to work. Any ideas??
UPDATE: 12-29-2010 : Here is the correct code, answer provided by our friend Goblin below. Works perfectly!
...
<Setter Property="ToolTip">
<Setter.Value>
<!-- Item of interest -->
<ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}">
<StackPanel>
<Image/>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ErrorMessageConverter}">
<Binding Path="Tag"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</ToolTip>
</Setter.Value>
</Setter>
...