【问题标题】:WPF Label: Using the tooltip of the underlying ControlWPF 标签:使用底层控件的工具提示
【发布时间】:2018-09-21 06:06:41
【问题描述】:

我有一个位于矩形顶部的 WPF 标签。这些矩形有单独的工具提示。我想显示底层 Rectangle 的 Tooltip 而忽略 Label 的 Tooltip,我该如何在 wpf/c# 中做到这一点。

【问题讨论】:

标签: c# wpf


【解决方案1】:

您可以将标签的IsHitTestVisible 属性设置为False,这样矩形将接收来自鼠标而不是标签的输入。

【讨论】:

  • 谢谢,正是我要找的东西
【解决方案2】:

如果没有代码,很难说出你真正想要它做什么

我会简单地对工具提示使用相同的方法

<Label Name="L1" ToolTipOpening="ToolTipMethod">
<Label Name="L2" ToolTipOpening="ToolTipMethod">

private void ToolTipMethod(object sender, ToolTipEventArgs e)
{
    //your code
}

【讨论】:

    【解决方案3】:

    我想你可能想要这样的东西:

    这只是纯 xaml:

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
    
        <Rectangle Grid.Row="0"
                   ToolTip="Rectangle 1"
                   Fill="Red" />
    
        <Label Grid.Column="0"
               Content="Label"
               HorizontalAlignment="Left"
               VerticalAlignment="Top"
               Width="50"
               Height="30"
               Background="LightBlue"/>
    
        <Rectangle Grid.Column="1"
                   ToolTip="Rectangle 2"
                   Fill="IndianRed" />
    
        <Label Grid.Column="1"
               Content="Label"
               HorizontalAlignment="Left"
               VerticalAlignment="Top"
               Width="50"
               Height="30"
               Background="LightBlue"/>
    
        <Rectangle Grid.Column="2"
                   ToolTip="Rectangle 3"
                   Fill="Red" />
    
        <Label Grid.Column="2"
               Content="Label"
               HorizontalAlignment="Left"
               VerticalAlignment="Top"
               Width="50"
               Height="30"
               Background="LightBlue"/>
    </Grid>
    

    当然,您可以找到更好的方法来定位标签并定义它们的大小以获得您想要的,这只是一个示例。

    【讨论】:

      猜你喜欢
      • 2018-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      相关资源
      最近更新 更多