42

I can bind to a collection item using index:

<TextBlock FontStyle="Italic"  Text="{Binding Path=Exchanges[0].Name}" />

but what about using a dictionary key?

Path=Exchanges['AMEX'].Name
Eliahu Aaron
  • 4,103
  • 5
  • 27
  • 37
Sonic Soul
  • 23,855
  • 37
  • 130
  • 196

1 Answers1

72

yep.. works like a charm

<TextBlock FontStyle="Italic"  Text="{Binding Path=ExchangesDictionary[AMEX].Name}" />
Sonic Soul
  • 23,855
  • 37
  • 130
  • 196
  • didn't work for me though. My Dictionary was something like Dictionary IconDetails and doesn't work when I use this Content="{Binding Path=IconDetails.x}" or Content="{Binding Path=IconDetails.IconPositionDetails.x}" any idea? – Jayson Ragasa Sep 07 '12 at 14:30
  • Thanks. This helped a lot – wingerse Jan 04 '16 at 21:25
  • 1
    @JaysonRagasa Your binding path does not supply a key, you still need `[string]`. – Wobbles Jan 13 '17 at 16:33
  • Thanks, it works at run time. but at design time XAML throws an error of: "Invalid property path syntax". – SamBerk Nov 16 '21 at 17:22