Tooltip's Horizontal/Vertical offset seems to not work the first time the tooltip is created.
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;
}
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Tooltip's Horizontal/Vertical offset seems to not work the first time the tooltip is created.
One question, how are you moving up the tooltip?
I mean, in your code the VerticalOffset just gets the Y from the mouse position, because offset.Y is always 0, so the top-left corner of the tooltip should be aligned to the mouse, but in the video when the mouse is moved it then gets aligned to the bottom-left corner of the tooltip.
In case you are using ActualHeight of the tooltip to calculate an offset, I guess the problem is that during Opened event the ToolTip is not yet measured, and ActualHeight has not been calculated. You can add a SizeChanged handler and call UpdatePosition there to solve that.
I mean, in your code the VerticalOffset just gets the Y from the mouse position, because offset.Y is always 0, so the top-left corner of the tooltip should be aligned to the mouse, but in the video when the mouse is moved it then gets aligned to the bottom-left corner of the tooltip.
In case you are using ActualHeight of the tooltip to calculate an offset, I guess the problem is that during Opened event the ToolTip is not yet measured, and ActualHeight has not been calculated. You can add a SizeChanged handler and call UpdatePosition there to solve that.
Re: Tooltip's Horizontal/Vertical offset seems to not work the first time the tooltip is created.
Ah, the size was the problem. I listened to SizeChanged & updated the position off of that, thanks.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Tooltip's Horizontal/Vertical offset seems to not work the first time the tooltip is created.
Great, thanks for the update.
Who is online
Users browsing this forum: Google [Bot] and 21 guests