【问题标题】:Make tooltip area bigger than the control使工具提示区域大于控件
【发布时间】:2016-05-03 09:47:11
【问题描述】:

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

我想让工具提示激活的区域更大,但保持实际线的大小相同,因为用户实际将鼠标悬停在上面是相当困难的。

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

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

<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>
  • Visual Studio 2015
  • WPF
  • C#
  • 基础设施 XamDataChart

【问题讨论】:

    标签: c# wpf tooltip infragistics xamdatachart


    【解决方案1】:

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

    如下使用Fill property如果Mouse 超过Path 形状,您的ToolTip 将变为visible。:

     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 captureMousein screenshot, but mouse is in between the shape while image was captured. RemoveFill propertyfromPathand then see the change in ouput.

    【讨论】:

      【解决方案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>
      

      【讨论】:

      • 这样做不好,不应该像上面那样在标记中添加更多元素。这是一个不好的做法。我们正在向逻辑树添加不必要的控制,并使标记更加模糊。
      猜你喜欢
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      • 2018-12-08
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多