UserControl 而不是 DataTemplates - 有没有办法处理大集合?
有两种方法。可能两个人都是傻子吧…… 我必须展示一些物品收藏。
第一个。
我使用 DataTemplate 作为 ListBoxItem。 只需设置 itemSource = myCollection;
就这样。简单的方案。
第二个。
我收藏中的每一项都有属性view。这是一个用户控件。这定义了项目的渲染方式。
仅使用 ContentPresenter 创建DataTemplate。
将内容属性绑定到视图。
只需设置 itemSource = myCollection;
就这样。更复杂。但也有效。
第二个人有生存权吗?我的疑问是我必须为我的集合中的每个项目创建 UserControl 实例吗?
收藏超过500件是不是太贵了?
谢谢。
There are two ways. May be both are stupid...
I have to display some collections of items.
First one.
I use DataTemplate for ListBoxItem.
Just set itemSource = myCollection;
That's all. Simple scheme.
Second one.
Each item in my collection has property view. It's a UserControl. That define how item renders.
Create DataTemplate with ContentPresenter only.
Binding Content property to a view.
Just set itemSource = myCollection;
That's all. More complex. But works too.
Has second one right to live? My doubt is that I have to create instance of UserControl for every item in my collection?
Is not it too expensive for collection with over than 500 items?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为有太大区别,使用 DataTemplate 方法,框架将为集合中的每个项目创建一个 DataTemplate 实例。在第二种方法中,将为每个项目创建用户控件的实例,可能还有更多控件,但每个项目只有几个。
第二种方法更可取的原因之一是您可以了解绑定内容的逻辑。这可能意味着列表中的每个项目都有不同的用户控件。 Caliburn Micro 让您可以非常自然地使用这种方法。
I don't believe there is much difference, with the DataTemplate approach the framework will create an instance of the DataTemplate for each item in the collection. In the second approach an instance of the user control will be created for each item, there may be a few more controls but only a few per item.
One reason the second approach could be preferable is that you can have logic around which content is bound. This could mean different user controls for each item in the list. Caliburn Micro lets you use this approach very naturally.