我正在尝试显示由ItemsControl需要从概念上不相关的源提取数据的项目生成的工具提示.例如,假设我有一个Item类,如下所示:
public class Item
{
public string ItemDescription { get; set; }
public string ItemName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我可以使用工具提示在ItemsControl中显示Item,如下所示:
<ItemsControl x:Name="itemsControl" ItemsSource="{Binding Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemName}">
<TextBlock.ToolTip>
<ToolTip>
<TextBlock Text="{Binding ItemDescription}" />
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
但说我有一个可以通过访问其他属性DataContext的ItemsControl.有没有办法从工具提示中做到这一点?例如,
<ItemsControl x:Name="itemsControl" ItemsSource="{Binding Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemName}">
<TextBlock.ToolTip>
<ToolTip>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="{Binding ItemDescription}" />
<TextBlock Grid.Row="1" Text="{Bind this to another property of the …Run Code Online (Sandbox Code Playgroud)