예제 #1
0
 public static void SetActualOrientation(System.Windows.Controls.Primitives.Popup popup, PopupOrientation orientation)
 {
     //popup.AssertNotNull("popup");
     popup.SetValue(ActualOrientationProperty, orientation);
 }
예제 #2
0
 public static void SetPreferredOrientations(System.Windows.Controls.Primitives.Popup popup, PopupOrientationCollection orientations)
 {
     //popup.AssertNotNull("popup");
     popup.SetValue(PreferredOrientationsProperty, orientations);
 }
예제 #3
0
 public static PopupOrientation GetActualOrientation(System.Windows.Controls.Primitives.Popup popup)
 {
     //popup.AssertNotNull("popup");
     return(popup.GetValue(ActualOrientationProperty) as PopupOrientation);
 }
예제 #4
0
 public static void SetPlacementParent(System.Windows.Controls.Primitives.Popup popup, FrameworkElement placementParent)
 {
     //popup.AssertNotNull("popup");
     popup.SetValue(PlacementParentProperty, placementParent);
 }
예제 #5
0
 public static PopupOrientationCollection GetPreferredOrientations(System.Windows.Controls.Primitives.Popup popup)
 {
     //popup.AssertNotNull("popup");
     return(popup.GetValue(PreferredOrientationsProperty) as PopupOrientationCollection);
 }
예제 #6
0
파일: Popup.cs 프로젝트: jensweller/Catel
 public PopupWatcher(System.Windows.Controls.Primitives.Popup popup)
 {
     this.popup = popup;
 }
예제 #7
0
 public static FrameworkElement GetPlacementParent(System.Windows.Controls.Primitives.Popup popup)
 {
     //popup.AssertNotNull("popup");
     return(popup.GetValue(PlacementParentProperty) as FrameworkElement);
 }
예제 #8
0
 public PopupWatcher(System.Windows.Controls.Primitives.Popup popup)
 {
     this.popup = popup;
 }
예제 #9
0
        private static bool TryPlacePopup(System.Windows.Controls.Primitives.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);
        }
예제 #10
0
 private static void SetPopup(DependencyObject dependencyObject, System.Windows.Controls.Primitives.Popup popup)
 {
     //popup.AssertNotNull("popup");
     dependencyObject.SetValue(PopupProperty, popup);
 }
예제 #11
0
 public static void SetStaysOpen(System.Windows.Controls.Primitives.Popup popup, bool staysOpen)
 {
     //popup.AssertNotNull("popup");
     popup.SetValue(StaysOpenProperty, staysOpen);
 }
예제 #12
0
 public static bool GetStaysOpen(System.Windows.Controls.Primitives.Popup popup)
 {
     //popup.AssertNotNull("popup");
     return((bool)popup.GetValue(StaysOpenProperty));
 }