Joe Krueger
Joe Krueger

Reputation: 43

XAML bind to Collection[index].ObjectProperty

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

Answers (2)

Simon_Weaver
Simon_Weaver

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

N_A
N_A

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

Related Questions