WPF 列调整大小性能问题

发布于 2024-07-18 19:23:35 字数 745 浏览 1 评论 0原文

WPF 中是否存在与网格列大小调整相关的已知性能问题?

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

关于我的具体案例的更多细节:

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

以下是一些观察结果:

  • 将样式 Horizo​​ntalContentAlignment="Stretch" 添加到列表项会使 ComboBox 拉伸且 TextBlock 可单击,但也会使列调整大小变慢。
  • 将 Background="Transparent" 添加到 StackPanel 或插入其中的元素也可以解决问题,但会导致调整大小变慢。
  • 添加具有 Orientation="Horizo​​ntal" 属性的外部 StackPanel 可以使调整大小变得平滑,但我无法应用所描述的样式。

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

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:

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.

Here are some observations:

  • Adding style HorizontalContentAlignment="Stretch" to the items of the list makes the ComboBoxes stretch and the TextBlocks clickable, but also column resize slow.
  • Adding Background="Transparent" to either the StackPanel or the elements that are inserted inside them solves the problem too, but makes resizing slow.
  • Adding an outer StackPanel with property Orientation="Horizontal" makes resizing smooth, but I'm unable to apply the styles as described.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朕就是辣么酷 2024-07-25 19:23:35

您是否尝试过虚拟化 ListView 中的元素? 当您进行虚拟化时,虚拟化面板只会为视图中的元素创建视觉效果。 这允许您拥有大量项目,而不会出现您提到的性能问题。 有关详细信息,请参阅 VirtualizingStackPanel。 还有布局系统。 您可以创建自己的虚拟化面板。 如果您在 google 上查找“virtualizing+wpf”,您会发现很多有关虚拟化 Canvas、WrapPanel 等的内容。

我希望这会有所帮助。

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.

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文