ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / GraphicElement Class / CanApplyStyle Method
The style item to check whether its styling can be applied
Example

In This Topic
    CanApplyStyle Method (GraphicElement)
    In This Topic
    Gets whether the StyleItem can be applied
    Syntax
    public override bool CanApplyStyle( 
       StyleItem styleItem
    )
    Public Overrides Function CanApplyStyle( _
       ByVal styleItem As StyleItem _
    ) As Boolean

    Parameters

    styleItem
    The style item to check whether its styling can be applied

    Return Value

    Remarks
    Styles cannot be applied to CIMPictureGraphic. If the underlying graphic is null false will also be returned.
    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