绑定到Silverlight 4中的DependencyObjects集合 [英] Binding to a collection of DependencyObjects in Silverlight 4

查看:96
本文介绍了绑定到Silverlight 4中的DependencyObjects集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Silverlight 4开始,可以将数据绑定到DependencyObject(而不是先前版本中的Framework元素)。到目前为止这么好,但是如何再次绑定DependencyObjects的集合。

As of Silverlight 4 it is possible to data bind against a DependencyObject (instead of a Framework element in previous versions). So far so good, but how do I bind agains a collection of DependencyObjects.

DataContext不会从ObservableCollection传递给集合元素,因此DependencyProperties DependencyObjects从不被调用(也不是更改的事件)。 DependencyObject不提供SetBinding或DataContext手动初始化绑定。

The DataContext is not passed from the ObservableCollection to the collection elements, so that the DependencyProperties of the DependencyObjects are never called (neither the changed events). Neither the DependencyObject offers SetBinding or DataContext to initialize the binding manually.

感谢您的任何建议。

推荐答案

为了让DataContext在这种情况下传播,持有该集合的DependencyProperty必须是类型 DependencyObjectCollection< T> 。 DataContext通过DependencyProperties和DependencyObjectCollections传播。

To get the DataContext to propagate in this case, the DependencyProperty that holds the collection must be of type DependencyObjectCollection<T>. DataContext propagates through DependencyProperties and DependencyObjectCollections.

这篇关于绑定到Silverlight 4中的DependencyObjects集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