//Create a north arrow for a specific map frame and assign a north arrow style item.
//Construct on the worker thread
await QueuedTask.Run(() =>
{
//Reference a North Arrow in a style
StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D");
NorthArrowStyleItem naStyleItm = stylePrjItm.SearchNorthArrows("ArcGIS North 10")[0];
//Build geometry
Coordinate2D center = new Coordinate2D(7, 5.5);
//Reference MF, create north arrow and add to layout
MapFrame mf = layout.FindElement("New Map Frame") as MapFrame;
if (mf == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING");
return;
}
//At 2.x -
//NorthArrow arrowElm = LayoutElementFactory.Instance.CreateNorthArrow(layout, center, mf, naStyleItm);
//arrowElm.SetName("New North Arrow");
//arrowElm.SetHeight(1.75);
//arrowElm.SetX(7);
//arrowElm.SetY(6);
var naInfo = new NorthArrowInfo()
{
MapFrameName = mf.Name,
NorthArrowStyleItem = naStyleItm
};
var arrowElm = ElementFactory.Instance.CreateMapSurroundElement(
layout, center.ToMapPoint(), naInfo, "New North Arrow") as NorthArrow;
arrowElm.SetHeight(1.75);
arrowElm.SetX(7);
arrowElm.SetY(6);
});