Reputation: 43
I have an observable collection of objects in my VM. I want to bind to a property of a specific item in the list in a text block, something like this:
Binding="{MyVMCollection[0].Description}"
But this syntax does not work. Is it possible to do what I am after and if so, how?
Thanks!
Upvotes: 4
Views: 2703
Reputation: 146198
The type of the object needs to be a type where an array index would normally work for this to work. I'm not sure the exact constraints but use Type[]
if in doubt.
eg. If it is some weird enumerable type like IOrderedEnumerable<T>
(or some wierd LINQy type) then something like {Binding List[0]}
won't work.
Upvotes: 1
Reputation: 19897
You're missing the Binding
keyword and I think you also need to use Path
.
Binding="{Binding Path=MyVMCollection[0].Description}"
Upvotes: 6