WPF What is a more reliable ToolTip replacement?

Viewed 32

I currently have a large canvas nested inside a Zoom and Pan control, which in turn is nested inside a ScrollViewer.

My intention is to have a tooltip, positioned relative to the mouse position, that remains open. This is handled like so (ignore the offsets and the conditional):

private void ScrollViewer_MouseMove(object sender, MouseEventArgs e)
{
     ((ToolTip)mapScroll.ToolTip).Placement = System.Windows.Controls.Primitives.PlacementMode.Relative;
     ((ToolTip)mapScroll.ToolTip).HorizontalOffset = e.GetPosition(this).X;
     if (e.GetPosition(this).Y > 300)
     {
          ((ToolTip)mapScroll.ToolTip).VerticalOffset = e.GetPosition(this).Y;
     }
     else
     {
          ((ToolTip)mapScroll.ToolTip).VerticalOffset = e.GetPosition(this).Y;
     }
}

And since the tooltip will automatically disappear when a button is pressed:

private void mapGrid_MouseUp(object sender, MouseButtonEventArgs e)
{
     ((ToolTip)mapScroll.ToolTip).IsOpen = true;
}

Now, normally everything works fine - I can tweak the offsets to get the tooltip where I need it to be, and it will follow the cursor around like it should. That is, until I pan the canvas. As soon as I move the mouse after releasing the middle mouse button, the tooltip will jump to a completely different position, but still move around with the mouse. At that point, the only way to get it back to its original offset, is by moving the mouse outside of the ScrollViewer so it disappears, and mousing-over the ScrollViewer again.

So I either need to know how to duplicate this "reset" without having to mouse out/mouse in, or find some other element to use as a tooltip that will actually stay in one spot, relative to the mouse pointer. I should add, that I have already tried nulling out and creating a new instance of the tooltip on mouse up - with no effect.

Any help, as always, is greatly appreciated.

0 Answers
Related