ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / GraphicElement Class / ApplyStyle Method / ApplyStyle(StyleItem,Boolean) Method
The style item to apply
Set to true to re-apply the current symbol size to the new symbol.
Example

In This Topic
    ApplyStyle(StyleItem,Boolean) Method
    In This Topic
    Apply the given style to the element. Retain the current symbol size for Point, Line, Polygon, and Text elements. This method must be called on the MCT. Use QueuedTask.Run
    Syntax
    public virtual void ApplyStyle( 
       StyleItem styleItem,
       bool keepSymbolSize
    )
    Public Overloads Overridable Sub ApplyStyle( _
       ByVal styleItem As StyleItem, _
       ByVal keepSymbolSize As Boolean _
    ) 

    Parameters

    styleItem
    The style item to apply
    keepSymbolSize
    Set to true to re-apply the current symbol size to the new symbol.
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    Incorrect style item for element
    Remarks
    Call CanApplyStyle to determine if the input style can be applied. The keepSymbolSize parameter is honored by Point, Line, Polygon, and Text graphic elements. When set true, the current symbol size of the graphic element symbol is applied to the new point, line, polygon or text symbol being set from the styleItem.
    Example
    Apply a style to a Graphic Element
    //Run within QueuedTask context.
    //Get the Style project items in the project
    var styleProjectItems = Project.Current?.GetItems<StyleProjectItem>();
    //Get the ArcGIS 2D Style Project Item
    var styleProjectItem = 
    styleProjectItems.OfType<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D");
    if (styleProjectItem == null) return;
    //Get the north arrow style item you need
    var pointStyleItem = 
    styleProjectItem.SearchSymbols(StyleItemType.PointSymbol, "Circle 3").FirstOrDefault();
    if (pointStyleItem == null) return;
    //Select a North arrow layout element
    var layoutPointElement = layout.GetSelectedElements().FirstOrDefault();
    if (layoutPointElement != null && layoutPointElement is GraphicElement ge)
    {
      if (layoutPointElement.CanApplyStyle(pointStyleItem))
      {
        //The magic happens here
        //for Graphic Elements such as Point, Lines, Polys, text, preserve size.           
        ge.ApplyStyle(pointStyleItem, true); 
      }
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.2 or higher.
    See Also