ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Framework Namespace / FrameworkApplication Class / ContextMenuDataContextAs<T> Method
Example

In This Topic
    ContextMenuDataContextAs<T> Method
    In This Topic
    Gets the contextual data as the requested type T. Contextual data represents the selected item (or items) that is passed to a command when executing that command on a context menu.
    Syntax
    Public Shared Function ContextMenuDataContextAs(Of T As Class)() As T
    public static T ContextMenuDataContextAs<T>()
    where T: class

    Type Parameters

    T

    Return Value

    The contextual data as a T if supported, null otherwise.
    Remarks
    Use this method to obtain the context in a specific situation. Only certain contextual situations are supported. If not supported, then null will be returned. One example of a supported situation is the treeview of the attributes window. it displays the features currently selected in the map. If you add a custom button to the context menu of the Attributes window you can retrieve the information of the feature(s) highlighted in the treeview when your button is executed by using this function as follows FrameworkApplication.ContextMenuDatacontextAs<SelectionSet>. The features highlighted will be returned as a SelectionSet.
    Example
    Retrieve SelectionSet from command added to Attribute Pane Context Menu
    // Retrieves the SelectionSet from a command that was added and executed from the Attribute Pane Context Menu 
    await QueuedTask.Run(async () =>
    {
      var selSet = FrameworkApplication.ContextMenuDataContextAs<SelectionSet>();
      if (selSet == null)
        return;
    
      int count = selSet.Count;
      if (count == 0)
        return;
    
      var op = new EditOperation
      {
        Name = "Delete context"
      };
      op.Delete(selSet);
      await op.ExecuteAsync();
    });
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.1 or higher.
    See Also