{
// Note: the following should be embedded in a QueuedTask.Run() statement
{
//Get the layer's definition, using the community sample Data\Admin\AdminSample.aprx
if (featureLayer.GetDefinition() is not CIMFeatureLayer lyrDefn)
{
// not a feature layer, leave
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.
featureLayer.SetDefinition(lyrDefn);
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)