ArcGIS Pro 3.7 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 Overridable Function CanApplyStyle( _
       ByVal styleItem As StyleItem _
    ) As Boolean
    public virtual bool CanApplyStyle( 
       StyleItem styleItem
    )

    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
    {
      //Note: Must be on QueuedTask.Run
      //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 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.2 or higher.
    See Also