Binding to a collection of DependencyObjects in Si

2019-05-10 02:39发布

问题:

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.

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.

Thanks for any advice here.

回答1:

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.