private AdornerLayer FindAdornerLayer() { //var window = Window.GetWindow(AdornedElement); //return window.FindChild<AdornerLayer>(); ScrollViewer parent = AdornedElement.FindParent <ScrollViewer>(); if (parent != null) { return(AdornerLayer.GetAdornerLayer(parent)); } return(AdornerLayer.GetAdornerLayer(AdornedElement)); }
private bool ShouldOpenOnTop() { FrameworkElement container = AdornedElement.FindParent <VirtualizingStackPanel>(); if (container == null) { container = AdornedElement.FindParent <Window>(); } if (container != null) { Point relativeLocation = AdornedElement.TranslatePoint(new Point(0, 0), container); if (_openPreference == PopupOpenPreference.Top) { //double heightAbove = container.ActualHeight - (relativeLocation.Y + (AdornedElement as FrameworkElement).ActualHeight); double heightAbove = relativeLocation.Y; if (heightAbove >= _content.DesiredSize.Height) { return(true); } else { return(false); } } else if (_openPreference == PopupOpenPreference.Bottom) { double heightBelow = container.ActualHeight - (relativeLocation.Y + (AdornedElement as FrameworkElement).ActualHeight); if (heightBelow >= _content.DesiredSize.Height) { return(false); } else { return(true); } } } return(true); }