private Rect CalcPlacement(NearbyLocation location, Rect windowRect) { switch (location) { case NearbyLocation.DownLeft: return(new Rect(_placement.Left - windowRect.Left, _placement.Bottom - windowRect.Top, windowRect.Width, windowRect.Height)); case NearbyLocation.DownRight: return(new Rect(_placement.Right - windowRect.Right, _placement.Bottom - windowRect.Top, windowRect.Width, windowRect.Height)); case NearbyLocation.UpLeft: return(new Rect(_placement.Left - windowRect.Left, _placement.Top - windowRect.Bottom, windowRect.Width, windowRect.Height)); case NearbyLocation.UpRight: return(new Rect(_placement.Right - windowRect.Right, _placement.Top - windowRect.Bottom, windowRect.Width, windowRect.Height)); case NearbyLocation.LeftSideTop: return(new Rect(_placement.Left - windowRect.Right, _placement.Top - windowRect.Top, windowRect.Width, windowRect.Height)); case NearbyLocation.LeftSideBottom: return(new Rect(_placement.Left - windowRect.Right, _placement.Bottom - windowRect.Bottom, windowRect.Width, windowRect.Height)); case NearbyLocation.RightSideTop: return(new Rect(_placement.Right - windowRect.Left, _placement.Top - windowRect.Top, windowRect.Width, windowRect.Height)); case NearbyLocation.RightSideBottom: return(new Rect(_placement.Right - windowRect.Left, _placement.Bottom - windowRect.Bottom, windowRect.Width, windowRect.Height)); default: return(new Rect(_placement.Left - windowRect.Left, _placement.Bottom - windowRect.Top, windowRect.Width, windowRect.Height)); } }
private static Point LocateNearby(Rect elementRect, Rect windowRect, NearbyLocation location) { switch (location) { case NearbyLocation.DownLeft: return(new Point(elementRect.Left - windowRect.Left, elementRect.Bottom - windowRect.Top)); case NearbyLocation.DownRight: return(new Point(elementRect.Right - windowRect.Right, elementRect.Bottom - windowRect.Top)); case NearbyLocation.UpLeft: return(new Point(elementRect.Left - windowRect.Left, elementRect.Top - windowRect.Bottom)); case NearbyLocation.UpRight: return(new Point(elementRect.Right - windowRect.Right, elementRect.Top - windowRect.Bottom)); case NearbyLocation.LeftSideTop: return(new Point(elementRect.Left - windowRect.Right, elementRect.Top - windowRect.Top)); case NearbyLocation.LeftSideBottom: return(new Point(elementRect.Left - windowRect.Right, elementRect.Bottom - windowRect.Bottom)); case NearbyLocation.RightSideTop: return(new Point(elementRect.Right - windowRect.Left, elementRect.Top - windowRect.Top)); case NearbyLocation.RightSideBottom: return(new Point(elementRect.Right - windowRect.Left, elementRect.Bottom - windowRect.Bottom)); default: return(new Point(elementRect.Left - windowRect.Left, elementRect.Bottom - windowRect.Top)); } }
internal WindowLocator(FrameworkElement target, Rect rectOnTarget, Window window, NearbyLocation location) { _placement = new Rect(target.PointToScreen(rectOnTarget.TopLeft), target.PointToScreen(rectOnTarget.BottomRight)); _workingArea = GetWorkingAreaOf(target); _location = location; _window = window; _window.LayoutUpdated += Window_LayoutUpdated; Rect r = GetWindowPlacement(false); _window.WindowStartupLocation = WindowStartupLocation.Manual; _window.Left = r.X; _window.Top = r.Y; }
public static void LocateNearby(FrameworkElement target, Window window, NearbyLocation location) { new WindowLocator(target, window, location); }
public static void ShowNearby(Window window, FrameworkElement element, NearbyLocation location) { WindowLocator.LocateNearby(element, window, location); window.Show(); }
private static Rect TryLocate(Window window, Size windowSize, Thickness margin, Rect elementRect, NearbyLocation location, Rect workingArea) { Rect rW = GetWindowRect(window, windowSize, margin); Rect r0 = new Rect(LocateNearby(elementRect, rW, location), windowSize); if (workingArea.Contains(r0)) { return(r0); } foreach (NearbyLocation l in NearbyLocationCandidates[location]) { Rect r = new Rect(LocateNearby(elementRect, rW, l), windowSize); if (workingArea.Contains(r)) { return(r); } } if (workingArea.Right < r0.Right) { r0.X += (workingArea.Right - r0.Right); } if (workingArea.Bottom < r0.Bottom) { r0.Y += (workingArea.Bottom - r0.Bottom); } if (r0.Left < workingArea.Left) { r0.X = workingArea.Left; } if (r0.Top < workingArea.Top) { r0.Y = workingArea.Top; } return(r0); }