Example #1
0
        /// <summary>
        /// Returns the size of the container for a given item.  The size can come from the container, a lookup, or a guess depending
        /// on the virtualization state of the item.
        /// </summary>
        /// <returns>The cached or estimated size.</returns>
        /// <remarks>This estimation looks if the given index is cached. If not it returns the maximum height of the cached
        /// containers. If no container is cached, returns zero.
        /// One case it fails is, if all cached items are bigger
        /// than the estimated items. This leads to jumping scrollbars. The effect is not that bad, if many items will be visualized.</remarks>
        private double GetCachedOrEstimatedHeight(TreeView tree, int level)
        {
            if (cachedSizes.ContainsItems(0))
            {
                return(cachedSizes.GetEstimate(0));
            }

            return(tree.CachedSizes.GetEstimate(level));
        }
        public void AddInEmptyCache()
        {
            var expected = 43.0;
            var target   = new SizesCache();

            target.AddOrChange(0, expected);

            Assert.AreEqual(expected, target.GetEstimate(0));
        }
        public void AddInFilledCache()
        {
            var target = new SizesCache();

            target.AddOrChange(0, 43);
            target.AddOrChange(0, 46);
            target.AddOrChange(0, 46);

            Assert.AreEqual(46, target.GetEstimate(0));
        }
        public void CleanUpFilledCacheNormalCase()
        {
            var target = new SizesCache();

            target.AddOrChange(0, 40);
            target.AddOrChange(0, 41);
            target.AddOrChange(0, 42);
            target.AddOrChange(0, 43);

            target.CleanUp(0);
            Assert.AreEqual(0, target.GetEstimate(0));
        }
        public void ChangeWithMaxItems()
        {
            var target = new SizesCache();

            target.AddOrChange(0, 1);
            target.AddOrChange(0, 1);
            target.AddOrChange(0, 3);
            target.AddOrChange(0, 3);
            target.AddOrChange(0, 5);
            target.AddOrChange(0, 7);
            target.AddOrChange(0, 7);
            target.AddOrChange(0, 9);
            target.AddOrChange(0, 9);
            target.AddOrChange(0, 11);
            target.AddOrChange(0, 11);
            target.AddOrChange(0, 11);

            Assert.AreEqual(11, target.GetEstimate(0));
        }