2

我有一个带有细线的图表作为标记,用户可以将鼠标悬停在上面以获取它们的值。

我想让工具提示激活的区域更大,但保持实际线的大小相同,因为实际悬停非常困难。

我还有一条用户可以拖动的线,很难找到精确的点来单击和拖动。

这是我的标记模板,但我不确定如何实现这个目标,谁能指出我正确的方向?

<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>
  • 视觉工作室 2015
  • WPF
  • C#
  • 基础设施 XamDataChart
4

2 回答 2

3

您的实际问题是您没有使用Fill propertyof Path,因此在创建此形状时,行之间实际上没有任何内容,这就是为什么如果您在指针位于 this 内IsMouseOver时检查属性,它将返回。但是,如果您指定结果将如预期的那样。MouseshapefalseFill property

Fill property如下使用,如果任何地方都变形了,ToolTip会是visibleMousePath这样。:

 Fill="Transparent"

所以你的输出不会在视觉上受到影响。下面是一个示例程序。

XAML:

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

输出:

工具提示

Sorry,don't know how to capture鼠标in screenshot, but mouse is in between the shape while image was captured. Remove填充属性from路径and then see the change in ouput.

于 2016-05-07T13:20:07.600 回答
2

如果我理解正确,您只想在路径表示的矩形内显示工具提示。如果是这样,您可以将路径包装在透明边框中并在边框上设置工具提示:

    <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>
于 2016-05-06T10:35:25.860 回答