ApplyStyle(StyleItem,Boolean) Method
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
Public Overloads Overridable Sub ApplyStyle( _
ByVal As StyleItem, _
ByVal As Boolean _
)
Parameters
- styleItem
- The style item to apply
- keepSymbolSize
- Set to true to re-apply the current symbol size
to the new symbol.
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);
}
}
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3.2 or higher.