C# 如何将集合中的集合绑定到上下文菜单并通过单击获取上下文菜单项
我尝试将C# 如何将集合中的集合绑定到上下文菜单并通过单击获取上下文菜单项,c#,wpf,mvvm,caliburn,C#,Wpf,Mvvm,Caliburn,我尝试将itemssource(集合中的集合)绑定到上下文菜单,并希望通过单击(MVVM)Caliburn获取上下文菜单项 <TreeView x:Name="TreeViewName" BorderThickness="0" ItemsSource="{Binding RegionsTree}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate Items
itemssource
(集合中的集合)绑定到上下文菜单,并希望通过单击(MVVM)Caliburn获取上下文菜单项
<TreeView x:Name="TreeViewName" BorderThickness="0" ItemsSource="{Binding RegionsTree}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<RadioButton Tag="{Binding DataContext, ElementName=TreeViewName}" Content="{Binding Name}"
cal:Message.Attach="[Click]=[ShowItemScreen($dataContext)];[PreviewMouseRightButtonDown]=[Action OnContextMenuOpening($source)]"
GroupName="TestTree">
<RadioButton.ContextMenu>
<ContextMenu ItemsSource="{Binding RegionCategories}" cal:Action.TargetWithoutContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="MenuItem.Header" Value="{Binding Name}" />
<Setter Property="MenuItem.ItemsSource" Value="{Binding Commands}" />
<Setter Property="cal:Message.Attach" Value="[Action ContextMenuItemClick($eventArgs)]"/>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</RadioButton.ContextMenu>
</RadioButton>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle >
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="True"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
到目前为止您尝试了什么?实际问题是什么?你有什么问题吗?你检查过类似的问题吗?我试着使用代码隐藏并获取原始源代码,但这样我在coxtext菜单项上只有文本,并尝试使用viewmodel,但当我单击我的项目时,这是正常的,但当我单击子项目(使用itemsource)时,我有一个例外。是的,我检查过类似的问题,但这没有帮助。异常消息“找不到方法的目标”能否共享viewmodel代码?也看看这个