コード例 #1
0
        internal void ClearElementOnDataSourceChange(VirtualizingLayoutContext context, NotifyCollectionChangedEventArgs args)
        {
            if (m_cachedFirstElement != null)
            {
                bool shouldClear = false;
                switch (args.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    shouldClear = args.NewStartingIndex == 0;
                    break;

                case NotifyCollectionChangedAction.Replace:
                    shouldClear = args.NewStartingIndex == 0 || args.OldStartingIndex == 0;
                    break;

                case NotifyCollectionChangedAction.Remove:
                    shouldClear = args.OldStartingIndex == 0;
                    break;

                case NotifyCollectionChangedAction.Reset:
                    shouldClear = true;
                    break;

                case NotifyCollectionChangedAction.Move:
                    throw new NotImplementedException();
                }

                if (shouldClear)
                {
                    context.RecycleElement(m_cachedFirstElement);
                    m_cachedFirstElement = null;
                }
            }
        }
コード例 #2
0
        internal void UninitializeForContext(VirtualizingLayoutContext context)
        {
            FlowAlgorithm.UninitializeForContext(context);

            if (m_cachedFirstElement != null)
            {
                context.RecycleElement(m_cachedFirstElement);
            }
        }
コード例 #3
0
 // If it's realized then we shouldn't be caching it
 internal void EnsureFirstElementOwnership(VirtualizingLayoutContext context)
 {
     if (m_cachedFirstElement != null && FlowAlgorithm.GetElementIfRealized(0) != null)
     {
         // We created the element, but then flowlayout algorithm took ownership, so we can clear it and
         // let flowlayout algorithm do its thing.
         context.RecycleElement(m_cachedFirstElement);
         m_cachedFirstElement = null;
     }
 }
コード例 #4
0
        internal void ClearElementOnDataSourceChange(VirtualizingLayoutContext context, NotifyCollectionChangedEventArgs args)
        {
            if (m_cachedFirstElement != null)
            {
                // The first element of UniformGridLayout is special since we use its size to
                // determine the size of all the other elements. So if the first item has changed
                // we will need to clear it and re-evalauate all the items with the new item size.
                bool shouldClear = false;
                switch (args.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    shouldClear = args.NewStartingIndex == 0;
                    break;

                case NotifyCollectionChangedAction.Replace:
                    shouldClear = args.NewStartingIndex == 0 || args.OldStartingIndex == 0;
                    break;

                case NotifyCollectionChangedAction.Remove:
                    shouldClear = args.OldStartingIndex == 0;
                    break;

                case NotifyCollectionChangedAction.Reset:
                    shouldClear = true;
                    break;

                case NotifyCollectionChangedAction.Move:
                    shouldClear = args.NewStartingIndex == 0 || args.OldStartingIndex == 0;
                    break;
                }

                if (shouldClear)
                {
                    context.RecycleElement(m_cachedFirstElement);
                    m_cachedFirstElement = null;
                }
            }
        }
コード例 #5
0
        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);
                    }
                }
            }
        }