C# WPF 工具提示未显示在子网格上 [英] C# WPF Tooltips not showing on child grid

查看:24
本文介绍了C# WPF 工具提示未显示在子网格上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,工具提示不会显示在我的子网格中.

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>

我一直在显示mygrid tooltip 2",即使我已经覆盖了它的孩子的工具提示 - 它不会显示.

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.

任何想法将不胜感激,也可能是我可以阅读的链接.我的 WPF 书籍和 msdn 目前没有产生任何实质性的东西.

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.

谢谢,

推荐答案

@Isak,谢谢,你的 Background="Transparent" 帮助了我的最终解决方案.

@Isak, thanks, your Background="Transparent" assisted in my final solution.

我最终放弃了带有定义行/列的网格,并使用了带有嵌套 StackPanel 的网格.

I ultimately threw away the Grid with defined rows / columns, and resorted to a Grid with nested StackPanels.

以前 Grid.Rows 是由 ContentControls 填充的,我用包含我需要显示的信息的本地 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

IsHitTestVisible="False"

在父网格中用作背景图像的图像上.

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:

<ResourceDictionary xmlns="...
  <DataTemplate DataType="...
    <Grid Style="...
      <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

       <Grid Name="LeftColumn" Grid.Column="0">
         <TextBlock Style="{StaticResource TextHeader}"
                    Text="Review 10 Patients"/>

         <Image RenderOptions.BitmapScalingMode="NearestNeighbor"
                SnapsToDevicePixels="True"
                Stretch="None"
                DockPanel.Dock="Top"
                IsHitTestVisible="False"
                Source="((INSERT IMAGE HERE))" Margin="0,-2,0,10"/>

然后我的解决方案网格如下[替换初始帖子代码]:

And then my solution grid as follows [replaces initial post code]:

       <StackPanel>

         <StackPanel Background="Transparent" Orientation="Horizontal">
           <Image Style="{StaticResource InfoImage}" Margin="3">
             <ToolTipService.ToolTip>
               <ToolTip Width="200" Style="{StaticResource ToolTip}"
                        Content="ToolTip 1"/>
             </ToolTipService.ToolTip>
           </Image>

           <TextBlock Width="140" Style="{StaticResource Text_SelfTitle}"
                      Text="Text Field 1"/>
           <TextBlock Width="145" Style="{StaticResource Text_SelfQuestions}"
                      Text="Text Field 2"/>
         </StackPanel>

         <StackPanel Background="Transparent" Orientation="Horizontal">
            ((... similar as above...))
         </StackPanel>

         <StackPanel Background="Transparent" Orientation="Horizontal">
            ((... similar as above...))
         </StackPanel>

       </StackPanel>
     </Grid>
  </Grid>

如果您遇到类似的情况,希望这对其他人有所帮助.

Hope this helps somebody else should you experience something similar.

这篇关于C# WPF 工具提示未显示在子网格上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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