GetControlWorkArea() public static method

Returns screen workarea in witch control is placed
public static GetControlWorkArea ( FrameworkElement control ) : Rect
control System.Windows.FrameworkElement Control
return System.Windows.Rect
Esempio n. 1
0
        /// <inheritdoc />
        protected override void OnDropDownOpened(EventArgs e)
        {
            base.OnDropDownOpened(e);

            Mouse.Capture(this, CaptureMode.SubTree);

            if (this.SelectedItem is not null)
            {
                Keyboard.Focus(this.ItemContainerGenerator.ContainerOrContainerContentFromItem <IInputElement>(this.SelectedItem));
            }

            this.focusedElement = Keyboard.FocusedElement;

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

            this.canSizeY = true;

            if (this.scrollViewer is not null)
            {
                this.scrollViewer.Width  = double.NaN;
                this.scrollViewer.Height = double.NaN;
            }

            var popupChild = this.DropDownPopup?.Child as FrameworkElement;

            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;
            }

            popupChild?.UpdateLayout();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
        }