使用String键绑定到索引属性

Shi*_*mmy 4 vb.net wpf xaml dictionary idictionary

假设我想绑定到TKey与XAML字符串的字典:

<Label DataContext="{MyDictionary}" Content="{Binding Item("OK")}" />
Run Code Online (Sandbox Code Playgroud)

不行.

我该怎么办?

我说的是物品("钥匙")

Tho*_*que 12

试试看:

<Label DataContext="{Binding MyDictionary}" Content="{Binding [OK]}" />
Run Code Online (Sandbox Code Playgroud)

或者那(更简单):

<Label Content="{Binding MyDictionary[OK]}" />
Run Code Online (Sandbox Code Playgroud)

  • 好吧,我知道列表索引是可能的,我不确定字典键..我只是尝试过,它工作;) (2认同)