Esempio n. 1
0
        // As InRibbonGallery switches modes from RibbonGallery being inside Ribbon or in Popup, the Visual parents needs to be changed.
        // and Visual properties of some Visuals needs to be coerced.
        private void PrivateManageRibbonGalleryVisualParent()
        {
            CoerceVisibilityPropertiesOnRibbonGallery();

            if (IsInInRibbonMode)
            {
                if (_firstGallery != null)
                {
                    if (_itemsPresenter != null)
                    {
                        RibbonMenuItemsPanel panel = (VisualTreeHelper.GetChildrenCount(_itemsPresenter) > 0 ? VisualTreeHelper.GetChild(_itemsPresenter, 0) : null) as RibbonMenuItemsPanel;
                        if (panel != null)
                        {
                            panel.RemoveFirstGallery(this);
                        }
                    }

                    if (_contentPresenter != null)
                    {
                        _contentPresenter.Content = _firstGallery;
                    }
                }
            }
            else
            {
                // Removes _firstGallery from ContentPresenter and add it to the ItemsPresenter
                if (_contentPresenter != null)
                {
                    _contentPresenter.Content = null;
                }

                if (_itemsPresenter != null)
                {
                    if (VisualTreeHelper.GetChildrenCount(_itemsPresenter) > 0)
                    {
                        RibbonMenuItemsPanel panel = VisualTreeHelper.GetChild(_itemsPresenter, 0) as RibbonMenuItemsPanel;
                        if (panel != null && _firstGallery != null)
                        {
                            panel.ReInsertFirstGallery(this);
                        }
                    }
                }
            }
        }
        public static Size GetMinDropDownSize(RibbonMenuItemsPanel itemsHost, Popup popup, Thickness borderThickness)
        {
            Size minSize = new Size();

            if (itemsHost != null)
            {
                minSize = itemsHost.CachedAutoSize;
                if (popup != null)
                {
                    FrameworkElement popupChild = popup.Child as FrameworkElement;
                    if (popupChild != null && DoubleUtil.GreaterThan(popupChild.MinWidth, minSize.Width))
                    {
                        // MenuButton's BorderThickness around the ItemsPresenter
                        minSize.Width = popupChild.MinWidth - (borderThickness.Left + borderThickness.Right);
                    }
                }
            }

            return(minSize);
        }