【发布时间】:2018-09-21 06:06:41
【问题描述】:
我有一个位于矩形顶部的 WPF 标签。这些矩形有单独的工具提示。我想显示底层 Rectangle 的 Tooltip 而忽略 Label 的 Tooltip,我该如何在 wpf/c# 中做到这一点。
【问题讨论】:
-
请在您的问题下方分享代码和其他详细信息。还要检查stackoverflow.com/questions/46004591/…
我有一个位于矩形顶部的 WPF 标签。这些矩形有单独的工具提示。我想显示底层 Rectangle 的 Tooltip 而忽略 Label 的 Tooltip,我该如何在 wpf/c# 中做到这一点。
【问题讨论】:
您可以将标签的IsHitTestVisible 属性设置为False,这样矩形将接收来自鼠标而不是标签的输入。
【讨论】:
如果没有代码,很难说出你真正想要它做什么
我会简单地对工具提示使用相同的方法
<Label Name="L1" ToolTipOpening="ToolTipMethod">
<Label Name="L2" ToolTipOpening="ToolTipMethod">
private void ToolTipMethod(object sender, ToolTipEventArgs e)
{
//your code
}
【讨论】:
我想你可能想要这样的东西:
这只是纯 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>
当然,您可以找到更好的方法来定位标签并定义它们的大小以获得您想要的,这只是一个示例。
【讨论】: