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

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

    Parameters

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

    Return Value

    Remarks
    Implemented in derived classes
    Example
    Apply a style to a North Arrow
    //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.FirstOrDefault(s => s.Name == "ArcGIS 2D");
    if (styleProjectItem == null) return;
    //Get the north arrow style item you need
    var northArrowStyleItem = 
    styleProjectItem.SearchSymbols(StyleItemType.NorthArrow, "ArcGIS North 18").FirstOrDefault();
    if (northArrowStyleItem == null) return;
    //Select a North arrow layout element
    var northArrowElement = layout.GetSelectedElements().OfType<NorthArrow>().FirstOrDefault();
    if (northArrowElement != null)
    {
      //Check if the input style can be applied to the element
      if (northArrowElement.CanApplyStyle(northArrowStyleItem))
        //Apply the style
        northArrowElement.ApplyStyle(northArrowStyleItem);
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.2 or higher.
    See Also