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
Asked
Active
Viewed 782 times
1 Answers
1
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.

BradleyDotNET
- 60,462
- 10
- 96
- 117
-
Note, you should almost *never* need to do this, bindings *belong* in XAML, but it is the exact same. – BradleyDotNET Nov 06 '14 at 23:42
-
Pretty cool, i will give it a go tomorrow first thing in the morning and set as the correct answer if it works. Thanks @BradleyDotNET – Bruno Pires Lavigne Quintanilh Nov 06 '14 at 23:44
-
Sure, i understand that, it just makes sense on the project i am working on. Thanks – Bruno Pires Lavigne Quintanilh Nov 06 '14 at 23:48
-
@BrunoPiresLavigneQuintanilh I figured you probably did, but I though it needed *some* disclaimer for future readers if nothing else. – BradleyDotNET Nov 06 '14 at 23:50