internal void EnsureElementSize( Size availableSize, VirtualizingLayoutContext context, double layoutItemWidth, double layoutItemHeight, UniformGridLayoutItemsStretch stretch, Orientation orientation, double minRowSpacing, double minColumnSpacing, int 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); _cachedFirstElement = null; } else { if (_cachedFirstElement == null) { // we only cache if we aren't realizing it _cachedFirstElement = context.GetOrCreateElementAt( 0, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); // expensive } _cachedFirstElement.Measure(availableSize); SetSize(_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(_cachedFirstElement); if (added) { _cachedFirstElement = null; } } } }
internal void EnsureElementSize( Size availableSize, VirtualizingLayoutContext context, double layoutItemWidth, double LayoutItemHeight, UniformGridLayoutItemsStretch stretch, Orientation orientation, double minRowSpacing, double minColumnSpacing) { 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); _cachedFirstElement = null; } else { if (_cachedFirstElement == null) { // we only cache if we aren't realizing it _cachedFirstElement = context.GetOrCreateElementAt( 0, ElementRealizationOptions.ForceCreate | ElementRealizationOptions.SuppressAutoRecycle); // expensive } _cachedFirstElement.Measure(availableSize); // This doesn't need to be done in the UWP version and I'm not sure why. If we // don't do this here, and we receive a recycled element then it will be shown // at its previous arrange point, but we don't want it shown at all until its // arranged. _cachedFirstElement.Arrange(new Rect(-10000.0, -10000.0, 0, 0)); SetSize(_cachedFirstElement, layoutItemWidth, LayoutItemHeight, availableSize, stretch, orientation, minRowSpacing, minColumnSpacing); // See if we can move ownership to the flow algorithm. If we can, we do not need a local cache. bool added = FlowAlgorithm.TryAddElement0(_cachedFirstElement); if (added) { _cachedFirstElement = null; } } } }