Question

I am customizing the tooltip on my user control so that it looks like a callout. The tooltip is set to appear above the control (Placement=Top) with an arrow pointing down toward it.

The problem is when the control is near the edge of the screen, the tooltip is not aligned to the left-side of the control. As a result, the arrow points to an empty space to the left of the control.

Even worse, if the control is near the top of the screen, the tooltip shows up below the target control and the arrow pointing down.

Any idea how to resolve this? I am looking for some way to programmatically create the tooltip on the fly or set a trigger to select the Style based on some properties in the tooltip but I don't know how.

Was it helpful?

Solution

I have faced the same problem in the past and what I did was get the position of the PlacementTarget via PointToScreen(new Point(0,0)) and get the position of the ToolTip by calling the same method and then doing the math to figure out whether the ToolTip is correctly positioned or not. If it wasn't, then I changed the Placement of the ToolTip according to whether it was showing up to the left, right, above or below the PlacementTarget. Also, keep in mind, that PointToScreen() will only work once the ToolTip has rendered so attach a handler to ToolTip.Open and do it in there. Hope this helped. Let me know if you come across a more efficient/better way to solve this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top