Ejemplo n.º 1
0
 /// <summary>Compares this structure with another <see cref="T:System.Windows.Controls.Primitives.CustomPopupPlacement" /> structure to determine whether they are equal.</summary>
 /// <param name="o">The <see cref="T:System.Windows.Controls.Primitives.CustomPopupPlacement" /> structure to compare.</param>
 /// <returns>
 ///     <see langword="true" /> if the structures have the same values; otherwise, <see langword="false" />.</returns>
 // Token: 0x06005C88 RID: 23688 RVA: 0x001A0904 File Offset: 0x0019EB04
 public override bool Equals(object o)
 {
     if (o is CustomPopupPlacement)
     {
         CustomPopupPlacement customPopupPlacement = (CustomPopupPlacement)o;
         return(customPopupPlacement._primaryAxis == this._primaryAxis && customPopupPlacement._point == this._point);
     }
     return(false);
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Compares the value of this struct with another object.
        /// </summary>
        /// <param name="o">An object to compare to.</param>
        /// <returns>True if equivalent. False otherwise.</returns>
        public override bool Equals(object o)
        {
            if (o is CustomPopupPlacement)
            {
                CustomPopupPlacement placement = (CustomPopupPlacement)o;
                return((placement._primaryAxis == _primaryAxis) && (placement._point == _point));
            }

            return(false);
        }
Ejemplo n.º 3
0
        private CustomPopupPlacement[] MKPopupPlacement(Size a, Size b, Point c)
        {
            //
            // MKRoot.AlignReferencePoint.

            // TODO: The MenuKiller's align reference report must report when it changes, so we can reposition the
            // Popup... However, it'd be nice to know whether that is possible at all.
            // ISSUE: The popup kills performance, moving it makes matters A LOT worse
            CustomPopupPlacement pl = new CustomPopupPlacement(new Point(0, 0), PopupPrimaryAxis.None);
            CustomPopupPlacement[] arr = new CustomPopupPlacement[1];
            arr[0] = pl;
            return arr;
        }
Ejemplo n.º 4
0
        // Provide to possible places for the Popup when Placement
        // is set to Custom.
        public CustomPopupPlacement[] placePopup(Size popupSize,
                                                 Size targetSize,
                                                 Point offset)
        {
            CustomPopupPlacement placement1 =
                new CustomPopupPlacement(new Point(-50, 100), PopupPrimaryAxis.Vertical);

            CustomPopupPlacement placement2 =
                new CustomPopupPlacement(new Point(10, 20), PopupPrimaryAxis.Horizontal);

            CustomPopupPlacement[] ttplaces =
                    new CustomPopupPlacement[] { placement1, placement2};
            return ttplaces;
        }
        // Calculate two variants: below and upper ribbon
        private CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupSize, Size targetSize, Point offset)
        {
            if (this.PlacementTarget == null)
            {
                return new CustomPopupPlacement[] { };
            }

            Ribbon ribbon = null;
            UIElement topLevelElement = null;
            FindControls(this.PlacementTarget, ref ribbon, ref topLevelElement);

            // Exclude QAT items
            var notQuickAccessItem = !IsQuickAccessItem(this.PlacementTarget);
            var notContextMenuChild = !IsContextMenuChild(this.PlacementTarget);
            var rightToLeftOffset = this.FlowDirection == FlowDirection.RightToLeft
                                           ? -popupSize.Width
                                           : 0;

            var decoratorChild = GetDecoratorChild(topLevelElement);

            if (notQuickAccessItem
                && this.IsRibbonAligned
                && ribbon != null)
            {
                var belowY = ribbon.TranslatePoint(new Point(0, ribbon.ActualHeight), this.PlacementTarget).Y;
                var aboveY = ribbon.TranslatePoint(new Point(0, 0), this.PlacementTarget).Y - popupSize.Height;
                var below = new CustomPopupPlacement(new Point(rightToLeftOffset, belowY + 1), PopupPrimaryAxis.Horizontal);
                var above = new CustomPopupPlacement(new Point(rightToLeftOffset, aboveY - 1), PopupPrimaryAxis.Horizontal);
                return new[] { below, above };
            }

            if (notQuickAccessItem
                && this.IsRibbonAligned
                && notContextMenuChild
                && topLevelElement is Window == false
                && decoratorChild != null)
            {
                // Placed on Popup?                
                var belowY = decoratorChild.TranslatePoint(new Point(0, ((FrameworkElement)decoratorChild).ActualHeight), this.PlacementTarget).Y;
                var aboveY = decoratorChild.TranslatePoint(new Point(0, 0), this.PlacementTarget).Y - popupSize.Height;
                var below = new CustomPopupPlacement(new Point(rightToLeftOffset, belowY + 1), PopupPrimaryAxis.Horizontal);
                var above = new CustomPopupPlacement(new Point(rightToLeftOffset, aboveY - 1), PopupPrimaryAxis.Horizontal);
                return new[] { below, above };
            }

            return new[] {
                new CustomPopupPlacement(new Point(rightToLeftOffset, this.PlacementTarget.RenderSize.Height + 1), PopupPrimaryAxis.Horizontal),
                new CustomPopupPlacement(new Point(rightToLeftOffset, -popupSize.Height - 1), PopupPrimaryAxis.Horizontal)};
        }
