ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Legend Class
Members Example

In This Topic
    Legend Class
    In This Topic
    Represents a legend element on a page layout.
    Object Model
    Legend ClassCoordinate2D StructureEnvelope ClassCIMElement ClassGeometry ClassIElementContainer InterfaceMapFrame Class
    Syntax
    Remarks
    There are currently no additional members but this class can be used to determine the type of MapSurround and element may be.
    Example
    Create Legend
    //Create a legend for an associated map frame.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope geometry
      Coordinate2D leg_ll = new Coordinate2D(6, 2.5);
      Coordinate2D leg_ur = new Coordinate2D(8, 4.5);
      //At 2.x - Envelope leg_env = EnvelopeBuilder.CreateEnvelope(leg_ll, leg_ur);
      Envelope leg_env = EnvelopeBuilderEx.CreateEnvelope(leg_ll, leg_ur);
    
      //Reference MF, create legend and add to layout
      MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame;
      if (mapFrame == null)
      {
        //TODO handle null map frame
        return;
      }
      //At 2.x - Legend legendElm = LayoutElementFactory.Instance.CreateLegend(
      //                                               layout, leg_env, mapFrame);
      //         legendElm.SetName("New Legend"); 
      var legendInfo = new LegendInfo()
      {
        MapFrameName = mapFrame.Name
      };
      Legend legendElm = ElementFactory.Instance.CreateMapSurroundElement(
                          layout, leg_env, legendInfo, "New Legend") as Legend;
    });
    Create Legend 2
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(6, 2.5);
    Coordinate2D ur = new Coordinate2D(8, 4.5);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    //Reference MF, create legend and add to layout
    MapFrame mf = layout.FindElement(mapFrameName) as MapFrame;
    var surroundInfo = new LegendInfo()
    {
      MapFrameName = mf.Name
    };
    
    var legendElm = ElementFactory.Instance.CreateMapSurroundElement(
      layout, env.Center, surroundInfo) as Legend;
    legendElm.SetName("New Legend");
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Layouts.Element
             ArcGIS.Desktop.Layouts.MapSurround
                ArcGIS.Desktop.Layouts.Legend

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also