Как привязать коллекцию в коллекции к контекстному меню и взять пункт контекстного меню через клик - PullRequest
2 голосов
/ 28 марта 2019

Я пытаюсь привязать 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>
...