Ejemplo n.º 6
0
        // Calculate two variants: below and upper ribbon
        CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupSize, Size targetSize, Point offset)
        {
            if (PlacementTarget == null) return new CustomPopupPlacement[] {};

            Ribbon ribbon = null;
            UIElement topLevelElement = null;
            FindControls(PlacementTarget, ref ribbon, ref topLevelElement);

            // Exclude QAT items
            bool notQuickAccessItem = !IsQuickAccessItem(PlacementTarget);
            bool notContextMenuChild = !IsContextMenuChild(PlacementTarget);
            double rightToLeftOffset = FlowDirection == FlowDirection.RightToLeft
                                           ? -popupSize.Width
                                           : 0;

            if (notQuickAccessItem && IsRibbonAligned && (ribbon != null))
            {
                double belowY = ribbon.TranslatePoint(new Point(0, ribbon.ActualHeight), PlacementTarget).Y;
                double aboveY = ribbon.TranslatePoint(new Point(0, 0), PlacementTarget).Y - popupSize.Height;
                CustomPopupPlacement below = new CustomPopupPlacement(new Point(rightToLeftOffset, belowY + 1), PopupPrimaryAxis.Horizontal);
                CustomPopupPlacement above = new CustomPopupPlacement(new Point(rightToLeftOffset, aboveY - 1), PopupPrimaryAxis.Horizontal);
                return new CustomPopupPlacement[] { below, above };
            }
            else if (notQuickAccessItem && IsRibbonAligned && notContextMenuChild && (!(topLevelElement is Window)))
            {
                // Placed on Popup?                
                UIElement decoratorChild = GetDecoratorChild(topLevelElement);
                double belowY = decoratorChild.TranslatePoint(new Point(0, ((FrameworkElement)decoratorChild).ActualHeight), PlacementTarget).Y;
                double aboveY = decoratorChild.TranslatePoint(new Point(0, 0), PlacementTarget).Y - popupSize.Height;
                CustomPopupPlacement below = new CustomPopupPlacement(new Point(rightToLeftOffset, belowY + 1), PopupPrimaryAxis.Horizontal);
                CustomPopupPlacement above = new CustomPopupPlacement(new Point(rightToLeftOffset, aboveY - 1), PopupPrimaryAxis.Horizontal);
                return new CustomPopupPlacement[] { below, above };
            }
            else
            {
                return new CustomPopupPlacement[] { 
                    new CustomPopupPlacement(new Point(rightToLeftOffset, PlacementTarget.RenderSize.Height + 1), PopupPrimaryAxis.Horizontal),
                    new CustomPopupPlacement(new Point(rightToLeftOffset, -popupSize.Height - 1), PopupPrimaryAxis.Horizontal)};
            }
        }
        /// <summary>
        /// Ensure the position of the tooltip to be exactly below the <see cref="T:RibbonBar"/> if available, otherwise use default positioning.
        /// </summary>
        private CustomPopupPlacement[] PopupPlacement(Size popupSize, Size targetSize, Point offset)
        {
            RibbonBar ribbon = GetRibbonBar();
            double y = ActualHeight;
            double x = 0.0d;

            if (ribbon != null)
            {
                FrameworkElement owner = this.PlacementTarget as FrameworkElement;
                if (!(owner is RibbonApplicationMenu))
                {
                    if (owner.IsDescendantOf(ribbon))
                    {
                        Point p = ribbon.TranslatePoint(new Point(), owner);
                        y = ribbon.ActualHeight  + p.Y;
                    }
                    else
                    {
                        Popup popup = ribbon.Popup;
                        FrameworkElement child = popup.Child as FrameworkElement;
                        if (child != null)
                        {
                            Point p = child.TranslatePoint(new Point(), owner);
                            y = child.ActualHeight + p.Y;
                        }
                    }
                }
                else
                {
                    y = owner.ActualHeight + 4.0d;
                    x = 0d;
                }
            }

            CustomPopupPlacement placement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.Vertical);
            return new CustomPopupPlacement[] { placement };
        }
 private void ToggleLanguagePopup(ButtonBase button)
 {
     _langPopup.PlacementTarget = button;
     _langPopup.Placement = PlacementMode.Custom;
     _langPopup.CustomPopupPlacementCallback = (size, targetSize, offset) =>
     {
         var placement1 =
             new CustomPopupPlacement(new Point(0 - (size.Width - targetSize.Width), (0 - size.Height) - 5),
                 PopupPrimaryAxis.Horizontal);
         return new[] {placement1, placement1};
     };
     _langPopup.IsOpen = true;
 }
