/// <summary> /// Invoked when the System.Windows.Controls.ItemsControl.Items property changes. /// </summary> /// <param name="e">Information about the change.</param> protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { foreach (var element in e.NewItems.OfType <UIElement>()) { RibbonAttachedProperties.SetAppropriateSize(element, State == RibbonGroupBoxState.QuickAccess ? RibbonGroupBoxState.Collapsed : State); } } base.OnItemsChanged(e); }
// Set child sizes private static void SetChildSizes(RibbonGroupBoxState ribbonGroupBoxState, ItemsControl ribbonGroupBox) { if (ribbonGroupBox.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) { return; } foreach (var item in ribbonGroupBox.Items) { RibbonAttachedProperties.SetAppropriateSize(ribbonGroupBox.ItemContainerGenerator.ContainerFromItem(item), ribbonGroupBoxState); } }