Prism: Injecting view from one module into another view in a second module RRS feed

  • Question

  • Hi,

    I need some help figuring out how to inject a view from one module into another view in a second module, using the Prism library.

    I have a CreateOrderView inside my Order module. This view gets injected into a region in the Shell. Now I need to display a PersonCardView inside this CreateOrderView. PersonCardView is a view from my PhoneBookModule.

    The view model for PersonCardView takes a Person argument in the constructor which contains the data that the view will display.

    In my CreateOrderView, how can I define a "placeholder" to "inject" this PersonCardView? I don't think it would be appropiate to define a region here since it's always this single view, and nothing else. If the two views was in the same module, I could just include it like this:

    <PersonCardView DataContext="{Binding PersonCardViewModel}"/>

    CreateOrderViewModel would of course hold a property called PersonCardViewModel containing the viewmodel for the PersonCardView.

    But I can't see how to do it this way unless I create a reference between the two modules and I would like to avoid that.

    Any ideas?

    Thank you!

    Saturday, April 30, 2011 10:31 AM


  • Hi,

    You need to create a ParentView and Child View.

    Define a Parent view, that takes single view and apply main region to it and apply scoped region to other child views.

    Now for displaying view from another module, you need to create a region and pass aruguments in regioncontext.


    <ContentControl Margin="0,50,0,0" cal:RegionManager.RegionName="{x:Static Infra:RegionNames.Item.MiddlePane}"                                             cal:RegionManager.RegionContext="{Binding Path=BusinessEntityId}"/>

     public static class Item


            public const string MiddlePane = "PersonCreateView.MiddlePane";


    and write this into your child view's module.

        public class BusinessEntityModule : IModule 


            private IRegionManager _regionManager;


            public BusinessEntityModule(IRegionManager regionManager)


                this._regionManager = regionManager;



            public void Initialize()


                _regionManager.RegisterViewWithRegion(Infrastructure.RegionNames.Item.MiddlePane, typeof(Views.PersonCreateView));







    • Proposed as answer by Jie Bao Monday, May 2, 2011 6:08 AM
    • Marked as answer by Jie Bao Monday, May 9, 2011 12:11 PM
    Monday, May 2, 2011 6:01 AM