ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Layouts.Events Namespace / ElementEventArgs Class / Elements Property
Example

In This Topic
    Elements Property (ElementEventArgs)
    In This Topic
    Gets the list of elements that have been updated.
    Syntax
    public IElement[] Elements {get;}
    Public ReadOnly Property Elements As IElement()
    Example
    Subscribe to ElementSelectionChangedEvent
    ArcGIS.Desktop.Layouts.Events.ElementEvent.Subscribe((args) => {
      //check if the container is a graphics layer - could be a Layout (or even map view)
      if (args.Container is ArcGIS.Desktop.Mapping.GraphicsLayer graphicsLayer)
      {
        //get the total selection count for the container
        var count = args.Elements.Count();
        //Check count - could have been an unselect or clearselect
        if (count > 0)
        {
          //this is a selection or add to selection
          var elems = graphicsLayer.GetSelectedElements();
          //TODO process the selection...
        }
        else
        {
          //This is an unselect or clear selection
          //TODO process the unselect or clear select
        }
      }
    });
    ElementEvent_ElementAdded
    //Report the event args when an element is added to the layout.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.ElementAddedEvent.Subscribe((args) => 
    //{
    //  var elements = args.Elements;
    //  string elemNames = "null";
    //  if (elements != null && elements.Count() > 0)
    //  {
    //    elemNames = string.Join(",", elements.Select(e => e.Name).ToList());
    //  }
    //  System.Windows.MessageBox.Show("ElementAddedEvent:" +
    //  Environment.NewLine +
    //  "   arg Elements: " + elemNames.ToString() +
    //  Environment.NewLine +
    //  "   arg Layout: " + args.Layout.Name);
    //});
    
    ArcGIS.Desktop.Layouts.Events.ElementEvent.Subscribe((args) =>
    {
      string elemNames = "null";
      if (args.Elements?.Count() > 0)
      {
        elemNames = string.Join(",", args.Elements.Select(e => e.Name).ToList());
      }
      if (args.Hint == ElementEventHint.ElementAdded)
      {
        System.Diagnostics.Debug.WriteLine($"ElementEventHint.ElementAdded: {elemNames}");
      }
    });
    ElementEvent_ElementRemoved
    //Report the event args when an element is removed from the layout.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.ElementRemovedEvent.Subscribe((args) => 
    //{
    //  var elements = args.Elements;
    //  string elemNames = "null";
    //  if (elements != null && elements.Count() > 0)
    //  {
    //    elemNames = string.Join(",", elements.Select(e => e.Name).ToList());
    //  }
    //  System.Windows.MessageBox.Show("ElementRemovedEvent:" +
    //  Environment.NewLine +
    //  "   arg Elements: " + elemNames.ToString() +
    //  Environment.NewLine +
    //  "   arg Layout: " + args.Layout.Name);
    //});
    
    ArcGIS.Desktop.Layouts.Events.ElementEvent.Subscribe((args) =>
    {
      string elemNames = "null";
      if (args.Elements?.Count() > 0)
      {
        elemNames = string.Join(",", args.Elements.Select(e => e.Name).ToList());
      }
      if (args.Hint == ElementEventHint.ElementRemoved)
      {
        System.Diagnostics.Debug.WriteLine($"ElementEventHint.ElementRemoved: {elemNames}");
      }
    });
    ElementEvent_PlacementChanged
    //Report the event args when an element's placement properties are changed.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.ElementsPlacementChangedEvent.Subscribe((args) => 
    //{
    //  var elements = args.Elements;
    //  string elemNames = "null";
    //  if (elements != null && elements.Count() > 0)
    //  {
    //    elemNames = string.Join(",", elements.Select(e => e.Name).ToList());
    //  }
    //  System.Windows.MessageBox.Show("ElementsPlacementChangedEvent:" +
    //  Environment.NewLine +
    //  "   arg Elements: " + elemNames.ToString() +
    //  Environment.NewLine +
    //  "   arg Layout: " + args.Layout.Name);
    //});
    
    ArcGIS.Desktop.Layouts.Events.ElementEvent.Subscribe((args) =>
    {
      string elemNames = "null";
      if (args.Elements?.Count() > 0)
      {
        elemNames = string.Join(",", args.Elements.Select(e => e.Name).ToList());
      }
      if (args.Hint == ElementEventHint.PlacementChanged)
      {
        System.Diagnostics.Debug.WriteLine($"ElementEventHint.PlacementChanged: {elemNames}");
      }
    });
    ElementEvent_StyleChanged
    //Report the event args when an element's style is changed.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.ElementStyleChangedEvent.Subscribe((args) => 
    //{
    //  var elements = args.Elements;
    //  string elemNames = "null";
    //  if (elements != null && elements.Count() > 0)
    //  {
    //    elemNames = string.Join(",", elements.Select(e => e.Name).ToList());
    //  }
    //  System.Windows.MessageBox.Show("ElementStyleChangedEvent:" +
    //  Environment.NewLine +
    //  "   arg Elements: " + elemNames.ToString() +
    //  Environment.NewLine +
    //  "   arg Layout: " + args.Layout.Name);
    //});
    ArcGIS.Desktop.Layouts.Events.ElementEvent.Subscribe((args) =>
    {
      string elemNames = "null";
      if (args.Elements?.Count() > 0)
      {
        elemNames = string.Join(",", args.Elements.Select(e => e.Name).ToList());
      }
      if (args.Hint == ElementEventHint.StyleChanged)
      {
        System.Diagnostics.Debug.WriteLine($"ElementEventHint.StyleChanged: {elemNames}");
      }
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also