我有一个Prism v4 / MEF / WPF解决方案,可以将模块视图加载到我的Avalon Dock中的DocumentPane中。我正在尝试在关闭事件上创建一个句柄(当按下'X'以关闭DocumentPane时)。我无法弄清楚,这是我的RegionAdapter类创建DockableContent的部分,也是我尝试处理close事件的部分(我试过3个事件):
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的close事件?
我用于此RegionAdapter的代码基于http://blog.raffaeu.com/archive/2010/07/04/wpf-and-prism-tab-region-adapter-part-02.aspx
答案 0 :(得分:1)
在http://avalondock.codeplex.com/discussions/231982?ProjectName=avalondock
找到答案我不得不补充道:
IsCloseable = true
HideOnClose = false