首页 > 其他分享 >WPF ScrollViewer.IsDeferredScrollingEnabled is true can enhance the performance hugely when there is

WPF ScrollViewer.IsDeferredScrollingEnabled is true can enhance the performance hugely when there is

时间:2024-09-20 17:38:23浏览次数:8  
标签:huge set ScrollViewer get Windows there System using public

When an items control is using a virtualizing panel and it contains a large number of complex items, setting IsDeferredScrollingEnabled to true can result in a significant performance improvement by avoiding the rendering of intermediate states. Applications such as Microsoft Outlook scroll through long lists in this fashion.

 

<Window x:Class="WpfApp387.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp387"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <local:ItemsList x:Key="itemsList"/>
    </Window.Resources>
    <Grid>
        <ListBox ItemsSource="{StaticResource itemsList}"
                 VirtualizingPanel.IsVirtualizing="True"
                 VirtualizingPanel.CacheLength="100"
                 VirtualizingPanel.CacheLengthUnit="Item"
                 VirtualizingPanel.VirtualizationMode="Recycling"
                 ScrollViewer.IsDeferredScrollingEnabled="True">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Image Source="{Binding ImgUrl}" Width="200" Height="500" Stretch="Uniform"/>
                        <TextBlock Text="{Binding Name}" 
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontSize="50"
                                   Foreground="Red"/>
                    </Grid>                    
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>


//cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace WpfApp387
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }

    public class ItemsList : List<Book>
    {
        public ItemsList()
        {
            var imgsList = Directory.GetFiles(@"../../Images");
            if (imgsList != null && imgsList.Any())
            {
                int imgsCount = imgsList.Count();
                for (int i = 0; i < 1000000; i++)
                {
                    this.Add(new Book()
                    {
                        Id = i,
                        Name = $"Name_{i+1}",
                        Title = $"Title_{i}",
                        Topic = $"Topic_{i}",
                        ImgUrl = imgsList[i % imgsCount]
                    });
                }
            }
        }
    }

    public class Book
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public string Title { get; set; }

        public string Topic { get; set; }

        public string ImgUrl { get; set; }
    }

}

 

标签:huge,set,ScrollViewer,get,Windows,there,System,using,public
From: https://www.cnblogs.com/Fred1987/p/18422915

相关文章

  • Ethereum学习笔记 ---- 多重继承中的 C3线性化算法
    目录举个反例分析错误原因举个正例分析solidity中的多重继承多重继承合约的storagelayout学习solidity合约多重继承时,官方文档介绍solidity采用C3线性化算法来确定多重依赖中的继承顺序。维基百科上有很好的说明:C3线性化C3linearization下面通过实验来深入理解一下......
  • Ethereum学习笔记 ---- 使用 Remix 调试功能理解 bytes 在 memory 中的布局
    目录编写合约编译、部署、调用合约调试交易1.调用函数bytesInMemory(),分析bytes的MemoryLayout执行RETUR前的最后一刻,stack快照如下执行完毕时刻的MemoryLayout对MemoryLayout的分析2.调用函数bytesArrayInMemmory(4),分析bytes[]的MemoryLayout执行RETUR前......
  • 在Spring Boot项目中集成Geth(Go Ethereum)
    在SpringBoot项目中集成Geth(GoEthereum)客户端,通常是为了与以太坊区块链进行交互。以下是一些基本的步骤和考虑因素,帮助你在SpringBoot应用程序中集成Geth。安装Geth首先,你需要在你的机器上安装Geth。你可以从官方网站下载适合你操作系统的版本。启动Geth安装完成后......
  • Docker无法运行java虚拟机报错There is insufficient memory for the Java Runtime
    镜像导入到docker后无法启动容器的问题,但是上传到别的服务器上面又可以正常启动容器,报错信息如下:#ThereisinsufficientmemoryfortheJavaRuntimeEnvironmenttocontinue.#CannotcreateGCthread.Outofsystemresources.#Cannotsavelogfile,dumptoscree......
  • HDU 2999 Stone Game, Why are you always there?
    题目链接:HDU2999【StoneGame,Whyareyoualwaysthere?】思路    由于只能取连续的一段石子,当取出的石子是这段石子的中间一部分时就相当于将一段石子分成两段石子,简单异或一下求SG值就行了代码intsg[N],vis[N],a[N];intn,m,k;voidgetsg(){memset......
  • WPF ScrollViewer控件 触屏滑动
    备份下  原文 https://www.cnblogs.com/webenh/p/18207292<ScrollViewerx:Name="scroll"TouchDown="mScrollViewer_TouchDown"TouchMove="mScrollViewer_TouchMove"TouchUp="mScrollViewer_TouchUp"></ScrollViewer>......
  • 区块链入门基础课:《Nethereum教程》零基础玩转以太坊开发(三)合约状态
    今天我们要讨论的是如何与智能合约进行交互,获取合约状态。下面的示例将会详细讲解如何与合约进行交互,及一些概念性的解释,有需要的朋友们可以收藏一下。一:概念解释在下面示例之前呢,我先解释下为什么需要调用合约状态,以及合约状态对开发而言有什么作用。实时的了解合约状......
  • linux部署Hugegraph
    HugeGraph是一款易用、高效、通用的开源图数据库系统(GraphDatabase)。一、基本概述功能特性:HugeGraph实现了ApacheTinkerPop3框架,并完全兼容Gremlin查询语言,具备完善的工具链组件,助力用户轻松构建基于图数据库之上的应用和产品。它支持百亿以上的顶点和边快速导入,并提供毫秒级......
  • 翻译《The Old New Thing》- Why isn’t there a SendThreadMessage function?
    Whyisn'tthereaSendThreadMessagefunction?-TheOldNewThing(microsoft.com)https://devblogs.microsoft.com/oldnewthing/20081223-00/?p=19743RaymondChen 2008年12月23日为什么没有SendThreadMessage函数?简要文章讨论了Windows中不存在`SendThread......
  • The remote session was disconnected because there are no Remote Desktop License
    远程桌面登录报错,信息如下:TheremotesessionwasdisconnectedbecausetherearenoRemoteDesktopLicenseServersavailabletoprovidealicense.therearenoRDConnectionBrokerserversintheserverpool.Tomanageadeployment,youmustaddalltheserv......