views:

104

answers:

1

Say I wanna bind to dictionary that TKey is string with XAML:

<Label DataContext="{MyDictionary}" Content="{Binding Item("OK")}" />

Doesn't work.

How should I do it?

I am talking about the Item("Key")

+5  A: 

Try that :

<Label DataContext="{Binding MyDictionary}" Content="{Binding [OK]}" />

Or that (a bit simpler) :

<Label Content="{Binding MyDictionary[OK]}" />
Thomas Levesque
+1 That's brilliant I had no idea you could do that!
Preet Sangha
well, I knew it was possible with list indexes, I wasn't sure about dictionary keys.. I just tried, and it worked ;)
Thomas Levesque