NoVa Code Camp Presentation Materials

For those who attended today's talk,"Intro to Composite Apps with Prism," the presentation materials are on my shared SkyDrive folder.

To get started with your own CompositeWPF app, here's a quick cheat-sheet of steps. You can reference the demo code as well, to see how each step was implemented.
  1. Download and build the libraries from http://www.codeplex.com/compositewpf
  2. Start a new WPF application project
  3. Add references to either the built CompositeWPF libraries or the actual project files (it's probably more efficient to just reference the built libraries, in a common place)
  4. Delete Window1.xaml and create a new WPF Window called Shell.xaml
  5. Add the http://www.codeplex.com/CompositeWPF namespace to the namespaces in Shell.xaml
  6. Create one or more named regions in Shell.xaml.
  7. In App.Xaml, remove StartupUri (remember, we'll be loading the appropriate window with the bootstrapper).
  8. Create a new class, called Bootstrapper. Derive from UnityBootstrapper.
  9. In Bootstrapper, override CreateShell(): instantiate, show, and return the Shell window.
  10. In App.Xaml.cs, override OnStartup(). Create a new Bootstrapper object and call its Run() method.
  11. Add a module to your solution. This is a regular class library. Name it Module. Make sure the class implements IModule, which requires the Initialize() method.
  12. Create a view by adding a WPF user control to your new module. Start off simple, and just add something like a TextBlock so you can see your view later.
  13. Add an IRegionManager parameter to the constructor (which will be filled in by the Unity Container). Save it off in a member variable.
  14. Have the Initialize() method call RegisterViewsAndServices() (a private method on your module). In RegisterViewsAndServices(), register your module's view with the RegionManager, and assign it to one of your named regions.
  15. Now that your module exists, go back to your main app's project (ours was the Demo project). Add a reference to your new module. Then, in Bootstrapper.cs, override GetModuleCatalog(), and create a new catalog with your new module.
That should do it - when running your app, you should see your view appear in your app's window, wherever you placed the named region. For our demo app, we used a grid with three regions aligned row by row.

For any questions regarding the demo code, please leave a comment here.

Thanks for attending!

1 comments:

Kendrick said...

Hi David,

Thanks for posting your demo code from the Northern Va. Code Camp presentation! I was able to open the project, add the appropriate references to the CAL and I got the demo to run.

Quick question: how do the Views get associated with the ViewModels during runtime? (Is that done by the omnipetent unity?) Let's take the PersonDetailsModule specifically. I see in the code-behind file for PersonDetailsView.xaml.cs that the PersonDetailsView constructor takes a PersonDetailsViewModel as a parameter and sets it as the data context for the view. But "who" actually calls the PersonDetailsView constructor, and how does "it" know how to instantiate a PersonDetailsViewModel and pass it into the PersonDetailsView constructor?

I'm curious as to how this works because I want to try extending a module to have more than one view and possibly more than one viewmodel -- and understand the lifetime of the view and viewmodel instances.

I appreciate any insight you can offer.

Thanks much,
Ken