Search code examples
wpfvb.netxamldictionaryidictionary

Binding to indexed property with String key


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")


Solution

  • Try that :

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

    Or that (a bit simpler) :

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