This project has moved. For the latest updates, please go here.

Dynamically loaded views

Oct 25, 2010 at 7:50 PM

Hi Jeremy,

I'm a long time follower of your blog and I really appreciate what you have done for the community. Keep up the great work!

At my company we are evaluating Jounce for an upcoming project and we have a question around dynamically loading views from a separate XAP.

The concept of providing hints to Jounce about the location of the views via the ViewXapRouter is great, but the downside of this approach is that we would need a separate property for each view. How would you solve the problem of providing multiple view locations in an "elegant" way? An ExportProvider is a possibility, but is there another way?

Thanks,

Rodolfo Maspoch

ZyTech Software Solutions

Coordinator
Oct 25, 2010 at 9:43 PM

I guess first I'm curious about your definition of elegant.

It does require tying the views to the XAPs, but I've done it in the past with just a single class that only serves the purpose of exporting the routes, i.e. like this:

public class AccountModuleRoutes
{
   public ViewXapRoute AccountListRoute 
   {
      get { return ViewXapRoute.Create("AccountList", "Account.Xap"); }
   }

   public ViewXapRoute ContactListRoute 
   {
      get { return ViewXapRoute.Create("ContactList", "Account.Xap"); }
   }

}

Certainly if you want something like "give me a list of views that belong to a XAP" then we could do that - then either an export provider or even a helper class that parses the list and composes the exported values would work (I'm looking at exposing the root container via the deployment service for just this purpose). Let me know what your thoughts are on some of these options and how I can help.

Oct 25, 2010 at 11:06 PM

Thanks for your response.

I guess "elegant" wasn't the right word, probably "automatic" it's closer to what I was referring to. I was thinking more along the lines of "create view routes for the views in the XAP". As I'm sure you know, in PRISM you can have a list of your modules in XAML (and their dependencies) and the views are automatically discovered using that information. I kind of like that idea because it allows you to create a new module in a separate Xap, add your module to the module definition file and if you planned your UI layout accordingly, you are up and running without touching any code in the rest of your app.

In any case, exposing the container would also work for me.

 

Coordinator
Oct 25, 2010 at 11:14 PM

Now I might be mistaken, but doesn't PRISM have to load the module to discover the views? In other words, if I want to go to a view, I have to know the view is in MODULEB and load MODULEB and then the view will automatically register to the region, correct? Or have I missed something?

In Jounce, you can easily load the module by importing IDeploymentService and requesting the XAP, and all views will be discovered there - you won't have to use routes at all. The only reason to use routes is to allow the navigation to automatically know which XAP contains which views so you can wait to load the XAP until the view is triggered. I remember from PRISM that I had to know when I was going to a module, and while loading the module wired my views, I had to load the module first. Again, you can do that here, but I built the routes so that I wouldn't have to worry about it.

The only way to know the view is in the XAP is to load and inspect the XAP - I don't want to do that because there is no sense in pulling it in until we need it, and I don't want the various view models to have to worry about "where" a view is an load a module just so they can get to a view.

Oct 27, 2010 at 10:43 AM

I have another problem but close.

I import my main menu from a sql database with view name and xap name.

I would like create, How can I export  to MEF from my menuitem constructor.