Beispiel #1
0
        /// <summary>
        /// 开始虚拟化子项
        /// </summary>
        private void BeginItemsVirtualizing(ScrollViewerView view, ScrollViewerView final)
        {
            Rect viewport = new Rect(view.HorizontalOffset - ScrollOwner.ViewportWidth * 0.5, view.VerticalOffset - ScrollOwner.ViewportHeight * 0.5, ScrollOwner.ViewportWidth * 2, ScrollOwner.ViewportHeight * 2);

            foreach (var context in layoutContext)
            {
                bool IsBeginRealize = false;

                foreach (var item in context.Elements)
                {
                    if (item is IVirtualizingItem)
                    {
                        if (ShouldBeVirtualized(item, viewport))
                        {
                            (item as IVirtualizingItem).Virtualize();
                            if (IsBeginRealize)
                            {
                                break;
                            }
                        }
                        else
                        {
                            IsBeginRealize = true;
                            (item as IVirtualizingItem).Realize();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 判断一个元素在指定的 ScrollViewerView 是否应该被虚拟化
        /// </summary>
        /// <param name="item">需要测量的元素</param>
        /// <param name="view">指定的视图</param>
        /// <returns></returns>
        private bool ShouldBeVirtualized(UIElement item, ScrollViewerView view)
        {
            Rect arrange  = GetArrange(item);
            Rect viewport = new Rect(view.HorizontalOffset - ScrollOwner.ViewportWidth * 0.5, view.VerticalOffset - ScrollOwner.ViewportHeight * 0.5, ScrollOwner.ViewportWidth * 2, ScrollOwner.ViewportHeight * 2);

            viewport.Intersect(arrange);
            return(viewport == Rect.Empty);
        }