'TextBlock Tooltip converter with multiple data contexts
In my TextBlock.ToolTip I try to use a converter with two inputs. The first one Name just works fine.
Since the TextBlock is inside a DataGrid, I need to change the data context for the second input ListOfElements.
I tried using the PlacementTarget Keyword but it didn't worked.
I have the following XAML code:
<TextBlock.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TooltipConverter}">
<Binding Path="Name"></Binding>
<Binding Path="PlacementTarget.DataContext.ListOfElements" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=UserControl}"></Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</TextBlock.ToolTip>
What I am trying to achieve is accessing two parameters from two different data contexts.
Solution 1:[1]
Set the ToolTip property to a ToolTip element and bind to this one:
<TextBlock>
<TextBlock.ToolTip>
<ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TooltipConverter}">
<Binding Path="Name" />
<Binding Path="PlacementTarget.DataContext.ListOfElements"
RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType=ToolTip}" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mm8 |
