예제 #1
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public static FrameworkElement GetPlacementParent(Windows.Popup popup)
 {
     //popup.AssertNotNull("popup");
     return popup.GetValue(PlacementParentProperty) as FrameworkElement;
 }
예제 #2
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public PopupWatcher(Windows.Popup popup)
 {
     this.popup = popup;
 }
예제 #3
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public static void SetPlacementChild(Windows.Popup popup, FrameworkElement placementChild)
 {
     //popup.AssertNotNull("popup");
     popup.SetValue(PlacementChildProperty, placementChild);
 }
예제 #4
0
파일: Popup.cs 프로젝트: 925coder/ravendb
        private static void InvalidatePosition(Windows.Popup popup)
        {
            if (popup.IsOpen)
                PositionPopup(popup);

            popup.Opened -= OnPopupOpened;
            popup.Opened += OnPopupOpened;

            var child = GetPlacementChild(popup) ?? popup.Child as FrameworkElement;

            if (child != null)
            {
                SetPopup(child, popup);
                child.SizeChanged -= OnChildSizeChanged;
                child.SizeChanged += OnChildSizeChanged;
            }
        }
예제 #5
0
파일: Popup.cs 프로젝트: 925coder/ravendb
        private static FrameworkElement FindHighestAncestor(Windows.Popup popup)
        {
            var ancestor = (FrameworkElement)popup;

            while (true)
            {
                var parent = VisualTreeHelper.GetParent(ancestor) as FrameworkElement;

                if (parent == null)
                    return ancestor;

                ancestor = parent;
            }
        }
예제 #6
0
파일: Popup.cs 프로젝트: 925coder/ravendb
        private static void PositionPopup(Windows.Popup popup)
        {
            var parent = popup.Parent as FrameworkElement;
            var placementParent = GetPlacementParent(popup) ?? popup.Parent as FrameworkElement;
            var placementChild = GetPlacementChild(popup) ?? popup.Child as FrameworkElement;

            if (parent == null || placementParent == null || placementChild == null)
                return;

            var preferredOrientations = GetPreferredOrientations(popup) ?? Enumerable.Empty<PopupOrientation>();

            foreach (var preferredOrientation in preferredOrientations)
            {
                if (TryPlacePopup(popup, parent, placementParent, placementChild, preferredOrientation))
                    return;
            }

            var fallbackOrientations = from placement in popupPlacements
                                       from horizontalAlignment in horizontalAlignments
                                       from verticalAlignment in verticalAlignments
                                       where preferredOrientations.FirstOrDefault(x => x.Placement == placement && x.HorizontalAlignment == horizontalAlignment && x.VerticalAlignment == verticalAlignment) == null
                                       select new PopupOrientation() { Placement = placement, HorizontalAlignment = horizontalAlignment, VerticalAlignment = verticalAlignment };

            foreach (var fallbackOrientation in fallbackOrientations)
            {
                if (TryPlacePopup(popup, parent, placementParent, placementChild, fallbackOrientation))
                    return;
            }

            // give up and just use the first preferred orientation, if any
            var orientation = GetPreferredOrientations(popup).FirstOrDefault();

            if (orientation != null)
                SetActualOrientation(popup, orientation);
        }
