Wpf 使用字符串键绑定到索引属性
假设我想用XAML绑定到TKey是字符串的字典:Wpf 使用字符串键绑定到索引属性,wpf,vb.net,xaml,dictionary,idictionary,Wpf,Vb.net,Xaml,Dictionary,Idictionary,假设我想用XAML绑定到TKey是字符串的字典: <Label DataContext="{MyDictionary}" Content="{Binding Item("OK")}" /> 不起作用 我该怎么做 我说的是项目(“关键”)试试: <Label DataContext="{Binding MyDictionary}" Content="{Binding [OK]}" /> 或者(简单一点): 嗯,我知道列表索引是可能的,但我不确定字典键。。我刚试
<Label DataContext="{MyDictionary}" Content="{Binding Item("OK")}" />
不起作用
我该怎么做
我说的是项目(“关键”)试试:
<Label DataContext="{Binding MyDictionary}" Content="{Binding [OK]}" />
或者(简单一点):
嗯,我知道列表索引是可能的,但我不确定字典键。。我刚试过,结果成功了;)对我来说,第一个建议是这样的。但是,当键有空格或其他特殊字符(如句点和斜杠)时,这不起作用。我试着把钥匙放进双引号和单引号中,但都不起作用。
<Label Content="{Binding MyDictionary[OK]}" />