我使用從https://compositewpfcontrib.svn.codeplex.com/svn/Trunk/src/Extensions.Infragistics/Composite.Wpf.Infragistics/CompositeWPFContrib.Composite.Wpf.Infragistics/XamDockManager/Regions/TabGroupPaneRegionAdapter.cs TabGroupPaneRegionAdapter。問題與TabGroupPaneRegionAdapter infragistics
我遇到的問題是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);
}
}
任何幫助將非常感激感謝。 Imad。