2011-05-24 79 views
4

由於某些原因,工具提示不會顯示在我的子網格中。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提示2」顯示,即使我已經覆蓋了工具提示爲它的孩子 - 它不會顯示。

我減輕了資源字典中控制模板的複雜性,直到我現在只剩下上面的這一點,而且還是一無所有。

任何想法將不勝感激,也可能鏈接,我可以讀到它。我的WPF書籍和msdn目前沒有生成任何多餘的資金。

感謝,

+0

我試過了你的代碼,我沒有發現任何問題。工具提示顯示爲意圖。圖像和文本控件顯示各自的工具提示 – biju 2011-05-24 06:41:40

+0

我重新檢查了源文件,發現我忘記提及源xaml作爲「ResourceDictionary」啓動,並且頁面本身是「DataTemplate」,不知道是否應該重要,顯然它確實如此。 後端框架被設計爲使用這些數據模板並生成所需的頁面,除了子子網格之外,其完美地工作。 <資源字典> <電網Grid.Row = 「1」> <電網提示=工作> <網格工具提示=沒有工作> – Neville 2011-05-25 00:16:03

回答

1

@Isak,謝謝,您的Background="Transparent"輔助我的最終解決方案。

我最終扔掉了已定義的行/列的網格,並採用了嵌套StackPanels的網格。

之前GridController被ContentControls填充,我用本地的Stackpanels取代了這個,它包含我需要顯示的信息並且似乎已經解決了這個問題,但只是在向StackPanel添加了「Transparent」標記之後,還有一個

IsHitTestVisible="False" 

在父網格圖像作爲背景圖像。

這裏有一個我當前的解決方案的例子,第二部分取代了我原來的文章中看到的代碼。

首先,讓有問題的代碼之前基本源文件格式是這樣的:

<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"/> 

然後我的解決方案網格如下[替換初始郵編]:

 <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> 

希望這可以幫助別人你應該體驗類似的東西。

9

爲了讓東西在WPF能夠顯示工具提示,它必須是可見的命中測試。

在面板的情況下,通過將背景顏色設置爲null(這是所有面板的默認設置)之外的其他顏色來完成此操作。如果您希望您的面板不可見,但仍有資格進行命中測試,則可以使用Transparent作爲背景顏色。

<Grid Background="Transparent" ToolTip="This Will Be Shown"> 
    <!-- other stuff --> 
</Grid> 

<Grid ToolTip="This Will NOT Be Shown"> 
    <!-- other stuff --> 
</Grid> 
+0

伊薩克感謝,我已經試過你提出的後臺方法上面沒有成功,我甚至將其更改爲紅色,顯示確切的網格行,但仍然沒有工具提示。嘆。我已經在biju留言了一些額外的細節,可能會影響它嗎? – Neville 2011-05-25 00:19:26