0

我正在使用来自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);
        }
    }

任何帮助将不胜感激谢谢。伊玛德。

4

2 回答 2

1

我相信您可以在这里关注 Infragistics 论坛主题关于同样的问题:

http://www.infragistics.com/community/forums/t/73207.aspx

于 2012-09-05T09:14:35.127 回答
0

这里有一个更好的用于 xamDockManager 的区域适配器。

http://brianlagunas.com/xamdockmanageran-updated-prism-region-adapter/

于 2013-05-29T03:31:34.230 回答