Tooltip's Horizontal/Vertical offset seems to not work the first time the tooltip is created.
Posted: 30 Nov 2020, 17:43
You can see a video of the problem here: https://files.catbox.moe/an40mv.mp4
I created a tooltip that follows the cursor. However, as you can see in the video, whenever I close and reopen the view the tooltip's position will not update at first.
The Mouse.GetPosition is returning the correct position, but it seems setting the Horizontal/Vertical offset during this time does not work. Only after the mouse starts to move (which UpdatePosition is called in PlacementTarget_MouseMove) does the tooltip's position update correctly.
I created a tooltip that follows the cursor. However, as you can see in the video, whenever I close and reopen the view the tooltip's position will not update at first.
Code: Select all
private void SmartToolTip_Opened(object sender, RoutedEventArgs args)
{
_targetElement = PlacementTarget;
_targetElement.MouseMove += PlacementTarget_MouseMove;
UpdatePosition(Mouse.GetPosition(_targetElement));
}
private void UpdatePosition(Point position)
{
Point spacing = new Point(40, 40);
Point offset = new Point(
HorizontalPlacement == HorizontalPlacement.Left ? -ActualWidth - spacing.X : spacing.X,
0);
HorizontalOffset = position.X + offset.X;
VerticalOffset = position.Y + offset.Y;
}