GetControlMonitor() public static méthode

Returns monitor in witch control is placed
public static GetControlMonitor ( FrameworkElement control ) : Rect
control System.Windows.FrameworkElement Control
Résultat System.Windows.Rect
Exemple #1
0
        // Handles resize both drag
        private void OnResizeBothDelta(object sender, DragDeltaEventArgs e)
        {
            // Set height
            SetDragHeight(e);

            // Set width
            menuPanel.Width = Double.NaN;
            if (Double.IsNaN(galleryPanel.Width))
            {
                galleryPanel.Width = galleryPanel.ActualWidth;
            }

            double           monitorRight = RibbonControl.GetControlMonitor(this).Right;
            FrameworkElement popupChild   = popup.Child as FrameworkElement;
            double           delta        = monitorRight - this.PointToScreen(new Point()).X - popupChild.ActualWidth - e.HorizontalChange;
            double           deltaX       = popupChild.ActualWidth - galleryPanel.ActualWidth;
            double           deltaBorders = dropDownBorder.ActualWidth - galleryPanel.ActualWidth;

            if (delta > 0)
            {
                galleryPanel.Width = Math.Max(galleryPanel.Width + e.HorizontalChange, ActualWidth - deltaBorders);
            }
            else
            {
                galleryPanel.Width = Math.Max(monitorRight - this.PointToScreen(new Point()).X - deltaX, ActualWidth - deltaBorders);
            }
        }
Exemple #2
0
        // Handles resize both drag
        private void OnResizeBothDelta(object sender, DragDeltaEventArgs e)
        {
            // Set height
            this.SetDragHeight(e);

            // Set width
            this.menuPanel.Width = double.NaN;
            if (double.IsNaN(this.galleryPanel.Width))
            {
                this.galleryPanel.Width = this.galleryPanel.ActualWidth;
            }

            var monitorRight = RibbonControl.GetControlMonitor(this).Right;
            var popupChild   = this.DropDownPopup.Child as FrameworkElement;
            var delta        = monitorRight - this.PointToScreen(new Point()).X - popupChild.ActualWidth - e.HorizontalChange;
            var deltaX       = popupChild.ActualWidth - this.galleryPanel.ActualWidth;
            var deltaBorders = this.dropDownBorder.ActualWidth - this.galleryPanel.ActualWidth;

            if (delta > 0)
            {
                this.galleryPanel.Width = Math.Max(0, Math.Max(this.galleryPanel.Width + e.HorizontalChange, this.ActualWidth - deltaBorders));
            }
            else
            {
                this.galleryPanel.Width = Math.Max(0, Math.Max(monitorRight - this.PointToScreen(new Point()).X - deltaX, this.ActualWidth - deltaBorders));
            }
        }
Exemple #3
0
        private void SetDragHeight(DragDeltaEventArgs e)
        {
            if (!canSizeY)
            {
                return;
            }

            if (double.IsNaN(scrollViewer.Height))
            {
                scrollViewer.Height = scrollViewer.ActualHeight;
            }

            if (ShowPopupOnTop)
            {
                var monitorTop = RibbonControl.GetControlMonitor(this).Top;

                // Calc shadow height
                var delta = this.PointToScreen(new Point()).Y - dropDownBorder.ActualHeight - e.VerticalChange - monitorTop;
                if (delta > 0)
                {
                    scrollViewer.Height = Math.Max(0,
                                                   Math.Min(Math.Max(galleryPanel.GetItemSize().Height, scrollViewer.Height + e.VerticalChange),
                                                            MaxDropDownHeight));
                }
                else
                {
                    delta = this.PointToScreen(new Point()).Y - dropDownBorder.ActualHeight - monitorTop;
                    scrollViewer.Height = Math.Max(0,
                                                   Math.Min(Math.Max(galleryPanel.GetItemSize().Height, scrollViewer.Height + delta),
                                                            MaxDropDownHeight));
                }
            }
            else
            {
                var monitorBottom = RibbonControl.GetControlMonitor(this).Bottom;
                var popupChild    = popup.Child as FrameworkElement;
                var delta         = monitorBottom - this.PointToScreen(new Point()).Y - ActualHeight - popupChild.ActualHeight - e.VerticalChange;
                if (delta > 0)
                {
                    scrollViewer.Height = Math.Max(0,
                                                   Math.Min(Math.Max(galleryPanel.GetItemSize().Height, scrollViewer.Height + e.VerticalChange),
                                                            MaxDropDownHeight));
                }
                else
                {
                    delta = monitorBottom - this.PointToScreen(new Point()).Y - ActualHeight - popupChild.ActualHeight;
                    scrollViewer.Height = Math.Max(0,
                                                   Math.Min(Math.Max(galleryPanel.GetItemSize().Height, scrollViewer.Height + delta),
                                                            MaxDropDownHeight));
                }
            }
        }
