/// <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); }
/// <summary> /// Moves a cell view around in the collection. /// </summary> /// <param name="index">Index of the cell view to move.</param> /// <param name="direction">The change in position, relative to the current position.</param> public virtual void Move(int index, int direction) { Debug.Assert(index >= 0 && index < CellViewList.Count); Debug.Assert(index + direction >= 0 && index + direction < CellViewList.Count); IFrameCellView CellView = CellViewList[index]; CellViewList.RemoveAt(index); CellViewList.Insert(index + direction, CellView); }
/// <summary> /// Inserts a new cell view in the collection. /// </summary> /// <param name="index">Index where to insert the cell view.</param> /// <param name="cellView">The cell view to insert.</param> public virtual void Insert(int index, IFrameCellView cellView) { Debug.Assert(index >= 0 && index <= CellViewList.Count); CellViewList.Insert(index, cellView); foreach (IFrameCellView Item in CellViewList) { if (Item is IFrameContainerCellView AsContainerCellView) { Debug.Assert(AsContainerCellView.ParentCellView == this); } } }
/// <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)); }
/// <summary> /// Removes a cell view from the collection. /// </summary> /// <param name="index">Index where to remove the cell view.</param> public virtual void Remove(int index) { Debug.Assert(index >= 0 && index <= CellViewList.Count); CellViewList.RemoveAt(index); }