【问题标题】:Display tooltip through invisible control /button WPF通过隐形控件/按钮 WPF 显示工具提示
【发布时间】:2016-10-04 07:35:09
【问题描述】:

为什么在 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>

【问题讨论】:

    标签: wpf


    【解决方案1】:

    IsHitTestVisible="False" 设置为Button

    在用户 cmets 之后编辑 #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>
    

    【讨论】:

    • 按钮现在似乎没有响应点击?
    • @Snovva1 那么你无法用工具提示实现你想要做的事情。
    • 我认为这解决了我的问题。我会测试它并告诉你。
    【解决方案2】:

    设置面板 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-25
      • 2014-07-29
      相关资源
      最近更新 更多