Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1485
ContextMenu for specific nodes - how to bind a command to a XamMenuItem?
posted

Hi,

We're using MVVM, so I'm using the "enhanced" XamDataTree posted by an Infragistics employee in one of the forums - the one that adds the possibility to bind the selected item.  Anyway, that's not the problem: I need different context menus for each NodeLayout types.  The commands are in the ViewModel used as the DataContext for the view (and the XamDataTree uses that as its DataContext as well.)  However, when we get to the node level, it becomes a XamDataTreeNodeDataContext and as a result, the command (which is in the "real" DataContext) cannot be bound to - i.e. the binding cannot be resolved.

Here's the XAML: (it's not complete yet as I'm still experimenting with this - eventually all NodeLayouts will have their own context menu).  The XamContextMenu.Opening event handler simply makes the node the user right-clicks on the selected+active node (again, based on some code found in the forums here.)

<CmsCommon:XamDataTreeMvvm.GlobalNodeLayouts>
    <ig:NodeLayout 
        Key="DomainLayout" 
        TargetTypeName="DomainData" 
        DisplayMemberPath="Name"
        >
        <ig:NodeLayout.ItemTemplate>
            <DataTemplate>
                <TextBlock
                    Text="{Binding Path=Data.Name}"
                    >
                    <ig:ContextMenuService.Manager>
                        <ig:ContextMenuManager>
                            <ig:ContextMenuManager.ContextMenu>
                                <ig:XamContextMenu
                                    Opening="XamContextMenu_Opening">
                                    <ig:XamMenuItem 
                                        Header="New classification" 
                                        >
                                        <ig:XamMenuItem.InputBindings>
                                            <MouseBinding MouseAction="LeftClick" Command="{Binding Path=NewClassificationCommand}" />
                                        </ig:XamMenuItem.InputBindings>

                                    </ig:XamMenuItem>
                                    <ig:XamMenuItem Header="Delete" />
                                </ig:XamContextMenu>
                            </ig:ContextMenuManager.ContextMenu>
                        </ig:ContextMenuManager>
                    </ig:ContextMenuService.Manager>
                </TextBlock>
            </DataTemplate>
        </ig:NodeLayout.ItemTemplate>
    </ig:NodeLayout>
    <ig:NodeLayout Key="ClassificationLayout" TargetTypeName="ClassificationData" DisplayMemberPath="Name"/>
    <ig:NodeLayout Key="ClassificationVersionLayout" TargetTypeName="ClassificationVersionData" DisplayMemberPath="Name"/>
    <ig:NodeLayout Key="ClassificationVersionItemLayout" TargetTypeName="ClassificationVersionItemData" DisplayMemberPath="Name"/>
</CmsCommon:XamDataTreeMvvm.GlobalNodeLayouts>

Any idea on how to go about resolving this?  I've tried a few things without success.  Using WPF 4.0, by the way.

Thanks,
Michel

Parents Reply Children
No Data