Get the view in an own RegionAdapter when navigatiing wiht PRISM

368 views Asked by At

I am working with PRISM and trying to learn how to use it properly. So far I created 3 views:

  • MainWindow: This is my Shell Containing 2 Buttons for Navigation: ViewA,ViewB
  • ViewA
  • ViewB

The Shell hosts a Region (DockManager from SyncFusion) to inject views into. Inside the ViewModel of the Shell I use a DelegateCommand to Navigate:

_regionManager.RequestNavigate("ContentRegion", uri);

The views are registered inside the Bootstrapper

Container.RegisterTypeForNavigation<ViewA>("ViewA");
Container.RegisterTypeForNavigation<ViewB>("ViewB");

This works fine when I use a simple TabControl to host my region. To use the DockManager from the SyncFusion Toolkit I created an adapter and have overridden the function:

protected override void Adapt(IRegion region, DockingManager regionTarget)
    {
        region.Views.CollectionChanged += delegate
        {
            foreach (var child in region.Views.Cast<UserControl>())
            {
                if (!regionTarget.Children.Contains(child))

                {
                    regionTarget.BeginInit();
                    regionTarget.Children.Add(child);
                    regionTarget.EndInit();
                }
            }
        };
        regionTarget.WindowClosing += delegate (object sender, WindowClosingEventArgs args)
        {
            var child = args.TargetItem as UserControl;
            region.Remove(child);
        };
        regionTarget.CloseButtonClick += delegate (object sender, CloseButtonEventArgs args) 
        {
            var child = args.TargetItem as UserControl;
            region.Remove(child);
        };

        region.NavigationService.Navigated += RegionTarget_Navigated;        
    }
private void RegionTarget_Navigated(object sender, RegionNavigationEventArgs e)
    {

    }

What I am now trying to handle is the case that a view is navigated to, which is already contained in my DockingManager. In this case the view should be set as active. To achieve that I tried to subscribe to the 'Navigated'-Event of the Region. Would this be the right way? How can I get the correct View from the Navigation-URI? Or should I try on handle that scenario inside my viewmodels (with OnNavigatedTo from INavigationAware).

2

There are 2 answers

0
AudioBubble On

Activation can be handled by listening to the ActiveViews.CollectionChanged event and then activate the correct tab in your docking control. It would be better to have a custom RegionBehavior handle this for you instead of putting it in the RegionAdapter.

You can use this blog post about writing an adapter for the Infragistics xamDockManager as a guide: http://brianlagunas.com/xamdockmanager-prism-region-adapter-update-3/

0
Marimuthu S On

You can set the active window to DockingManager based on Navigation Uri from Navigated event of NavigationService. Please download the sample from the following link. http://www.syncfusion.com/downloads/support/directtrac/172521/ze/PrismUnityApp71278521315.zip