2011-02-11 123 views
1

我有一個Prism v4/MEF/WPF解決方案,它將模塊視圖加載到我的Avalon Dock中的DocumentPane中。我試圖在close事件上創建一個句柄(當按下'X'關閉一個DocumentPane時)。我無法弄清楚,這是創建DockableContent和也是我試圖處理關閉事件(我試着用3個事件)的我RegionAdapter類的部分:Prism,AvalonDock區域適配器(處理關閉DocumentPane事件)

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<System.ComponentModel.CancelEventArgs>(Manager_DocumentClosing); 

       regionTarget.Items.Add(newContentPane); 
       newContentPane.Activate(); 
      } 
     } 
    } 
    else if (e.Action == NotifyCollectionChangedAction.Remove) 
    { 
     // this is never hit 
     Debug.WriteLine("removed"); 
    } 
} 

這些事件從不打(我在每一箇中都有一個debug.writeline):

 newContentPane.Closed += new EventHandler(newContentPane_Closed); 
     newContentPane.Manager.DocumentClosed +=new EventHandler(Manager_DocumentClosed); 
     newContentPane.Manager.DocumentClosing +=new EventHandler<System.ComponentModel.CancelEventArgs>(Manager_DocumentClosing); 

我該如何處理DocumentPane的關閉事件?

我用這個RegionAdapter的代碼是基於關閉的http://blog.raffaeu.com/archive/2010/07/04/wpf-and-prism-tab-region-adapter-part-02.aspx

回答