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
1235
ContextMenu DataContext (DataItem)
posted

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.

Greetings
yannik

Parents
No Data
Reply
  • 22015
    Verified Answer
    posted

    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.

    DataTree_ContextMenu.zip
Children