我正在使用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);
}
}
非常感谢任何帮助。 伊马德。
答案 0 :(得分:1)
我相信你可以在这里关注同样的事情来跟踪Infragistics论坛主题:
答案 1 :(得分:0)
这里有一个更好的xamDockManager区域适配器。
http://brianlagunas.com/xamdockmanageran-updated-prism-region-adapter/