예제 #7
0
파일: Popup.cs 프로젝트: 925coder/ravendb
        private static bool TryPlacePopup(Windows.Popup popup, FrameworkElement parent, FrameworkElement placementParent, FrameworkElement placementChild, PopupOrientation orientation)
        {
            var availableWidth = placementParent.ActualWidth;
            var availableHeight = placementParent.ActualHeight;

            SetActualOrientation(popup, orientation);
            placementChild.Measure(new Size(availableWidth, availableHeight));

            var requiredWidth = placementChild.DesiredSize.Width;
            var requiredHeight = placementChild.DesiredSize.Height;
            var placementTarget = GetPlacementTarget(popup) ?? parent;
            var parentTransform = placementTarget.TransformToVisual(parent);
            var popupLocation = parentTransform.Transform(new Point(0, 0));

            switch (orientation.Placement)
            {
                case PopupPlacement.Top:
                    popupLocation.Y -= requiredHeight;
                    break;
                case PopupPlacement.Bottom:
                    popupLocation.Y += placementTarget.ActualHeight;
                    break;
                case PopupPlacement.Left:
                    popupLocation.X -= requiredWidth;
                    break;
                case PopupPlacement.Right:
                    popupLocation.X += placementTarget.ActualWidth;
                    break;
            }

            if (orientation.Placement == PopupPlacement.Top || orientation.Placement == PopupPlacement.Bottom)
            {
                switch (orientation.HorizontalAlignment)
                {
                    case PopupHorizontalAlignment.RightCenter:
                        popupLocation.X += ((placementTarget.ActualWidth / 2) - requiredWidth);
                        break;
                    case PopupHorizontalAlignment.Center:
                        popupLocation.X += ((placementTarget.ActualWidth - requiredWidth) / 2);
                        break;
                    case PopupHorizontalAlignment.LeftCenter:
                        popupLocation.X += (placementTarget.ActualWidth / 2);
                        break;
                    case PopupHorizontalAlignment.Right:
                        popupLocation.X += (placementTarget.ActualWidth - requiredWidth);
                        break;
                }
            }

            if (orientation.Placement == PopupPlacement.Left || orientation.Placement == PopupPlacement.Right)
            {
                switch (orientation.VerticalAlignment)
                {
                    case PopupVerticalAlignment.BottomCenter:
                        popupLocation.Y += ((placementTarget.ActualHeight / 2) - requiredHeight);
                        break;
                    case PopupVerticalAlignment.Center:
                        popupLocation.Y += ((placementTarget.ActualHeight - requiredHeight) / 2);
                        break;
                    case PopupVerticalAlignment.TopCenter:
                        popupLocation.Y += (placementTarget.ActualHeight / 2);
                        break;
                    case PopupVerticalAlignment.Bottom:
                        popupLocation.Y += (placementTarget.ActualHeight - requiredHeight);
                        break;
                }
            }

            var popupLocationRelativeToPlacementParent = popupLocation;

            if (parent != placementParent)
            {
                var placementParentTransform = placementTarget.TransformToVisual(placementParent);
                popupLocationRelativeToPlacementParent = placementParentTransform.Transform(popupLocation);
            }

            if (popupLocationRelativeToPlacementParent.X < 0
                || popupLocationRelativeToPlacementParent.Y < 0
                || (popupLocationRelativeToPlacementParent.X + requiredWidth) > availableWidth
                || (popupLocationRelativeToPlacementParent.Y + requiredHeight) > availableHeight)
            {
                // not enough room
                return false;
            }

            popup.HorizontalOffset = popupLocation.X;
            popup.VerticalOffset = popupLocation.Y;

            return true;
        }
예제 #8
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public static void SetStaysOpen(Windows.Popup popup, bool staysOpen)
 {
     //popup.AssertNotNull("popup");
     popup.SetValue(StaysOpenProperty, staysOpen);
 }
예제 #9
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 private static void SetPopup(DependencyObject dependencyObject, Windows.Popup popup)
 {
     //popup.AssertNotNull("popup");
     dependencyObject.SetValue(PopupProperty, popup);
 }
예제 #10
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public static bool GetStaysOpen(Windows.Popup popup)
 {
     //popup.AssertNotNull("popup");
     return (bool)popup.GetValue(StaysOpenProperty);
 }
예제 #11
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public static void SetActualOrientation(Windows.Popup popup, PopupOrientation orientation)
 {
     //popup.AssertNotNull("popup");
     popup.SetValue(ActualOrientationProperty, orientation);
 }
예제 #12
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public static PopupOrientation GetActualOrientation(Windows.Popup popup)
 {
     //popup.AssertNotNull("popup");
     return popup.GetValue(ActualOrientationProperty) as PopupOrientation;
 }
예제 #13
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public static void SetPreferredOrientations(Windows.Popup popup, PopupOrientationCollection orientations)
 {
     //popup.AssertNotNull("popup");
     popup.SetValue(PreferredOrientationsProperty, orientations);
 }
예제 #14
0
파일: Popup.cs 프로젝트: 925coder/ravendb
 public static PopupOrientationCollection GetPreferredOrientations(Windows.Popup popup)
 {
     //popup.AssertNotNull("popup");
     return popup.GetValue(PreferredOrientationsProperty) as PopupOrientationCollection;
 }