Can't get a simple example with a region to work

Topics: Prism v4 - WPF 4
Apr 17, 2012 at 8:01 PM
Edited Apr 17, 2012 at 8:31 PM

I am new to WPF and Prism with MVVM, and I am trying to experiment with regions.  I have a simple learning project with a shell that contains a grid.  Cell 0,0 of the grid contains a stackPanel which is designated as a region.  My intention is to inject into the region a view which consists of nothing more than a canvas with a red background.  What I get instead is text which follows:

Resolution of the dependency failed, type = "simpletest.Modules.Views.ucanvas", name = "(none)".

I have read the Prism 4.1 document and I have experiemnted with the Quickstarts.  I am trying to adapt what I have learned in the Quickstarts, but progress is slow.  Can anybody point me to a very simple example of injecting of simple content (not data) into a named region?

My failed code, as goofy as it may be, follows:

using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;

using simpletest.Modules.Models;
using simpletest.Modules.Views;

namespace simpletest.Modules.Views
  public class ucanvasModule : IModule
    private readonly IRegionManager regionManager;
    private readonly IUnityContainer container;

    public ucanvasModule(IUnityContainer container, IRegionManager regionManager)
      this.container = container;
      this.regionManager = regionManager;

    public void Initialize()
      this.container.RegisterType<IUnityContainer>(new ContainerControlledLifetimeManager());

      this.container.RegisterType<IUnityContainer>(new ContainerControlledLifetimeManager());
      this.regionManager.RegisterViewWithRegion("GridColumn0Row0Region", () => this.container.Resolve<ucanvas>());
Apr 17, 2012 at 9:43 PM


You can find a very simple example of how to register a view to be injected in a region (using the RegisterViewWithRegion method) in the Hello World QuickStart provided with Prism. Also, you can compare your application against this QuickStart to check if there is any missing code required to start-up a Prism application.

Regarding the code snippet you posted, I am a bit confused about what you are trying to accomplish in the following line:

this.container.RegisterType<IUnityContainer>(new ContainerControlledLifetimeManager());
As far as I know, this sentence is not required to inject a view in a region and might even cause an unexpected behavior in your application.

Based on your description of the problem, it seems that the container cannot compose the ucanvas type. As far as I know, this can be caused by several reasons. So, if the aforementioned suggestions were not useful to help you solve this problem, you can provide us with your sample application so that we take and look at it and help you further with this.

I hope you find this useful,

Damian Cherubini

Apr 18, 2012 at 2:20 PM


I uploaded a small sample based on the description you made. You can find it in my SkyDrive account  under the name "CanvasSample", I hope you can use it to find any differences with your own implementation.

Additionally, I believe you could find the following resources useful, which might help you in the learning process:


Agustin Adami

Apr 18, 2012 at 5:02 PM
Edited Apr 18, 2012 at 5:03 PM
Regarding the code snippet you posted, I am a bit confused about what you are trying to accomplish in the following line:

 this.container.RegisterType<IUnityContainer>(new ContainerControlledLifetimeManager());


I'm not sure what I meant by it either.

Apr 18, 2012 at 5:04 PM

aadami, thank you for the training links.  I could certainly use more training.