CanApplyStyle Method (Element)
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);
}
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3.2 or higher.