/// <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) { foreach (UIElement element in Children) { if (SimpleView.GetUIElementType(element) == UIElementTypes.Primary) { if (CanCollapseSecondary && IsSecondaryElementCollapsed) { var minimumCollapsedWidth = 0d; var mainAreaLeft = 0d; if (HeaderRenderer != null) { minimumCollapsedWidth = HeaderRenderer.GetMinimumCollapsedAreaWidth(this); if (SecondaryAreaLocation == SecondaryAreaLocation.Left) { mainAreaLeft = minimumCollapsedWidth + (minimumCollapsedWidth > 0d ? ElementSpacing : 0d); } } var primaryArea = new Rect(mainAreaLeft, 0d, finalSize.Width - minimumCollapsedWidth - (minimumCollapsedWidth > 0d ? ElementSpacing : 0d), finalSize.Height); if (HeaderRenderer != null) { primaryArea = HeaderRenderer.GetPrimaryClientArea(primaryArea, this); } _currentPrimaryArea = primaryArea; element.Arrange(primaryArea); } else { var currentX = 0d; if (SecondaryAreaLocation == SecondaryAreaLocation.Left) { currentX = SecondaryElementWidth + ElementSpacing; } var primaryArea = new Rect(currentX, 0d, Math.Max(finalSize.Width - SecondaryElementWidth - ElementSpacing, 0), finalSize.Height); if (HeaderRenderer != null) { primaryArea = HeaderRenderer.GetPrimaryClientArea(primaryArea, this); } _currentPrimaryArea = primaryArea; element.Arrange(primaryArea); } } else { if (CanCollapseSecondary && IsSecondaryElementCollapsed) { _currentSecondaryArea = new Rect(-100000d, -100000d, 0d, finalSize.Height); element.Arrange(_currentSecondaryArea); } else { var secondaryArea = SecondaryAreaLocation == SecondaryAreaLocation.Left ? new Rect(0d, 0d, SecondaryElementWidth, finalSize.Height) : new Rect(finalSize.Width - SecondaryElementWidth, 0d, SecondaryElementWidth, finalSize.Height); if (HeaderRenderer != null) { secondaryArea = HeaderRenderer.GetSecondaryClientArea(secondaryArea, this); } _currentSecondaryArea = secondaryArea; element.Arrange(secondaryArea); } } } return(base.ArrangeOverride(finalSize)); }
/// <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 StandardPrimarySecondaryHorizontalPanelHeaderRenderer(); } foreach (UIElement element in Children) { if (SimpleView.GetUIElementType(element) == UIElementTypes.Primary) { if (CanCollapseSecondary && IsSecondaryElementCollapsed) { var minimumCollapsedWidth = 0d; var mainAreaLeft = 0d; if (HeaderRenderer != null) { minimumCollapsedWidth = HeaderRenderer.GetMinimumCollapsedAreaWidth(this); if (SecondaryAreaLocation == SecondaryAreaLocation.Left) { mainAreaLeft = minimumCollapsedWidth + (minimumCollapsedWidth > 0d ? ElementSpacing : 0d); } } var primaryArea = new Rect(mainAreaLeft, 0d, availableSize.Width - minimumCollapsedWidth - (minimumCollapsedWidth > 0d ? ElementSpacing : 0d), availableSize.Height); if (HeaderRenderer != null) { primaryArea = HeaderRenderer.GetPrimaryClientArea(primaryArea, this); } element.Measure(primaryArea.Size); } else { var currentX = 0d; if (SecondaryAreaLocation == SecondaryAreaLocation.Left) { currentX = SecondaryElementWidth + ElementSpacing; } var primaryArea = new Rect(currentX, 0d, Math.Max(availableSize.Width - SecondaryElementWidth - ElementSpacing, 0), availableSize.Height); if (HeaderRenderer != null) { primaryArea = HeaderRenderer.GetPrimaryClientArea(primaryArea, this); } element.Measure(primaryArea.Size); } } else { if (CanCollapseSecondary && IsSecondaryElementCollapsed) { element.Measure(new Size(0, availableSize.Height)); } else { var secondaryArea = SecondaryAreaLocation == SecondaryAreaLocation.Left ? new Rect(0d, 0d, SecondaryElementWidth, availableSize.Height) : new Rect(availableSize.Width - SecondaryElementWidth, 0d, SecondaryElementWidth, availableSize.Height); if (HeaderRenderer != null) { secondaryArea = HeaderRenderer.GetSecondaryClientArea(secondaryArea, this); } element.Measure(secondaryArea.Size); } } } return(base.MeasureOverride(availableSize)); }