Esempio n. 1
0
        internal static RibbonControlSizeDefinition GetFrozenControlSizeDefinition(RibbonImageSize imageSize,
                                                                                   bool isLabelVisible)
        {
            if (isLabelVisible)
            {
                switch (imageSize)
                {
                case RibbonImageSize.Large:
                    return(LargeImageWithLabel);

                case RibbonImageSize.Small:
                    return(SmallImageWithLabel);

                default:
                    return(NoImageWithLabel);
                }
            }
            else
            {
                switch (imageSize)
                {
                case RibbonImageSize.Large:
                    return(LargeImageWithoutLabel);

                case RibbonImageSize.Small:
                    return(SmallImageWithoutLabel);

                default:
                    return(NoImageWithoutLabel);
                }
            }
        }
        private static object CoerceDefaultControlSizeDefinition(DependencyObject d, object baseValue)
        {
            if (baseValue == null)
            {
                RibbonControlGroup controlGroup = (RibbonControlGroup)d;
                RibbonImageSize    imageSize    = RibbonImageSize.Collapsed;
                bool isLabelVisible             = false;
                int  itemCount  = controlGroup.Items.Count;
                bool childFound = false;

                // Get the largest ControlSizeDefinition variant for all
                // the child controls and construct a union ControlSizeDefinition.
                for (int i = 0; i < itemCount; i++)
                {
                    RibbonControl ribbonControl = controlGroup.ItemContainerGenerator.ContainerFromIndex(i) as RibbonControl;
                    if (ribbonControl != null && ribbonControl.Visibility != Visibility.Collapsed)
                    {
                        UIElement contentChild = ribbonControl.ContentChild;
                        if (contentChild != null && contentChild.Visibility != Visibility.Collapsed)
                        {
                            RibbonControlSizeDefinition currentLargeCsd = RibbonControlService.GetDefaultControlSizeDefinition(contentChild);
                            if (currentLargeCsd == null)
                            {
                                contentChild.CoerceValue(RibbonControlService.DefaultControlSizeDefinitionProperty);
                                currentLargeCsd = RibbonControlService.GetDefaultControlSizeDefinition(contentChild);
                            }

                            if (currentLargeCsd != null)
                            {
                                childFound = true;
                                if (imageSize == RibbonImageSize.Collapsed)
                                {
                                    imageSize = currentLargeCsd.ImageSize;
                                }
                                else if (currentLargeCsd.ImageSize == RibbonImageSize.Large)
                                {
                                    imageSize = RibbonImageSize.Large;
                                }

                                isLabelVisible |= currentLargeCsd.IsLabelVisible;

                                if (isLabelVisible && imageSize == RibbonImageSize.Large)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                if (childFound)
                {
                    return(RibbonControlSizeDefinition.GetFrozenControlSizeDefinition(imageSize, isLabelVisible));
                }
            }
            return(baseValue);
        }
        private static object CoerceDefaultControlSizeDefinition(DependencyObject d, object baseValue)
        {
            if (baseValue == null)
            {
                RibbonImageSize imageSize = RibbonImageSize.Collapsed;
                if (RibbonControlService.GetLargeImageSource(d) != null)
                {
                    imageSize = RibbonImageSize.Large;
                }
                else if (RibbonControlService.GetSmallImageSource(d) != null)
                {
                    imageSize = RibbonImageSize.Small;
                }
                bool isLabelVisible = !string.IsNullOrEmpty(RibbonControlService.GetLabel(d));

                return(RibbonControlSizeDefinition.GetFrozenControlSizeDefinition(imageSize, isLabelVisible));
            }
            return(baseValue);
        }
 internal static RibbonControlSizeDefinition GetFrozenControlSizeDefinition(RibbonImageSize imageSize,
     bool isLabelVisible)
 {
     if (isLabelVisible)
     {
         switch (imageSize)
         {
             case RibbonImageSize.Large:
                 return LargeImageWithLabel;
             case RibbonImageSize.Small:
                 return SmallImageWithLabel;
             default:
                 return NoImageWithLabel;
         }
     }
     else
     {
         switch (imageSize)
         {
             case RibbonImageSize.Large:
                 return LargeImageWithoutLabel;
             case RibbonImageSize.Small:
                 return SmallImageWithoutLabel;
             default:
                 return NoImageWithoutLabel;
         }
     }
 }