Hello Infragistics-Team,
i want to build up a contextmenu for the xamdatatree (add new, delete, edit/rename) in WPF. If i work with the xaml XamDataTree.ContextMenu / ContextMenu and commands, the DataContext is my viewmodel (view), so i cant identify the dataitem that fired the contextmenu function. Its not the ActiveNode too, and even if, i wouldnt like it too much to bind it and look into it out of the executed command.
So i ended up define the command on the viewmodel (dataitem) itself, and build up the contextmenu on the view PreviewMouseRightButtonDown. I dont really like that and got a problem to enter edit mode because i would have to transport it all back to the view: viewmodel(dataitem)-list-viewmodel-view.
Even if i work with MenuItem-Click events i cant identify the source-dataitem.. (sender is menuitem with DataContext of my viewmodel again.. and some RoutedEventArgs..)
Btw is there really no built-in contextmenu for that? AllowEditing / IsMouseActionEditingEnabled fx..
If we can solve the first DataContext question, the other questions doesnt matter anymore.
Greetingsyannik
Hello Yannik,
Thank you for your post!
I have been looking into your issue and have created a small sample application for you.
In it I have a simple XamDataTree bind to a collection from ViewModel. Then I am creating two ContextMenus - one for the XamDataTree itself and one for the XamDataTreeNodeControls and assign those menus in styles.
The commands for the ContextMenus I am creating in the ViewModel. In order to know, which on which node from the xamDataTree was the ContextMenu opened I am binding the CommandParameter for the MenuItems of the treeNodeContextMenu ContextMenu to the Data. The Data represents the node, on which the ContextMenu was opened.
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.
Hello Gergana,
thank you for your fast answer, including an example.
That is the NodeContextMenu i was looking for.
Greetings
Yannik
Hi,
I used your example, however i have two issues with it that i hope you can help with:
1. The ContextMenu is going horizontally instead of vertically
2. How do i use commands that are on the Node/Item view model and not the data tree view model?
Thanks
Thank you for the feedback. I am glad I was able to help.