References in other assemblies

May 11, 2010 at 9:13 AM

Targets: WPF, .NET 4.0, nRoute 4.5

What i am trying to do, is define Viewmodels/Views in self contained DLLs (similar to having module DLLs in Prism) so that i can avoid having all my functionality in one central DLL.  Then i want to navigate between these views defined in the referenced DLLs.  When i try to do this, i get the URL not found page (which is nice btw).  Now i read about the SiteArea functionality you added in nRoute 4 and thought that this was exactly what i needed.  However i have been unable to get it to work - i couldnt see this in any of your samples and by my reasoning it should be incredibly easy to use so i must be missing something obvious.  Can you possibly post a small snippet/sample showing how in WPF i can achieve navigation to views defined in other DLLs and let me know if the SiteArea approach is the right one to use.  I think updating the SimpleMVVM sample to include this idea would be very useful for others too as its a common scenario in WPF development at least.

cheers, X

May 18, 2010 at 1:13 AM
Edited May 18, 2010 at 1:14 AM

I sorted this out - seems that the site areas HAVE to be in a sitemap?  I was trying to avoid this as i have no need for a sitemap, but so be it.


X - Author of Procreate

May 20, 2010 at 1:01 AM
Hi Xcalibur, sorry I was to respond to your question earlier but it slipped by me - anyway, as you wanted I've updated the SimpleMVVM sample to show how you can load and use views housed in external dlls. Note, the main trick with using views in external dlls is to always specify the SiteArea when navigating - you'll see all navigation and controller-action related behaviors support specifying the SiteArea. Also check out other samples and info on the updated SimpleMVVM app here Cheers, Rishi
May 22, 2010 at 5:50 PM
Edited May 22, 2010 at 5:51 PM

Actually ive found that explicitly specifying the sitearea when navigating is not necessary?  It seems that nRoute is smart enough to find the view in the appropriate sitearea by itself.  I assume there would be a problem if two assemblies defined views with the same URL and i would then need to specify the sitearea.  I simplify specified the siteareas like so:

                        <n:SiteArea Key="SalesModule" InitializeOnLoad="True" RemoteUrl="SalesModule.dll" />
                        <n:SiteArea Key="LoginModule" InitializeOnLoad="True" RemoteUrl="LoginModule.dll" />

I have just seen your updated samples post and will have a look and get back to you if there are any issues.


May 22, 2010 at 7:09 PM
Hi XCalibur, well in your SiteMap xaml I can see you've set InitializeOnLoad to be true - this means it will load n' initialize all the site-area resources when the application starts. However, this is done asynchronously which means you have no control over when it would will load exactly. Now if you are on a LAN or your own computer it might load quite fast but it is still indeterminate from a programmer's point-of-view - so I would still recommend that if you are navigating to a resource in SalesModule (from outside the SalesModule) then you specify the SiteArea in your navigation related behavior - unless you specifically block and make sure it has loaded first using the API in SiteMapService class. Also, remember if a SiteArea has not loaded and you try to navigate to a view in SiteArea without specifying the SiteArea name then it will cause a navigation error until the SiteArea is loaded. Hope this is clear? Rishi
May 23, 2010 at 5:26 PM

Ahh i understand, thanks for pointing that out.