当前位置:网站首页>WPF ListBox虚拟化
WPF ListBox虚拟化
2022-06-21 20:41:00 【zLulus】
在ListBox加载大量数据的情况下,如果不进行虚拟化,内存将逐渐增大,长时间运行后将造成卡顿
所以需要虚拟化
写法
<ListBox x:Name="listBox" VirtualizingStackPanel.VirtualizationMode="Recycling" VirtualizingStackPanel.IsVirtualizing="True">
<ListBox.ItemsPanel>
<ItemsPanelTemplate >
<VirtualizingStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
VirtualizationMode包括Recycling和Standard
Recycling:重复利用
Standard:创建和丢弃容器
测试:定时向ListBox加入数据
Timer timer;
int number = 1;
timer=new Timer();
timer.Interval = 1;
timer.Elapsed += AddData;
listBox.ItemsSource = new ObservableCollection<string>();
timer.Start();
private void AddData(object sender, ElapsedEventArgs e)
{
listBox.Dispatcher.Invoke(() =>
{
number++;
var dataContext = listBox.ItemsSource as ObservableCollection<string>;
if (dataContext != null)
dataContext.Add(number.ToString());
if (listBox.Items.Count > 0)
{
listBox.ScrollIntoView(listBox.Items[listBox.Items.Count - 1]);
}
if (dataContext != null && dataContext.Count > 200)
{
dataContext.Clear();
}
});
}
参考资料
How to use UI virtualization with redefined ListBox templates
VirtualizationMode Enum
WPF 列表开启虚拟化的方式
示例代码
边栏推荐
- 【深入理解TcaplusDB技术】Tmonitor后台一键安装
- 专业字体设计编辑Glyphs 3
- [deeply understand tcapulusdb technology] table management of document acceptance
- Use the for loop to calculate the odd and even sums in 1-100 [method 1]
- GDB调试实战(8)给程序传递启动参数
- [deeply understand tcapulusdb technology] tmonitor system upgrade
- GDB debugging practice (10) multi thread debugging
- FPGA之道——数字系统之间的接口电平标准
- nuxt ssr打包和部署
- 采样器合集
猜你喜欢

HIC Pro | HIC data processing tool

LeetCode-543-二叉树的直径

leetcode刷题:顺丰科技智慧物流校园技术挑战赛

【深入理解TcaplusDB技术】一键安装Tmonitor后台

【深入理解TcaplusDB技术】TcaplusDB构造数据

【LeetCode】8、字符串转换整数(atoi)

【深入理解TcaplusDB技术】TcaplusDB导入数据

安超云入选《CIOReview》2022年亚太区“十大云计算解决方案提供商”

nuxt ssr打包和部署

Thresholdtypes of opencvsharp threshold segmentation threshold function
随机推荐
Lifting method (I) AdaBoost
班主任让开股票账户,在启牛开户安全吗?
Paml| Shengxin software for calculating dn/ds value
PAML|计算dN/dS值的生信软件
Anaconda add channels
Notes on question brushing (17) -- binary search tree: about attribute problems
Use the do while loop to calculate the odd and even sums in 1-100 [method 1]
可乐与凉茶加速互卷
类库、框架、模块、组件等概念介绍
流式细胞分析Flowjo 10介绍以及超详细图文安装激活教程
promise错误捕获处理——Promisifying技术
软件架构介绍
Common abbreviations and terms of mitochondrial genome
Contact five heart matchmaker to take off the order
多进程和多线程的概念
Second understanding microservice
flutter系列之:flutter中的IndexedStack
es7创建索引模板
Use for, while and do while to find the sum of 1-100 circularly
GDB调试实战(7)信号处理