如何在wp7中动态添加listbox.itemsource中的元素?

发布于 2024-12-09 09:16:08 字数 150 浏览 1 评论 0原文

我有一个带有数据模板的列表框,有 2 个文本块,它们绑定某个类的某些属性,我有一个包含该类类型的元素的列表,我想动态显示此元素,即首先显示前 20 个元素,然后显示下一个 20 个元素等,但是我该怎么做,对于 itemsource 我只能分配一个列表,我无法动态向其添加元素,请帮助我。

I have a listbox with datatemplate, with 2 textblocks which binding some properties of some class,i have a list with elements of type of that class,i want to dynamically show this elements i.e at first show first 20 elements, than next 20 and etc, but how can I do that, to itemsource I can only assign a list, I can't add elements to it dynamically, please help me.

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

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

发布评论

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

评论(1

浸婚纱 2024-12-16 09:16:08

为了使 ListBox 在将项目添加到列表时动态更新,您需要选择一个在添加/删除项目时引发事件的集合类。您应该使用 ObservableCollection 作为您的 ItemsSource。该集合在修改时会引发 CollectionChanged 事件。 ListBox 处理此事件并相应更新。

In order for a ListBox to update dynamically as items are added to the list, you need to choose a collection class that raises events when items are added / removed. You should use ObservableCollection as your ItemsSource. This collection raises the CollectionChanged event when it is modified. ListBox handles this event and updates accordingly.

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