private IElementCollection GetPosition(RowView rowView, out int index) { if (Template.ContainerKind == ContainerKind.Row) { var placement = GetContainerViewPlacement(rowView.RowPresenter); if (placement == CurrentContainerViewPlacement.WithinList) { index = ContainerViewListStartIndex + GetContainerView(rowView).ContainerOrdinal - ContainerViewList.First.ContainerOrdinal; } else if (placement == CurrentContainerViewPlacement.BeforeList) { index = HeadScalarElementsCount; } else { Debug.Assert(placement == CurrentContainerViewPlacement.AfterList); index = ContainerViewListStartIndex + ContainerViewList.Count; } return(ElementCollection); } else { var blockView = rowView.GetBlockView(); index = blockView.BlockBindingsSplit + (rowView.RowPresenter.Index % FlowRepeatCount); return(blockView.ElementCollection); } }
private void Swap(RowView oldValue, RowView newValue) { var oldRowPresenter = oldValue.RowPresenter; var newRowPresenter = newValue.RowPresenter; var oldBlockView = oldValue.GetBlockView(); var newBlockView = newValue.GetBlockView(); var oldCollection = GetPosition(oldValue, out int oldIndex); var newCollection = GetPosition(newValue, out int newIndex); if (oldCollection == newCollection && oldIndex < newIndex) { newCollection.RemoveAt(newIndex); oldCollection.RemoveAt(oldIndex); } else { oldCollection.RemoveAt(oldIndex); newCollection.RemoveAt(newIndex); } oldValue.Reload(newRowPresenter); newValue.Reload(oldRowPresenter); newValue.SetBlockView(oldBlockView); oldValue.SetBlockView(newBlockView); if (oldCollection == newCollection && newIndex < oldIndex) { newCollection.Insert(newIndex, oldValue); oldCollection.Insert(oldIndex, newValue); } else { oldCollection.Insert(oldIndex, newValue); newCollection.Insert(newIndex, oldValue); } }
private ContainerView GetContainerView(RowView rowView) { if (Template.ContainerKind == ContainerKind.Row) { return(rowView); } else { return(rowView.GetBlockView()); } }