我正在使用来自https://compositewpfcontrib.svn.codeplex.com/svn/Trunk/src/Extensions.Infragistics/Composite.Wpf.Infragistics/CompositeWPFContrib.Composite.Wpf.Infragistics/XamDockManager/Regions/TabGroupPaneRegionAdapter.cs的 TabGroupPaneRegionAdapter 。
我遇到的问题是 contentpane 的 Closed 事件执行了两次,这可能是由于行 'contentPane.ExecuteCommand(ContentPaneCommands.Close);' 这意味着当按下十字按钮并第一次调用关闭事件时,它仍然存在于 xamDockManager 中,因此行“contentPane.ExecuteCommand(ContentPaneCommands.Close);” 再次执行并调用关闭事件。任何想法如何解决这个问题。
这是适配器的部分代码:
private void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, TabGroupPane regionTarget)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
//Add content panes for each associated view.
foreach (object item in e.NewItems)
{
UIElement view = item as UIElement;
if (view != null)
{
ContentPane newContentPane = new ContentPane();
newContentPane.Content = item;
//if associated view has metadata then apply it.
if (view.GetTabGroupPaneMetadata() != null)
{
newContentPane.Header = (view.GetTabGroupPaneMetadata()).Header;
}
//When contentPane is closed remove the associated region
newContentPane.Closed += delegate(object contentPaneSender, PaneClosedEventArgs args)
{
OnContentPaneClosed((ContentPane)contentPaneSender, args, region);
};
regionTarget.Items.Add(newContentPane);
}
}
}
else
{
if (e.Action == NotifyCollectionChangedAction.Remove)
{
//Associated View has been removed => remove the associated ContentPane from XamDockManager
XamDockManager xamDockManager = regionTarget.FindDockManager();
IEnumerable<ContentPane> contentPanes = xamDockManager.GetPanes(PaneNavigationOrder.VisibleOrder);
foreach (ContentPane contentPane in contentPanes)
{
if (e.OldItems.Contains(contentPane.Content))
{
contentPane.Content = null;
contentPane.CloseAction = PaneCloseAction.RemovePane;
contentPane.ExecuteCommand(ContentPaneCommands.Close);
}
}
}
}
}
private void OnContentPaneClosed(ContentPane contentPane, PaneClosedEventArgs args, IRegion region)
{
object view = contentPane.Content;
if (region.Views.Contains(view))
{
region.Remove(view);
}
}
任何帮助将不胜感激谢谢。伊玛德。