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

In This Topic
    ElementEventArgs Class
    In This Topic
    Provides data for the ElementEvent.
    Object Model
    ElementEventArgs ClassIElementContainer Interface
    Syntax
    public class ElementEventArgs : System.EventArgs 
    Public Class ElementEventArgs 
       Inherits System.EventArgs
    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_MapFrameActivated_Deactivated
    //Report the event args when a map frame is activated or deactivated.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.ActivateMapFrameEvent.Subscribe((args) =>
    //{
    //  System.Windows.MessageBox.Show("ActiveMapFrameEvent:" +
    //  Environment.NewLine +
    //  "   arg IsActivated: " + args.IsActivated.ToString() +
    //  Environment.NewLine +
    //  "   arg Layout: " + args.Layout.Name +
    //  Environment.NewLine +
    //  "   arg MapFrame: " + args.MapFrame.Name);
    //});
    
    ArcGIS.Desktop.Layouts.Events.ElementEvent.Subscribe((args) =>
    {
      var mapFrameName = args.Elements[0].Name;
      if (args.Hint == ElementEventHint.MapFrameActivated)
      {
        System.Diagnostics.Debug.WriteLine($"ElementEventHint.MapFrameActivated: {mapFrameName}");
      }
      else if (args.Hint == ElementEventHint.MapFrameDeactivated)
      {
        System.Diagnostics.Debug.WriteLine($"ElementEventHint.MapFrameDeactivated: {mapFrameName}");
      }
    });
    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}");
      }
    });
    ElementEvent_SelectionChanged
    //Report the event args when a layout's selection has changed.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.LayoutSelectionChangedEvent.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("LayoutSelectionChangedEvent:" +
    //  Environment.NewLine +
    //  "   arg Elements: " + elemNames.ToString() +
    //  Environment.NewLine +
    //  "   arg Layout: " + args.Layout.Name);
    //});
    
    ArcGIS.Desktop.Layouts.Events.ElementEvent.Subscribe((args) =>
    {
      if (args.Hint == ElementEventHint.SelectionChanged)
      {
        if (args.Container.GetSelectedElements()?.Count() > 0)
        {
          var elemNames = string.Join(",", args.Container.GetSelectedElements().Select(e => e.Name).ToList());
          System.Diagnostics.Debug.WriteLine($"ElementEventHint.SelectionChanged: {elemNames}");
        }
      }
    
    });
    ElementEvent_PropertyChanged
    //Report the event args when an element has been updated.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.ElementsUpdatedEvent.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("ElementsUpdatedEvent:" +
    //  Environment.NewLine +
    //  "   arg Elements: " + elemNames.ToString() +
    //  Environment.NewLine +
    //  "   arg Layout: " + args.Layout.Name);
    //});
    ArcGIS.Desktop.Layouts.Events.ElementEvent.Subscribe((args) =>
    {
      string elemNames = "null";
      //can be null if the name was changed
      if (args.Elements?.Count() > 0)
      {
        elemNames = string.Join(",", args.Elements.Select(e => e.Name).ToList());
      }
      else if (args.Container.GetSelectedElements()?.Count() > 0)
      {
        elemNames = string.Join(",", args.Container.GetSelectedElements().Select(e => e.Name).ToList());
      }
    
      if (args.Hint == ElementEventHint.PropertyChanged)
      {
        System.Diagnostics.Debug.WriteLine($"ElementEventHint.PropertyChanged: {elemNames}");
      }
    });
    Inheritance Hierarchy

    System.Object
       System.EventArgs
          ArcGIS.Desktop.Layouts.Events.ElementEventArgs

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also