Reputation: 2915
I have a Datagrid, where the rows are bound to viewmodels.
In my first column, I have an image control, which binds to the itemno in the row. This works fine.
Now, I want a tooltip, on this image, that shows a larger version of the image. I assumed it was quite easy, but I have realized, that the tooltip, probably doesn't get the datacontext of the row.
So, how do I get the tooltip, to bind to the same data as the row is bound to? In my code below, ItemNo on the tooltip is null, but on the "parent" image control, it has the correct value.
<DataGridTemplateColumn Header="Image" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<controls:ItemImage Width="16" Height="16" DataContext="{Binding ItemNo, IsAsync=True}" >
<controls:ItemImage.ToolTip>
<StackPanel>
<controls:ItemImage Width="300" Height="300" DataContext="{Binding ItemNo, IsAsync=True}" />
<Label Content="{Binding ItemNo}" />
</StackPanel>
</controls:ItemImage.ToolTip>
</controls:ItemImage>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Upvotes: 2
Views: 834
Reputation: 2579
Your tooltip dataContext is already set to ItemNo by default; that's why resetting it to:
<controls:ItemImage Width="300" Height="300" DataContext="{Binding ItemNo, IsAsync=True}" />
...doesn't work.
Just remove DataContext="{Binding ItemNo, IsAsync=True}"
Use snoop it will help you in viewwing binding errors or the already set dataContext.
Upvotes: 3