/// <summary> /// When overridden in a derived class, measures the size in layout required for child elements and determines a size for the <see cref="T:System.Windows.FrameworkElement" />-derived class. /// </summary> /// <param name="availableSize">The available size that this element can give to child elements. Infinity can be specified as a value to indicate that the element will size to whatever content is available.</param> /// <returns>The size that this element determines it needs during layout, based on its calculations of child element sizes.</returns> protected override Size MeasureOverride(Size availableSize) { if (HeaderRenderer == null) { HeaderRenderer = new TabItemsHeaderRenderer(); } var widest = 0d; var tallest = 0d; var availableItemSize = HeaderRenderer.GetClientRect(this, availableSize).Size; foreach (var element in Children.OfType <UIElement>().Where(e => e.Visibility == Visibility.Visible)) { element.Measure(availableItemSize); widest = Math.Max(widest, element.DesiredSize.Width); tallest = Math.Max(tallest, element.DesiredSize.Height); } base.MeasureOverride(availableSize); if (!double.IsInfinity(availableSize.Width) && !double.IsInfinity(availableSize.Height)) { return(availableSize); } return(new Size(widest, tallest)); }
/// <summary> /// When overridden in a derived class, positions child elements and determines a size for a <see cref="T:System.Windows.FrameworkElement" /> derived class. /// </summary> /// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param> /// <returns>The actual size used.</returns> protected override Size ArrangeOverride(Size finalSize) { if (HeaderRenderer == null) { HeaderRenderer = new TabItemsHeaderRenderer(); } var clientRect = HeaderRenderer.GetClientRect(this, finalSize); foreach (var element in Children.OfType <UIElement>().Where(e => e.Visibility == Visibility.Visible)) { element.Arrange(clientRect); } base.ArrangeOverride(finalSize); return(clientRect.Size); }