【问题标题】:Why ItemsControl.ToolTip is visible only if mouse over its item为什么 ItemsControl.ToolTip 只有在鼠标悬停在其项目上时才可见
【发布时间】:2012-07-29 00:18:49
【问题描述】:

这就是问题所在。我有一个 ItemsControl,如果用户将鼠标悬停在 ItemsControl 上,我想显示一个 ToolTip。看起来很简单,对吧?

这里是一个例子:

<ItemsControl BorderBrush="Blue" BorderThickness="1">
    <ItemsControl.ToolTip>
        <ToolTip Content="Text" />
    </ItemsControl.ToolTip>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <Label BorderBrush="Red" BorderThickness="1">One</Label>
    <Label BorderBrush="Red" BorderThickness="1">Two</Label>
    <Label BorderBrush="Red" BorderThickness="1">Three</Label>
    <Label BorderBrush="Red" BorderThickness="1">Four</Label>
    <Label BorderBrush="Red" BorderThickness="1">Five</Label>
    <Label BorderBrush="Red" BorderThickness="1">Six</Label>
    <Label BorderBrush="Red" BorderThickness="1">Seven</Label>
</ItemsControl>

使窗口宽度足够小,并让 WrapPanel 包裹一个项目。并尝试将鼠标悬停在 ItemsControl 上(ToolTip 不会出现),而不是悬停在 Label 上(ToolTip 会出现) .

为什么这种行为是正确的以及在这种情况下如何强制ToolTip出现?

【问题讨论】:

    标签: wpf xaml tooltip mouseover itemscontrol


    【解决方案1】:

    ToolTip for ItemsControl 在任何情况下都不会显示,除非你给 Background 一个 Brush

    <ItemsControl Background="Transparent"
    

    【讨论】:

    • 我在将鼠标悬停在 ItemsControl 的网格上时遇到了类似的问题。似乎除非您在控件上设置背景,否则如果您不在子元素上方,则鼠标悬停会落空。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    相关资源
    最近更新 更多