title: Prism, AvalonDock Region Adapter (Handling close DocumentPane event)
body: <p>I have a Prism v4 / MEF / WPF solution that loads module views into a DocumentPane in my Avalon Dock. I'm trying to create a handle on the close event (when the 'X' is pressed to close a DocumentPane). I can't figure it out, this is the portion of my RegionAdapter class that creates the DockableContent and also where I attempt to handle the close event (I tried with 3 events):</p>
  
  <pre><code>private void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DocumentPane regionTarget)
  {
      if (e.Action == NotifyCollectionChangedAction.Add)
      {
          foreach (object item in e.NewItems)
          {
              UIElement view = item as UIElement;
  
              if (view != null)
              {
                  DockableContent newContentPane = new DockableContent()
                  {
                      Content = item,
                      Title = ((ITabViewInfo)view).TabViewTitle
                      Icon = ((ITabViewInfo)view).TabViewIcon
                  };
                  newContentPane.Closed += new EventHandler(newContentPane_Closed);
                  newContentPane.Manager.DocumentClosed +=new EventHandler(Manager_DocumentClosed);
                  newContentPane.Manager.DocumentClosing +=new EventHandler&lt;System.ComponentModel.CancelEventArgs&gt;(Manager_DocumentClosing);
  
                  regionTarget.Items.Add(newContentPane);
                  newContentPane.Activate();
              }
          }
      }
      else if (e.Action == NotifyCollectionChangedAction.Remove)
      {
          // this is never hit
          Debug.WriteLine("removed");
      }
  }
  </code></pre>
  
  <p>These events are never hit (I have a debug.writeline in each one):</p>
  
  <pre><code>        newContentPane.Closed += new EventHandler(newContentPane_Closed);
          newContentPane.Manager.DocumentClosed +=new EventHandler(Manager_DocumentClosed);
          newContentPane.Manager.DocumentClosing +=new EventHandler&lt;System.ComponentModel.CancelEventArgs&gt;(Manager_DocumentClosing);
  </code></pre>
  
  <p>How can I handle the close event of a DocumentPane?</p>
  
  <p>The code I used for this RegionAdapter is based off of <a href="http://blog.raffaeu.com/archive/2010/07/04/wpf-and-prism-tab-region-adapter-part-02.aspx" rel="nofollow">http://blog.raffaeu.com/archive/2010/07/04/wpf-and-prism-tab-region-adapter-part-02.aspx</a></p>