WPF 通过虚拟化在网格中排列项目
我正在寻找在固定数量的行和任意数量的列中呈现相同大小的元素的方法。 (想想 iTunes 或 Picasa 的相册视图。我相信某些平台将其称为“gridview”)
WrapPanel
可以完成这项工作,但我要绑定一个非常大的对象集合,所以我需要虚拟化。
我一直在网上查找,发现了商业上可用的 VirtualizationWrapPanels
和关于如何实现自己的 VirtualizationPanel
的博客文章,但我似乎找不到任何更简单的解决方案。
是否可以使用标准 WPF 组件在网格样式视图(固定行数)中排列虚拟化数据绑定项?
I'm looking for way to present equally sized elements in a fixed number of rows and any number of columns. (Think of iTunes' or Picasa's album view. I believe some platforms refer to this as a 'gridview')
A WrapPanel
would do the job, but I'm binding against a very large collection of objects, so I need virtualization.
I've been looking around the web, and found both commercially available VirtualizationWrapPanels
and blog posts on how to implement your own VirtualizationPanel
, but I can't seem to find any simpler solutions.
Is it possible to arrange virtualized databound items in a grid-style view (fixed number of rows) with standard WPF components?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最近不得不寻找类似的功能,并努力寻找任何可以投入生产的东西。
我找到了一个系列包含虚拟化平铺面板的文章和示例代码。
我一直在用,而且还算稳定。但仍然需要做出一些改变。我们必须在面板中添加一些键盘控件,因为它尚未实现,需要更改选项卡以及调整图块大小等。如果您决定推出自己的键盘控件,那么这是一个很好的起点。
但一个主要的警告是,它还必须有一个被限制在有限大小的父级,否则会出错。这通常不是问题,因为您希望限制其大小,以便可以启用滚动。这个特定问题可能有解决方案,但我们没有时间进行调查。
I've recently had to have a hunt round for similar functionality and struggled to find anything that was production ready.
I found a series of articles and sample code that contain a Virtualizing Tile Panel.
I've been using it and it has been fairly stable. There were some changes that needed to be made though. We had to add some of the keyboard control into the panel as it wasn't implemented, tabbing needed to be changed as well as adjusting tile sizes, etc. It's a good starting point if you decide to roll your own.
One major caveat though was that it also MUST have a parent that is constrained to a limited size else it errors out. This is not normally an issue as you will want it to be limited in size so you can enable scrolling. There may be a solution to this particular problem but we didn't have time to investigate.
一种快速而肮脏的解决方案是使用“分组项”列表(在您的情况下是水平的)(在您的情况下是垂直的),这将确定所需的行数。虚拟化将发生在“石斑鱼”上。
A quick-and-dirty solution is to use a list (in your case a horizontal one) of "grouping items" (in your case vertical ones) which will determine desired number of rows. Virtualization will occur on the "groupers".
小组有责任提供虚拟化。不幸的是,该框架只提供了一个虚拟化StackPanel:
http:// /msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingpanel.aspx
这里有一篇非常好的博客文章提供了虚拟化 WrapPanel:
https://blogs.claritycon.com/custom-panels-in-silverlight-wpf- part-4-virtualization-7f3bded02587
另一种选择是使用 DataGrid,这将为您进行虚拟化。
It is the responsibility of the Panel to provide Virtualization. Unfortunately the framework only provides a virtualizing StackPanel:
http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingpanel.aspx
There is a very good blog post that provides a virtualizing WrapPanel here:
https://blogs.claritycon.com/custom-panels-in-silverlight-wpf-part-4-virtualization-7f3bded02587
Another alternative is to use a DataGrid, this will virtualize for you.