简体   繁体   English

在WPF中将行和列动态绑定到网格

[英]dynamic binding of rows and columns to a grid in WPF

With a DataGrid object in WPF, we can bind its rows to an observable collection such that as rows are added or removed to/from the collection, the UI updates to display the changes. 使用WPF中的DataGrid对象,我们可以将其行绑定到可观察的集合,以便在向集合中添加行或从集合中删除行时,UI会更新以显示更改。 I am looking to do something similar with a Grid control as part of a User Control I am trying to create. 我正在尝试使用Grid控件做类似的事情,作为我要创建的用户控件的一部分。 Is this possible? 这可能吗?

If you want to bind a collection to some sort of self updating UI in my experience an ItemsControl with custom ItemPanel and a ItemContainerStyle with a Template set as well as ItemTemplates for different kinds of objects in the collection is quite powerfulI. 如果您想以我的经验将集合绑定到某种类型的自我更新UI,则具有自定义ItemPanel的ItemsControl和具有模板集的ItemContainerStyle以及集合中不同对象的ItemTemplates都非常强大。 It all depends on your exect scenario though. 不过,这完全取决于您的示例场景。 If you can elaborate i could whip up some XAML. 如果可以详细说明,我可以介绍一些XAML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM