WPF ListView 性能非常慢 - 为什么? (ElementHost,还是其他原因?)
我有一个 Windows 窗体应用程序,它有一个包含 WPF UserControl 的 ElementHost...在我的 WPF 中,我有一个非常简单的 ListView:
<ListView Margin="4" ItemsSource="{Binding Notifications}">
<ListView.View>
<GridView>
<GridViewColumn Header="FirstName" DisplayMemberBinding="{Binding FirstName}" />
<GridViewColumn Header="LastName" DisplayMemberBinding="{Binding LastName}" />
<GridViewColumn Header="Address" DisplayMemberBinding="{Binding Address}" />
<GridViewColumn Header="City" DisplayMemberBinding="{Binding City}" />
<GridViewColumn Header="State" DisplayMemberBinding="{Binding State}" />
<GridViewColumn Header="Zip" DisplayMemberBinding="{Binding Zip}" />
</GridView>
</ListView.View>
</ListView>
如果我的源有 10 个项目,则表单加载时间不到一秒。 如果我的源有 1000 个项目,则需要 7 秒!!! 我的计时器仅考虑加载情况(而不考虑获取物品所需的时间)。
所以我的问题是:
使用 ElementHost 是性能噩梦吗?
WPF 数据绑定是性能噩梦吗?
ListView是一坨屎吗? (顺便说一句,与 WPFToolkit 的 DataGrid 的结果相同)?
I have a Windows Forms app, that has a single ElementHost containing a WPF UserControl... in my WPF, I have a VERY simple ListView:
<ListView Margin="4" ItemsSource="{Binding Notifications}">
<ListView.View>
<GridView>
<GridViewColumn Header="FirstName" DisplayMemberBinding="{Binding FirstName}" />
<GridViewColumn Header="LastName" DisplayMemberBinding="{Binding LastName}" />
<GridViewColumn Header="Address" DisplayMemberBinding="{Binding Address}" />
<GridViewColumn Header="City" DisplayMemberBinding="{Binding City}" />
<GridViewColumn Header="State" DisplayMemberBinding="{Binding State}" />
<GridViewColumn Header="Zip" DisplayMemberBinding="{Binding Zip}" />
</GridView>
</ListView.View>
</ListView>
If my source has 10 items, the form loads in less than one second. If my source has 1000 items, it takes 7 seconds!!! My timer is ONLY taking the loading into account (not how much time it takes to get the items).
So my question is:
Is using an ElementHost a performance nightmare?
Is WPF DataBinding a performance nightmare?
Is the ListView a piece of crap? (btw, same results with the WPFToolkit's DataGrid)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用虚拟化
Use virtualization
您可能还想查看关于代码项目的这篇优秀文章:
WPF:数据虚拟化
保罗·麦克莱恩
http://www.codeproject.com/KB/WPF/WpfDataVirtualization.aspx
它向您展示了一种以最少的内存和带宽使用更好的方法。
You may also want to check this excellent article on the Code Project:
WPF: Data Virtualization
By Paul McClean
http://www.codeproject.com/KB/WPF/WpfDataVirtualization.aspx
It show you a much better approach at minimal memory and bandwidth usage.
我遇到过一个案例,这里提供的答案并没有解决我的问题。 就我而言,将
ListView
的MaxHeight
属性设置为大于实际显示高度的值立即解决了问题,这要归功于 这个答案在这里,即使我无法解释它是如何以及为什么起作用的。I had a case where the answers presented here didn't solve my problem. In my case, setting the
MaxHeight
property of theListView
to a value larger than the actual displayed height solved it immediately, thanks to this answer here, even if I cannot explain how and why it worked.我有同样的问题。 将列表视图替换为包含 DataGridTextColumn 项目的 DataGrid 解决了该问题。
I had the same problem. Replacing the listview with DataGrid containing DataGridTextColumn items fixed the problem.