ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / UniqueValueRendererDefinition Class / UniqueValueRendererDefinition Constructor / UniqueValueRendererDefinition Constructor()
Example

In This Topic
    UniqueValueRendererDefinition Constructor()
    In This Topic
    Creates a UniqueValueRendererDefinition.
    Syntax
    Public Function New()
    public UniqueValueRendererDefinition()
    Example
    How to apply a color ramp from a style to a feature layer
    {
        List<string> fields = new List<string>() { "Field1" };
        //Note: Needs QueuedTask to run
        StyleProjectItem styleToUse =
          Project.Current.GetItems<StyleProjectItem>()
              .FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)");
        if (style == null) return;
        //Note: Needs QueuedTask to run
        var colorRampListFound = styleToUse.SearchColorRamps("Red-Gray (10 Classes)");
        if (colorRampListFound == null || colorRampListFound.Count == 0) return;
        CIMColorRamp cimColorRamp = null;
        CIMRenderer renderer = null;
    
        cimColorRamp = colorRampListFound[0].ColorRamp;
        var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp);
        renderer = featureLayer?.CreateRenderer(rendererDef);
        featureLayer?.SetRenderer(renderer);
    }
    Set unique value renderer to the selected feature layer of the active map
    {
        //field to be used to retrieve unique values
        //Note: Run within a QueuedTask
        var fields = new List<string> { "Type" };
        //constructing a point symbol as a template symbol
        CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(
            ColorFactory.Instance.GreenRGB, 16.0, SimpleMarkerStyle.Pushpin);
        CIMSymbolReference symbolPointTemplate = pointSym.MakeSymbolReference();
    
        //constructing renderer definition for unique value renderer
        UniqueValueRendererDefinition uniqueValueRendererDef =
      new UniqueValueRendererDefinition(fields, symbolPointTemplate);
    
        //creating a unique value renderer
        CIMUniqueValueRenderer uniqueValueRenderer = featureLayer.CreateRenderer(uniqueValueRendererDef) as CIMUniqueValueRenderer;
    
        //setting the renderer to the feature layer
        featureLayer.SetRenderer(uniqueValueRenderer);
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also