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); });
Target Platforms: Windows 11, Windows 10, Windows 8.1