Hi,
I am using TabGroupPaneRegionAdapter from https://compositewpfcontrib.svn.codeplex.com/svn/Trunk/src/Extensions.Infragistics/Composite.Wpf.Infragistics/CompositeWPFContrib.Composite.Wpf.Infragistics/XamDockManager/Regions/TabGroupPaneRegionAdapter.cs.
The problem I am getting with this is contentpane's Closed event executes two times which is probably due to line 'contentPane.ExecuteCommand(ContentPaneCommands.Close);' Which means when cross button was pressed and closed event was invoked first time it was still there in xamDockManager hence line "contentPane.ExecuteCommand(ContentPaneCommands.Close);" executes and invokes closed event again. Any ideas how to solve this.
Here is part of code from adapter:
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); } }
Any help will be much appreciated thanks.Imad.
Hello Imad,
Thank you for your post. I have been looking, but it seems like that I am missing something in your scenario, so if this is still an issue for you, could you please send an isolated sample project, where the issue is reproduced, so I can investigate it further for you.
Looking forward for your reply.
I am still having this issue. Will try to create a sample to send you that. Can you also please let me know if there is some premier support service that you have. Or what is the quick way to get your support, normally it takes lot of time to get a reponse back.
Thanks,
Imad.
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Thanks Stefan!
It worked.
I have investigate your sample and I can say that the behavior you encounter is expected, because when you press the close button of the pane it only hides, because this is its default PaneCloseAction and the closed event I called for the first time, after that you set its PaneCloseAction to RemovePane and executes the Close command, which cause the Closed event to fire fir the second time. My suggestion is to set the PaneCloseAction to RemovePane at the beginning, so the event could fire only once. You still will be able to clear Pane’s Content in the Closed event:
private void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, TabGroupPane regionTarget) { if (e.Action == NotifyCollectionChangedAction.Add) { //Add content panes for each associated view. foreach (FrameworkElement view in e.NewItems) { if (view != null && view is UserControlBase) { ContentPane newContentPane = new ContentPane() { Content = view, CloseAction = PaneCloseAction.RemovePane };//, DataContext = Content }; //newContentPane.Content = view; var headerBinding = new Binding("TabDisplayName"); headerBinding.Source = newContentPane.Content; newContentPane.SetBinding(ContentPane.HeaderProperty, headerBinding); var imageBinding = new Binding("TabImage"); imageBinding.Source = newContentPane.Content; newContentPane.SetBinding(ContentPane.ImageProperty, imageBinding); //// in closing event we will call usercontrol's CanShutdown and Shutdown methods newContentPane.Closing += delegate(object o, PaneClosingEventArgs args) { if (view is UserControlBase) args.Cancel = !((UserControlBase)view).CanShutdown(); }; //When contentPane is closed remove the associated region newContentPane.Closed += delegate(object contentPaneSender, PaneClosedEventArgs args) { if (view is UserControlBase) ((UserControlBase)view).Shutdown(); 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); } } } } }
Also here you can read more about our support policy:
http://es.infragistics.com/help/support-policies/
Hope this helps you.
Please find attached the sample that has the problem. You can put breakpoint in closing and closed event handlers in TabGroupPaneRegionAdapter to see the problem.