Prism-v2: Register views with names using View Discovery

The holidays are over, happy new year everyone and I hope it is a good one for all of you. It's time for the first post of the year, which continuing last year's trend will deal with Prism.

A couple of weeks ago this question in the Prism forum got Fer and I thinking how to set the name of views in a region using View Discovery. As Prism does not support this out of the box (which is kind of weird), we had a talk with Ezequiel and Julian and decided to use Prism's extensibility to get this done (this means not changing the Prism source code at all :) ).

A couple of changes needed to be performed to achieve this functionality:

  1. Create a new RegionViewRegistry. Its API would allow passing the name of the view as the parameter when registering it with a region:
  2. public interface IRegionViewWithNamesRegistry : IRegionViewRegistry
      {
          void RegisterViewWithRegion(string regionName, Type viewType, string viewName);
          void RegisterViewWithRegion(string regionName, Func<object> getContentDelegate, string viewName);
      }

  3. Extend the AutoPopulateRegionBehavior to register the view using its name. To get this done we inherited from the RegionBehavior base class.

Finally to check that everything worked correctly we created a small sample using the ViewDiscovery-UIComposition QS for Silverlight (the new registry and behavior must be registered in the bootstrapper).

You can download the code from here (use the ViewDiscoveryComposition.sln). The code is provided "AS IS" with no warranties and confers no rights.