ArcGIS Pro 3.2 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 static T ContextMenuDataContextAs<T>()
    where T: class
    Public Shared Function ContextMenuDataContextAs(Of T As Class)() As T

    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
    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();
      op.Name = "Delete context";
      op.Delete(selSet);
      await op.ExecuteAsync();
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.1 or higher.
    See Also