ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / GraphicFactory Class / CreateLegendPatchGraphic Method / CreateLegendPatchGraphic(PatchShape,Envelope,CIMSymbol) Method
The legend patch shape
The extent of the graphic element
The symbol to be used with the graphic
Example

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

    Parameters

    patchShape
    The legend patch shape
    extent
    The extent of the graphic element
    patchSymbol
    The symbol to be used with the graphic

    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