private void RealizeDefault() { IDataSourceItem pivotItem = this.view.SelectedDataSourceItem; this.RealizeItem(this.PivotItem, this.view.SelectedDataSourceItem); int prevIndex = (this.Children.Count / 2) - 1; IDataSourceItem prevItem = this.view.GetPreviousDataSourceItem(pivotItem); while (prevIndex >= 0) { this.RealizeItem(this.Children[prevIndex] as SlideViewItem, prevItem); prevIndex--; prevItem = this.view.GetPreviousDataSourceItem(prevItem); } int nextIndex = (this.Children.Count / 2) + 1; IDataSourceItem nextItem = this.view.GetNextDataSourceItem(pivotItem); while (nextIndex < this.Children.Count) { this.RealizeItem(this.Children[nextIndex] as SlideViewItem, nextItem); nextIndex++; nextItem = this.view.GetNextDataSourceItem(nextItem); } }
internal override void ResetRealizationStartWhenLowerUIBufferRecycled(double position) { double bottomDifference = position - this.GetItemLength(this.owner.lastItemCache); if (bottomDifference > this.bottomVirtualizationThreshold + this.ScrollOffset) { int rowCount = (int)Math.Round(bottomDifference / this.averageItemLength, 0); int itemCount = rowCount * this.stackCount; RadVirtualizingDataControlItem firstRealizedDataItem = this.owner.FirstRealizedDataItem; int currentFirstItemIndex = 0; if (firstRealizedDataItem != null) { currentFirstItemIndex = Math.Max(firstRealizedDataItem.associatedDataItem.Index - itemCount, 0); } IDataSourceItem newDataItem = firstRealizedDataItem.associatedDataItem; while (newDataItem.Index > currentFirstItemIndex) { newDataItem = newDataItem.Previous; Debug.Assert(newDataItem != null, "The currentLastItemIndex should be within the bounds of the flattened view of the collection."); } while (this.owner.realizedItems.Count > 0) { this.RecycleItem(this.owner.realizedItems[0]); } var newRealized = this.GetContainerForItem(newDataItem, false); double currentTop = this.ScrollOffset; this.PositionBottomRealizedItem(this.owner.lastItemCache, ref currentTop); } }
internal override void ResetRealizationStartWhenLowerUIBufferRecycled(double position) { double bottomDifference = position - this.GetItemLength(this.owner.lastItemCache); if (bottomDifference > this.bottomVirtualizationThreshold) { int itemCount = (int)Math.Round(bottomDifference / this.averageItemLength, 0); RadVirtualizingDataControlItem firstRealizedDataItem = this.owner.FirstRealizedDataItem; int currentFirstItemIndex = 0; if (firstRealizedDataItem != null) { currentFirstItemIndex = Math.Max(firstRealizedDataItem.associatedDataItem.Index - itemCount, 0); } IDataSourceItem newDataItem = firstRealizedDataItem.associatedDataItem; while (newDataItem.Index > currentFirstItemIndex) { newDataItem = newDataItem.Previous; Debug.Assert(newDataItem != null, "The currentLastItemIndex should be within the bounds of the flattened view of the collection."); } this.owner.ClearContainerForItemInternal(this.owner.lastItemCache, this.owner.lastItemCache.associatedDataItem); RadVirtualizingDataControlItem newRealized = this.GetContainerForItem(newDataItem, false); double currentTop = this.ScrollOffset; this.SetItemOffset(newRealized, currentTop - this.GetElementCanvasOffset(this.owner.itemsPanel)); } }
internal void Attach(IDataSourceItem item) { this.dataItem = item; if (item != null) { FrameworkElement contentAsUI = item.Value as FrameworkElement; if (contentAsUI != null) { ContentControl parent = contentAsUI.Parent as ContentControl; if (parent != null) { parent.Content = null; } } this.Content = item.Value; this.DataContext = item.Value; } else { this.Content = null; this.DataContext = null; } }
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 { this.owner.OnContainerStateChanged(cp, item, ItemState.Realizing); this.owner.PrepareContainerForItemInternal(cp, item); cp.Visibility = Visibility.Visible; } } 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 RadVirtualizingDataControlItem GetContainerForItem(IDataSourceItem item, int insertAt) { RadVirtualizingDataControlItem container = base.GetContainerForItem(item, insertAt); this.allItemsExtent += this.GetItemExtent(container); return(container); }
internal override void ReorderViewportItemsOnItemAddedOnTop(IDataSourceItem addedItem) { if (this.reorderMode == CollectionChangeItemReorderMode.MoveItemsDown) { this.ScrollToOffset(this.owner.manipulationContainer.VerticalOffset - this.averageItemLength, null); } }
private void OnStoryboardCompleted(object sender, object e) { bool changeSeletion = this.rotation == this.MaxRotationAngle; bool resetTransform = true; if (changeSeletion) { // we have made enough offset to move to the previous/next item IDataSourceItem item = this.panSign < 0 ? this.View.GetNextDataSourceItem() : this.View.GetPreviousDataSourceItem(); if (item != null) { this.View.ChangeSelectedItem(item, false); } // the owning panel will tell whether we will reset the transform or the panel itself will (valid when only the viewport item is realized) resetTransform = !this.Panel.OnSelectionAnimationCompleted(); this.selectionChangedSign = this.panSign; } else { this.selectionChangedSign = 0; } if (resetTransform) { this.ResetTransform(); } this.storyboard.Stop(); this.AnimationState = SlideViewAnimationState.None; }
internal void ApplyScrollOffsetForItem(IDataSourceItem item, double lastAverageLength) { if (lastAverageLength <= 0) { lastAverageLength = this.virtualizationStrategy.averageItemLength; if (lastAverageLength == 0) { lastAverageLength = DefaultItemLength; } } double offset = this.virtualizationStrategy.CalculateItemOffset(item, lastAverageLength); this.scrollScheduled = true; this.virtualizationStrategy.ScrollToOffset( offset, () => { // this.virtualizationStrategy.SetElementCanvasOffset(this.itemsPanel, this.virtualizationStrategy.ScrollOffset); //// Perform a balance to ensure that all buffers are filled. this.SubscribeRendering(); this.BalanceVisualSpace(); scrollScheduled = false; }); }
/// <summary> /// Occurs when the <see cref="P:ItemsSource"/> property has changed. /// </summary> /// <param name="oldSource"></param> protected override void OnItemsSourceChanged(IEnumerable oldSource) { base.OnItemsSourceChanged(oldSource); this.selectedDataSourceItem = null; this.ChangePropertySilently(SelectedItemProperty, null); }
/// <summary> /// Advances to the next item in the sequence. /// </summary> /// <param name="animate">True to perform a transition, false otherwise.</param> /// <returns>True if a next item exists, false otherwise.</returns> public bool MoveToNextItem(bool animate = true) { IDataSourceItem item = this.GetNextDataSourceItem(); if (item == null) { return(false); } if (animate && this.manipulationBehavior != null && this.IsLoaded) { this.manipulationBehavior.MoveToNextItem(); } else { this.selectedDataSourceItem = item; this.ChangePropertySilently(SelectedItemProperty, this.selectedDataSourceItem.Value); if (this.itemsPanel != null) { this.itemsPanel.InvalidateUI(); } } return(true); }
private void OnFlick(FlickGesture gesture) { if (this.ListSource.Count == 0) { return; } Debug.Assert(this.selectedDataSourceItem != null, "Must have selected item at this point"); IDataSourceItem item = null; if (gesture.Velocity.X < 0) { item = this.ListSource.GetItemAfter(this.selectedDataSourceItem); if (item == null) { item = this.ListSource.GetFirstItem(); } } else if (gesture.Velocity.X > 0) { item = this.ListSource.GetItemBefore(this.selectedDataSourceItem); if (item == null) { item = this.ListSource.GetLastItem(); } } if (item != null) { this.selectedDataSourceItem = item; this.ChangePropertySilently(SelectedItemProperty, this.selectedDataSourceItem.Value); } }
public void SetRenderInfo(IDataSourceItem item, ItemLayoutInfo info) { if (info != ItemLayoutInfo.Invalid) { this.itemSlotsRepository[item] = info; } }
internal override void ResetRealizationStartWhenUpperUIBufferRecycled(double position) { double topDifference = position + this.GetItemLength(this.owner.lastItemCache); if (topDifference < this.topVirtualizationThreshold) { int itemCount = (int)Math.Round(Math.Abs(topDifference) / this.averageItemLength, 0); RadVirtualizingDataControlItem lastRealizedDataItem = this.owner.LastRealizedDataItem; int currentLastItemIndex = this.owner.GetDataItemCount(); if (lastRealizedDataItem != null) { currentLastItemIndex = Math.Min(lastRealizedDataItem.associatedDataItem.Index + itemCount, currentLastItemIndex - 1); } IDataSourceItem newDataItem = lastRealizedDataItem.associatedDataItem; while (newDataItem.Index < currentLastItemIndex) { newDataItem = newDataItem.Next; Debug.Assert(newDataItem != null, "The currentLastItemIndex should be within the bounds of the flattened view of the collection."); } this.owner.ClearContainerForItemInternal(this.owner.lastItemCache, this.owner.lastItemCache.associatedDataItem); RadVirtualizingDataControlItem newRealized = this.GetContainerForItem(newDataItem, false); double currentBottom = this.ScrollOffset; this.SetItemOffset(newRealized, currentBottom - this.GetElementCanvasOffset(this.owner.itemsPanel)); } }
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(); IDataSourceItem firstViewportItem = this.GetTopVisibleContainer().associatedDataItem; while (this.owner.realizedItems.Count > 0) { RadDataBoundListBoxItem lastItem = this.owner.realizedItems[this.owner.realizedItems.Count - 1] as RadDataBoundListBoxItem; lastItem.SetVerticalOffset(0); lastItem.SetHorizontalOffset(0); this.owner.RecycleLastItem(); } this.owner.initialVirtualizationItem = firstViewportItem; this.owner.BeginAsyncBalance(); this.owner.BalanceVisualSpace(); } }
internal override void ReorderViewportItemsOnItemRemovedFromTop(IDataSourceItem removedItem) { //// We do this because we want to shift the realized items list //// backwards with one item this.owner.RecycleFirstItem(); this.ReorderViewportItemsStartingAtRow(this.GetWrapRowToStartReorderFrom(0, false)); }
private void RealizeItem(SlideViewItem container, IDataSourceItem dataItem) { object value = dataItem == null ? null : dataItem.Value; container.Attach(dataItem); container.ContentTemplate = this.view.GetItemTemplate(container, value); container.Style = this.view.GetItemContainerStyle(container, value); }
internal override RadVirtualizingDataControlItem GetContainerForItem(IDataSourceItem item, int insertAt) { RadVirtualizingDataControlItem container = base.GetContainerForItem(item, insertAt); this.realizedItemsLength += this.GetItemLength(container); return(container); }
/// <summary> /// Moves the specified item from its old index to its new index after a change of type Move /// has occurred in the original collection. /// </summary> /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance that comes with the event.</param> protected virtual void MoveItems(NotifyCollectionChangedEventArgs e) { int insertIndex = e.NewStartingIndex; int previousIndex = e.OldStartingIndex; IDataSourceItem itemToMove = this.items[previousIndex]; this.items.RemoveAt(e.OldStartingIndex); this.items.Insert(insertIndex, itemToMove); // update the moved item's index at its new position itemToMove.Index = insertIndex; IDataSourceItem newItemAtOldIndex = this.items[previousIndex]; newItemAtOldIndex.Next = null; newItemAtOldIndex.Previous = null; if (previousIndex > 0) { IDataSourceItem neighbourToNewItemAtOldIndex = this.items[previousIndex - 1]; neighbourToNewItemAtOldIndex.Next = newItemAtOldIndex; newItemAtOldIndex.Previous = neighbourToNewItemAtOldIndex; } if (previousIndex < this.Count - 1) { IDataSourceItem neighbourToNewItemAtOldIndex = this.items[previousIndex + 1]; neighbourToNewItemAtOldIndex.Previous = newItemAtOldIndex; newItemAtOldIndex.Next = neighbourToNewItemAtOldIndex; } IDataSourceItem oldItemAtNewIndex = this.items[insertIndex]; oldItemAtNewIndex.Previous = null; oldItemAtNewIndex.Next = null; if (insertIndex < this.Count - 1) { IDataSourceItem rightNeighbour = this.items[insertIndex + 1]; oldItemAtNewIndex.Next = rightNeighbour; rightNeighbour.Previous = oldItemAtNewIndex; } if (insertIndex > 0) { IDataSourceItem leftNeighbour = this.items[insertIndex - 1]; oldItemAtNewIndex.Previous = leftNeighbour; leftNeighbour.Next = oldItemAtNewIndex; } // Update the indices of all items before the new position by reducing them with 1 as the // item moved shifts all before it down with 1 index. for (int i = insertIndex - 1; i > previousIndex - 1; i--) { this.items[i].Index -= 1; } }
internal RadVirtualizingDataControlItem GenerateContainerForItem(IDataSourceItem item) { RadVirtualizingDataControlItem cp = this.GetContainerForItemOverride(); this.OnContainerStateChanged(cp, item, ItemState.Realizing); this.itemsPanel.Children.Add(cp); this.PrepareContainerForItemOverride(cp, item); return(cp); }
internal void UpdateCurrentItem(IDataSourceItem newCurrentItem) { if (this.currencyMode == CurrencyManagementMode.None) { return; } this.SetCurrentItemCore(newCurrentItem, false); }
/// <summary> /// Gets the item that is right after the specified one. /// </summary> /// <param name="item"></param> /// <returns></returns> public IDataSourceItem GetItemAfter(IDataSourceItem item) { if (item == null) { return(null); } return(item.Next); }
/// <summary> /// Gets the item that is just before the specified one. /// </summary> /// <param name="item"></param> /// <returns></returns> public IDataSourceItem GetItemBefore(IDataSourceItem item) { if (item == null) { return(null); } return(item.Previous); }
/// <summary> /// Retrieves the index of the specified item within the collection. /// </summary> /// <param name="item"></param> /// <returns></returns> public int IndexOf(IDataSourceItem item) { if (item == null) { return(-1); } return(item.Index); }
internal override void ReorderViewportItemsOnItemAddedOnTop(IDataSourceItem addedItem) { RadVirtualizingDataControlItem firstRealized = this.owner.firstItemCache; IDataSourceItem prev = this.owner.GetItemBefore(firstRealized.associatedDataItem); RadVirtualizingDataControlItem newFirst = this.GetContainerForItem(prev, false); newFirst.wrapRow = firstRealized.wrapRow; newFirst.wrapRow.firstItem = newFirst; this.ReorderViewportItemsStartingAtRow(newFirst.wrapRow); }
/// <summary> /// Determines whether the specified <see cref="IDataSourceItem"/> instance may be considered as a new Current item. /// </summary> /// <param name="newCurrent">The item instance to check for.</param> protected virtual bool IsNewCurrentItem(IDataSourceItem newCurrent) { if (newCurrent != this.currentItem) { return(true); } return(newCurrent != null && this.currentItem != null && !object.Equals(newCurrent.Value, this.currentItem.Value)); }
internal override void ReorderViewportItemsOnItemAddedOnTop(IDataSourceItem addedItem) { IDataSourceItem firstDataItem = addedItem.Previous; while (firstDataItem != null) { this.slotsRepository.Remove(firstDataItem.GetHashCode()); firstDataItem = firstDataItem.Previous; } }
internal override void ReorderViewportItemsOnItemRemovedFromTop(IDataSourceItem removedItem) { IDataSourceItem firstRealized = this.owner.listSource.GetItemAt(removedItem.Index); while (firstRealized != null) { this.slotsRepository.Remove(firstRealized.GetHashCode()); firstRealized = firstRealized.Previous; } }
public ItemLayoutInfo GetRenderInfo(IDataSourceItem item) { ItemLayoutInfo info; if (this.itemSlotsRepository.TryGetValue(item, out info)) { return(info); } return(ItemLayoutInfo.Invalid); }
internal override double CalculateItemOffset(IDataSourceItem item, double lastAverageLength) { if (item == null) { return(0); } var index = item.Index; return(lastAverageLength * index / this.StackCount); }