ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Core.Events Namespace / ProjectItemsChangedEvent Class
Members Example

In This Topic
    ProjectItemsChangedEvent Class
    In This Topic
    Occurs when a project item is added or removed
    Object Model
    ProjectItemsChangedEvent ClassSubscriptionToken ClassSubscriptionToken Class
    Syntax
    Example
    LayoutAdded_ProjectItemsChangedEvent_Add
    //Report the event args when a layout is added.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.LayoutAddedEvent.Subscribe((args) =>
    //{
    //  System.Windows.MessageBox.Show("LayoutAddedEvent:" +
    //    Environment.NewLine +
    //    "   arg Layout: " + args.Layout.Name);
    //});
    
    //Use ProjectItemsChangedEvent at 3.x
    ArcGIS.Desktop.Core.Events.ProjectItemsChangedEvent.Subscribe((args) => {
      //Layout added. Layout removed would be NotifyCollectionChangedAction.Remove
      if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add &&
          args.ProjectItem is LayoutProjectItem layoutProjectItem)
      {
        var layout_name = layoutProjectItem.Name; 
        var layout = layoutProjectItem.GetLayout();
        System.Diagnostics.Debug.WriteLine($"Layout Added: {layout_name}");
      }
    });
    
    LayoutRemoved_ProjectItemsChangedEvent_Remove
    //Report the event args when a layout is removed.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.LayoutRemovedEvent.Subscribe((args) =>
    //{
    //  System.Windows.MessageBox.Show("LayoutViewEvent:" +
    //  Environment.NewLine +
    //  "   arg Layout: " + args.Layout.Name);
    //});
    
    //Use ProjectItemsChangedEvent at 3.x
    ArcGIS.Desktop.Core.Events.ProjectItemsChangedEvent.Subscribe((args) => {
      //Layout added. Layout removed would be NotifyCollectionChangedAction.Remove
      if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove &&
          args.ProjectItem is LayoutProjectItem layoutProjectItem)
      {
        var layout_name = layoutProjectItem.Name;
        System.Diagnostics.Debug.WriteLine($"Layout Removed: {layout_name}");
      }
    });
    
    LayoutRemoved_ProjectItemsChangedEvent_Removing
    //Report the event args when a layout is about to be removed.
    
    //At 2.x - ArcGIS.Desktop.Layouts.Events.LayoutRemovingEvent.Subscribe((args) =>
    //{
    //  if (args.LayoutPath == "CIMPATH=layout.xml")
    //  {
    //    args.Cancel = true;
    //  }
    //  return Task.FromResult(0);
    //});
    
    //At 3.x use ProjectItemRemovingEvent
    ArcGIS.Desktop.Core.Events.ProjectItemRemovingEvent.Subscribe((args) =>
    {
      var layoutItems = args.ProjectItems.ToList().OfType<LayoutProjectItem>() ?? new List<LayoutProjectItem>();
      var layoutName = "DontDeleteThisOne";
      foreach(var layoutItem in layoutItems)
      {
        if (layoutItem.Name == layoutName)
        {
          args.Cancel = true;//Cancel the remove
          break;
        }
      }
      return Task.FromResult(0);
    });
    
    Inheritance Hierarchy

    System.Object
       ArcGIS.Core.Events.EventBase
          ArcGIS.Core.Events.CompositePresentationEvent<TPayload>
             ArcGIS.Desktop.Core.Events.ProjectItemsChangedEvent

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also