Example #1
0
        private RadSize MeasureVertically(RadSize availableSize, double offset, double bufferScale)
        {
            var context = new MeasureContext()
            {
                Offset      = offset,
                BufferScale = bufferScale
            };

            context.InitializeForVerticalMeasure(this.Layout, availableSize);
            this.AvailableLength = context.AvailableLength;

            var initialFirstVisibleIndex = context.FirstVisibleIndex;

            if (this.IsBufferNeeded)
            {
                context.FirstVisibleIndex = this.GenerateTopBufferItems(context.FirstVisibleIndex, context.AvailableLength, context.Offset, context);
                context.LastVisibleIndex  = context.FirstVisibleIndex;
            }

            this.MeasureForward(ref context);

            //TODO: Investigate the case with maximizing and incorrect scroll offset.
            if (context.AvailableLength - context.ForwardGeneratedLength > ListViewModel.DoubleArithmetics.Ceiling(1d / IndexStorage.PrecisionMultiplier))
            {
                if (this.viewportItemsCount < this.Layout.VisibleLineCount)
                {
                    // perform the measure logic again, since this difference will most probably occur when the Index tree is cleared before the measure pass
                    this.RecycleLocally();
                    context.InitializeForVerticalMeasure(this.Layout, availableSize);

                    if (this.IsBufferNeeded)
                    {
                        context.FirstVisibleIndex = this.GenerateTopBufferItems(context.FirstVisibleIndex, context.AvailableLength, context.Offset, context);
                        context.LastVisibleIndex  = context.FirstVisibleIndex;
                    }

                    this.MeasureForward(ref context);
                }
            }

            this.MeasureBackwards(ref context);

            if (this.IsBufferNeeded)
            {
                this.GenerateBottomBufferItems(context.LastVisibleIndex, context.AvailableLength, context);
            }

            var desiredSize = new RadSize(context.MaxLength, context.GeneratedLength);

            desiredSize.Width  = Math.Min(desiredSize.Width, ListViewModel.DoubleArithmetics.Ceiling(availableSize.Width));
            desiredSize.Height = Math.Min(desiredSize.Height, context.AvailableLength);

            this.Layout.UpdateAverageLength(context.FirstVisibleIndex, context.LastVisibleIndex);
            if (Math.Floor(context.Index) > initialFirstVisibleIndex)
            {
                (this.Owner as RadListView).updateService.RegisterUpdate((int)UpdateFlags.AffectsContent);
            }
            return(desiredSize);
        }
Example #2
0
        private RadSize MeasureVertically(RadSize availableSize, double offset, double bufferScale)
        {
            var context = new MeasureContext()
            {
                Offset      = offset,
                BufferScale = bufferScale
            };

            context.InitializeForVerticalMeasure(this, availableSize);

            this.AvailableLength = context.AvailableLength;

            // Always start with frozen containers unitl we generate row with cells.
            this.shouldGenerateFrozenContainer = true;

            if (this.IsBufferNeeded)
            {
                context.FirstVisibleIndex = this.GenerateTopBufferItems(context.FirstVisibleIndex, context.AvailableLength, context.Offset, context);
                context.LastVisibleIndex  = context.FirstVisibleIndex;
            }

            this.MeasureForward(ref context);

            ////TODO: We may need an additional synchronous measure pass in case less generated length (as in the Horizontal measure)

            this.MeasureBackwards(ref context);

            if (this.IsBufferNeeded)
            {
                this.GenerateBottomBufferItems(context.LastVisibleIndex, context.AvailableLength, context);
            }

            this.GenerateFrozenContainers();

            var desiredSize = new RadSize(context.MaxLength, context.GeneratedLength);

            desiredSize.Width  = Math.Min(desiredSize.Width, GridModel.DoubleArithmetics.Ceiling(availableSize.Width));
            desiredSize.Height = Math.Min(desiredSize.Height, context.AvailableLength);

            this.Layout.UpdateAverageLength(context.FirstVisibleIndex, context.LastVisibleIndex);

            return(desiredSize);
        }