ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / GraphicFactory Class / CreateLegendPatchGraphic Method / CreateLegendPatchGraphic(PatchShape,Envelope) Method
The legend patch shape
The extent of the graphic element
Example

In This Topic
    CreateLegendPatchGraphic(PatchShape,Envelope) Method
    In This Topic
    Create a polygon or line graphic of the specified ArcGIS.Core.CIM.PatchShape using the provided extent. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public CIMGraphic CreateLegendPatchGraphic( 
       PatchShape patchShape,
       Envelope extent
    )
    Public Overloads Function CreateLegendPatchGraphic( _
       ByVal patchShape As PatchShape, _
       ByVal extent As Envelope _
    ) As CIMGraphic

    Parameters

    patchShape
    The legend patch shape
    extent
    The extent of the graphic element

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    empty or null geometry
    Example
    Create Legend Patch Graphic
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
    plyCoords.Add(new Coordinate2D(1, 1));
    plyCoords.Add(new Coordinate2D(1.25, 2));
    plyCoords.Add(new Coordinate2D(1.5, 1.1));
    plyCoords.Add(new Coordinate2D(1.75, 2));
    plyCoords.Add(new Coordinate2D(2, 1.1));
    plyCoords.Add(new Coordinate2D(2.25, 2));
    plyCoords.Add(new Coordinate2D(2.5, 1.1));
    plyCoords.Add(new Coordinate2D(2.75, 2));
    plyCoords.Add(new Coordinate2D(3, 1));
    Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
    //Set symbolology, create and add element to layout
    CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
              ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
    CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
              ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline);
    
    var graphic = GraphicFactory.Instance.CreateLegendPatchGraphic(
                PatchShape.AreaBoundary, poly.Extent, polySym);
    
    //Make an element to add to GraphicsLayer or Layout
    //
    //var elemInfo = new ElementInfo()
    //{
    //  CustomProperties = null,
    //  Anchor = Anchor.LeftMidPoint
    //};
    //var ge = ElementFactory.Instance.CreateGraphicElement(container, graphic,
    //  "New Legend Patch", true, elemInfo);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also