WPF将Listbox绑定到字典的Keys,并获取更新

时间:2011-04-06 14:14:01

标签: wpf binding dictionary

我在我的C#代码中有一个字典,后面是WPF应用程序。 我想将一个列表框绑定到该词典的键,这是有效的。

但是我很明显也希望每当Dictionary有新元素或者删除一些元素时都会更新(我认为这是Binding oO的基本用法)...而且我遇到了麻烦,因为我理解浏览网络,我应该使用ObersvableCollection,字典不存在= /

另外,我更喜欢按原样使用字典。

看起来像这样:

<ListBox Margin="5" 
         Name="listBoxAvailableReplays" 
         Background="Transparent" 
         ItemsSource="{Binding}" 
         DataContext="{Binding UpdateSourceTrigger=PropertyChanged}" 
/>

代码隐藏(代码在构造函数中):

listBoxAvailableReplays.DataContext = 
          m_IFileHandlingBaboon.AvailableReplays.Keys;