c# Bind to indexed property in code

I have seen many examples on how to bind in xaml to a indexed property like sugested here. And it is easy to create a binding in code like this, really straight forward, but what about binding in code to a indexed property? Cheers

Upvotes: 1

Views: 830

Answers (1)

BradleyDotNET
BradleyDotNET

Reputation: 61349

The same exact way:

  Binding myBinding = new Binding("Contacts[John].PhoneNumber");
  myText.SetBinding(TextBlock.TextProperty, myBinding);

The Path you use doesn't change between setting in XAML and setting in Code-Behind.

Upvotes: 1

Related Questions