将 UControl 列表绑定到控件子属性?

发布于 2024-08-21 21:59:04 字数 433 浏览 3 评论 0原文

我有一个 ObservableCollection

我想通过 DataBinding 将此 List 绑定到父控件(比如说 GridWrapPanel)。 ..) 这有可能吗? Children 属性是只读的。 我不想在程序代码中这样做->不要迭代列表并将每个项目添加到 Children 属性。 我想将列表绑定到父控件 ->每次我向列表添加新项目时,视图都会自动更新。

有什么想法吗?

I have got an ObservableCollection<Button> buttonList; (this can be any other control: TextBox, TextBlock or even a UserControl).

I want to bind this List via DataBinding to a parent control (lets say a Grid or a WrapPanel,...)
Is this somehow possible? Children property is read only.
I do not want to do this in the program code -> Dont iterate through the list and add every item to the children property.
I want to BIND the List to a parent control -> the View is automatically updated, every time I add a new Item to the List.

Any Ideas?

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

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

发布评论

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

评论(1

丿*梦醉红颜 2024-08-28 21:59:04

Use ItemsControl, and bind your collection to ItemsSource.

And don't forget to read Dr. WPF's articles: ItemsControl: A to Z. This is second time I'm mentioning this blog today here, but he really-really deserves to be mentioned in every post related to collection of items and bindings :).

Cheers, Anvaka.

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