Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
how can a MenuItem in ContextMenu realize what object called the ContextMenu? I have databinded treeView and I want to know, which TextBlock item was right-clicked. I don't want the databinded object behind, I need work with the TextBlock. Thanks!
Posted

Take a look through this[^] from MSDN. It is about a ContextMenu on a TreeView but I think the techniques (and there are a few of them) should work for you.

You might also take a look at the PlacementTarget[^] property of the ContextMenu.
 
Share this answer
 
v2
Comments
Venkatesh Mookkan 23-Jan-11 21:37pm    
Good Answer. Proposed Answer
Alois Holub 24-Jan-11 10:54am    
Thanks, it really helped!
Hi I think this code can help u
void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
     TreeNode myNode =  treeView1.GetNodeAt(e.X, e.Y);
     if(myNode != null)
          //your code like treeView1.SelectedNode = myNode;
     else
          //your code like MessageBox.Show("No treenode selected", "Invalid selection");
}

Just remember that the if block is necessary else compiler may give a NullRefrenceException
Hope this help you
 
Share this answer
 
Comments
Alois Holub 24-Jan-11 5:00am    
This would maybe work form Windows Forms, but I am trying to work with WPF. But thanks anyway.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900