我想避免必须在XAML或代码手工创建一个菜单,通过结合到ICommand
衍生的对象的列表。但是,我遇到了一下,其中出现的菜单中有菜单项目两个层面的问题(即每个MenuItem
包含在MenuItem
):麻烦WPF菜单结合的ItemsSource
alt text http://i47.tinypic.com/j63lg2.png
我的猜测是,这是因为发生WPF自动生成我结合MenuItem
,但“浏览器”我使用其实已经是一个MenuItem
(它是从MenuItem
派生):
<ContextMenu
x:Name="selectionContextMenu"
ItemsSource="{Binding Source={x:Static OrangeNote:Note.MultiCommands}}"
ItemContainerStyleSelector="{StaticResource separatorStyleSelector}">
<ContextMenu.ItemTemplate>
<DataTemplate>
<Viewers:NoteCommandMenuItemViewer
CommandParameter="{Binding Source={x:Static OrangeNote:App.Screen}, Path=SelectedNotes}" />
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
(该ItemContainerStyleSelector是http://bea.stollnitz.com/blog/?p=23,这让我有我的绑定源里面Separator
元素。)
所以,菜单必然的ICommand
个集合,每个项目的CommandParameter
被设置为相同的全球目标(这恰好是一个集合,但那不重要)。
我的问题是,有没有我可以绑定这使得WPF不会自动在MenuItem
包装每个项目什么办法?
谢谢,这是一个更简单的解决方案! – devios1 2010-06-12 14:07:34