Hi All,
We are developing a customized tool using ArcGIS Pro SDK (v2.8) and .NET Framework. Is there any possibility to identify the user selected context menu item?
For example, if the user select "Parallel" context menu option, can we determine the selected option. Please find the below snapshot for reference.
Any ideas/inputs are most appreciated.
Thank you.
Solved! Go to Solution.
Hi,
No you cant tell what context menu item the user has chosen.
You can add your own command to the context menu and get the location of the mouse right-click if that helps.
Hi,
No you cant tell what context menu item the user has chosen.
You can add your own command to the context menu and get the location of the mouse right-click if that helps.
In the OnClick event handler for the menu item(s) you could write something to indicate which item was clicked to a text file and then read that text file elsewhere. For example, I'm using a dynamic menu and, in the OnClick method, I write the value of the clicked item index to the text file.
What I wrote in my previous response works, but a more elegant solution that I'd forgotten about is to use a "context" class, which "can be seen as a bucket to pass information around" - see https://stackoverflow.com/questions/6145091/the-term-context-in-programming.
1. Create a static class with a static public property anywhere you like
namespace ContextMenuDemo
{
public static class Context
{
public static int ClickedIndex = default;
}
}
2. Set the property in the OnClick event handler for the menu
protected override void OnClick(int index)
{
Context.ClickedIndex = index;
}
3. Access the property wherever required, e.g.,
private void ShowContextMenu(MapPoint clickedPoint)
{
var contextMenu = FrameworkApplication.CreateContextMenu("ContextMenu_Menus_DynamicMenu", () => ClientPoint);
contextMenu.Closed += (returnObject, routedEventArgs) =>
{
MessageBox.Show(Context.ClickedIndex.ToString());
};
}
It's a little confusing, but the word "Context" as the class name has nothing to do with the word "Context" in the namespace name or the menu type. You can call the class whatever you like. I just wanted to stick to the terminology describing the purpose of the class.
I also tried a couple of other options without success:
1. Accessing a context menu class property via the objects passed to the menu closed event handler;
2. Using a delegate passed to the menu class instance to set a property on the class in which the menu is created.