有一个包含一个ListBox一个用户控件。而ListBox使用另一个UserControl作为DataTemplate。如何进行数据绑定菜单项集合直接进入XAML
<ListBox x:Uid="SectionList" x:Name="SectionList" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<expander:ExpanderDataTemplate/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在后面的代码中,我将数据上下文设置为ObservableCollection。 ExpanderItem自曝以下的公共属性... 字符串名称, 的ObservableCollection的MenuItems, 布尔扩大, 用户控件控制 我已经实现INotifyPropertyChanged接口为这些属性。
而且我ExpanderDataTemplate看起来像这样...
<Border BorderThickness="0,1">
<Expander IsExpanded="{Binding Path=Expanded}" Content="{Binding Path=Control}">
<Expander.Header>
<StackPanel>
<TextBlock Text="{Binding Path=Name}"/>
<Menu x:Name="ConfigurationMenu" Background="Transparent">
<MenuItem x:Name="DropDownMenuItem" ItemsSource="{Binding Path=MenuItems}">
<MenuItem.Header>
<Image Source="..\..\images\dropdown_arrow.gif" SnapsToDevicePixels="True" Stretch="None"/>
</MenuItem.Header>
</MenuItem>
</Menu>
</StackPanel>
</Expander.Header>
</Expander>
</Border>
在这里,你可以看到,我有数据范围内的全部四个属性扩展,控制,名称和的MenuItems。所有的属性都得到了正确的界定并且可以期待MenuItems。 MenuItems是System.Windows.Controls.MenuItem的ObservableCollection。
我要实现期望的行为,当我点击DropDownMenuItem,我应该看到的数据有界的MenuItems集合作为子菜单。
请帮我解决这个问题。谢谢。
在此刻发生了什么? – 2010-02-08 22:37:37