C# 如何使工具提示随鼠标移动?

C# 如何使工具提示随鼠标移动?,c#,silverlight,visual-studio-2008,tooltip,deepzoom,C#,Silverlight,Visual Studio 2008,Tooltip,Deepzoom,我正在使用Silverlight 3+VSTS 2008。我有一个图像(多比例图像控件),并在该图像上放置工具提示。工具提示的功能运行良好。因为图像很大(大约500*500大小),而且最终用户可以在图片上移动鼠标,我想随着鼠标显示工具提示位置(即当鼠标移动时,我想随着鼠标移动工具提示)。当前,工具提示显示在固定位置 这是我目前的XAML代码,有什么办法解决这个问题吗 <MultiScaleImage x:Name="msi" Height="500" Width="500"&g

我正在使用Silverlight 3+VSTS 2008。我有一个图像(多比例图像控件),并在该图像上放置工具提示。工具提示的功能运行良好。因为图像很大(大约500*500大小),而且最终用户可以在图片上移动鼠标,我想随着鼠标显示工具提示位置(即当鼠标移动时,我想随着鼠标移动工具提示)。当前,工具提示显示在固定位置

这是我目前的XAML代码,有什么办法解决这个问题吗

      <MultiScaleImage x:Name="msi" Height="500" Width="500">
            <ToolTipService.ToolTip>
                <ToolTip Content="Here is a tool tip" Name="DeepZoomToolTip"></ToolTip>
            </ToolTipService.ToolTip>
        </MultiScaleImage>

工具提示控件设计为大致在鼠标与其绑定的元素相遇的位置弹出,并且无法响应移动事件。下面是一个自定义工具提示示例。我添加了背景和z索引,这样文本块就会出现在图像上。与鼠标位置的偏移使工具提示远离鼠标光标,以便平滑地设置移动动画

XAML:


我最终遇到了一个类似的问题,并通过使用弹出窗口解决了这个问题。post包含核心解决方案。以下是另一篇文章中建议的XAML:

<Canvas x:Name="LayoutRoot" Background="White">
<Image Source="/pretty-pretty.png" MouseMove="Image_MouseMove" MouseLeave="Image_MouseLeave"/>
<Popup Name="DeepZoomToolTip">
   <Border CornerRadius="1" Padding="1" Background="Azure" IsHitTestVisible="False">
       <TextBlock Text="Here is a tool tip" />
   </Border>
</Popup>
</Canvas>

你有没有找到解决办法?我正在尝试做一些类似的事情,并且一直在代码中创建工具提示对象并将其放置在后面,但是还没有让它工作。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ImageEditor
{
    public partial class TestControl : UserControl
    {
        private bool _tooltipVisible = false;
        public TestControl()
        {
            InitializeComponent();
        }

        private void theImage_MouseMove(object sender, MouseEventArgs e)
        {
            if (_tooltipVisible)
            {
                tt.SetValue(Canvas.TopProperty, e.GetPosition(theImage).Y - (5 + txtTooltip.Height));
                tt.SetValue(Canvas.LeftProperty, e.GetPosition(theImage).X - 5);
            }
        }

        private void theImage_MouseEnter(object sender, MouseEventArgs e)
        {
            _tooltipVisible = true;
            tt.Visibility = Visibility.Visible;
        }

        private void theImage_MouseLeave(object sender, MouseEventArgs e)
        {
            _tooltipVisible = false;
            tt.Visibility = Visibility.Collapsed;
        }
    }
}
<Canvas x:Name="LayoutRoot" Background="White">
<Image Source="/pretty-pretty.png" MouseMove="Image_MouseMove" MouseLeave="Image_MouseLeave"/>
<Popup Name="DeepZoomToolTip">
   <Border CornerRadius="1" Padding="1" Background="Azure" IsHitTestVisible="False">
       <TextBlock Text="Here is a tool tip" />
   </Border>
</Popup>
</Canvas>


private void Image_MouseMove(object sender, MouseEventArgs e)
{
    DeepZoomToolTip.IsOpen = true;
    DeepZoomToolTip.HorizontalOffset = e.GetPosition(LayoutRoot).X;
    DeepZoomToolTip.VerticalOffset = e.GetPosition(LayoutRoot).Y;
}

private void Image_MouseLeave(object sender, MouseEventArgs e)
{
    DeepZoomToolTip.IsOpen = false;
}