Ticket Q438709
Visible to All Users

How to handle the moment when an active tab is changed in Tabbed MDI mode

created 12 years ago

Hi,
I used
MDI Tabbed mode in my application,
and I want to catch some event when I switch window. I overrided method OnViewChanged() in my ViewController, but this is executed only if I open new window: http://www.elvacsolutions.eu/linked/video/tabSwitch.htm.
What's the best way?
Thanks for your advice.

Show previous comments (3)
Anatol (DevExpress) 12 years ago

    The Frame property of your controller returns the main window. This window does not contain a view. View is placed on a child window that represents a tab in the main window. So, you need to access the child Frame to get the view. From my point of view, it is better to create a WindowController for the child Frame and access the main frame's DocumentManager from it via the XafApplication.MainWindow property.

    SU SU
    Svatopluk Ulicny 12 years ago

      Hello, when I use window controller to Child Frame - event ‘Window_TemplateChanged’ will always invocation for the opening of a new View and event MdiChildActivate will registration on all open views. When I click to some opened view - event MdiChildActivate will invocation many times. I want from the window controller for the Main Window to find which View was activated. Or some other way to achieve the invocation of the some event at view controller for each click on this view in a tabbed UI.
      Thank you very much for help.

        I was directed here from Q439075. I'm having the exact same issue as Frank. I tried capturing the selected page changing from the tabbedmdimanager. I had the following in my event but the view periodically throws a null reference even if i check to ensure the mdichild is a detailviewform and the view is not null.
        ISupportMdiContainer container = Frame.Template as ISupportMdiContainer;
        (container.TabbedMdiManager.SelectedPage.MdiChild as DetailViewForm).View

        Answers approved by DevExpress Support

        created 12 years ago (modified 6 years ago)

        To accomplish this task, you can handle the DocumentManager.View.DocumentActivated event. Use the approach described in the following article to access the DocumentManager component: How to: Access the Document Manager.

        You can also reuse the functionality provided by our WinWindowTemplateController:

        C#
        public class MyWinWindowTemplateController : WinWindowTemplateController { protected override void OnDocumentActivated(DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e) { base.OnDocumentActivated(e); if (e.Document.Form is IViewHolder) { View activeView = ((IViewHolder)e.Document.Form).View; } } }

        Here is an example of how to handle the DocumentActivated event in older XAF versions:

        C#
        using DevExpress.ExpressApp.Templates; using DevExpress.ExpressApp.Win.Templates; public class MainWindowController : WindowController { public MainWindowController() { TargetWindowType = WindowType.Main; } protected override void OnActivated() { base.OnActivated(); Frame.TemplateChanged += Frame_TemplateChanged; } void Frame_TemplateChanged(object sender, EventArgs e) { if (((IModelOptionsWin)Application.Model.Options).UIType == UIType.TabbedMDI && Frame.Template is IXafDocumentsHostWindow) { ((IXafDocumentsHostWindow)Frame.Template).DocumentManager.ViewChanged += DocumentManager_ViewChanged; ((IXafDocumentsHostWindow)Frame.Template).DocumentManager.ViewChanging += DocumentManager_ViewChanging; } } void DocumentManager_ViewChanging(object sender, DevExpress.XtraBars.Docking2010.ViewEventArgs args) { args.View.DocumentActivated -= View_DocumentActivated; } void DocumentManager_ViewChanged(object sender, DevExpress.XtraBars.Docking2010.ViewEventArgs args) { args.View.DocumentActivated += View_DocumentActivated; } void View_DocumentActivated(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e) { if (e.Document.Form is IViewHolder) { View activeView = ((IViewHolder)e.Document.Form).View; } } protected override void OnDeactivated() { base.OnDeactivated(); Frame.TemplateChanged -= Frame_TemplateChanged; if (Frame.Template is IXafDocumentsHostWindow) { ((IXafDocumentsHostWindow)Frame.Template).DocumentManager.ViewChanged -= DocumentManager_ViewChanged; ((IXafDocumentsHostWindow)Frame.Template).DocumentManager.ViewChanging -= DocumentManager_ViewChanging; } } }

        Here is an example for older XAF versions that use the previous version of our frame templates:

        C#
        public class MainWindowController : WindowController { public MainWindowController() { TargetWindowType = WindowType.Main; } protected override void OnActivated() { base.OnActivated(); Frame.TemplateChanged += new EventHandler(Frame_TemplateChanged); } void Frame_TemplateChanged(object sender, EventArgs e) { if (((IModelOptionsWin)Application.Model.Options).UIType == UIType.TabbedMDI && Frame.Template is MainFormTemplateBase) { ((MainFormTemplateBase)Frame.Template).DocumentManager.View.DocumentActivated += new DevExpress.XtraBars.Docking2010.Views.DocumentEventHandler(View_DocumentActivated); } } void View_DocumentActivated(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e) { if (e.Document.Form is XtraFormTemplateBase) { View activeView = ((XtraFormTemplateBase)e.Document.Form).View; XtraMessageBox.Show(activeView.Id); } } protected override void OnDeactivated() { base.OnDeactivated(); Frame.TemplateChanged -= new EventHandler(Frame_TemplateChanged); } }
          Comments (2)
          EJ EJ
          Edilson Junior 8 years ago

            Hi!
            This doens't work for me. if (e.Document.Form is IViewHolder) is always false. I'm using templates. Does it mess it up?
            Thanks

            Dennis Garavsky (DevExpress) 8 years ago

              @Edilson: This example is intended for the new WinForms templates (WinApplication.UseOldTemplates = false). So, either ensure this condition or use another example for the old templates, which is also given above. If neither works for you, please submit a separate ticket via the Support Center (https://www.devexpress.com/Support/Center/Question/Create) and attach your problematic sample for us to debug it. Thanks.

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.