/// <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));
        }
        /// <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);
        }