2016-10-04 95 views
0

爲什麼在WPF中將項目懸停在透明控件後面時不顯示工具提示? 我如何通過隱形控件使UserControl顯示工具提示?我也嘗試用矩形而不是按鈕,結果相同,沒有工具提示。通過不可見控件/按鈕顯示工具提示WPF

<Grid Height="100" Width="100"> 
    <Rectangle Fill="Red" ToolTip="Tooltip is behind button" Height="20" Width="20" Margin="7,40,73,40"/> 
    <Rectangle Fill="Yellow" ToolTip="Also behind" Height="20" Width="20" Margin="67,40,13,40"/> 
    <Button Opacity="0" Background="Transparent" Height="100" Width="100"/> 
</Grid> 

回答

1

Button設置IsHitTestVisible="False"

用戶評論後編輯#1。

我認爲你應該這樣做:

<Button BorderThickness="0" BorderBrush="Transparent" Background="Transparent" Height="100" Width="100"> 
    <Grid Height="100" Width="100"> 
     <Rectangle Fill="Red" ToolTip="Tooltip is behind button" Height="20" Width="20" Margin="7,40,73,40"/> 
     <Rectangle Fill="Yellow" ToolTip="Also behind" Height="20" Width="20" Margin="67,40,13,40"/> 
    </Grid> 
</Button> 
+0

按鈕似乎沒有現在的點擊來應對呢? – Snovva1

+0

@ Snovva1然後你無法實現你想要的工具提示。 – AnjumSKhan

+0

@s看到我更新的答案 – AnjumSKhan

0

設置面板Z-索引,以便使你的元素前:

<Grid Height="100" Width="100"> 
     <Rectangle Panel.ZIndex="2" Fill="Red" ToolTip="Tooltip is behind button" Height="20" Width="20" Margin="7,40,73,40"/> 
     <Rectangle Panel.ZIndex="1" Fill="Yellow" ToolTip="Also behind" Height="20" Width="20" Margin="67,40,13,40"/> 
     <Button Panel.ZIndex="0" Opacity="0" Background="Transparent" Height="100" Width="100"/> 
    </Grid> 
+0

如果矩形點擊按鈕不會觸發事件... – Snovva1