ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Element Class / SetAnchor Method
Anchor
Example

In This Topic
    SetAnchor Method (Element)
    In This Topic
    Sets the anchor position of the element. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SetAnchor( 
       Anchor anchor
    )
    Public Sub SetAnchor( _
       ByVal anchor As Anchor _
    ) 

    Parameters

    anchor
    Anchor
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    This element requires its mapview to be active
    Remarks
    Placement for an element contained in graphics layer requires the mapview be active.
    Example
    Element_GetSetAnchor
    //Change the element's anchor position
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      Anchor elmAnchor = element.GetAnchor();
      elmAnchor = Anchor.CenterPoint;
    
      element.SetAnchor(elmAnchor); //You don't have to get to set; a shortcut would be: element.SetAnchor(Anchor.CenterPoint);
    });
    Update text element properties
    //Update text element properties for an existing text element.
    
    // Reference a layoutitem in a project by name
    LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>()
                          .FirstOrDefault(item => item.Name.Equals("MyLayout"));
    if (layoutItem != null)
    {
    
      //Perform on the worker thread
      QueuedTask.Run(() =>
      {
        // Reference and load the layout associated with the layout item
        Layout layout = layoutItem.GetLayout();
        if (layout != null)
        {
          // Reference a text element by name
          TextElement txtElm = layout.FindElement("MyTextElement") as TextElement;
          if (txtElm != null)
          {
            // Change placement properties
            txtElm.SetAnchor(Anchor.CenterPoint);
            txtElm.SetX(x);
            txtElm.SetY(y);
    
            // Change TextProperties
            TextProperties txtProperties = new TextProperties(
                             "Hello world", "Times New Roman", 48, "Regular");
            txtElm.SetTextProperties(txtProperties);
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also