private static Point GetAnchorPoint(Rect anchorRect, PopupAnchor edge) { double x, y; if (edge.HasFlagCustom(PopupAnchor.Left)) { x = anchorRect.X; } else if (edge.HasFlagCustom(PopupAnchor.Right)) { x = anchorRect.Right; } else { x = anchorRect.X + anchorRect.Width / 2; } if (edge.HasFlagCustom(PopupAnchor.Top)) { y = anchorRect.Y; } else if (edge.HasFlagCustom(PopupAnchor.Bottom)) { y = anchorRect.Bottom; } else { y = anchorRect.Y + anchorRect.Height / 2; } return(new Point(x, y)); }