将 UControl 列表绑定到控件子属性?
我有一个 ObservableCollection
我想通过 DataBinding
将此 List
绑定到父控件(比如说 Grid
或 WrapPanel
)。 ..) 这有可能吗? 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 ItemsControl,并将您的集合绑定到ItemsSource。
不要忘记阅读 WPF 博士的文章:ItemsControl:A to Z。这是我今天第二次在这里提到这个博客,但他真的非常值得在每一篇与项目和绑定集合相关的帖子中被提及:)。
干杯,安瓦卡。
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.