We have using the WPF popup control.
We need to know that how to calculate the distance / height or Y coordinate of Popup control from the Top of the screen. So, how to calculate it ?
Please see attached image for the issue screenshot.
Image for pop up with the issue
I tried two solutions as follows :
First solution -------------------------------------------------------
Window w = Application.Current.Point
relativePoint = popNonTopMostPopup.TransformToAncestor(w)
.Transform(new Point(0, 0));
Issue: It is always returns the same coordinates as relativePoint.X = 3.0 and relativePoint.Y = 25.96
My popup cotrol opens at the right side of map icons as shown in image...so when i click on different map icon, popup position is changed accordingly. So it should return the different geo-coordnates.
Second solution ----------------------------------------------------
Point position = popNonTopMostPopup.PointToScreen(new Point(0d, 0d)),
controlPosition = this.PointToScreen(new Point(0d, 0d));
position.X -= controlPosition.X;
position.Y -= controlPosition.Y;
Issue: Same issue with this solution also..it is always returning same geocoordinate every time that are position.X = 3.0 and position.Y = 49.0
You can use this:
TransformToAncestoras shown in here.Even in an
UserControlyou can access the parentOtherwise you can go with
Application.Current.MainWindowto get your MainWindow.You then go and get the position of your popup as shown above.
If needed you can add
System.Windows.SystemParameters.CaptionHeightto the result.This could look similar to this (untested):