I have a Datagrid which has a DataGridTemplateColumn containing a ListView whose Itemsource is bound to an array of string.
Within that ListView I have defined an ItemTemplate as I want the Foreground of each item in the list to be dependant on condition - so that's applied to a TextBlock.
I want a tooltip to display when each item in the ListView is hovered over, so I have a Tooltip defined in that TextBlock
What I'm trying to do is have that Tooltip display the title/detail about a specific item by using a converter (to get the index of the item in a different list).
For this I need the Tooltip to know the ListView item but I can't seem to get that to work. The TextBlock itself retrieves it using Path=.
, I have tried naming the TextBlock ListItem
and retrieving it as ElementName to no avail - the result is just empty string.
Here's the relevant xaml (with formatting properties removed).
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="ListItem" Text="{Binding Path=.}" Foreground="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ConvertItemToColour}}">
<TextBlock.ToolTip>
<ToolTip>
<StackPanel Orientation="Vertical">
<Label>
<TextBlock Text="{Binding ElementName=ListItem, Path=Text, Converter={StaticResource ConvertItemToTitle}}"/> <!-- Item Title -->
</Label>
<Label>
<TextBlock/> <!-- Item Description -->
</Label>
</StackPanel>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</DataTemplate>
</ListView.ItemTemplate>