wpf - TabItem : Show on header, 上的工具提示,但不在内容上

标签 wpf xaml tooltip tabcontrol tabitem

TabControl 的 TabItem 上的工具提示不仅会出现在 TabItem 的标题上,还会出现在任何未明确设置其自己的工具提示的 TabItem 内容上。

这是一个重现问题的示例:

<Window x:Class="TestToolTipsOnTabControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow">
    <Grid>
        <TabControl>
            <TabItem Header="Tab1"
                     ToolTip="Tooltip of tab1">
                <StackPanel>
                    <TextBlock Text="Content of tab1 with its own tooltip" 
                               ToolTip="Tooltip on content of tab1"/>
                    <TextBlock Text="more content of tab1" />
                </StackPanel>
            </TabItem>
            <TabItem Header="Tab2"
                     ToolTipService.ToolTip="Tooltip of tab2">
                <StackPanel>
                    <TextBlock Text="Content of tab2 with its own tooltip"
                               ToolTipService.ToolTip="Tooltip on content of tab2"/>
                    <TextBlock Text="more content of tab2" />
                </StackPanel>
            </TabItem>
            <TabItem Header="Tab3">
                <StackPanel>
                    <TextBlock Text="Content of tab3" />
                    <TextBlock Text="more content of tab3" />
                </StackPanel>
            </TabItem>
        </TabControl>
    </Grid>
</Window>

将鼠标指针移到“tab1 的更多内容”文本上将显示我想要的工具提示 只有显示在 TabItem 标题上。

有什么方法可以让工具提示只显示在 TabItem 标题上,而不显示在其他地方?

最佳答案

Is there any way to for the ToolTip to show up only on the TabItem header, but nowhere else?



您应该只申请 TooltipHeader不是全部TabItem所以将其更改为:
           <TabItem>
                <TabItem.Header>
                    <TextBlock Text="Tab1" 
                     ToolTip="Tooltip of tab1"/>
                </TabItem.Header>
                <StackPanel>
                    <TextBlock Text="Content of tab1 with its own tooltip" 
                               ToolTip="Tooltip on content of tab1"/>
                    <TextBlock Text="more content of tab1" />
                </StackPanel>
            </TabItem>

关于wpf - TabItem : Show on header, 上的工具提示,但不在内容上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17421647/

相关文章:

c# - 抑制 GridViewColumn 上的鼠标悬停效果

c# - 如何让组合框在弹出窗口关闭后直接适本地设置焦点

css - 使用 css 不显示工具提示框

c# - 在 WPF C# 中处理两个 UI 线程

c# - 从其他 Xaml 文件绑定(bind)到 Usercontrol 中的元素

c# - 多个键绑定(bind)到单个命令

javascript - Tippy.js 不显示数据属性中的内容?

jquery - 如果我们禁用单击按钮,工具提示不会隐藏

.net - 以编程方式强制 TextBox 值从 V 到 VM?

c# - 如何将焦点设置到 WPF 工具包数据网格的特定单元格