C# WPF 工具提示未显示在子网格上
由于某种原因,工具提示不会显示在我的子网格中。
<Grid DockPanel.Dock="Top"
Width="300px"
Height="250px"
ToolTipService.ToolTip="MainGrid Tooltip">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1.25*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
ToolTip="mygrid tooltip 2">
<StackPanel Orientation="Horizontal">
<Image Width="15"
Source="<<INSERT IMAGE FILE LOCATION HERE>>"
ToolTipService.ToolTip="Child Grid Tooltip 1"/>
<TextBlock Width="80"
Text="Random Text 2"
ToolTipService.ToolTip="Child Grid Tooltip 2"/>
<TextBlock Width="80"
Text="Random Text 3"
ToolTipService.ToolTip="Child Grid Tooltip 3"/>
</StackPanel>
</Grid>
我不断显示“mygrid tooltip 2”,即使我已经覆盖了它的子项的工具提示 - 它不会显示。
我已经通过在资源字典中使用控制模板来降低复杂性,直到现在只剩下上面的内容,但仍然什么也没有。
任何想法都将不胜感激,也许还有我可以阅读的链接。我的 WPF 书籍和 msdn 目前没有产生任何实质性内容。
谢谢,
For some reason the tooltips won't show in my child grid.
<Grid DockPanel.Dock="Top"
Width="300px"
Height="250px"
ToolTipService.ToolTip="MainGrid Tooltip">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1.25*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
ToolTip="mygrid tooltip 2">
<StackPanel Orientation="Horizontal">
<Image Width="15"
Source="<<INSERT IMAGE FILE LOCATION HERE>>"
ToolTipService.ToolTip="Child Grid Tooltip 1"/>
<TextBlock Width="80"
Text="Random Text 2"
ToolTipService.ToolTip="Child Grid Tooltip 2"/>
<TextBlock Width="80"
Text="Random Text 3"
ToolTipService.ToolTip="Child Grid Tooltip 3"/>
</StackPanel>
</Grid>
I keep getting the "mygrid tooltip 2" being displayed, even though I have overridden the tooltip for it's children - it won't show.
I have lessened the complexity from having control templates in resource dictionaries until I am now only left with this above, and still nothing.
any ideas will be greatly appreciated, also perhaps links where I can read up about it. my WPF book and msdn isn't producing anything substancial at the moment.
thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了让 WPF 中的某些内容能够显示工具提示,它必须对命中测试可见。
对于面板,这是通过将背景颜色设置为除
null
(这是所有面板的默认设置)之外的颜色来完成的。如果您希望面板不可见但仍符合命中测试的条件,则可以使用透明
作为背景颜色。In order for something in WPF to be able to display a tooltip, it has to be visible to hit testing.
In the case of panels, this is done by setting the background color to something besides
null
(which is the default for all panels). If you want your panels to be invisible but still be eligible for hit testing, you can useTransparent
as the background color.@Isak,谢谢,您的
Background="Transparent"
帮助我解决了最终的问题。我最终抛弃了具有定义的行/列的网格,并采用了具有嵌套 StackPanel 的网格。
以前 Grid.Rows 是由 ContentControls 填充的,我用包含我需要显示的信息的本地 Stackpanels 替换了它,这似乎已经解决了这个问题,但只有在我将“Transparent”标签添加到 stackpanels 以及
在父网格中的图像用作背景图像。
这是我当前解决方案的一个示例,第二部分替换了我原来的帖子中看到的代码。
首先,在获取相关代码之前的基本源文件布局如下所示:
然后我的解决方案网格如下[替换初始后代码]:
如果您遇到类似的事情,希望这对其他人有帮助。
@Isak, thanks, your
Background="Transparent"
assisted in my final solution.I ultimately threw away the Grid with defined rows / columns, and resorted to a Grid with nested StackPanels.
Previously the Grid.Rows were being populated by ContentControls, I replaced this with local Stackpanels containing the information I needed to display and that seemed to have solved it, but only after I added the "Transparent" tag to the stackpanels and also a
on an image in the parent grid which serves as a background image.
Herewith an example of my current solution, the second part which replaces the code seen in my original post.
First, the basic source file layout before getting to the code in question looks like this:
And then my solution grid as follows [replaces initial post code]:
Hope this helps somebody else should you experience something similar.