Пример #1
0
        /// <summary>
        /// Override for preparing the container.
        /// </summary>
        /// <param name="element">The element dependency object.</param>
        /// <param name="item">The item object.</param>
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);

            ContentPresenter container = element as ContentPresenter;

            this.containersByItem.Add(item, container);
            DependencyObject dependencyObject = item as DependencyObject;

            if (dependencyObject != null)
            {
                CascadingListBoxGroup.SetCascadingListBoxGroup(dependencyObject, this);
                LinkingWrapPanel.SetIsLinkedToNextChild(container, LinkingWrapPanel.GetIsLinkedToNextChild(dependencyObject));
                this.UpdateListVisibility(dependencyObject);
            }

#if SILVERLIGHT
            Canvas.SetZIndex(container, this.Items.Count - this.Items.IndexOf(item));
#endif
            ISplitItemsControl splitItemsControl = item as ISplitItemsControl;
            if (splitItemsControl == null)
            {
                FrameworkElement frameworkElement = item as FrameworkElement;

                if (frameworkElement != null && !string.IsNullOrEmpty(CascadingListBoxGroup.GetCascadingListBoxName(frameworkElement)))
                {
                    splitItemsControl = frameworkElement.FindName(CascadingListBoxGroup.GetCascadingListBoxName(frameworkElement)) as ISplitItemsControl;
                }
            }

            if (splitItemsControl != null)
            {
                CascadingListBoxGroup.SetCascadingListBoxGroup(splitItemsControl as DependencyObject, this);
                this.containersBySplitItemsControl.Add(splitItemsControl, container);
            }
        }
Пример #2
0
        /// <summary>
        /// The main layout algorithm for measure and arrange.
        /// </summary>
        /// <param name="arrange">Whether to arrange the children.</param>
        /// <param name="availableSize">The available size.</param>
        /// <returns>The final size.</returns>
        private Size MeasureArrangeChildren(bool arrange, Size availableSize)
        {
            double           currentChildWidth  = 0;
            double           tallestChildHeight = 0;
            double           currentX           = 0;
            double           currentY           = 0;
            double           width          = 0;
            List <UIElement> linkedChildren = new List <UIElement>();
            UIElement        previousChild  = null;

            foreach (UIElement child in this.Children)
            {
                if (previousChild != null && !LinkingWrapPanel.GetIsLinkedToNextChild(previousChild))
                {
                    foreach (UIElement linkedChild in linkedChildren)
                    {
                        double childWidth = linkedChild.DesiredSize.Width;
                        if (LinkingWrapPanel.GetCanResize(linkedChild) && childWidth > availableSize.Width && currentX == 0)
                        {
                            childWidth = availableSize.Width;
                        }

                        if (arrange)
                        {
                            linkedChild.Arrange(new Rect(currentX, currentY, childWidth, linkedChild.DesiredSize.Height));
                        }

                        currentX += childWidth;
                        if (currentX > width)
                        {
                            width = currentX;
                        }

                        if (tallestChildHeight < linkedChild.DesiredSize.Height)
                        {
                            tallestChildHeight = linkedChild.DesiredSize.Height;
                        }
                    }

                    currentChildWidth = 0;
                    linkedChildren.Clear();
                }

                if (!arrange)
                {
                    child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                }

                double childwidth = child.DesiredSize.Width;
                currentChildWidth += childwidth;
                if (currentX != 0.0 && currentX + currentChildWidth > availableSize.Width)
                {
                    currentX           = 0;
                    currentY          += tallestChildHeight;
                    tallestChildHeight = 0;
                }

                if (LinkingWrapPanel.GetCanResize(child) && childwidth > availableSize.Width && currentX == 0)
                {
                    currentChildWidth -= childwidth;
                    childwidth         = availableSize.Width;
                    if (!arrange)
                    {
                        child.Measure(new Size(childwidth, double.PositiveInfinity));
                    }

                    currentChildWidth += childwidth;
                }

                if (previousChild != null && !LinkingWrapPanel.GetIsLinkedToNextChild(previousChild) && !LinkingWrapPanel.GetIsLinkedToNextChild(child))
                {
                    if (arrange)
                    {
                        child.Arrange(new Rect(currentX, currentY, childwidth, child.DesiredSize.Height));
                    }

                    currentX += childwidth;

                    if (currentX > width)
                    {
                        width = currentX;
                    }

                    currentChildWidth = 0;

                    if (tallestChildHeight < child.DesiredSize.Height)
                    {
                        tallestChildHeight = child.DesiredSize.Height;
                    }
                }
                else
                {
                    linkedChildren.Add(child);
                }

                previousChild = child;
            }

            foreach (UIElement linkedChild in linkedChildren)
            {
                double childWidth = linkedChild.DesiredSize.Width;
                if (LinkingWrapPanel.GetCanResize(linkedChild) && childWidth > availableSize.Width && currentX == 0)
                {
                    childWidth = availableSize.Width;
                }

                if (arrange)
                {
                    linkedChild.Arrange(new Rect(currentX, currentY, childWidth, linkedChild.DesiredSize.Height));
                }

                currentX += childWidth;
                if (currentX > width)
                {
                    width = currentX;
                }

                if (tallestChildHeight < linkedChild.DesiredSize.Height)
                {
                    tallestChildHeight = linkedChild.DesiredSize.Height;
                }
            }

            return(new Size(
                       this.HorizontalAlignment == HorizontalAlignment.Stretch ? (!double.IsPositiveInfinity(availableSize.Width) ? availableSize.Width : width) : width,
                       this.VerticalAlignment == VerticalAlignment.Stretch ? (!double.IsPositiveInfinity(availableSize.Height) ? availableSize.Height : currentY + tallestChildHeight) : currentY + tallestChildHeight));
        }