/// <summary>
        /// Replaces a cell view with another in the collection.
        /// </summary>
        /// <param name="oldCellView">The cell view to replace.</param>
        /// <param name="newCellView">The new cell view.</param>
        public virtual void Replace(IFrameCellView oldCellView, IFrameCellView newCellView)
        {
            Debug.Assert(CellViewList.Contains(oldCellView));
            Debug.Assert(!CellViewList.Contains(newCellView));

            int Index = CellViewList.IndexOf(oldCellView);

            Replace(Index, newCellView);
        }
示例#2
0
        /// <summary>
        /// Measures the cell.
        /// </summary>
        /// <param name="collectionWithSeparator">A collection that can draw separators around the cell.</param>
        /// <param name="referenceContainer">The cell view in <paramref name="collectionWithSeparator"/> that contains this cell.</param>
        /// <param name="separatorLength">The length of the separator in <paramref name="collectionWithSeparator"/>.</param>
        public virtual void Measure(ILayoutCellViewCollection collectionWithSeparator, ILayoutCellView referenceContainer, Measure separatorLength)
        {
            CollectionWithSeparator = collectionWithSeparator;
            ReferenceContainer      = referenceContainer;
            SeparatorLength         = separatorLength;

            Debug.Assert(StateView != null);
            Debug.Assert(StateView.ControllerView != null);

            ILayoutMeasureContext MeasureContext = StateView.ControllerView.MeasureContext;

            Debug.Assert(MeasureContext != null);

            ILayoutFrameWithHorizontalSeparator AsFrameWithHorizontalSeparator = Frame as ILayoutFrameWithHorizontalSeparator;

            Debug.Assert(AsFrameWithHorizontalSeparator != null);

            bool OverrideReferenceContainer = false;

            // Ensures arguments of Arrange() are valid. This only happens for the root cell view, where there is no separator.
            if (collectionWithSeparator == null && referenceContainer == null)
            {
                collectionWithSeparator    = this;
                OverrideReferenceContainer = true;
                separatorLength            = Controller.Measure.Zero;
            }

            Measure Width  = Controller.Measure.Zero;
            Measure Height = Controller.Measure.Floating;

            for (int i = 0; i < CellViewList.Count; i++)
            {
                ILayoutCellView CellView = CellViewList[i];

                if (i > 0)
                {
                    // Starting with the second cell, we use the separator of our frame.
                    if (i == 1)
                    {
                        collectionWithSeparator    = this;
                        OverrideReferenceContainer = true;
                        separatorLength            = MeasureContext.GetHorizontalSeparatorWidth(AsFrameWithHorizontalSeparator.Separator);
                    }

                    Width += separatorLength;
                }

                if (OverrideReferenceContainer)
                {
                    referenceContainer = CellView;
                }

                Debug.Assert(collectionWithSeparator != this || CellViewList.IndexOf(referenceContainer) == i);
                CellView.Measure(collectionWithSeparator, referenceContainer, separatorLength);

                Size NestedCellSize = CellView.CellSize;
                Debug.Assert(RegionHelper.IsValid(NestedCellSize));

                bool IsFixed     = RegionHelper.IsFixed(NestedCellSize);
                bool IsStretched = RegionHelper.IsStretchedVertically(NestedCellSize);
                Debug.Assert(IsFixed || IsStretched);

                Debug.Assert(!NestedCellSize.Width.IsFloating);
                Width += NestedCellSize.Width;

                if (IsFixed)
                {
                    Debug.Assert(!NestedCellSize.Height.IsFloating);
                    if (Height.IsFloating || Height.Draw < NestedCellSize.Height.Draw)
                    {
                        Height = NestedCellSize.Height;
                    }
                }
            }

            Size AccumulatedSize = Size.Empty;

            if (!Width.IsZero)
            {
                AccumulatedSize = new Size(Width, Height + (HasBlockGeometry ? MeasureContext.BlockGeometryHeight : Controller.Measure.Zero));
            }

            CellSize       = AccumulatedSize;
            ActualCellSize = RegionHelper.InvalidSize;

            Debug.Assert(RegionHelper.IsValid(CellSize));
        }