Hello,
I have a xamTree databound with three levels of nodes. I put a context menu on the tree control. Right now a user can right click a node to pop up the context menu to add a child node. The problem is that unless they first LEFT click the node, then RIGHT click the node for the context menu, I am unable to get the selected node to add the child.
I tried adding a MouseRightButtonDown to the tree, but I get all different UIElements as the OriginalSource (could be TextBlock or Grid or Image depending on where they right clicked).
How can I select the node on right click before the context menu pops up?
Thanks,
-J
I need to do same thing for XamGrid. Can anybody help me in this.
Thanks! I actually came up with the same answer, just didnt use Linq to get the first element. Nice!
-Jeff
Hi,
You could obtain the XamTreeItem in the XamContextMenu Opening event, e.g. suppose you have something like:
<ig:ContextMenuService.Manager>
<ig:ContextMenuManager>
<ig:ContextMenuManager.ContextMenu>
<ig:XamContextMenu Opening="XamContextMenu_Opening">
<ig:XamMenuItem Header="Copy"/>
<ig:XamMenuItem Header="Paste"/>
</ig:XamContextMenu>
</ig:ContextMenuManager.ContextMenu>
</ig:ContextMenuManager>
</ig:ContextMenuService.Manager>
You could do the following in the event handler:
private void XamContextMenu_Opening(object sender, OpeningEventArgs e)
{
var items = e.GetClickedElements<XamTreeItem>();
if (items.Count == 0)
e.Cancel = true;
return;
}
items.First().IsSelected = true;
HTH,