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
Hello Michel,
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking into your post and I created a sample project for you with the functionality you want. Basically I changed the Binding Path of the Command, so I can get the DataContext of the XamDataTree, where is the Command.
Feel free to write me if you have further questions.
I did have something that worked with 11.1, but yesterday we upgrade to 12.2 and the context menus are broken and I also used a "SelectOnRightClick" behavior that was posted by an Infragistics employee and that was broken too. Not cool, after spending days getting this to work the first time.
Oh and, XamMenuItem needs a "Command" property. I can't believe that's still not in there. The workaround doesn't work so great (can't rely on it for enabled/disabled functionality).