Пример #1
0
        /// <summary>
        /// Expand part of the specified lazy box.
        /// Todo: implement firstItemToExpand, limItemToExpand.
        /// </summary>
        internal void ExpandItems(LazyBox <T> source, int firstItemToExpand, int limItemToExpand,
                                  int topOfFirstItemToExpand, int bottomOfLastItemToExpand)
        {
            var root          = ContainingBox.Root;
            int oldRootHeight = root.Height;
            var builder       = ContainingBox.Builder;

            builder.CurrentHookup = this;
            var objects = new T[limItemToExpand - firstItemToExpand];

            source.Items.CopyTo(firstItemToExpand, objects, 0, limItemToExpand - firstItemToExpand);
            int insertAt = Children.IndexOf(source);             // default, insert in place of source (or before it).

            if (firstItemToExpand > 0)
            {
                // we will keep source to represent the unexpanded items at the start.
                insertAt += 1;                 // insert right after source.
                if (limItemToExpand < source.Items.Count)
                {
                    // We will have to make a new lazy box to insert after the expanded items
                    var newLazyBox = new LazyBox <T>(source.Style, this,
                                                     source.Items.Skip(limItemToExpand));
                    Children.Insert(insertAt, newLazyBox);
                    ContainingBox.InsertBox(newLazyBox, source);
                    // We will still insert the expanded items after source, before newLazyBox.
                }
                // Remove the items no longer considered part of source.
                source.RemoveItems(firstItemToExpand, source.Items.Count - firstItemToExpand);
            }
            else if (limItemToExpand < source.Items.Count)
            {
                // We will keep source to represent the unexpanded items at the end.
                source.RemoveItems(0, limItemToExpand);
            }
            else
            {
                // Everything is being expanded: get rid of source altogether.
                ContainingBox.RemoveBoxes(source, source);
                Children.RemoveAt(insertAt);                 // get rid of the lazy box from hookup collection
            }

            // Generate the new items.
            for (int i = 0; i < objects.Length; i++)
            {
                BuildAnItemDisplay(builder, objects[i], insertAt + i);
            }
            using (var gh = ContainingBox.Root.Site.DrawingInfo)
            {
                ContainingBox.RelayoutWithParents(gh, true);
            }

            // Notify root of changed overall size and possibly scroll position.
            root.RaiseLazyExpanded(new RootBox.LazyExpandedEventArgs()
            {
                EstimatedTop    = topOfFirstItemToExpand,
                EstimatedBottom = bottomOfLastItemToExpand, DeltaHeight = root.Height - oldRootHeight
            });
        }