Dynamically Creating regions and Injecting Views

Topics: Prism v4 - WPF 4
Aug 20, 2014 at 9:48 PM
Edited Aug 20, 2014 at 9:57 PM
Hi

I am new to Mef+ Prism.We follow MVVM Pattern. I have been looking for a example for creating regions dynamically and injecting views into it but could not able to find a good example for it So starting this thread.

My Scenario: We are using Telerik Rad Controls for this.

I have a MEMBER who has multiple ORDERS associated to him.So When the user selects the member, All the orders that are associated to him should be displayed in each RadPane.
So I have to generate Radpanes dynamically depending upon the number of orders that the Member had. Generating these RadPanes is working but after these Radpanes are generated I have to Inject a View into it.Here comes the haredest part which I felt to achieve.I will Explain clearly.


Lets say MainView is the view that has to be injected into the RadPane every time when the RadPane created dynamically.

In MainView we have two ContentControls with names : dynamicDataRegion, dynamicNavigatorRegion as below

<ContentControl x:Name="dynamicNavigatorContent " Grid.Column="0" Grid.Row="2" />
<ContentControl x:Name="dynamicDataContent" Grid.Column="1" Grid.Row="2" />

So for every RadPane these two regions has to be created dynamically and Inject the view accordingly.

For this I have used the below code
foreach (var order in OrderListDetails)
{
//Naming the dynamicRegions
string dynamicDataRegion = review.OrderId.ToString();
string dynamicNavigatorRegion = (review.OrderId+"A").ToString();
//Instance of RadPane
RadPane radPaneItem = new RadPane();
//Getting the OrderData
//This will have all the deatils
//get the Details related for the OrderId
     CurrentOrder.GetOrder(order.OrderId);
//Creating an Instance of MainView
     var coreView = ContextManager.Current.MEFContainer.GetExportedValue<MainView>();
            ((MainViewModel)coreView.DataContext).GetMember();
            //Creating and Adding and Navigating
Microsoft.Practices.Prism.Regions.RegionManager.SetRegionName(coreView.dynamicDataContent, dynamicDataRegion);
Microsoft.Practices.Prism.Regions.RegionManager.SetRegionManager(coreView.dynamicDataContent,ContextManager.Current.RegionManager);
DataCollectionDesktopContextManager.Current.RegionManager.RequestNavigate(dynamicDataRegion, ViewNames.DataView);

Upto here It is working fine.This DataView is getting injected dyanamically I am happy for that but when I am trying to do the same for that second view too whic is not working for me.Can anyone help me please on this.Below is the code I have used to inject the Secondview which is NavigationView(which is a TreeView)
            //Creating and Adding and Navigating
Microsoft.Practices.Prism.Regions.RegionManager.SetRegionName(coreView.dynamicNavigatorContent , dynamicNavigatorRegion);
Microsoft.Practices.Prism.Regions.RegionManager.SetRegionManager(coreView.dynamicNavigatorContent , ContextManager.Current.RegionManager);
            ContextManager.Current.RegionManager.RequestNavigate(dynamicNavigatorRegion, ViewNames.AbstractionNavigatorView);
            //assing Mainview to RadPane's Content
            radPaneItem.Content = coreView;
            //Panes is a ObeservableCOllection <RadPane>
            Panes.Add(radPaneItem);
        }
When I do this, I am not able to see the Scond view.Only the First view whic i DataView I seeing.Can any one help me on this please.I have been working on this for a long time.

Thanks!!