Ejemplo n.º 9
0
        public CustomPopupPlacement[] placePopup(Size popupSize, Size targetSize, Point offset)
        {
            CustomPopupPlacement placement1 =
               new CustomPopupPlacement(new Point((System.Windows.SystemParameters.WorkArea.Width - 300), (System.Windows.SystemParameters.WorkArea.Height - 300)), PopupPrimaryAxis.Vertical);

            CustomPopupPlacement placement2 =
                new CustomPopupPlacement(new Point((System.Windows.SystemParameters.WorkArea.Width - 300),(System.Windows.SystemParameters.WorkArea.Height - 300)), PopupPrimaryAxis.Horizontal);

            CustomPopupPlacement[] ttplaces =
                    new CustomPopupPlacement[] { placement1, placement2 };
            return ttplaces;
        }
        public void ShowNotification(INotification notification)
        {
            Argument.IsNotNull(() => notification);

            if (IsSuspended)
            {
                Log.Debug("Notifications are suspended, queueing notification");

                _notificationsQueue.Enqueue(notification);

                return;
            }

            EnsureMainWindow();

            _dispatcherService.BeginInvoke(() =>
            {
                Log.Debug("Showing notification '{0}'", notification);

                var notificationLocation = _notificationPositionService.GetLeftTopCorner(NotificationSize, CurrentNotifications.Count);

                var popup = new Popup();

                popup.AllowsTransparency = true;
                popup.Placement = PlacementMode.Custom;
                popup.CustomPopupPlacementCallback += (popupSize, targetSize, offset) =>
                {
                    var x = DpiHelper.CalculateSize(DpiHelper.DpiX, notificationLocation.X);
                    var y = DpiHelper.CalculateSize(DpiHelper.DpiY, notificationLocation.Y);

                    var popupPlacement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.None);

                    var ttplaces = new [] { popupPlacement };
                    return ttplaces;
                };

                //popup.Placement = PlacementMode.AbsolutePoint;
                //popup.PlacementRectangle = new Rect(notificationLocation.X, notificationLocation.Y, NotificationSize.Width, NotificationSize.Height);

                var notificationViewModel = _viewModelFactory.CreateViewModel<NotificationViewModel>(notification);
                notificationViewModel.ClosedAsync += async (sender, e) => popup.IsOpen = false;

                // TODO: consider factory
                var notificationView = new NotificationView();
                notificationView.DataContext = notificationViewModel;
                notificationView.Unloaded += OnNotificationViewUnloaded;

                popup.Child = notificationView;

                popup.IsOpen = true;

                OpenedNotification.SafeInvoke(this, new NotificationEventArgs(notification));

                CurrentNotifications.Add(notification);
            });
        }
