Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4066800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:10:18+00:00 2026-05-20T16:10:18+00:00

I currently have a treeview that displays data using a hierarchicaldatatemplate and when the

  • 0

I currently have a treeview that displays data using a hierarchicaldatatemplate and when the user clicks on the Remove button, it removes the selected node(s). This works as intended.

However, Instead of having the user click a button I’m trying to have the command be executed by right clicking a node and selecting the appropriate menu item.

This is proving to be much more difficult because it is being picked up by the ViewModel of a node (which doesn’t know anything about the View) instead of the View’s corresponding ViewModel.

Is there someway to hand the control over to the ViewModel of the View instead?

Here is the code for the Remove Button:

View:

        <Button Content="Remove" Grid.Row="2" Height="23" VerticalAlignment="Top" Name="removeButton" 
                Width="75"  Margin="5,20,5,0"  Command="{Binding Path=RemoveCommand}" />

ViewModel:

public RelayCommand RemoveCommand
        {
            get
            {
                if (_removeCommand == null)
                {
                    _removeCommand = new RelayCommand(
                        () => this.Remove()
                        );
                }
                return _removeCommand;
            }
        }

        public void Remove()
        {
            _organLocationTree2.RemoveOrganLocations(ProjectOrganLocationView.GetExtendedTreeView().SelectedItems);
            ProjectOrganLocationView.GetExtendedTreeView().SelectedItems.Clear();

            base.RaisePropertyChanged("DestOrganTree");
        }

And the XAML for the menu item:

            <local:ExtendedTreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding SubOrganLocations}">
                    <TextBlock Text="{Binding OrganName}" >
            <TextBlock.ContextMenu>
                <ContextMenu>
                    <MenuItem Header ="Add SubNode" Command="{Binding Path=MenuItem_Add}"></MenuItem>
                    <MenuItem Header ="Remove Node" Command="{Binding Path=RemoveCommand}"></MenuItem>
                    <MenuItem Header ="Edit Node" Command="{Binding Path=ProjMenuItem_Edit}"
                              CommandParameter="{Binding DestOrganTree, Path=Selected.OrganName}"></MenuItem>
                </ContextMenu>
            </TextBlock.ContextMenu>
                    </TextBlock>
                </HierarchicalDataTemplate>
            </local:ExtendedTreeView.ItemTemplate>
        </local:ExtendedTreeView>

I tried to implement a Remove command in the ViewModel of the node, but since it doesn’t know anything about the View it got very messy very quickly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:10:18+00:00Added an answer on May 20, 2026 at 4:10 pm

    Well, I found my mistake, I was binding the context menu to the nodes of the tree instead of the tree itself. I moved the context menu outside of the declaration and it now works as intended.

    Here’s my updated xaml for anyone else that has this issue:

     <local:ExtendedTreeView.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header ="Add SubNode" Command="{Binding Path=MenuItem_Add}"></MenuItem>
                                <MenuItem Header ="Remove Node" Command="{Binding Path=RemoveCommand}"></MenuItem>
                                <MenuItem Header ="Edit Node" Command="{Binding Path=ProjMenuItem_Edit}"
                                          CommandParameter="{Binding DestOrganTree, Path=Selected.OrganName}"></MenuItem>
                            </ContextMenu>                        
                        </local:ExtendedTreeView.ContextMenu>
    
                        <local:ExtendedTreeView.ItemTemplate>
                            <HierarchicalDataTemplate ItemsSource="{Binding SubOrganLocations}">
                                <TextBlock Text="{Binding OrganName}" >
                                </TextBlock>
                            </HierarchicalDataTemplate>
                        </local:ExtendedTreeView.ItemTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data hierarchy that I currently display in a treeview. I was
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have an app (in Silverlight), using mv-vm, that has an interface to
I currently have a simple tree view that contains one parent node with multiple
I have a TreeView that allows users to select certain elements of hierarchical data
I have a WinForm TreeView Control that displays the Parent Child relationship of CaseNotes(I
I have a TreeView implemented in WPF that is bound to some XML data
I have a little WPF app, that has a TreeView to display hierarchical data.
i have a TreeView that once the user drops the item to the desired
Currently have a drop down menu that is activated on a hover (from display:none

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.