internal void EnsureElementSize( Size availableSize, VirtualizingLayoutContext context, double layoutItemWidth, double LayoutItemHeight, UniformGridLayoutItemsStretch stretch, Orientation orientation, double minRowSpacing, double minColumnSpacing, uint maxItemsPerLine) { if (maxItemsPerLine == 0) { maxItemsPerLine = 1; } if (context.ItemCount > 0) { // If the first element is realized we don't need to cache it or to get it from the context var realizedElement = FlowAlgorithm.GetElementIfRealized(0); if (realizedElement != null) { realizedElement.Measure(availableSize); SetSize(realizedElement, layoutItemWidth, LayoutItemHeight, availableSize, stretch, orientation, minRowSpacing, minColumnSpacing, maxItemsPerLine); m_cachedFirstElement = null; } else { if (m_cachedFirstElement == null) { // we only cache if we aren't realizing it m_cachedFirstElement = context.GetOrCreateElementAt(0, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); // expensive } m_cachedFirstElement.Measure(availableSize); SetSize(m_cachedFirstElement, layoutItemWidth, LayoutItemHeight, availableSize, stretch, orientation, minRowSpacing, minColumnSpacing, maxItemsPerLine); // See if we can move ownership to the flow algorithm. If we can, we do not need a local cache. bool added = FlowAlgorithm.TryAddElement0(m_cachedFirstElement); if (added) { m_cachedFirstElement = null; } } } }
private void MakeAnchor( VirtualizingLayoutContext context, int index, Size availableSize) { m_elementManager.ClearRealizedRange(); // FlowLayout requires that the anchor is the first element in the row. var internalAnchor = m_algorithmCallbacks.Algorithm_GetAnchorForTargetElement(index, availableSize, context); Debug.Assert(internalAnchor.Index <= index); // No need to set the position of the anchor. // (0,0) is fine for now since the extent can // grow in any direction. for (int dataIndex = internalAnchor.Index; dataIndex < index + 1; ++dataIndex) { var element = context.GetOrCreateElementAt(dataIndex, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); element.Measure(m_algorithmCallbacks.Algorithm_GetMeasureSize(dataIndex, availableSize, context)); m_elementManager.Add(element, dataIndex); } }
internal void EnsureElementSize( Size availableSize, VirtualizingLayoutContext context, double layoutItemWidth, double LayoutItemHeight, UniformGridLayoutItemsStretch stretch, Orientation orientation, double minRowSpacing, double minColumnSpacing, uint maxItemsPerLine) { if (maxItemsPerLine == 0) { maxItemsPerLine = 1; } if (context.ItemCount > 0) { // If the first element is realized we don't need to get it from the context var realizedElement = FlowAlgorithm.GetElementIfRealized(0); if (realizedElement != null) { realizedElement.Measure(availableSize); SetSize(realizedElement.DesiredSize, layoutItemWidth, LayoutItemHeight, availableSize, stretch, orientation, minRowSpacing, minColumnSpacing, maxItemsPerLine); } else { // Not realized by flowlayout, so do this now! if (context.GetOrCreateElementAt(0, ElementRealizationOptions.ForceCreate) is { } firstElement) { firstElement.Measure(availableSize); SetSize(firstElement.DesiredSize, layoutItemWidth, LayoutItemHeight, availableSize, stretch, orientation, minRowSpacing, minColumnSpacing, maxItemsPerLine); context.RecycleElement(firstElement); } } } }