Exemple #4
0
        // Handles resize both drag
        private void OnResizeBothDelta(object sender, DragDeltaEventArgs e)
        {
            // Set height
            this.SetDragHeight(e);

            // Set width
            this.menuPanel.Width = double.NaN;
            if (double.IsNaN(this.scrollViewer.Width))
            {
                this.scrollViewer.Width = this.scrollViewer.ActualWidth;
            }

            var monitorRight = RibbonControl.GetControlMonitor(this).Right;
            var popupChild   = this.DropDownPopup.Child as FrameworkElement;

            if (popupChild == null)
            {
                return;
            }

            var delta        = monitorRight - this.PointToScreen(default).X - popupChild.ActualWidth - e.HorizontalChange;
Exemple #5
0
        /// <summary>
        /// Implements custom placement for ribbon popup
        /// </summary>
        /// <param name="popupsize"></param>
        /// <param name="targetsize"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupsize, Size targetsize, Point offset)
        {
            if (popup != null)
            {
                Rect  monitorRect = RibbonControl.GetControlMonitor(this);
                Point pos         = PointToScreen(new Point());

                if (ShowPopupOnTop)
                {
                    return(new CustomPopupPlacement[]
                    {
                        new CustomPopupPlacement(new Point(0, -dropDownBorder.ActualHeight), PopupPrimaryAxis.Horizontal),
                    });
                }
                else
                {
                    return(new CustomPopupPlacement[]
                    {
                        new CustomPopupPlacement(new Point(0, ActualHeight), PopupPrimaryAxis.Horizontal),
                    });
                }
            }
            return(null);
        }
Exemple #6
0
        /// <summary>
        ///     Reports when a combo box's popup opens.
        /// </summary>
        /// <param name="e">The event data for the <see cref="E:System.Windows.Controls.ComboBox.DropDownOpened" /> event.</param>
        protected override void OnDropDownOpened(EventArgs e)
        {
            base.OnDropDownOpened(e);

            Mouse.Capture(this, CaptureMode.SubTree);

            if (this.SelectedItem != null)
            {
                Keyboard.Focus(this.ItemContainerGenerator.ContainerFromItem(this.SelectedItem) as IInputElement);
            }

            this.focusedElement = Keyboard.FocusedElement;

            if (this.focusedElement != null)
            {
                this.focusedElement.LostKeyboardFocus += this.OnFocusedElementLostKeyboardFocus;
            }

            this.canSizeY = true;

            this.galleryPanel.Width  = double.NaN;
            this.scrollViewer.Height = double.NaN;

            var popupChild  = this.DropDownPopup.Child as FrameworkElement;
            var heightDelta = popupChild.DesiredSize.Height - this.scrollViewer.DesiredSize.Height;

            var initialHeight = Math.Min(RibbonControl.GetControlWorkArea(this).Height * 2 / 3, this.MaxDropDownHeight);

            if (double.IsNaN(this.DropDownHeight) == false)
            {
                initialHeight = Math.Min(this.DropDownHeight, this.MaxDropDownHeight);
            }

            if (this.scrollViewer.DesiredSize.Height > initialHeight)
            {
                this.scrollViewer.Height = initialHeight;
            }
            else
            {
                initialHeight = this.scrollViewer.DesiredSize.Height;
            }

            var monitor = RibbonControl.GetControlMonitor(this);
            var delta   = monitor.Bottom - this.PointToScreen(new Point()).Y - this.ActualHeight - initialHeight - heightDelta;

            if (delta >= 0)
            {
                this.ShowPopupOnTop = false;
            }
            else
            {
                var deltaTop = this.PointToScreen(new Point()).Y - initialHeight - heightDelta - monitor.Top;

                if (deltaTop > delta)
                {
                    this.ShowPopupOnTop = true;
                }
                else
                {
                    this.ShowPopupOnTop = false;
                }

                if (deltaTop < 0)
                {
                    delta = Math.Max(Math.Abs(delta), Math.Abs(deltaTop));

                    if (delta > this.galleryPanel.GetItemSize().Height)
                    {
                        this.scrollViewer.Height = delta;
                    }
                    else
                    {
                        this.canSizeY            = false;
                        this.scrollViewer.Height = this.galleryPanel.GetItemSize().Height;
                    }
                }
            }

            popupChild.UpdateLayout();
        }
Exemple #7
0
        /// <summary>
        /// Reports when a combo box's popup opens.
        /// </summary>
        /// <param name="e">The event data for the <see cref="E:System.Windows.Controls.ComboBox.DropDownOpened"/> event.</param>
        protected override void OnDropDownOpened(EventArgs e)
        {
            base.OnDropDownOpened(e);
            Mouse.Capture(this, CaptureMode.SubTree);
            if (SelectedItem != null)
            {
                Keyboard.Focus(ItemContainerGenerator.ContainerFromItem(SelectedItem) as IInputElement);
            }
            focusedElement = Keyboard.FocusedElement;
            focusedElement.LostKeyboardFocus += OnFocusedElementLostKeyboardFocus;

            canSizeX = true;
            canSizeY = true;

            galleryPanel.Width  = double.NaN;
            scrollViewer.Height = double.NaN;

            FrameworkElement popupChild = popup.Child as FrameworkElement;

            scrollViewer.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            popupChild.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            popup.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            double heightDelta = popupChild.DesiredSize.Height - scrollViewer.DesiredSize.Height;

            double initialHeight = Math.Min(RibbonControl.GetControlWorkArea(this).Height * 2 / 3, MaxDropDownHeight);

            if (!double.IsNaN(DropDownHeight))
            {
                initialHeight = Math.Min(DropDownHeight, MaxDropDownHeight);
            }
            if (scrollViewer.DesiredSize.Height > initialHeight)
            {
                scrollViewer.Height = initialHeight;
            }
            else
            {
                initialHeight = scrollViewer.DesiredSize.Height;
            }

            Rect   monitor = RibbonControl.GetControlMonitor(this);
            double delta   = monitor.Bottom - this.PointToScreen(new Point()).Y - ActualHeight - initialHeight - heightDelta;

            if (delta >= 0)
            {
                ShowPopupOnTop = false;
            }
            else
            {
                double deltaTop = this.PointToScreen(new Point()).Y - initialHeight - heightDelta - monitor.Top;
                if (deltaTop > delta)
                {
                    ShowPopupOnTop = true;
                }
                else
                {
                    ShowPopupOnTop = false;
                }

                if (deltaTop < 0)
                {
                    delta = Math.Max(Math.Abs(delta), Math.Abs(deltaTop));
                    if (delta > galleryPanel.GetItemSize().Height)
                    {
                        scrollViewer.Height = delta;
                    }
                    else
                    {
                        canSizeY            = false;
                        scrollViewer.Height = galleryPanel.GetItemSize().Height;
                    }
                }
            }
            popupChild.UpdateLayout();
        }