Exemplo n.º 1
0
        private void ArrangePopup()
        {
            if (((this.m_popup != null) && (this.m_popupRoot != null)) && this.m_popup.IsOpen)
            {
                System.Windows.Interop.Content content = Application.Current.Host.Content;
                double actualWidth  = content.ActualWidth;
                double actualHeight = content.ActualHeight;
                double num3         = this.m_popupRoot.ActualWidth;
                double num4         = this.m_popupRoot.ActualHeight;
                if (((actualHeight != 0.0) && (actualWidth != 0.0)) && ((num3 != 0.0) && (num4 != 0.0)))
                {
                    GeneralTransform transform = null;
                    try
                    {
                        transform = this.m_popupRoot.TransformToVisual(null);
                    }
                    catch
                    {
                        //Don't need to do nothing.
                    }
                    if (transform != null)
                    {
                        Point  point  = new Point(0.0, 0.0);
                        Point  point2 = new Point(1.0, 0.0);
                        Point  point3 = new Point(0.0, 1.0);
                        Point  point4 = transform.Transform(point);
                        Point  point5 = transform.Transform(point2);
                        Point  point6 = transform.Transform(point3);
                        double x      = point4.X;
                        double y      = point4.Y;
                        double num7   = base.ActualHeight;
                        double num8   = base.ActualWidth;

                        this.m_popup.HorizontalOffset    = 0.0;
                        this.m_popup.VerticalOffset      = 0.0;
                        this.m_canvasPopupOutside.Width  = actualWidth;
                        this.m_canvasPopupOutside.Height = actualHeight;
                        Matrix identity = Matrix.Identity;
                        identity.M11      = point5.X - point4.X;
                        identity.M12      = point5.Y - point4.Y;
                        identity.M21      = point6.X - point4.X;
                        identity.M22      = point6.Y - point4.Y;
                        identity.OffsetX -= point4.X;
                        identity.OffsetY -= point4.Y;
                        MatrixTransform transform2 = new MatrixTransform();
                        transform2.Matrix = identity;
                        this.m_canvasPopupOutside.RenderTransform = transform2;
                        this.m_popupRoot.MinWidth            = num8;
                        this.m_popupRoot.MaxWidth            = actualWidth;
                        this.m_popupRoot.MinHeight           = num7;
                        this.m_popupRoot.MaxHeight           = actualHeight;
                        this.m_popupRoot.HorizontalAlignment = HorizontalAlignment.Left;
                        this.m_popupRoot.VerticalAlignment   = VerticalAlignment.Top;



                        try
                        {
                            transform = this.TransformToVisual(null);
                        }
                        catch
                        {
                            //Don't need to do nothing.
                        }
                        point4 = transform.Transform(point);
                        if ((this.m_popupRoot.ActualWidth - base.ActualWidth) <= point4.X)
                        {
                            Canvas.SetLeft(this.m_popupRoot, -(this.m_popupRoot.ActualWidth - this.ActualWidth));
                        }
                        else
                        {
                            Canvas.SetLeft(this.m_popupRoot, 0);
                        }

                        if (this.m_popupRoot.ActualHeight <= (actualHeight - point4.Y - base.ActualHeight))
                        {
                            Canvas.SetTop(this.m_popupRoot, base.ActualHeight);
                        }
                        else
                        {
                            Canvas.SetTop(this.m_popupRoot, -this.m_popupRoot.ActualHeight);
                        }



                        bool   isTop  = false;
                        bool   isLeft = false;
                        double popY   = Canvas.GetTop(this.m_popupRoot);
                        double popX   = Canvas.GetLeft(this.m_popupRoot);
                        if (popY < 0)
                        {
                            isTop = true;
                        }
                        if (popX < 0)
                        {
                            isLeft = true;
                        }

                        if (isTop && isLeft)
                        {
                            this.m_popupContent.Margin = new Thickness(0, 1, 0, 0);
                            VisualStateManager.GoToState(this, "PopTopLeftState", false);
                        }
                        else if (!isTop && isLeft)
                        {
                            this.m_popupContent.Margin = new Thickness(0, -1, 0, 0);
                            VisualStateManager.GoToState(this, "PopBottomLeftState", false);
                        }
                        else if (!isTop && !isLeft)
                        {
                            this.m_popupContent.Margin = new Thickness(0, -1, 0, 0);
                            VisualStateManager.GoToState(this, "PopBottomRightState", false);
                        }
                        else if (isTop && !isLeft)
                        {
                            this.m_popupContent.Margin = new Thickness(0, 1, 0, 0);
                            VisualStateManager.GoToState(this, "PopTopRightState", false);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void ArrangePopup(Popup ElementPopup,
                                 Canvas ElementPopupChildCanvas,
                                 Canvas ElementOutsidePopup,
                                 FrameworkElement ElementPopupChild,
                                 ContentControl LeaderPopupContent,
                                 StackPanel ElementPopupChildMaxRangeStackPanel,
                                 Control AssociatedControl,
                                 ExpandDirection ExpandDirection,
                                 bool EnforceMinWidth = true,
                                 bool isNestedPopup   = true
                                 )
        {
            if (ElementPopup != null && AssociatedControl != null)
            {
                bool isRTL = (AssociatedControl.FlowDirection == FlowDirection.RightToLeft);
                System.Windows.Interop.Content content = System.Windows.Application.Current.Host.Content;
                double applicationWidth  = content.ActualWidth;
                double applicationHeight = content.ActualHeight;
                double popupWidth        = ElementPopupChild.ActualWidth;
                double popupHeight       = ElementPopupChild.ActualHeight;
                if ((applicationHeight != 0.0) && (applicationWidth != 0.0))
                {
                    GeneralTransform transform = AssociatedControl.TransformToVisual(null);
                    if (isRTL && transform is MatrixTransform)
                    {
                        var mt = (MatrixTransform)transform;
                        transform = new MatrixTransform
                        {
                            Matrix = new Matrix
                            {
                                M11     = mt.Matrix.M11,
                                M12     = mt.Matrix.M12,
                                M21     = mt.Matrix.M21,
                                M22     = mt.Matrix.M22,
                                OffsetX = mt.Matrix.OffsetX - AssociatedControl.ActualWidth,
                                OffsetY = mt.Matrix.OffsetY,
                            }
                        };
                    }
                    if (transform != null)
                    {
                        Point  topLeftTransPoint    = new Point(0.0, 0.0);
                        Point  topRightTransPoint   = new Point(1.0, 0.0);
                        Point  bottomLeftTransPoint = new Point(0.0, 1.0);
                        Point  topLeftPosition      = transform.Transform(topLeftTransPoint);
                        Point  topRightPosition     = transform.Transform(topRightTransPoint);
                        Point  bottomLeftPosition   = transform.Transform(bottomLeftTransPoint);
                        double xDropDown            = topLeftPosition.X;
                        double yDropDown            = topLeftPosition.Y;
                        double widthRatio           = Math.Abs((double)(topRightPosition.X - topLeftPosition.X));
                        double heightRatio          = Math.Abs((double)(bottomLeftPosition.Y - topLeftPosition.Y));
                        double heightDropDown       = AssociatedControl.ActualHeight * heightRatio;
                        double widthDropDown        = AssociatedControl.ActualWidth * widthRatio;
                        double yBottomDropDown      = yDropDown + heightDropDown;
                        if ((heightDropDown != 0.0) && (widthDropDown != 0.0))
                        {
                            popupWidth  *= widthRatio;
                            popupHeight *= heightRatio;
                            double maxDropDownHeight = double.PositiveInfinity;
                            if (ExpandDirection == ExpandDirection.BottomLeft)
                            {
                                if (double.IsInfinity(maxDropDownHeight) || double.IsNaN(maxDropDownHeight))
                                {
                                    maxDropDownHeight = ((applicationHeight - heightDropDown) * 3.0) / 5.0;
                                }
                                bool flag = true;
                                if (applicationHeight < (yBottomDropDown + popupHeight))
                                {
                                    flag            = false;
                                    yBottomDropDown = yDropDown - popupHeight;
                                    if (yBottomDropDown < 0.0)
                                    {
                                        if (yDropDown < ((applicationHeight - heightDropDown) / 2.0))
                                        {
                                            flag            = true;
                                            yBottomDropDown = yDropDown + heightDropDown;
                                        }
                                        else
                                        {
                                            flag            = false;
                                            yBottomDropDown = yDropDown - popupHeight;
                                        }
                                    }
                                }
                                if (popupHeight != 0.0)
                                {
                                    if (flag)
                                    {
                                        maxDropDownHeight = Math.Min(applicationHeight - yBottomDropDown, maxDropDownHeight);
                                    }
                                    else
                                    {
                                        maxDropDownHeight = Math.Min(yDropDown, maxDropDownHeight);
                                    }
                                }
                            }
                            else
                            {
                                if (double.IsInfinity(maxDropDownHeight) || double.IsNaN(maxDropDownHeight))
                                {
                                    maxDropDownHeight = applicationHeight - 2 * RIGHT_CENTER_TOP_BOTTOM_MARGIN;
                                }
                            }
                            popupWidth  = Math.Min(popupWidth, applicationWidth);
                            popupHeight = Math.Min(popupHeight, maxDropDownHeight);
                            popupWidth  = Math.Max(widthDropDown, popupWidth);
                            double applicationRemainWidth = 0.0;
                            double leaderWidth            = GetFrameworkElementWidth(LeaderPopupContent);
                            if (double.IsNaN(leaderWidth) || double.IsInfinity(leaderWidth))
                            {
                                leaderWidth = 0;
                            }

                            if (AssociatedControl.FlowDirection == FlowDirection.LeftToRight)
                            {
                                if (applicationWidth < (xDropDown + popupWidth))
                                {
                                    applicationRemainWidth = applicationWidth - (popupWidth + xDropDown);
                                }
                            }
                            else if (0.0 > (xDropDown - popupWidth))
                            {
                                applicationRemainWidth = xDropDown - popupWidth;
                            }

                            ElementPopup.HorizontalOffset = 0.0;
                            ElementPopup.VerticalOffset   = 0.0;

                            Matrix identity = Matrix.Identity;
                            identity.OffsetX -= topLeftPosition.X / widthRatio;
                            identity.OffsetY -= topLeftPosition.Y / heightRatio;
                            MatrixTransform transform2 = new MatrixTransform();
                            transform2.Matrix = identity;

                            if (ElementOutsidePopup != null)
                            {
                                ElementOutsidePopup.Width           = applicationWidth / widthRatio;
                                ElementOutsidePopup.Height          = applicationHeight / heightRatio;
                                ElementOutsidePopup.RenderTransform = transform2;
                            }

                            double minWidthDropDown = 0.0;
                            if (EnforceMinWidth)
                            {
                                minWidthDropDown           = widthDropDown / widthRatio;
                                ElementPopupChild.MinWidth = minWidthDropDown;
                            }

                            double maxPopupWidth = double.PositiveInfinity;
                            bool   reversePopupExpandDirection = false;
                            if (ExpandDirection == ExpandDirection.BottomLeft)
                            {
                                maxPopupWidth = applicationWidth / widthRatio;
                            }
                            else
                            {
                                maxPopupWidth = applicationWidth - (xDropDown + widthDropDown) - leaderWidth;
                                maxPopupWidth = maxPopupWidth / widthRatio;

                                if (maxPopupWidth < popupWidth)
                                {
                                    double tempMaxPopupWidth;
                                    //try show on the other side
                                    tempMaxPopupWidth = xDropDown - leaderWidth;
                                    if (tempMaxPopupWidth >= 0 && tempMaxPopupWidth > maxPopupWidth)
                                    {
                                        maxPopupWidth = tempMaxPopupWidth;
                                        reversePopupExpandDirection = true;
                                    }
                                }
                            }

                            ElementPopupChild.MaxWidth            = Math.Max(minWidthDropDown, maxPopupWidth);
                            ElementPopupChild.MinHeight           = heightDropDown / heightRatio;
                            ElementPopupChild.MaxHeight           = Math.Max((double)0.0, (double)(maxDropDownHeight / heightRatio));
                            ElementPopupChild.HorizontalAlignment = HorizontalAlignment.Left;
                            ElementPopupChild.VerticalAlignment   = VerticalAlignment.Top;
                            ElementPopupChild.FlowDirection       = AssociatedControl.FlowDirection;

                            if (ElementPopupChildMaxRangeStackPanel != null) //if horizontal central alignment, then simply reuse the maxrange canvas and align within
                            {
                                double top      = isNestedPopup ? (heightDropDown - popupHeight) / 2 : Math.Max(0.0, yDropDown + (heightDropDown - popupHeight) / 2);
                                double overflow = Math.Abs(Math.Min(applicationHeight - (yDropDown + (yBottomDropDown - yDropDown) / 2 + popupHeight / 2 + RIGHT_CENTER_TOP_BOTTOM_MARGIN), 0.0));
                                if (overflow > 0)
                                {
                                    top -= overflow;                                              //move up if overflowing underneath
                                }
                                top = Math.Max(top, -yDropDown + RIGHT_CENTER_TOP_BOTTOM_MARGIN); //did our best to calculate top, so set to top or application level x=0

                                Canvas.SetTop(ElementPopupChildMaxRangeStackPanel, top);
                                ElementPopupChildMaxRangeStackPanel.Width  = maxPopupWidth;
                                ElementPopupChildMaxRangeStackPanel.Height = popupHeight;

                                if (isRTL && isNestedPopup)
                                {
                                    reversePopupExpandDirection = !reversePopupExpandDirection;
                                }

                                if (reversePopupExpandDirection)
                                {
                                    Canvas.SetLeft(ElementPopupChildMaxRangeStackPanel, isNestedPopup ? -xDropDown : 0);
                                }
                                else
                                {
                                    Canvas.SetLeft(ElementPopupChildMaxRangeStackPanel, (isNestedPopup ? 0: xDropDown) + AssociatedControl.ActualWidth + leaderWidth);
                                }

                                if (reversePopupExpandDirection)
                                {
                                    ElementPopupChild.HorizontalAlignment = HorizontalAlignment.Right;
                                }

                                SetupLeader(LeaderPopupContent, ElementPopupChildMaxRangeStackPanel, reversePopupExpandDirection, xDropDown, yDropDown, heightDropDown, ExpandDirection, AssociatedControl, isNestedPopup);
                            }
                            else
                            {
                                SetPopupTop(ElementPopupChild, yBottomDropDown, heightRatio, yDropDown, popupHeight, applicationHeight, ExpandDirection);
                                SetPopupLeft(ElementPopupChild, applicationRemainWidth, widthRatio, popupWidth, maxPopupWidth, reversePopupExpandDirection, ExpandDirection, AssociatedControl, xDropDown);
                                SetupLeader(LeaderPopupContent, ElementPopupChild, reversePopupExpandDirection, xDropDown, yDropDown, heightDropDown, ExpandDirection, AssociatedControl, isNestedPopup);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ArrangePopup()
        {
            if (((this._popup != null) && (this._popupRoot != null)) && this._popup.IsOpen)
            {
                System.Windows.Interop.Content content = Application.Current.Host.Content;
                double actualWidth  = content.ActualWidth;
                double actualHeight = content.ActualHeight;
                double num3         = this._popupRoot.ActualWidth;
                double num4         = this._popupRoot.ActualHeight;
                if (((actualHeight != 0.0) && (actualWidth != 0.0)) && ((num3 != 0.0) && (num4 != 0.0)))
                {
                    GeneralTransform transform = null;
                    try
                    {
                        transform = this._popupRoot.TransformToVisual(null);
                    }
                    catch
                    {
                        //Don't need to do nothing.
                    }

                    if (transform != null)
                    {
                        Point  point  = new Point(0.0, 0.0);
                        Point  point2 = new Point(1.0, 0.0);
                        Point  point3 = new Point(0.0, 1.0);
                        Point  point4 = transform.Transform(point);
                        Point  point5 = transform.Transform(point2);
                        Point  point6 = transform.Transform(point3);
                        double x      = point4.X;
                        double y      = point4.Y;
                        double num7   = base.ActualHeight;
                        double num8   = base.ActualWidth;

                        num3 = Math.Min(num3, actualWidth);
                        num4 = Math.Min(num4, actualHeight);
                        num3 = Math.Max(num8, num3);
                        double num10 = x;
                        if (actualWidth <= (num10 + num3))
                        {
                            num10 = actualWidth - num3;
                            num10 = Math.Max(0.0, num10);
                        }
                        double num11 = y + num7;
                        if (actualHeight <= (num11 + num4))
                        {
                            num11 = y - num4;
                            if (num11 < 0.0)
                            {
                                if (y < ((actualHeight - num7) / 2.0))
                                {
                                    num11 = y + num7;
                                }
                                else
                                {
                                    num11 = y - num4;
                                }
                            }
                        }
                        this._popup.HorizontalOffset    = 0.0;
                        this._popup.VerticalOffset      = 0.0;
                        this._canvasPopupOutside.Width  = actualWidth;
                        this._canvasPopupOutside.Height = actualHeight;
                        Matrix identity = Matrix.Identity;
                        identity.M11      = point5.X - point4.X;
                        identity.M12      = point5.Y - point4.Y;
                        identity.M21      = point6.X - point4.X;
                        identity.M22      = point6.Y - point4.Y;
                        identity.OffsetX -= point4.X;
                        identity.OffsetY -= point4.Y;
                        MatrixTransform transform2 = new MatrixTransform();
                        transform2.Matrix = identity;
                        this._canvasPopupOutside.RenderTransform = transform2;
                        this._popupRoot.MinWidth            = num8;
                        this._popupRoot.MaxWidth            = actualWidth;
                        this._popupRoot.MinHeight           = num7;
                        this._popupRoot.MaxHeight           = actualHeight;
                        this._popupRoot.HorizontalAlignment = HorizontalAlignment.Left;
                        this._popupRoot.VerticalAlignment   = VerticalAlignment.Top;

                        Canvas.SetLeft(this._popupRoot, num10 - x);
                        Canvas.SetTop(this._popupRoot, num11 - y);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Toggle full screen
        /// </summary>
        /// <param name="sender">the full screen button</param>
        /// <param name="e">the mouse button event args</param>
        private void OnFullScreen(object sender, MouseButtonEventArgs e)
        {
            var content = new System.Windows.Interop.Content();

            content.IsFullScreen = !content.IsFullScreen;
        }