如何将集合中的集合绑定到上下文菜单并通过单击获取上下文菜单项

时间:2019-03-28 08:21:30

标签: c# wpf mvvm caliburn

我尝试将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>

0 个答案:

没有答案