2

I try to bind itemssource (collection in collection) to context menu and i want to take a context menu item through click (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>
Rekshino
  • 6,954
  • 2
  • 19
  • 44
  • What is the actual question? Do you have a problem? Did you check similar questions [like this one](https://stackoverflow.com/questions/53396484/wpf-dynamic-context-menu-with-caliburn-micro)? – Panagiotis Kanavos Mar 28 '19 at 08:25
  • i try use code behind and take Original source but in this way i have only text on coxtext menu item and try use viewmodel but i when i click on My item this is normal but when i click on subitems(with itemsource ) i have an exception – Andriy Borysenko Mar 28 '19 at 08:26
  • yeah, i checked similiar questions but this not help. exception message "No target found for method" – Andriy Borysenko Mar 28 '19 at 08:34
  • Can you share your viewmodel code? Also have a look at this [thread](https://stackoverflow.com/questions/13587368/no-target-found-for-method-thrown-by-caliburn-message-attach) – Pavel Anikhouski Mar 28 '19 at 08:46
  • sorry i cant . In view model i have collection that have another collection items .for example (new List{ new Command{ id,name,Commands(collection)}.Then i binding through obs collection to view and take contex item in function that take parametr dynamic item – Andriy Borysenko Mar 28 '19 at 08:50

0 Answers0