我的XAML ...的Silverlight 4 {}绑定通用字典到列表框中
<ListBox Margin="6,35,6,6" Name="lbLayers" SelectionMode="Extended" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Key,Mode=TwoWay}" />
<TextBlock Text="{Binding Value.Visible,Mode=TwoWay,StringFormat='Visible: {0}'}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
..和我的代码是...
void GameEvents_MapCreated(object sender, Zider.EventArgs.MapEventArgs e)
{
HookMapLayerEvents(false);
this.map = e.Map;
HookMapLayerEvents(true);
this.lbLayers.ItemsSource = this.map.Layers;
}
this.map。图层是类型的通用字典(字符串,MapLayer(Tile))
当我在列表框中设置ItemSource时,字典中没有任何项目可以启动。当我点击一个按钮时,当我添加地图图层
this.map.Layers.Add("key", new MapLayer<Tile>());
此外MapLayer实现INotifyPropertyChanged为它的属性。
对于我的生活,我似乎无法获得要显示在列表框中的项目。
经过一些更多的搜索后,我遇到了这篇文章http://blogs.microsoft.co.il/blogs/shimmy/archive/2010/12/26/observabledictionary-lt-tkey-tvalue-gt-c.aspx我将ItemSource设置为一个没有实现INotifyCollectionChanged接口的集合。 – 2011-05-13 21:26:23