C# 使工具提示区域大于控件
我有一个以细线为标记的图表,用户可以将鼠标悬停在上面以获取其值 我想使激活工具提示的区域变大,但保持实际线条的大小不变,因为用户很难将鼠标悬停在上面 我也有一行,用户可以拖动周围,这是非常困难的,以获得准确的地点点击和拖动 这是我的标记模板,但我不确定如何实现这一目标,有人能告诉我正确的方向吗C# 使工具提示区域大于控件,c#,wpf,tooltip,infragistics,xamdatachart,C#,Wpf,Tooltip,Infragistics,Xamdatachart,我有一个以细线为标记的图表,用户可以将鼠标悬停在上面以获取其值 我想使激活工具提示的区域变大,但保持实际线条的大小不变,因为用户很难将鼠标悬停在上面 我也有一行,用户可以拖动周围,这是非常困难的,以获得准确的地点点击和拖动 这是我的标记模板,但我不确定如何实现这一目标,有人能告诉我正确的方向吗 <Geometry x:Key="LineGeometry">M 0,0 L 5,0 L 5,15 L 0,15 Z</Geometry> <DataTemplate>
<Geometry x:Key="LineGeometry">M 0,0 L 5,0 L 5,15 L 0,15 Z</Geometry>
<DataTemplate>
<!-- Define the template for the actual markers -->
<Path Width="10"
Height="10"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Data="{StaticResource LineGeometry}"
Stretch="Fill"
Stroke="{StaticResource BlackBrush}"
StrokeThickness="0.5">
<Path.ToolTip>
<!-- Lots of tooltip definition stuff -->
</Path.ToolTip>
</Path>
</DataTemplate>
m0,0l5,0l5,15l0,15z
- Visual Studio 2015
- WPF
- C#
- 基础设施XamDataChart
<Border Background="Transparent">
<Path Width="10"
Height="10"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Data="{StaticResource LineGeometry}"
Stretch="Fill"
Stroke="Black"
StrokeThickness="0.5"></Path>
<Border.ToolTip>
<TextBlock Text="Tooltip" />
</Border.ToolTip>
</Border>
您的实际问题是您没有使用
路径的填充属性
,因此当创建此形状时,行与行之间实际上没有任何内容,这就是为什么当鼠标
指针位于此形状
内时,如果您选中IsMouseOver
属性,它将返回false
。但是,如果指定填充属性
,结果将与预期一致
按如下所示使用填充属性
,如果鼠标
位于路径
任意形状上,则工具提示
将可见
:
Fill="Transparent"
因此,您的输出不会受到视觉上的影响。下面是一个示例程序
XAML:
M 0,0 L 5,0 L 5,15 L 0,15 Z
输出:
抱歉,不知道如何在屏幕截图中捕获
鼠标,但在捕获图像时,鼠标位于形状之间。移除
填充
属性,然后查看输出中的更改。
<Window.Resources>
<Geometry x:Key="LineGeometry">M 0,0 L 5,0 L 5,15 L 0,15 Z</Geometry>
</Window.Resources>
<StackPanel>
<Path Width="100"
Height="100"
Name="path"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Data="{StaticResource LineGeometry}"
Stretch="Fill"
Stroke="Red" Margin="50"
StrokeThickness="5"
Fill="Transparent"
MouseLeftButtonDown="Path_MouseLeftButtonDown">
<Path.ToolTip>
<TextBlock Text="This is My Tooltip of Path" />
</Path.ToolTip>
</Path>
<StackPanel Orientation="Horizontal">
<Label Content="Is Mouse Over Path : " />
<Label Content="{Binding ElementName=path,Path=IsMouseOver}" BorderThickness="0.5" BorderBrush="Black"/>
</StackPanel>
</StackPanel>
这样做是不好的,不应该像上面那样在标记中添加更多的元素。这是个坏习惯。我们正在向逻辑树添加不必要的控件,并使标记更加模糊。