What's the best prism region to hold MDI windows?

Topics: Prism v4 - WPF 4
Apr 1, 2013 at 12:23 PM
Hi All,

Currently I am using Prism 4.1 as my component application development platform. I am using WPFMDI(http://wpfmdi.codeplex.com/) so that i can hold each view of module as a child of MdiContainer, in order to make this, i wrote below custom region adaptor:

protected override void Adapt(IRegion region, MdiContainer regionTarget)
    {
        region.Views.CollectionChanged += (sender, e) =>
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (FrameworkElement element in e.NewItems)
                    {
                        IView view = element as IView;
                        if (null != view)
                        {
                            BaseViewModel viewModel = view.GetViewModel();
                            if (null != viewModel)
                            {
                                MdiChild mdiChild = new MdiChild();
                                if (null != viewModel.ViewObject)
                                {
                                    mdiChild.Title = viewModel.ViewObject.Title;
                                    mdiChild.Height = viewModel.ViewObject.Height;
                                    mdiChild.Width = viewModel.ViewObject.Width;
                                }
                                mdiChild.Content = element;
                                regionTarget.Children.Add(mdiChild);
                                IRegionManagerService regionManagerService = ServiceLocator.Current.GetInstance<IRegionManagerService>();
                                regionManagerService.AddView(viewModel.ViewObject);
                            }
                        }
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (UIElement elementLoopVariable in e.OldItems)
                    {
                        var element = elementLoopVariable;

                        //if (regionTarget.Items.Contains(element))
                        //{
                        //    regionTarget.Items.Remove(element);
                        //}
                    }
                    break;
            }
        };
    }
However, I need to implement below features:

when a view is requested via RequestNavigate, if it's not opened yet(I check this via Uri with query parameter), the view is shown as a child of mdicontaner.
if it's opened already, I need to activate it as a child of mdicontaner.

Could anyone give me some idea which region i should use, i am currently using MdiContainer as prism container, but i don't think it's good, there should be some better solution...
Developer
Apr 4, 2013 at 5:57 PM
Hi Peter,

I believe I am not fully understanding you question.

The navigation functionality you are describing of "activating an existing view based on the navigation parameters or injecting a new one if it does not exist" is already supported by Prism's navigation API as out of the box. You can find a description of this in the following section of the documentation:
Hence, you would only need to adapt the MdiContainer control to a region (like with your region adapter) and sync the Views and ActiveViews collections of the region with the visual state of the corresponding controls (for example, the non active views could be shown as minimized MdiChild and the active ones as opened). Which type of region are you using in your region adapter? ( Region, SingleActiveRegion, AllActiveRegion, etc)

Thanks,

Damian Cherubini
http://blogs.southworks.net/dcherubini