WPF 列调整大小性能问题 [英] WPF column resize performance issues

查看:55
本文介绍了WPF 列调整大小性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般来说,WPF 中是否存在与网格列调整大小相关的任何已知性能问题?

Are there in general any known performance issues in WPF related to grid column resizing?

我有一个应用程序,我需要在一个列中做一些特定的事情,但是对于所有不同的解决方案,我发现调整列大小变得很慢.这适用于我的列表中通常有 1000 多个元素的情况,但我认为这对于 WPF 来说还不算太多……?所以;一般的问题是您是否遇到过缓慢调整列大小的情况,以及您是否找到了解决方案?是什么原因造成的?

I have an application where I need to do some particular things in a column, but for all the different solutions I find the column resizing gets slow. This applies when I have typically more than 1000 elements in my list, but I assume this isn't too much for WPF..? So; the general question is whether you've experienced slow column resizing, and whether you've found solutions for this? What was causing it?

关于我的特定案例的更多细节:

Some more details about my particular case:

我的专栏中可以有两种不同的内容;组合框或文本块.ComboBox 应填满整列并调整列大小,然后单击带有 TextBlock 的列的空白区域应选择该行.这就是问题所在.对于我必须解决的所有解决方案,列调整大小变慢.我发现使调整大小平滑的唯一方法是在它们外部添加一个带有 Orientation="Horizo​​ntal" 的 StackPanel,但是这样我无法实现上述样式.

I can have two different things in my columns; ComboBox or TextBlock. The ComboBox should fill the whole column and follow on column resize, and clicking an empty area of a column with a TextBlock should select the row. This is where the problem is. For all solutions I have to this the column resizing gets slow. The only way to make resizing smooth that I've found is by adding a StackPanel outside them with Orientation="Horizontal", but with this I'm unable to achieve the styles described above.

以下是一些观察:

  • 向列表项添加样式 Horizo​​ntalContentAlignment="Stretch" 会使 ComboBoxes 拉伸且 TextBlocks 可点击,但列调整大小也会变慢.
  • 向 StackPanel 或插入其中的元素添加 Background="Transparent" 也可以解决问题,但会使调整大小变慢.
  • 添加一个带有属性 Orientation="Horizo​​ntal" 的外部 StackPanel 可以平滑调整大小,但我无法应用所描述的样式.

推荐答案

您是否尝试过虚拟化 ListView 中的元素?虚拟化时,虚拟化面板只会为视图中的元素创建视觉效果.这使您可以拥有大量项目而不会出现您提到的性能问题.有关更多详细信息,请参阅 VirtualizingStackPanel.还有布局系统.您可以创建自己的虚拟化面板.如果您在 google 上查找virtualizing+wpf",您会发现很多关于虚拟化 Canvases、WrapPanels 等的搜索结果.

Have you tried virtualizing the elements in the ListView? When you are virtualizing, the virtualizing panel only creates the visuals for the elements that are in the view. This allows you to have large numbers of items without performance issues like you mention. See VirtualizingStackPanel for more details. Also The Layout System. You can create your own virtualizing panels. If you look up "virtualizing+wpf" on google you'll find lots of hits for virtualizing Canvases, WrapPanels, and etc.

我希望这会有所帮助.

这篇关于WPF 列调整大小性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