C# using ContextMenu

There is an application I want to make using C#, this is part of it's UI:

enter image description here

The white area below the Menu bar represents a Tree View object. I want the Tree_View menu to be appeared everywhere in the white area when the mouse is right clicked.

This is the XAML code for the Tree_View object (mind the foo function there):

<MenuItem Name="Menu_Tree" Header="_Tree_View">
    <MenuItem Header="_New_Scene" IsCheckable="false" Click = foo/>
    <MenuItem Header="_Copy_This_Scene" IsCheckable="false"/>
    <MenuItem Header="_Remove_This_Scene" IsCheckable="false"/>
    <Separator />
    <MenuItem Header="_New_Shot" IsCheckable="false"/>
    <MenuItem Header="_Copy_This_Shot" IsCheckable="false"/>
    <MenuItem Header="_Remove_This_Shot" IsCheckable="false"/>
    <Separator />
    <MenuItem Header="_Move_This_Shot_Up" IsCheckable="false"/>
    <MenuItem Header="_Move_This_Shot_Down" IsCheckable="false"/>

and this is the XAML code for the Tree_View object:

<Grid Name="TreeHolder" Column="0" Margin="20,10,10,10" Background="DimGray">
    <TreeView Name="myTree" MouseRightButtonDown="something" ToolTip="Right Click to Add or Remove Scenes and Scots.">

This is the something function which should be triggered by the right-click:

private void something(object sender, MouseButtonEventArgs e)
        ContextMenu cm = new ContextMenu();
        //cm.Items.Add("Add a New Scene ?", ... );
        Menu_Tree.ContextMenu = cm;

Since nothing works there, I want to ask the following:

a) How to make the Tree_view menu list be appeared in the Tree_View object white area as well?

b) If so, how will I make it an enabled menu, for example be able to trigger the foo function?

(with other worlds, make an exact copy of the menu list, make it visible with right click and make it working as well)

I strongly believe that it has to do with the ContextMenu which I am not able to use it fairly, so any help would be highly appreciated.

Read more here: https://stackoverflow.com/questions/68458544/c-sharp-using-contextmenu

Content Attribution

This content was originally published by user3060854 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: