tags:

views:

31

answers:

1

Is it possible to use binding to add objects to a XAML collection.

something like

<x:Array Type="sys:Int32">
   <Binding Source="obj", Path="Prop1"/>
   <Binding Source="obj", Path="Prop2"/>
</x:Array>
+1  A: 

No, the target of a data binding must be a dependency property and an element of a collection is not a property.

I can think of two workarounds, but both are ugly and I wouldn't use any of them:

  1. You can create a MarkupExtention that will create a collection with whatever you want, you can even create one that create a collection from bindings, but the syntax will be very strange and the collection content won't be updated from the binding source.
  2. You can also create a new collection class that inherits from DependencyObject and have dependecy properties for elements in teh collection (properties e0, e1, e2 ... that will update the contant of the collection when set).

I would try to find a way to accomplish what you want to do without filling a collection from data binding.

Nir
OK, thanks. I'll do it in code-behind instead.
adrianm