Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将集合中的集合绑定到上下文菜单并通过单击获取上下文菜单项_C#_Wpf_Mvvm_Caliburn - Fatal编程技术网

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代码?也看看这个