通过隐形控件/按钮WPF显示工具提示

时间:2016-10-04 07:35:09

标签: wpf

为什么在WPF中将项目悬停在透明控件后面时不显示工具提示? 如何让UserControl通过隐形控件显示工具提示?我也试过用矩形代替按钮,结果相同,没有工具提示。

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

2 个答案:

答案 0 :(得分:1)

IsHitTestVisible="False"设置Button

用户评论后编辑#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>

答案 1 :(得分:0)

设置面板ZIndex以便将元素放在前面:

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