protected override sw.Size MeasureOverride(sw.Size constraint) { // once loaded, act as normal if (IsLoaded) { return(base.MeasureOverride(constraint)); } // not loaded yet, let's calculate size based on all tabs var size = new sw.Size(0, 0); var selectedSize = new sw.Size(0, 0); var selected = SelectedItem as swc.TabItem; foreach (var tab in Items.Cast <swc.TabItem>()) { var tabContent = tab.Content as sw.FrameworkElement; if (tabContent == null) { continue; } tabContent.Measure(constraint); var tabSize = tabContent.DesiredSize; if (tab == selected) { selectedSize = tabSize; } size = size.Max(tabSize); } var baseSize = base.MeasureOverride(constraint); // calculate size of the border around the content based on selected tab's content size var borderSize = baseSize.Subtract(selectedSize); // return max height with border return(size.Add(borderSize)); }
public static Size Bounds(this Size size, Size minimum, Size maximum) { if (minimum.Width > maximum.Width || minimum.Height > maximum.Height) { throw new Granular.Exception("Invalid bounds (minimum: {0}, maximum: {1})", minimum, maximum); } return(size.Max(minimum).Min(maximum)); }