internal override void OnOrientationChanged(Orientation newValue) { base.OnOrientationChanged(newValue); if (this.owner == null || !this.owner.IsTemplateApplied) { return; } if (this.owner.GetItemCount() > 0) { this.owner.StopAllAddedAnimations(); this.owner.StopAllRemovedAnimations(); while (this.owner.realizedItems.Count > 0) { RadVirtualizingDataControlItem lastItem = this.owner.realizedItems[this.owner.realizedItems.Count - 1]; lastItem.SetVerticalOffset(0); lastItem.SetHorizontalOffset(0); this.owner.RecycleLastItem(); } this.owner.BeginAsyncBalance(); this.owner.BalanceVisualSpace(); } }
private void SynchItemOffsetInRow(WrapRow row) { RadVirtualizingDataControlItem firstItem = row.firstItem; switch (this.orientationCache) { case Orientation.Horizontal: while (true) { firstItem.SetVerticalOffset(row.rowOffset); firstItem = firstItem.next; if (firstItem.wrapRow != row) { break; } } break; case Orientation.Vertical: while (true) { firstItem.SetHorizontalOffset(row.rowOffset); firstItem = firstItem.next; if (firstItem.wrapRow != row) { break; } } break; } }
internal virtual void SetItemOffset(RadVirtualizingDataControlItem item, double offset) { if (this.LayoutOrientation == Orientation.Vertical) { item.SetVerticalOffset(offset); } else { item.SetHorizontalOffset(offset); } }
private void PositionRealizedItemTop(RadVirtualizingDataControlItem firstRealizedItem, ref double visibleItemsTop) { Rect slot = this.FindFreeSpotForItemTop(firstRealizedItem); switch (this.orientationCache) { case Orientation.Horizontal: firstRealizedItem.SetHorizontalOffset(slot.Left); firstRealizedItem.SetVerticalOffset(slot.Top); visibleItemsTop = slot.Top - this.ScrollOffset; break; case Orientation.Vertical: firstRealizedItem.SetVerticalOffset(slot.Top); firstRealizedItem.SetHorizontalOffset(slot.Left); visibleItemsTop = slot.Left - this.ScrollOffset; break; } this.EnsureCorrectLayout(); }
internal override bool PositionBottomRealizedItem(RadVirtualizingDataControlItem lastRealizedItem, ref double visibleItemsBottom) { Rect slot = this.FindFreeSpotForItemBottom(lastRealizedItem); switch (this.orientationCache) { case Orientation.Horizontal: visibleItemsBottom = slot.Bottom; lastRealizedItem.SetHorizontalOffset(slot.Left); lastRealizedItem.SetVerticalOffset(slot.Top); this.slotsRepository[lastRealizedItem.associatedDataItem.GetHashCode()] = (int)(slot.Left / this.itemExtent); break; case Orientation.Vertical: visibleItemsBottom = slot.Right; lastRealizedItem.SetVerticalOffset(slot.Top); lastRealizedItem.SetHorizontalOffset(slot.Left); this.slotsRepository[lastRealizedItem.associatedDataItem.GetHashCode()] = (int)(slot.Top / this.itemExtent); break; } return(true); }
private void SynchRowItemsHorizontalStartPosition(WrapRow row) { RadVirtualizingDataControlItem firstItem = row.firstItem; double currentPosition = this.wrapLineAlignment == WrapLineAlignment.Center ? (this.owner.availableWidth - this.GetRowExtent(row)) / 2 : this.wrapLineAlignment == WrapLineAlignment.Near ? 0 : this.owner.availableWidth - this.GetRowExtent(row); while (true) { firstItem.SetHorizontalOffset(currentPosition); currentPosition += firstItem.width; firstItem = firstItem.next; if (firstItem == null || firstItem.wrapRow != row) { break; } } }
internal virtual RadVirtualizingDataControlItem GetContainerForItem(IDataSourceItem item, int insertAt) { RadVirtualizingDataControlItem cp = null; if (this.owner.recycledItems.Count == 0) { cp = this.owner.GenerateContainerForItem(item); } else { cp = this.owner.recycledItems.Dequeue(); if ((this.owner.itemAddedAnimationCache != null && RadAnimationManager.IsAnimationScheduled(cp, this.owner.itemAddedAnimationCache)) || (this.owner.itemRemovedAnimationCache != null && RadAnimationManager.IsAnimationScheduled(cp, this.owner.itemRemovedAnimationCache))) { this.owner.recycledItems.Enqueue(cp); cp = this.owner.GenerateContainerForItem(item); } else { cp.SetVerticalOffset(0); cp.SetHorizontalOffset(0); this.owner.OnContainerStateChanged(cp, item, ItemState.Realizing); this.owner.PrepareContainerForItemInternal(cp, item); cp.Visibility = Visibility.Visible; } } cp.SetScrollDirection(this.LayoutOrientation); this.MeasureContainer(cp); this.InsertIntoViewport(cp, insertAt); this.owner.firstItemCache = this.owner.realizedItems[0]; this.owner.lastItemCache = this.owner.realizedItems[this.owner.realizedItems.Count - 1]; return(cp); }
internal override void ReorderViewportItemsOnItemAdded(int physicalChangeLocation, RadVirtualizingDataControlItem addedItem) { this.owner.OnContainerStateChanged(addedItem, addedItem.associatedDataItem, ItemState.Realized); int slot = -1; //TODO rearange items if (this.slotsRepository.TryGetValue(addedItem.next.associatedDataItem.GetHashCode(), out slot)) { this.slotsRepository.Remove(addedItem.next.associatedDataItem.GetHashCode()); this.slotsRepository.Add(addedItem.associatedDataItem.GetHashCode(), slot); RadVirtualizingDataControlItem nextContainer = addedItem.next; addedItem.SetHorizontalOffset(nextContainer.horizontalOffsetCache); addedItem.SetVerticalOffset(nextContainer.verticalOffsetCache); } RadVirtualizingDataControlItem pivotContainer = addedItem.next; int containersToSkip = 0; if (pivotContainer != null) { containersToSkip = Math.Max(this.stackCount - this.owner.realizedItems.IndexOf(pivotContainer), 0); } while (pivotContainer != null) { if (containersToSkip > 0) { containersToSkip--; continue; } this.slotsRepository.Remove(pivotContainer.associatedDataItem.Index); pivotContainer = pivotContainer.next; } this.ReorderViewportOnItemsChanged(); }
internal override void OnContainerSizeChanged(RadVirtualizingDataControlItem container, Size newSize, Size oldSize) { base.OnContainerSizeChanged(container, newSize, oldSize); if (!this.topRealized.Contains(container)) { RadVirtualizingDataControlItem pivotContainer = container.next; int containersToSkip = 0; if (pivotContainer != null) { containersToSkip = Math.Max(this.stackCount - this.owner.realizedItems.IndexOf(pivotContainer), 0); } while (pivotContainer != null) { if (containersToSkip > 0) { containersToSkip--; continue; } this.slotsRepository.Remove(pivotContainer.associatedDataItem.GetHashCode()); pivotContainer = pivotContainer.next; } this.ReorderViewportOnItemsChanged(); } else { double newOffset = 0; double offsetDelta = 0; switch (this.orientationCache) { case Orientation.Horizontal: offsetDelta = newSize.Height - oldSize.Height; newOffset = container.verticalOffsetCache - offsetDelta; container.SetVerticalOffset(newOffset); double horizontalOffset = container.horizontalOffsetCache; while (container.previous != null) { container = container.previous; if (container.horizontalOffsetCache == horizontalOffset) { container.SetVerticalOffset(container.verticalOffsetCache - offsetDelta); } } break; case Orientation.Vertical: offsetDelta = newSize.Width - oldSize.Width; newOffset = container.horizontalOffsetCache - offsetDelta; container.SetHorizontalOffset(newOffset); double verticalOffset = container.verticalOffsetCache; while (container.previous != null) { container = container.previous; if (container.verticalOffsetCache == verticalOffset) { container.SetHorizontalOffset(container.horizontalOffsetCache - offsetDelta); } } break; } } //Extend the length with the new diff, although the extension could be less var prevLength = this.Orientation == Windows.UI.Xaml.Controls.Orientation.Horizontal ? oldSize.Height : oldSize.Width; var sizeChange = this.GetItemLength(container) - prevLength; this.CorrectScrollableContentSize(sizeChange); this.EnsureCorrectLayout(); this.CheckBottomScrollableBounds(); }
internal override bool PositionTopRealizedItem(ref double visibleItemsTop) { RadVirtualizingDataControlItem firstRealizedItem = this.owner.firstItemCache; WrapRow firstWrapRow = null; int wrapRowsCount = this.wrapRows.Count; if (wrapRowsCount > 0) { firstWrapRow = this.wrapRows[0]; } bool isEnoughSpaceForItemInRow = this.CheckEnoughSpaceForItemInRow(firstWrapRow, firstRealizedItem, false); if (firstWrapRow == null || !isEnoughSpaceForItemInRow) { if (!isEnoughSpaceForItemInRow) { visibleItemsTop -= firstWrapRow.rowLength; this.OnRowFilled(firstWrapRow, false); if (!this.CanRealizeTop(visibleItemsTop)) { return(false); } } firstWrapRow = this.InsertWrapRowAt(0); firstWrapRow.lastItem = firstRealizedItem; firstWrapRow.rowLength = this.GetItemLength(firstRealizedItem); firstWrapRow.rowOffset = firstWrapRow.next != null ? firstWrapRow.next.rowOffset - firstWrapRow.rowLength : 0; } double currentRowLength = firstWrapRow.rowLength; double difference = 0; switch (this.orientationCache) { case Orientation.Horizontal: difference = firstRealizedItem.height - currentRowLength; if (currentRowLength < firstRealizedItem.height) { firstWrapRow.rowLength = firstRealizedItem.height; visibleItemsTop -= difference; firstWrapRow.rowOffset -= difference; } firstRealizedItem.SetVerticalOffset(firstWrapRow.rowOffset); if (firstWrapRow.firstItem == null) { firstRealizedItem.SetHorizontalOffset(this.owner.availableWidth - firstRealizedItem.width); } else { firstRealizedItem.SetHorizontalOffset(firstWrapRow.firstItem.horizontalOffsetCache - firstRealizedItem.width); if (difference != 0) { this.SynchItemOffsetInRow(firstWrapRow); } } break; case Orientation.Vertical: difference = firstRealizedItem.width - currentRowLength; if (currentRowLength < firstRealizedItem.width) { firstWrapRow.rowLength = firstRealizedItem.width; visibleItemsTop -= difference; firstWrapRow.rowOffset -= difference; } firstRealizedItem.SetHorizontalOffset(firstWrapRow.rowOffset); if (firstWrapRow.firstItem == null) { firstRealizedItem.SetVerticalOffset(this.owner.availableHeight - firstRealizedItem.height); } else { firstRealizedItem.SetVerticalOffset(firstWrapRow.firstItem.verticalOffsetCache - firstRealizedItem.height); if (difference != 0) { this.SynchItemOffsetInRow(firstWrapRow); } } break; } firstWrapRow.firstItem = firstRealizedItem; firstRealizedItem.wrapRow = firstWrapRow; if (this.owner.IsFirstItemFirstInListSource()) { this.OnRowFilled(firstWrapRow, false); } return(true); }
internal override bool PositionBottomRealizedItem(RadVirtualizingDataControlItem item, ref double visibleItemsBottom) { RadVirtualizingDataControlItem realizedItem = item; double itemLength = this.GetItemLength(realizedItem); WrapRow lastWrapRow = null; int wrapRowsCount = this.wrapRows.Count; if (wrapRowsCount > 0) { lastWrapRow = this.wrapRows[wrapRowsCount - 1]; } bool isEnoughSpaceForItemInRow = true; if (lastWrapRow != null) { isEnoughSpaceForItemInRow = this.CheckEnoughSpaceForItemInRow(lastWrapRow, realizedItem, true); } if (lastWrapRow == null || !isEnoughSpaceForItemInRow) { if (!isEnoughSpaceForItemInRow) { visibleItemsBottom += lastWrapRow.rowLength; this.OnRowFilled(lastWrapRow, true); if (!this.CanRealizeBottom(visibleItemsBottom)) { return(false); } } lastWrapRow = this.InsertWrapRowAt(wrapRowsCount); lastWrapRow.firstItem = realizedItem; if (lastWrapRow.previous == null) { double defaultPosition = 0; if (this.owner.scrollScheduled) { defaultPosition = this.ScrollOffset; } lastWrapRow.rowOffset = this.averageItemLength > 0 ? item.AssociatedDataItem.Index / this.averageItemCountPerRow * this.averageItemLength : defaultPosition; } else { lastWrapRow.rowOffset = lastWrapRow.previous.rowOffset + lastWrapRow.previous.rowLength; } lastWrapRow.rowLength = itemLength; } double currentRowLength = lastWrapRow.rowLength; switch (this.orientationCache) { case Orientation.Horizontal: if (currentRowLength < realizedItem.height) { lastWrapRow.rowLength = realizedItem.height; visibleItemsBottom += realizedItem.height - currentRowLength; } realizedItem.SetVerticalOffset(lastWrapRow.rowOffset); if (lastWrapRow.lastItem == null) { realizedItem.SetHorizontalOffset(0); } else { realizedItem.SetHorizontalOffset(lastWrapRow.lastItem.horizontalOffsetCache + lastWrapRow.lastItem.width); } break; case Orientation.Vertical: if (currentRowLength < realizedItem.width) { lastWrapRow.rowLength = realizedItem.width; visibleItemsBottom += realizedItem.width - currentRowLength; } realizedItem.SetHorizontalOffset(lastWrapRow.rowOffset); if (lastWrapRow.lastItem == null) { realizedItem.SetVerticalOffset(0); } else { realizedItem.SetVerticalOffset(lastWrapRow.lastItem.verticalOffsetCache + lastWrapRow.lastItem.height); } break; } lastWrapRow.lastItem = realizedItem; realizedItem.wrapRow = lastWrapRow; if (this.owner.IsLastItemLastInListSource()) { this.OnRowFilled(lastWrapRow, true); } return(true); }