WPF中列表框项目的自定义工具提示 [英] Custom tooltip for listbox item in WPF

查看:71
本文介绍了WPF中列表框项目的自定义工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListBox,它显示Talent对象的ObservableCollection.当用户将鼠标悬停在列表框中的每个项目上时,我想在工具提示中显示有关人才的几条信息.

I've got a ListBox that displays an ObservableCollection of Talent objects. When the user hovers over each item in the ListBox, I'd like to display in the ToolTip several pieces of information about the Talent.

我的列表框:

<ListBox ItemsSource="{Binding ElementName=CE_Races_racesLB, Path=SelectedItem.Talents}" ItemTemplate="{StaticResource removableTalentListTemplate}" />

ItemTemplate:

The ItemTemplate:

<DataTemplate x:Key="removableTalentListTemplate">
    <StackPanel>
        <TextBlock FontSize="13" Text="{Binding Path=tName}" VerticalAlignment="Center" Width="175" Height="18" Grid.Column="0" />
    </StackPanel>
</DataTemplate>

如果将ToolTipService.ToolTip ="{Binding Path = Description"添加到TextBlock属性,则可以显示人才描述.但是,当我尝试创建这样的自定义工具提示时:

I can display the Description of the Talent if I add ToolTipService.ToolTip="{Binding Path=Description" to the TextBlock properties. However, when I try to create a custom ToolTip like such:

<DataTemplate x:Key="removableTalentListTemplate">
    <StackPanel>
        <TextBlock FontSize="13" Text="{Binding Path=tName}" VerticalAlignment="Center" Width="175" Height="18" Grid.Column="0" />
            <TextBlock.ToolTip>
                <ToolTip>
                    <StackPanel>
                        <TextBlock Text="{Binding Path=Description}" />
                    </StackPanel>
                </ToolTip>
            </TextBlock.ToolTip>
        </TextBlock>
    </StackPanel>
</DataTemplate>

当我将鼠标悬停在ListBox项上时,工具提示仅显示"System.Windows.Controls.StackPanel".我真的很想创建一个显示很多信息的不错的工具提示,但是我无法克服这个障碍.这是现在的屏幕截图: http://silkforge.com/dev/ss.jpg .您看不到鼠标,但是可以在ListBox项目"Acute Hearing I"下看到工具提示.

When I go to mouseover the ListBox item, the tooltip just says "System.Windows.Controls.StackPanel". I'd really like to create a nice ToolTip showing lots of info but I can't get past this roadblock. Here's a screenshot of what it looks like now: http://silkforge.com/dev/ss.jpg. You can't see the mouse, but you can see the tooltip just under the ListBox item "Acute Hearing I".

推荐答案

您尝试过吗?

<TextBlock Text="{Binding Path=tName}">
  <ToolTipService.ToolTip>
    <StackPanel>
      <TextBlock Text="{Binding Path=Description}" />
    </StackPanel>
  </ToolTipService.ToolTip>
</TextBlock>

这篇关于WPF中列表框项目的自定义工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