ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.CIM Namespace / CIMLabelClass Class / Expression Property
Example

In This Topic
    Expression Property (CIMLabelClass)
    In This Topic
    Gets or sets the label expression.
    Syntax
    public string Expression {get; set;}
    Public Property Expression As String
    Example
    Modify label expression using Arcade
    var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.ShapeType == esriGeometryType.esriGeometryPolygon);
    if (lyr == null) return;
    QueuedTask.Run(() =>
    {
      //Get the layer's definition
      //community sample Data\Admin\AdminSample.aprx
      var lyrDefn = lyr.GetDefinition() as CIMFeatureLayer;
      if (lyrDefn == null) return;
      //Get the label classes - we need the first one
      var listLabelClasses = lyrDefn.LabelClasses.ToList();
      var theLabelClass = listLabelClasses.FirstOrDefault();
      //set the label class Expression to use the Arcade expression
      theLabelClass.Expression = "return $feature.STATE_NAME + TextFormatting.NewLine + $feature.POP2000;";
      //Set the label definition back to the layer.
      lyr.SetDefinition(lyrDefn);
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also