绑定到可观察集合 silverlight 4,网格
我可以将一个简单的“网格”绑定到可观察的集合吗?所以我有一个只有一列和几行的网格。这些行在运行时填充一些可以删除/添加的超链接等。我不想每次都编写函数来添加/删除它们,而更喜欢使用可观察的集合并让网格自行更新。一个简单的网格可以做到这一点吗?我尝试过,但它甚至没有编译。
谢谢
[编辑]解决了。标记的答案是正确的[/编辑]
Can I bind a simple 'grid' to an observable collection? So i have a grid with just one column and several rows. The rows get populated at runtime with some hyperlinks which can get deleted/added etc. I don't want to write functions to add/remove them from the grid everytime and would prefer to use an observable collection and let the grid update itself. Can a simple grid do that ? i tried but it didn't even compile.
Thanks
[EDIT] Solved. The marked answer is correct [/EDIT]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
其他答案涵盖了各种基础,但您的具体要求由
ItemsControl
满足。您可能希望将其包含在ScrollViewer
中,以防万一您拥有的链接多于一次可以看到的链接。您将拥有如下标记:-您的可观察集合将包含类似类型的对象列表:-
Other answers cover various bases but your specific requirement is filled by the
ItemsControl
. You would probably want to contain it inScrollViewer
just in case where you have more links than can be seen at one time. You would have markup something like this:-Your observable collection would contain a list of objects of a type like:-
Silverlight 不支持这一点。您有两种选择,要么使用
DataGrid
,要么使用以下代码,该代码允许您在ItemsControl
中使用Grid
,这将实现您的目标是在之后。http://www.scottlogic.co.uk/blog/colin/2010/11/using-a-grid-as-the-panel-for-an-itemscontrol/
Silverlight does not support this. You have two options, either use a
DataGrid
or use the following code that allows you to use aGrid
within anItemsControl
which will achieve what you are after.http://www.scottlogic.co.uk/blog/colin/2010/11/using-a-grid-as-the-panel-for-an-itemscontrol/
@ColinE 是正确的,您无法绑定到
Grid
,但您可以将ObservableCollection
绑定到DataGrid
> 或ItemsControl
。@ColinE is correct, you can't bind to a
Grid
, but you can bind anObservableCollection
to aDataGrid
or anItemsControl
.