Treelistview getting node on right click

4 posts, 0 answers
  1. Rajashree
    Rajashree avatar
    2 posts
    Member since:
    Aug 2011

    Posted 25 Apr 2013 Link to this post

    I am using MVVM. I wanted to know how to get the Node when you do right click on the node to View Model. My selected node and where am doing the right click is different
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Apr 2013 Link to this post

    Hi Rajashree,

    You need to handle MouseRightButtonDown event, find the element underneath and get its corresponding data item. It could be something like follows:

    private void clubsGrid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
           {
               var clickedElement = e.OriginalSource as FrameworkElement;
               if (clickedElement != null)
               {
                   var item = clickedElement.DataContext as Club;
               }
           }

    If you want to select that item, you can just assign it to the SelectedItem property.

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Rajashree
    Rajashree avatar
    2 posts
    Member since:
    Aug 2011

    Posted 26 Apr 2013 Link to this post

    Is there any way that we will get the node without writing code-behind in View (MVVM). Passing this as event argument to some method in view model.
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 26 Apr 2013 Link to this post

    Hi Rajashree,

    if you want to keep your code-behind clean, you can either crate an attached behavior and handle the event there (just like in this demo) or work with the patter illustrated in this article (all you need to do in this case is to pass the arguments of the event). 

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top