Ejemplo n.º 11
0
		public CustomPopupPlacement [] CustomPopupPlacementCallbackHandler (Size PopupSize, Size TargetSize, Point Offset)
			{
			throw new NotImplementedException ("Endlich bin ich da - im CustomPopupPlacementCallbackHandler");
			CustomPopupPlacement [] PossiblePositions = new CustomPopupPlacement [0];
			//ParentGrid.UpdateLayout ();
			//Context.UpdateLayout ();
			//Context.PlacementTarget = ParentGrid;
			//Context.PlacementRectangle = new Rect (0, 0, ParentGrid.ActualWidth, ParentGrid.ActualHeight);
			//double CursorLeft = e.CursorLeft;
			//double CursorTop = e.CursorTop;
			//double FrameHeight = ParentGrid.ActualHeight;
			//double FrameWidth = ParentGrid.ActualWidth;
			//double ContextHeight = Context.ActualHeight;
			//double ContextWidth = Context.ActualWidth;
			//double HorizontalOffset = 0;
			//double VerticalOffset = 0;
			//Context.HorizontalOffset = HorizontalOffset;
			//Context.VerticalOffset = VerticalOffset;
			return PossiblePositions;
			}
Ejemplo n.º 12
0
        private CustomPopupPlacement[] CustomPlacement(Size popupSize, Size targetSize, Point offset)
        {
            System.Windows.Point screenPoint = owningExtension.TranslateToScreenPoint(CursorPosition);

            CustomPopupPlacement bottomPlacement = new CustomPopupPlacement()
            {
                Point = new Point(screenPoint.X, screenPoint.Y + Configurations.FontDisplayHeight),
                PrimaryAxis = PopupPrimaryAxis.Vertical
            };

            CustomPopupPlacement topPlacement = new CustomPopupPlacement()
            {
                Point = new Point(screenPoint.X, screenPoint.Y - popupSize.Height),
                PrimaryAxis = PopupPrimaryAxis.Vertical
            };

            return (new CustomPopupPlacement[] { bottomPlacement, topPlacement });
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get the point at which callout will be placed and show the correct pointer.
        /// </summary>
        /// <param name="popupSize">Size.</param>
        /// <param name="targetSize">Size.</param>
        /// <param name="offset">Point.</param>
        /// <returns>If the Popup is hidden by a screen edge at the first position, 
        /// the Popup is placed at the second position and so on.</returns>
        private CustomPopupPlacement[] _GetTopLeftPointShowPointer(Size popupSize, Size targetSize, Point offset)
        {
            // If visible part of the cell is smaller then callout pointer - dont show callout.
            if (targetSize.Height < _pointerHeight ||
                targetSize.Width < _ConvertWidth(_pointerHorizontalOffset))
            {
                Close(true);
                return null;
            }

            // Point in which top left corner of callout will be placed.
            CustomPopupPlacement topLeftPoint;

            // Check that this is callout with upper pointer.
            if (_IsUpperPointer())
            {
                _MakeTopPointerVisible();

                // Check that this is left/right pointer and provide proper points for pointer.
                if (_IsLeftPointer())
                {
                    TopPointer.Points = _GetTopLeftPoints();
                    // Callout will point to bottom left corner of target.
                    topLeftPoint = new CustomPopupPlacement(
                        new Point(0, targetSize.Height), PopupPrimaryAxis.Vertical);
                }
                else
                {
                    TopPointer.Points = _GetTopRightPoints(grid.ActualWidth);

                    // Callout will point to bottom right corner of target.
                    topLeftPoint = new CustomPopupPlacement(
                        new Point(targetSize.Width - popupSize.Width, targetSize.Height), PopupPrimaryAxis.Vertical);
                }
            }
            else
            {
                _MakeBottomPointerVisible();

                if (_IsLeftPointer())
                {
                    BottomPointer.Points = _GetBottomLeftPoints();
                    // Callout will point to upper left corner of target.
                    topLeftPoint = new CustomPopupPlacement(
                        new Point(0, -popupSize.Height), PopupPrimaryAxis.Horizontal);
                }
                else
                {
                    BottomPointer.Points = _GetBottomRightPoints(grid.ActualWidth);
                    // Callout will point to upper right corner of target.
                    topLeftPoint = new CustomPopupPlacement(
                        new Point(targetSize.Width - popupSize.Width, -popupSize.Height), PopupPrimaryAxis.Horizontal);
                }
            }
            CustomPopupPlacement[] points = new CustomPopupPlacement[] { topLeftPoint };

            return points;
        }
Ejemplo n.º 14
0
        private CustomPopupPlacement[] PlacePopup(Size popupSize, Size targetSize, Point offset)
        {
            double popupChildMargin = 0.0;
            FrameworkElement popupChild;
            if ((popupChild = _popup.Child as FrameworkElement) != null)
            {
                popupChildMargin = (FlowDirection == FlowDirection.LeftToRight) ?  popupChild.Margin.Left : popupChild.Margin.Right ;
            }

            if (double.IsNaN(_popupOffsetY))
            {
                // Popup is opened for the first time, there could be two positions.
                // to logical right of Target or logical left of Target

                CustomPopupPlacement logicalRightPosition;
                CustomPopupPlacement logicalLeftPosition;
                if (FlowDirection == FlowDirection.LeftToRight)
                {
                    logicalRightPosition = new CustomPopupPlacement(new Point(targetSize.Width, offset.Y), PopupPrimaryAxis.Vertical);
                    logicalLeftPosition = new CustomPopupPlacement(new Point(-popupSize.Width - popupChildMargin, offset.Y), PopupPrimaryAxis.Vertical);
                }
                else
                {
                    logicalRightPosition = new CustomPopupPlacement(new Point(-targetSize.Width - popupSize.Width - popupChildMargin, offset.Y), PopupPrimaryAxis.Vertical);
                    logicalLeftPosition = new CustomPopupPlacement(new Point(- popupChildMargin, offset.Y), PopupPrimaryAxis.Vertical);
                }

                return new CustomPopupPlacement[] { logicalRightPosition, logicalLeftPosition };
            }

            // Either resizing or when popup contents changed in size (e.g. Gallery filtering)
            // Top edge should remain constant constant
            double topEdge = _popupOffsetY + offset.Y;
            if (!IsDropDownPositionedLeft)
            {
                if (FlowDirection == FlowDirection.LeftToRight)
                {
                    // Anchor to right side of Target
                    return new CustomPopupPlacement[] { new CustomPopupPlacement(new Point(targetSize.Width, -topEdge), PopupPrimaryAxis.Vertical) };
                }
                else
                {
                    // Anchor to logical right side of Target
                    return new CustomPopupPlacement[] { new CustomPopupPlacement(new Point(-targetSize.Width - popupSize.Width - popupChildMargin, -topEdge), PopupPrimaryAxis.Vertical) };
                }
            }
            else
            {
                if (FlowDirection == FlowDirection.LeftToRight)
                {
                    // Anchor to left side of Target
                    return new CustomPopupPlacement[] { new CustomPopupPlacement(new Point(-popupSize.Width - popupChildMargin, -topEdge), PopupPrimaryAxis.Vertical) };
                }
                else
                {
                    // Anchor to logical left side of Target
                    return new CustomPopupPlacement[] { new CustomPopupPlacement(new Point(-popupChildMargin, -topEdge), PopupPrimaryAxis.Vertical) };
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     RibbonToolTip custom placement logic
        /// </summary>
        /// <param name="popupSize">The size of the popup.</param>
        /// <param name="targetSize">The size of the placement target.</param>
        /// <param name="offset">The Point computed from the HorizontalOffset and VerticalOffset property values.</param>
        /// <returns>An array of possible tooltip placements.</returns>
        private CustomPopupPlacement[] PlaceRibbonToolTip(Size popupSize, Size targetSize, Point offset)
        {
            UIElement placementTarget = this.PlacementTarget;
            double belowOffsetY = 0.0;
            double aboveOffsetY = 0.0;
            double offsetX = FlowDirection == FlowDirection.LeftToRight ? 0.0 : -popupSize.Width;

            if (IsPlacementTargetInRibbonGroup)
            {
                // If the PlacementTarget is within a RibbonGroup we proceed
                // with the custom placement policy.

                // Walk up the visual tree from PlacementTarget to find the Ribbon
                // if exists or the root element which is likely a PopupRoot.
                Ribbon ribbon = null;
                DependencyObject rootElement = null;
                DependencyObject element = placementTarget;
                while (element != null)
                {
                    ribbon = element as Ribbon;
                    if (ribbon != null)
                    {
                        break;
                    }

                    rootElement = element;
                    element = VisualTreeHelper.GetParent(element);
                }

                double additionalOffset = 1.0;
                FrameworkElement referenceFE = null;

                if (ribbon != null)
                {
                    additionalOffset = 0.0;
                    referenceFE = ribbon;
                }
                else
                {
                    if (rootElement != null)
                    {
                        referenceFE = rootElement as FrameworkElement;
                    }
                }

                if (referenceFE != null)
                {
                    // When RibbonControl (PlacementTarget) is within a collapsed group RibbonToolTip is
                    // placed just below the Popup or just above the Popup (in case there is not enough
                    // screen space left below the Popup).

                    MatrixTransform transform = referenceFE.TransformToDescendant(placementTarget) as MatrixTransform;
                    if (transform != null)
                    {
                        MatrixTransform deviceTransform = new MatrixTransform(RibbonHelper.GetTransformToDevice(referenceFE));
                        GeneralTransformGroup transformGroup = new GeneralTransformGroup();
                        transformGroup.Children.Add(transform);
                        transformGroup.Children.Add(deviceTransform);

                        Point leftTop, rightBottom;
                        transformGroup.TryTransform(new Point(0, 0), out leftTop);
                        transformGroup.TryTransform(new Point(referenceFE.ActualWidth, referenceFE.ActualHeight), out rightBottom);

                        belowOffsetY = rightBottom.Y + additionalOffset;
                        aboveOffsetY = leftTop.Y - popupSize.Height - additionalOffset;
                    }
                }
            }
            else
            {
                // If PlacementTarget isn't within a RibbonGroup we shouldn't have
                // gotten here in the first place. But now that we are we will make
                // the best attempt at emulating PlacementMode.Bottom.
                FrameworkElement placementTargetAsFE = placementTarget as FrameworkElement;
                if (placementTargetAsFE != null)
                {
                    belowOffsetY = targetSize.Height;
                    aboveOffsetY = -popupSize.Height;
                }
            }

            // This is the prefered placement, below the ribbon for controls within Ribbon or below the Popup for controls within Popup.
            CustomPopupPlacement placementPreffered = new CustomPopupPlacement(new Point(offsetX, belowOffsetY), PopupPrimaryAxis.Horizontal);

            // This is a fallback placement, if the tooltip will not fit below the ribbon or Popup, place it above the ribbon or Popup.
            CustomPopupPlacement placementFallback = new CustomPopupPlacement(new Point(offsetX, aboveOffsetY), PopupPrimaryAxis.Horizontal);

            return new CustomPopupPlacement[] { placementPreffered, placementFallback };
        }
Ejemplo n.º 16
0
        public CustomPopupPlacement[] PlacePopup(Size popupSize, Size targetSize, Point offset)
        {
            Point popupLocation = new Point(targetSize.Width - popupSize.Width, targetSize.Height);

            CustomPopupPlacement placement1 =
                new CustomPopupPlacement(popupLocation, PopupPrimaryAxis.Vertical);

            CustomPopupPlacement placement2 =
                new CustomPopupPlacement(popupLocation, PopupPrimaryAxis.Horizontal);

            CustomPopupPlacement[] ttplaces =
                new CustomPopupPlacement[] { placement1, placement2 };
            return ttplaces;
        }
Ejemplo n.º 17
0
        private CustomPopupPlacement[] CustomPopUpTarget(Size popupSize, Size targetSize, Point offset)
        {
            var height = targetSize.Height;
            var x = targetSize.Width - popupSize.Width;

            var placement = new CustomPopupPlacement(new Point(x, height), PopupPrimaryAxis.Horizontal);
            return new[] {placement};
        }
Ejemplo n.º 18
0
        private static CustomPopupPlacementCallback CreatePlacementCallback(Popup popup)
        {
            return delegate(Size popupSize, Size targetSize, Point offset)
                   {
                       int dockedScreenIndex = GetDockedScreen(popup);
                       if (dockedScreenIndex < 0)
                           return new CustomPopupPlacement[0];

                       Screen dockedScreen;
                       if (dockedScreenIndex < Screen.AllScreens.Length)
                           dockedScreen = Screen.AllScreens[dockedScreenIndex];
                       else
                           dockedScreen = Screen.PrimaryScreen;

                       var workingArea = dockedScreen.WorkingArea;

                       var popupWidth = popupSize.Width;
                       var popupHeight = popupSize.Height;

                       var areaLeft = workingArea.Left;
                       var areaTop = workingArea.Top;
                       var areaWidth = workingArea.Width;
                       var areaHeight = workingArea.Height;

                       var popupLeft = 0.0;
                       var popupTop = 0.0;

                       HorizontalAlignment horizontal = GetDockHorizontal(popup);
                       VerticalAlignment vertical = GetDockVertical(popup);

                       switch (horizontal)
                       {
                           case HorizontalAlignment.Left:
                               popupLeft = areaLeft;
                               break;
                           case HorizontalAlignment.Center:
                               popupLeft = areaLeft + (areaWidth / 2 - popupWidth / 2);
                               break;
                           case HorizontalAlignment.Right:
                               popupLeft = areaLeft + areaWidth - popupWidth;
                               break;
                           case HorizontalAlignment.Stretch:
                               popupLeft = areaLeft;
                               popupWidth = areaWidth;
                               break;
                       }

                       switch (vertical)
                       {
                           case VerticalAlignment.Top:
                               popupTop = areaTop;
                               break;
                           case VerticalAlignment.Center:
                               popupTop = areaTop + (areaHeight / 2 - popupHeight / 2);
                               break;
                           case VerticalAlignment.Bottom:
                               popupTop = areaTop + areaHeight - popupHeight;
                               break;
                           case VerticalAlignment.Stretch:
                               popupTop = areaTop;
                               popupHeight = areaHeight;
                               break;
                       }
                       if ((popupTop < areaTop) || (popupTop + popupHeight > areaTop + areaHeight))
                       {
                           popupTop = areaTop;
                           popupHeight = areaHeight;
                       }
                       if ((popupLeft < areaLeft) || (popupLeft + popupWidth > areaLeft + areaWidth))
                       {
                           popupLeft = areaLeft;
                           popupWidth = areaWidth;
                       }
                       var popupLocation = new Point(popupLeft, popupTop);
                       if (horizontal == HorizontalAlignment.Stretch)
                           popup.Width = areaWidth;
                       if (vertical == VerticalAlignment.Stretch)
                           popup.Height = areaHeight;

                       var popupPlacement = new CustomPopupPlacement(popupLocation, PopupPrimaryAxis.Horizontal);
                       return new[]
                                  {
                                      popupPlacement
                                  };
                   };
        }