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?
您应该只申请
Tooltip
到 Header
不是全部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/