<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>David Hill's WebLog : Prism</title><link>http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx</link><description>Tags: Prism</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Prism and MEF</title><link>http://blogs.msdn.com/dphill/archive/2009/12/09/prism-and-mef.aspx</link><pubDate>Wed, 09 Dec 2009 12:47:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9934539</guid><dc:creator>dphill</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9934539.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9934539</wfw:commentRss><description>&lt;p&gt;One of the most highly anticipated of the new technologies coming in .NET 4.0 and Silverlight 4.0 is the Managed Extensibility Framework (MEF). Folks that are familiar with Prism and that have been looking at MEF have been wondering how Prism and MEF relate to each other. At a high level, MEF shares some of the same goals as Prism in terms of supporting easy to extend applications, and this has led to a lot of questions on how MEF and Prism relate to each other and about the future direction of Prism once MEF is released next year. Hopefully this post will go a long to clearing up the confusion and give you a sense of how we think Prism and MEF will work together.&lt;/p&gt;  &lt;p&gt;First of all, it’s important to note that Prism and MEF are very much complementary technologies. MEF allows you to create &lt;b&gt;extensible applications&lt;/b&gt; by providing support for automatic component discovery and composition. It does not focus on application- or UI-level patterns or on any specific UI technology. Prism on the other hand provides support for creating &lt;b&gt;modular composite client applications&lt;/b&gt; built on Silverlight and/or WPF. As such it supports a wide range of patterns including the higher level UI patterns and concepts that are need to support composite clients – such as modularity, module deployment, loosely coupled communication, commanding, and separated presentation patterns such as Model-View-ViewModel, etc.&lt;/p&gt;  &lt;p&gt;There is clearly some overlap between MEF and Prism (since modular composite client applications are by definition extensible!!) but MEF by itself in no way replaces or obviates the need for Prism – they are each targeted at different parts of the overall puzzle. MEF in fact is fantastic news for Prism, because it means that we can now leverage core capabilities that are provided by the .NET Framework, whereas in the past we’ve had to build those capabilities as part of Prism itself.&lt;/p&gt;  &lt;h4&gt;Prism 4.0&lt;/h4&gt;  &lt;p&gt;In the next version of Prism (Prism 4.0) we’ll be focusing on leveraging MEF as much as possible and ensuring that Prism and MEF work seamlessly together. We’ll be kicking off the Prism 4.0 project early next year and, as always, we’ll be providing drops every two weeks during development so you’ll be able to provide feedback and direct the scope and focus of the project as we go. But since MEF integration is likely be one of the first things that we’ll tackle, I think it’s worth describing our current thinking on how we think Prism can leverage MEF and how they can complement each other so that you can provide feedback to us before we start. In the rest of this post I’ll outline a couple of the areas where I think MEF and Prism can be closely integrated. Let me know what you think.&lt;/p&gt;  &lt;h4&gt;Component Composition&lt;/h4&gt;  &lt;p&gt;Firstly, let’s talk about component composition. Prism uses the Dependency Injection pattern (DI) quite extensively because it helps to maintain loose coupling between the various components in an application. I’m not going to get into the “is MEF a DI container or isn’t it” discussion here :-) but suffice it to say that there are similarities and differences between the way MEF works and the way that typical Dependency Injection containers work. The upshot is that there are things that MEF does well and there are things that DI containers do well, but the important thing is that both MEF and DI containers promote loose coupling between components, which is a very good thing.&lt;/p&gt;  &lt;p&gt;In the Prism 2.0 Quick Starts and the Reference Implementation we use the &lt;a href="http://www.codeplex.com/unity" target="_blank"&gt;Unity Application Block&lt;/a&gt; as our DI container of choice. However, it’s important to note that the Prism code libraries themselves do &lt;b&gt;&lt;u&gt;NOT&lt;/u&gt;&lt;/b&gt; depend explicitly on Unity, or in fact on any specific DI container implementation. This is an important point. It was an &lt;b&gt;explicit&lt;/b&gt; design decision to allow the use of &lt;b&gt;any&lt;/b&gt; other DI container (such as CastleWindsor, StructureMap, AutoFac, Ninject, etc) or the use of &lt;b&gt;any&lt;/b&gt; other kind of component composition strategy that suites your needs – such as the component composition strategy supported by MEF!&lt;/p&gt;  &lt;p&gt;So the design of Prism allows you to use MEF with Prism 2.0 today, even though Prism 2.0 was shipped early this year way before MEF was broadly available. It’s pretty easy to use MEF instead of a DI container within a Prism module to help you wire up Views, ViewModels, Controllers, or Presenters, or to get references to EventAggregator or RegionManager instances provided by the Shell. In fact, using MEF like this can actually simplify the code somewhat since it can automatically discover available types without you having to register them explicitly with the DI container. You can also use MEF’s meta-data support to do conditional component composition. We’ll be exploring and providing guidance for these scenarios in Prism 4.0.&lt;/p&gt;  &lt;p&gt;Another interesting possibility is to use both MEF and a DI container together in the same application. There are some advantages to this since it allows you to leverage the strengths of each in various situations. In fact, Unity 2.0 (which is currently in development as part of &lt;a href="http://www.codeplex.com/entlib" target="_blank"&gt;EntLib 5.0&lt;/a&gt;) will support the hybrid use of MEF and a DI container and make it seamless and straightforward. In Prism 4.0, we’ll be exploring and providing guidance for the use of MEF + DI container hybrid approaches in the context of composite client application development.&lt;/p&gt;  &lt;h4&gt;Catalogs and Modules&lt;/h4&gt;  &lt;p&gt;The use of MEF and/or DI container to help with component composition is pretty straightforward, and largely independent of the higher level constructs and patterns in Prism. But one area where the overlap between MEF and these higher level Prism concepts is not quite as clear cut is in the area of Catalogs and Modules. This area has caused some confusion in part because of overlapping terminology and, in some cases, because of the similar concepts applied at different levels of granularity.&lt;/p&gt;  &lt;p&gt;To recap, Prism uses the notion of a module to represent a collection of features, components, and resources that make up a &lt;strong&gt;functional unit&lt;/strong&gt; within the application. Prism modules can be developed, tested and deployed independently. They frequently consist of multiple assemblies and other resources packaged up into an easily deployable unit (for example in a XAP file). Prism provides infrastructure for the flexible deployment of modules. In the case of Silverlight, for example, modules can be downloaded with the core application, or can be downloaded in the background or on-demand.&lt;/p&gt;  &lt;p&gt;Prism applications use a &lt;strong&gt;module catalog&lt;/strong&gt; to tell it which modules to load. Module catalogs can be &lt;b&gt;static&lt;/b&gt; (i.e. the list of modules is predetermined before run-time) or &lt;b&gt;dynamic&lt;/b&gt; (i.e. the list of modules is determined at run-time and can take into account the user’s ID, role, configuration, installed modules, wind direction, etc). Dynamic module catalogs can be used to extend an application after its initial deployment. They can be implemented in many different ways. For example, you can build a dynamic catalog by reading a (local or remote) config file, or by using a web service that specifies the modules to load, or by scanning a particular folder to see what modules have been installed.&lt;/p&gt;  &lt;p&gt;Once a module is loaded, Prism looks for an entry type that supports the IModule interface. This interface has only one method – Initialize – and can be used to provide any initialization logic that the module provides. Typically, this method is used to register types within the module with the DI container so that they can be accessed by other modules and the shell. Another common use of this method is to register Views contained within the module with UI regions. The module can do anything it needs to though, including kicking off background threads, making web service calls or downloading additional data or resources. Of course, you don’t have to provide any initialization logic if your module doesn’t require it.&lt;/p&gt;  &lt;p&gt;Now, MEF too has the concept of a &lt;strong&gt;component catalog&lt;/strong&gt;. When you &lt;strong&gt;import&lt;/strong&gt; a type in MEF (i.e. you’ve expressed a dependency in one class to another class of a certain type), its resolves that type by looking in the MEF catalog which defines all of the types that are available for &lt;strong&gt;export&lt;/strong&gt; (i.e. types that can be used by MEF to satisfy imports). This is a very powerful feature of MEF and allows you to express dependencies between components and have them fulfilled for you pretty much automatically, without having to explicitly register types with a DI container or having to resort to closely-coupled techniques like ‘new’ or CreateInstance. Note, I say ‘type’ here to keep things simple but MEF generalizes the relationship between importer and exporter using contracts, but contracts most often equate to types, and types can be interfaces.&lt;/p&gt;  &lt;p&gt;So Prism module catalogs are really not the same as MEF catalogs since they’re specifying things at completely different levels of granularity. In addition, MEF does not provide any support for the packaging or conditional deployment of functional units within an application. However, there is clearly some overlap here since, at a lower level, Prism modules essentially contain a bunch of components that can import and export types so that they can be hooked up to components from other modules or the shell.&lt;/p&gt;  &lt;p&gt;You can imagine using both Prism module catalogs and MEF catalogs together. The key here I think is for Prism to focus on the packaging, deployment and activation of coarse grained functional units (modules), as defined by either a static or dynamic module catalog, and to use MEF to support the flexible, meta-data driven composition of components within and across modules and the shell.&lt;/p&gt;  &lt;p&gt;For example, imagine using Prism to build modules that represent functional units within an application and having it take care of their packaging and deployment via a dynamic or static module catalog. As each Prism module is loaded, the component dependencies within it (i.e. imports and exports) can be made available to MEF for component composition. In a sense, each module represents a catalog of components that MEF can use to fulfill and resolve component dependencies. There are other possibilities I am sure, and we’ll be exploring these as part of Prism 4.0…&lt;/p&gt;  &lt;h4&gt;Prism 4.0 Needs You!&lt;/h4&gt;  &lt;p&gt;Our goal for Prism 4.0 is to leverage MEF, and other .NET 4.0 and Silverlight 4.0 features, as much as possible so that we can provide a flexible and powerful environment for building modular, composite client applications on WPF and Silverlight 4.0. MEF is an exciting new technology and it’s great to see some level of support for loosely coupled component composition finally make it into the .NET Framework. I’m looking forward to exploring the possibilities here and I think it’s going to be pretty cool…&lt;/p&gt;  &lt;p&gt;As well as MEF integration, for Prism 4.0 we’re looking at also providing more guidance on the ViewModel pattern, navigation, out of browser applications, developer/designer workflow, user experience patterns, visual studio templates, and a whole host of other areas. Which ones we tackle will depend on you, so as always, if you have any ideas or feedback, please let us know!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9934539" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/MEF/default.aspx">MEF</category></item><item><title>Prism &amp; WCF RIA Services</title><link>http://blogs.msdn.com/dphill/archive/2009/11/24/prism-wcf-ria-services.aspx</link><pubDate>Wed, 25 Nov 2009 00:22:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9928297</guid><dc:creator>dphill</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9928297.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9928297</wfw:commentRss><description>&lt;p&gt;Back in August I did a &lt;a href="http://blogs.msdn.com/dphill/archive/2009/08/17/prism-and-net-ria-services.aspx" target="_blank"&gt;post&lt;/a&gt; that described how you could use .NET RIA Services and Prism together. That post, and the associated sample app, was based on the .NET RIA Services July CTP.&lt;/p&gt;  &lt;h4&gt;.NRS –&amp;gt; WRS&lt;/h4&gt;  &lt;p&gt;A couple of weeks ago at PDC those terribly nice RIA Services chaps released a Beta version, for both Silverlight 3.0 and 4.0. And in time-honored Microsoft tradition, they also changed the name – it now seems to be officially named WCF RIA Services (WRS for short) – to reflect the switch to WCF as the underlying service implementation. You can download the WRS Beta &lt;a href="http://www.silverlight.net/getstarted/riaservices/" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I’ve updated the Prism/WRS sample to work with the Beta drop. You can download it &lt;a href="http://dphill.members.winisp.net/Download/PrismRiaServicesSample2.zip" target="_blank"&gt;here&lt;/a&gt;. The sample targets Silverlight 3.0, WRS Beta and VS 2008. I’m sure with some tweaking it will be relatively easy to get working on Silverlight 4.0 and VS 2010 too. As before, the sample requires the Northwind sample database to be installed and running.&lt;/p&gt;  &lt;h4&gt;Prism 2.1 –&amp;gt; Prism 4.0&lt;/h4&gt;  &lt;p&gt;The sample was also updated to use the latest Prism 2.1 release (which you can download &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=387c7a59-b217-4318-ad1b-cbc2ea453f40&amp;amp;displaylang=en" target="_blank"&gt;here&lt;/a&gt;). This is a minor update to the 2.0 (February) release and contains a couple of minor updates in the commanding area. Prism 2.1 was also fully tested against Silverlight 3.0 and against Silverlight 4.0 Beta…&lt;/p&gt;  &lt;p&gt;With the release of Silverlight 4.0 Beta, and with VS2010 and .NET 4.0 at Beta 2, we are ramping up our planning for the next major version of Prism. We’re thinking of calling it Prism 4.0 (skipping whole version numbers is another time-honored Microsoft tradition) – so that it lines up with Silverlight 4.0, WPF 4.0 and .NET 4.0!! Planned release date is late spring next year, but as always, once the project is underway we’ll be releasing intermediate drops every two weeks.&lt;/p&gt;  &lt;p&gt;I’ll be posting much more on our Prism 4.0 plans in a week or so, but if you have any ideas for what you’d like to see in Prism 4.0 please send them my way…&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9928297" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/.NET+Ria+Services/default.aspx">.NET Ria Services</category></item><item><title>Blend Behaviors</title><link>http://blogs.msdn.com/dphill/archive/2009/09/25/blend-behaviors.aspx</link><pubDate>Sat, 26 Sep 2009 02:18:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9899750</guid><dc:creator>dphill</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9899750.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9899750</wfw:commentRss><description>&lt;p&gt;Expression Blend 3 includes a number of very cool new features (see &lt;a href="http://www.microsoft.com/expression/products/Blend_Features.aspx" target="_blank"&gt;here&lt;/a&gt; for a good summary). But there are two that I think are particularly important – SketchFlow Rapid Prototyping, and Blend Behaviors. I’ll cover SketchFlow in some depth in a future post. In this post I’m going to talk about Blend behaviors and how they can be used to extend Helix, my prototype Silverlight navigation framework.&lt;/p&gt;  &lt;h4&gt;What Are Behaviors?&lt;/h4&gt;  &lt;p&gt;Behaviors are objects that encapsulate some form of interactive behavior. Blend allows them to be easily 'attached’ to visual elements in the UI, via drag-drop or declaratively in XAML. They enable developers or designers to rapidly add rich interactivity to the UI without having to write code.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_2.png"&gt;&lt;img style="border-right-width: 0px; margin: 5px 10px 5px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_thumb.png" width="244" height="212" /&gt;&lt;/a&gt; Blend 3 ships with a number of behaviors (shown left) that allow you to easily animate an element, change it’s visual state, start/stop a storyboard, play sounds, etc.&lt;/p&gt;  &lt;p&gt;However, the key thing is that Blend allows you to create new behaviors of your very own. And not only that, but when you do they will automatically show up in the Blend toolbox ready for use by a developer or a UI designer.&lt;/p&gt;  &lt;p&gt;There is also an Expression Gallery &lt;a href="http://gallery.expression.microsoft.com/en-us/site/search?f%5B0%5D.Type=Tag&amp;amp;f%5B0%5D.Value=Behavior" target="_blank"&gt;here&lt;/a&gt; dedicated to community developed behaviors, so if you develop a particularly cool behavior you can readily share it with other Blend users.&lt;/p&gt;  &lt;h4&gt;Behaviors – Think XAML Extension Methods!&lt;/h4&gt;  &lt;p&gt;The implementation details and concepts behind Blend behaviors are pretty simple. They leverage the simple but powerful ‘attached property’ mechanism in WPF and Silverlight. Instead of attaching a simple value though (like Grid.Row=”2”) you’re attaching an object that encapsulates behavior. Such objects are sometimes called Attached Behaviors. They provide an elegant way to extend existing controls without having to modify the control’s code or it’s UI template. I like to think of attached behaviors as the XAML equivalent of extension methods in C#.&lt;/p&gt;  &lt;p&gt;Developers have been using attached behaviors for quite a while now as a way of extending Silverlight and WPF. In fact, they are pretty much the only way that you &lt;em&gt;can&lt;/em&gt; extend Silverlight, since it lacks a number of other key extensibility mechanisms (such as custom markup extensions). As such, they’ve proven to be a very useful way to add missing functionality to Silverlight.&lt;/p&gt;  &lt;p&gt;For example, since Silverlight controls do not (yet) inherently support commanding, we used this technique in Prism for wiring up button-derived controls to commands on the ViewModel:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000"&gt;prism:Click&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Command&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding ViewOrdersCommand}&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;I also used this technique in Helix to implement CollectionView support (now thankfully redundant since it’s supported in Silverlight 3.0).&lt;/p&gt;

&lt;p&gt;Both Prism and Helix provide base classes that allow you to more easily create attached behaviors, and there are a number of other third party behavior frameworks that you can use too. But now that we have the Blend Behaviors Framework, we can hopefully all standardize on a single framework.&lt;/p&gt;

&lt;h4&gt;Triggers, Actions and Behaviors&lt;/h4&gt;

&lt;p&gt;Blend behaviors actually come in two main flavors – Actions and what I’ll call Full Behaviors.&lt;/p&gt;

&lt;p&gt;Actions are simple behaviors that encapsulate an action (believe it or not) that are associated with a trigger. You can use an action and trigger pair to make something happen as the result of an event fired by the parent control. You can, for example,&amp;#160; change a property value, control a storyboard, play a sound, or cause a control to move to a particular visual state as the result of a Click, MouseLeave, MouseEnter, MouseLeftButtonDown event, or any other event that the parent control fires.&lt;/p&gt;

&lt;p&gt;Here’s a simple example – when the user moves the mouse over the image, the opacity property is changed to 0.5:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Image&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Source&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MyImage.png&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;i:Interaction.Triggers&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;i:EventTrigger&lt;/span&gt; &lt;span style="color: #ff0000"&gt;EventName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MouseEnter&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;          &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ic:ChangePropertyAction&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PropertyName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Opacity&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0.5&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;i:EventTrigger&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;i:Interaction.Triggers&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Image&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You could of course choose a different event to trigger the action, or choose a different property to change. Blend makes it very easy to drag an action onto a control and to configure it to do what you want.&lt;/p&gt;

&lt;p&gt;Some actions operate solely on the parent control that the trigger is connected to. Some actions can operate on a control other than the parent. These actions are called Targeted Actions. If no target is explicitly specified, the target defaults to the parent control.&lt;/p&gt;

&lt;p&gt;You’ll notice that the EventTrigger is added to a triggers collection. That means you can add as many triggers to a control as you like. Other types of triggers are possible too, not just ones that are associated with the target control’s events. For example, you can imagine using mouse/stylus gestures as triggers, etc.&lt;/p&gt;

&lt;p&gt;Full behaviors are useful for encapsulating more complex interactive behavior that aren’t necessarily associated with a single trigger. The following example uses one of the coolest behaviors that Blend provides – the MouseDragElementBehavior. By simply attaching this behavior to a control, you can allow the user to drag it around in the UI!&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Image&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Source&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MyImage.png&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;i:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;il:MouseDragElementBehavior&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ConstrainToParentBounds&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;i:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Image&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Again, you’ll notice that it gets added to a behavior collection, so you can have multiple behaviors on a single control.&lt;/p&gt;

&lt;p&gt;Blend provides an assembly, &lt;strong&gt;System.Windows.Interactivity&lt;/strong&gt;, that contains a number of base classes that you can use to define your own triggers, actions and behaviors. Simply add a reference to this assembly to your project (you’ll find it in the ‘C:\Program Files\Microsoft SDKs\Expression\Blend 3\Interactivity\Libraries\Silverlight|WPF’ directory or thereabouts) and away you go. Any triggers, actions, or behaviors that you define will automatically be available in the Blend toolbox. Let’s see this in action…&lt;/p&gt;

&lt;h4&gt;A Custom Action&lt;/h4&gt;

&lt;p&gt;Some of you may have been following my series of posts on the Helix navigation framework for Silverlight. If so, you’ll know that Helix provides a NavigateLink control that you can use within a page to link to another page that the user can navigate to. The NavigateLink control derives from Silverlight’s HyperlinkButton control. It’s a very simple control – the only thing is really does is to fire a navigate event up the visual tree so that it can be handled by a Frame control which then manages the actual navigation.&lt;/p&gt;

&lt;p&gt;But what if you don’t want to use a NavigateLink button control to initiate navigation? Say you want to navigate using a different control, like an Image or a ListBox, or in response to a different event than Click, like MouseEnter/Leave or SelectionChanged? Well, now you can with the HelixNavigateAction!&lt;/p&gt;

&lt;p&gt;The HelixNavigateAction class is pretty simple. It derives from the Blend TargetedTriggerAction class – the target in this case is a Frame so you can initiate navigation on a specific frame. It defines two dependency properties, NavigateUri and NavigationParameter. The overridden Invoke method is the only interesting part of this class and is shown below.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Invoke( &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter )&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    Uri navigationUri = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NavigateUri;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #008000"&gt;// Navigate to the specified Uri.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NavigateUri != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; )&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #008000"&gt;// See if we have to format the navigation Uri with&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #008000"&gt;// any parameters.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #008000"&gt;// See if the target frame has been specified explicitly.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #008000"&gt;// If not, bubble a request navigate event through the visual tree.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        Frame frame = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Target &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Frame;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( frame != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; )&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            frame.Navigate( navigationUri );&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            &lt;span style="color: #008000"&gt;// Bubble the RequestNavigate event to the nearest&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            &lt;span style="color: #008000"&gt;// parent Frame.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            UIElement parent = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.AssociatedObject &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; UIElement;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            parent.RaiseEvent(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;              Microsoft.Samples.Helix.Controls.Frame.RequestNavigateEvent,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;              &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RequestNavigateEventArgs( navigationUri, TargetName ) );&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;As you can see, we first check to see if a target Frame has been specified. If it has, we call the Navigate method on it directly. If not, then we raise a RequestNavigate event which will bubble up through the visual tree until a containing Frame control is found. That’s pretty much it. In the next section we’ll see how we can use the HelixNavigateAction class in Blend.&lt;/p&gt;

&lt;table style="border-bottom: #808000 thin solid; border-left: #808000 thin solid; border-top: #808000 thin solid; border-right: #808000 thin solid" border="0" cellspacing="0" cellpadding="8" width="80%" bgcolor="#bdb76b" frame="border" align="center"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="100%"&gt;While creating actions in Blend is fairly straightforward, there are a couple of wrinkles to be aware of… 
        &lt;br /&gt;

        &lt;br /&gt;If you look closely at the classes provided in the System.Windows.Interactivity namespace, you’ll see that there are two main action classes – TriggerAction&amp;lt;T&amp;gt; and TargetedTriggerAction&amp;lt;T&amp;gt;. Both ultimately derive from the TriggerAction base class. Now you’d probably think that the generic parameter &amp;lt;T&amp;gt; in each of these classes would specify the same kind of type. 

        &lt;br /&gt;

        &lt;br /&gt;Well, it seems that the &amp;lt;T&amp;gt; in TriggerAction&amp;lt;T&amp;gt; specifies the type of &lt;strong&gt;&lt;u&gt;Associated&lt;/u&gt;&lt;/strong&gt; (parent) control, but the &amp;lt;T&amp;gt; in TargetedTriggerAction&amp;lt;T&amp;gt; specifies the type of the &lt;strong&gt;&lt;u&gt;Target&lt;/u&gt;&lt;/strong&gt; control. For a TargetedTriggerAction, to constrain the type of the parent control, you have to add a TypeContstraint attribute to the class: 

        &lt;br /&gt;

        &lt;br /&gt;

        &lt;div id="codeSnippetWrapper"&gt;
          &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
            &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;[TypeConstraint( &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;( UIElement ) )]&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
        &lt;/div&gt;

        &lt;br /&gt;Not sure why they did it like this… This design seems a little weird to me. I would have thought something like TargetedTriggerAction&amp;lt;A,T&amp;gt; would have worked better, then you could specify the types of the Associated and Target controls in the same consistent way… 

        &lt;br /&gt;

        &lt;br /&gt;The other thing to be aware of is that, if a Target value is not explicitly defined for an Action, the Target property will be set to the Associated parent control instance. This means that the type of the Target has to be &lt;strong&gt;&lt;u&gt;assignable&lt;/u&gt;&lt;/strong&gt; to the type of the Associated control. For example, we’d ideally like our HelixNavigateAction class to target Frame controls, but be associated with any type of control. Something like this: 

        &lt;br /&gt;

        &lt;br /&gt;

        &lt;div id="codeSnippetWrapper"&gt;
          &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
            &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;[TypeConstraint( &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;( UIElement ) )]  &amp;lt;- Type of Associated Control&lt;/pre&gt;
&lt;!--CRLF--&gt;

            &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; HelixNavigateAction :&lt;/pre&gt;
&lt;!--CRLF--&gt;

            &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        TargetedTriggerAction&amp;lt;Frame&amp;gt; &amp;lt;- Type of Target Control&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
        &lt;/div&gt;

        &lt;br /&gt;This won’t work unfortunately since if a Target is not explicitly specified, it will be assigned the Associated control (which is probably not a Frame) so an InvalidOperation exception will be thrown at runtime. Again, not sure why they did it like this. I would have thought that leaving Target as null if it hadn’t been explicitly specified would have worked better. Yes, you’d have to check for null and then perform the action on the Associated object (maybe) but you’d have much more control and flexibility… Ho hum… 

        &lt;br /&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h4&gt;HelixNavigateAction In Action&lt;/h4&gt;

&lt;p&gt;So with our newly minted HelixNavigateAction class all compiled, let’s put it through it’s paces in Blend. You can download the sample project (including the latest version of Helix) &lt;a href="http://dphill.members.winisp.net/Download/Helix-Navigation-0.31.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We’ll start with a simple app with main screen that contains a frame (the big area on the left) and four headline controls (on the right).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_thumb_1.png" width="404" height="296" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’re going to use the HelixNavigateAction to navigate the frame to various pages as the user clicks on the headline controls on the right. If you click on the Assets tab and then on Behaviors, you will see a list of Behaviors and Actions that you can use. You’ll notice that the HelixNavigateAction is already there for us!&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_thumb_3.png" width="404" height="144" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Simply drag the HelixNavigateAction over and drop it one of the headline controls on the right hand side of the main screen. You see the action get added to the object tree and the property grid will show various trigger and action properties. Let’s setup the trigger first by choosing the MouseLeftButtonDown event in the EventName dropdown. Next, we’ll set the target. For this we can use the rather nifty target picker! You just click on the round target icon and then click on the Frame and hey presto! the TargetName property is filled in:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_thumb_6.png" width="404" height="117" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Finally, we just have to specify the Uri to navigate to. For that we simply use the dropdown on the NavigateUri property and select whichever page we want to navigate to:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/BlendBehaviors_8E68/image_thumb_7.png" width="417" height="287" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Repeat for the other three controls and that’s it, we’re all done! For grins, change the trigger event to MouseEnter to get a ‘hot-spot’ navigation effect. You can run the completed app &lt;a href="http://dphill.members.winisp.net/BlendBehaviorSample.html" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With Blend and the Blend Behaviors Framework we have a pretty powerful and flexible way to create re-usable components that encapsulate interactive behavior and a way to use them to snap together an application very rapidly.&lt;/p&gt;

&lt;p&gt;I’ve only really scratched the surface here. There are plenty of other cool and powerful things that we can do with behaviors. Also, it may be that we can leverage this framework in the next release of Prism, and thereby replace our implementation in favor of the Blend implementation. Not only will this reduce the amount of code in Prism, it will also allow us to leverage the built-in design-time support that Blend provides…&lt;/p&gt;

&lt;h4&gt;Helix&lt;/h4&gt;

&lt;p&gt;I made a few small changes to the Helix framework to support the use of Blend Behaviors. I also updated the samples for Silverlight 3.0. You can download the latest version &lt;a href="http://dphill.members.winisp.net/Download/Helix-Navigation-0.31.zip" target="_blank"&gt;here&lt;/a&gt; (version 0.31).&lt;/p&gt;

&lt;h4&gt;Blend Behavior Resources&lt;/h4&gt;

&lt;p&gt;You might find the following resources useful as you explore Blend and the Blend Behaviors Framework:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The Expression Blend home page: &lt;a title="http://expression.microsoft.com/en-us/cc136530.aspx" href="http://expression.microsoft.com/en-us/cc136530.aspx"&gt;http://expression.microsoft.com/en-us/cc136530.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Expression Behavior Gallery: &lt;a title="http://gallery.expression.microsoft.com/en-us/site/search?f%5B0%5D.Type=Tag&amp;amp;f%5B0%5D.Value=Behavior" href="http://gallery.expression.microsoft.com/en-us/site/search?f%5B0%5D.Type=Tag&amp;amp;f%5B0%5D.Value=Behavior"&gt;http://gallery.expression.microsoft.com/en-us/site/search?f%5B0%5D.Type=Tag&amp;amp;f%5B0%5D.Value=Behavior&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Christian Schormann’s posts on Behaviors: &lt;a title="http://electricbeach.org/?cat=30" href="http://electricbeach.org/?cat=30"&gt;http://electricbeach.org/?cat=30&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Kirupa Chinnathambi’s posts on Behaviors: &lt;a title="http://blog.kirupa.com/?cat=18" href="http://blog.kirupa.com/?cat=18"&gt;http://blog.kirupa.com/?cat=18&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899750" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Helix/default.aspx">Helix</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Blend/default.aspx">Blend</category></item><item><title>Prism Training Classes</title><link>http://blogs.msdn.com/dphill/archive/2009/09/18/prism-training-classes.aspx</link><pubDate>Fri, 18 Sep 2009 19:27:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9896859</guid><dc:creator>dphill</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9896859.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9896859</wfw:commentRss><description>&lt;p&gt;Due to popular demand, and hopefully signs of a recovering economy, the Rolling Thunder chaps are running another online Prism training course. It’s a 3 day course and runs from October 27th to the 29th. Full details here:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.rollthunder.com/prism/prismpublicclass.htm" href="http://www.rollthunder.com/prism/prismpublicclass.htm"&gt;http://www.rollthunder.com/prism/prismpublicclass.htm&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9896859" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category></item><item><title>Prism And .Net RIA Services</title><link>http://blogs.msdn.com/dphill/archive/2009/08/17/prism-and-net-ria-services.aspx</link><pubDate>Tue, 18 Aug 2009 03:06:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9873200</guid><dc:creator>dphill</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9873200.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9873200</wfw:commentRss><description>&lt;p&gt;For the past couple of weeks I’ve been working on a sample that shows how you can use Prism and .Net RIA Services (I’m going to call it .NRS for short) together. In this post I’m going to walk you through the sample and show how you can structure a Prism &amp;amp; .NRS solution that uses modules as a way to compose applications from both a services and a UI perspective. You can download the source code for the sample application &lt;a href="http://dphill.members.winisp.net/Download/PrismRiaServicesSample.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you’re not familiar with .NRS, it’s framework and related tools that allows you to define a set of entities (or business objects if you prefer) on the server and have those entities made available automatically within your Silverlight client project. You can then use those entities within your Silverlight application where you can create, edit or delete them via the UI, and then save the changes back to the server. .NRS takes care of sending data and updates over the wire so you don’t have to worry about creating and maintaining web services and service references. .NRS also provides support for meta-data driven cross-tier validation and provides common application services, such as user profile, authentication and authorization. See &lt;a href="http://silverlight.net/forums/t/80529.aspx" target="_blank"&gt;here&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/brada/archive/2009/03/19/what-is-net-ria-services.aspx" target="_blank"&gt;here&lt;/a&gt; for more details on .NRS and download the July CTP from &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;amp;displaylang=en" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Quite a few folks have asked me whether Prism and .NRS can work together. The answer, happily, is that Prism and .NRS not only work together they actually complement each other pretty well. When we developed Prism 2.0, we had an item on our backlog to provide guidance on getting data from the server to the client and back again. Unfortunately we didn’t get to that item in Prism 2.0, but .NRS provides support for exactly that scenario. Using Prism and .NRS together is relatively straightforward but there are few issues that you need to be aware of. .NRS is currently available as a CTP so there may be an opportunity for the .NRS folks to address some of these issues before the final release.&lt;/p&gt;  &lt;h3&gt;The Big Picture&lt;/h3&gt;  &lt;p&gt;As you know, Prism provides support for building modular client applications in WPF or Silverlight. Prism modules often encapsulate a ‘vertical’ slice of the application’s overall functionality by including all of the view, view model, model and service components required to implement that slice. Such modules are frequently re-usable across multiple applications, allowing you to compose or extend applications from packages of functionality. For example, you might have a financial services application with modules that provide real-time and historical market data, analyst reports, portfolio management, 401K management, options trading, etc. Each of these functional areas can be encapsulated in one or more modules and this allows you to build a single application from an open-ended set of modules, or even a family of applications that each focus on a particular user role or business area.&lt;/p&gt;  &lt;p&gt;So how does .NRS fit into this picture? &lt;/p&gt;  &lt;p&gt;More and more folks have ‘service enabled’ their back-end systems as part of their move to a service oriented architecture and that has enabled access to a lot of useful data and business processes. Having access to these services is great but it doesn’t really get you very far. The challenge then becomes how to build a compelling and consistent user experience on top of those services. To do that you need a client-side representation of the service that can be composed into a user experience. That representation can of course be a Prism module. The module interacts with the back-end service and provides a user experience for it that can be composed into an application alongside other such modules that represent other back-end services. In effect, Prism &amp;amp; .NRS together provide a way to construct data services and corresponding client-side modules that can be combined into interesting applications.&lt;/p&gt;  &lt;p&gt;.NRS allows client-side and server-side projects to be linked together so that they can communicate with each other and share code. .NRS supports a number of configurations but the one we’re most interested in is where the client-side project is a Prism module, and the server side project is a .NRS class library that implements a single data service. In this configuration, the client-side modules are composed into a Shell, and the server-side class libraries are hosted in a web application.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismAnd.NetRIAServices_C009/PrismRiaServices_2.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="PrismRiaServices" border="0" alt="PrismRiaServices" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismAnd.NetRIAServices_C009/PrismRiaServices_thumb.png" width="500" height="388" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;The Sample Application&lt;/h3&gt;  &lt;p&gt;To show how all of this works we’re going to create a simple order management application which uses two modules – one to display the user’s current orders, and one to display the product catalog. Each module consumes a corresponding data services on the server side. You can imagine that in a real enterprise, the order management system and the product management system could be entirely separate systems. In our simple example, we’re using a single database to represent both (the Northwind database) but we’ll build two independent data services to show how services can be composed.&lt;/p&gt;  &lt;p&gt;Before we get started, you’ll need to install &lt;a href="http://silverlight.net/getstarted/silverlight3/default.aspx" target="_blank"&gt;Silverlight 3.0&lt;/a&gt;, the .Net RIA Services &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;amp;displaylang=en" target="_blank"&gt;July CTP&lt;/a&gt;, and the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=06616212-0356-46A0-8DA2-EEBC53A68034&amp;amp;displaylang=en" target="_blank"&gt;Northwind sample database&lt;/a&gt;. We’ll also use the Prism Quick Start Solution I outlined in a previous &lt;a href="http://blogs.msdn.com/dphill/archive/2009/06/15/prism-quick-start-kit-update.aspx" target="_blank"&gt;post&lt;/a&gt;. We’ll start by creating a copy of the Silverlight Quick Start solution and build our application on top of that. When you open the solution, Visual Studio will convert it into a Silverlight 3.0 project. The solution includes two modules called Module1 and Module2. Rename them OrderModule and CatalogModule (you might to change the corresponding assembly name, default namespace and XAP file name too).&lt;/p&gt;  &lt;p&gt;The next step is to create the Order and Catalog data services. These are the server-side .NRS class libraries that implement the data services that we’re going to consume in the corresponding Prism modules. Add two new .Net RIA Services Class Library projects to the solution named OrderServices and CatalogServices respectively. You’ll see that this actually creates two projects in a folder – one for the server-side and one for the client-side. We don’t need the client-side project (since we’re going to use the Prism module projects to consume the services) so go ahead and delete the client-side projects OrderServices and CatalogServices, but keep the server-side projects OrderServices.Web and CatalogServices.Web. These server-side projects each come with WorkerRole class (for reasons that escape me) so delete those too.&lt;/p&gt;  &lt;p&gt;Before we go any further we need to link the various projects together. We link the two server-side projects to the Web project by simply adding project references. This will cause the services to be ‘hosted’ in the Web project. That was the easy bit. Now we need to associate our client-side module projects with their corresponding server-side service projects. If you look at the module project properties dialog you’ll see there is a .Net RIA Service Link dropdown. This feature lets us link our client-side and server-side projects so that the .NRS tooling can copy and generate the right files. What we want to do is to link our module projects to the corresponding service projects.&lt;/p&gt;  &lt;p&gt;Unfortunately, .NRS won’t let us do this easily within Visual Studio. The dropdown only shows the Web project, and not the server-side class library projects that implement the services. That’s because Prism module projects are considered Silverlight application projects (i.e. they produce a XAP file) and not Silverlight class library projects. .NRS only seems to allow Silverlight class library projects to be linked to .NRS server-side class library projects in the project properties dialog. I am not sure why .NRS has this restriction. The simple workaround is to open up the .csproj file in Notepad and add the link manually:&lt;/p&gt;  &lt;p&gt;&amp;lt;LinkedServerProject&amp;gt;..\OrderServices.Web\OrderServices.Web.csproj&amp;lt;/LinkedServerProject&amp;gt;&lt;/p&gt;  &lt;p&gt;Now when you open up the module project properties dialog you’ll see the correct .NRS link in place:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismAnd.NetRIAServices_C009/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismAnd.NetRIAServices_C009/image_thumb_1.png" width="452" height="82" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The next step is to include the right assembly references in the Web and the Prism Module and Shell projects. For the Web project, add references to the .NRS DataAnnotations, DomainServices, and Web.Ria assemblies – Note that the .NRS version of the DataAnnotations assembly is marked as version 99.0.0.0 (don’t know why but I’m sure this is temporary). For the module and shell projects add references to the .NRS DataAnnotations and Windows.Ria assemblies.&lt;/p&gt;  &lt;p&gt;Everything should now compile ok. If you view all files in the module projects you‘ll see a new folder called ‘Generated_Code’. This is where .NRS will generate or copy the code that will allow us to interact with the corresponding services.&lt;/p&gt;  &lt;p&gt;The next step is to implement the services themselves and the client-side app logic to consume them. This step is pretty straightforward and follows the many tutorials out there on .NRS (like Brad Abrams’ great &lt;a href="http://blogs.msdn.com/brada/default.aspx" target="_blank"&gt;series&lt;/a&gt; on .NRS) so I’m not going to go into the details here (this post is long enough already). I will however summarize the process and call out a few interesting points along the way.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;To implement the Catalog Service, we add an ADO.Net Entity Data Model that pulls in the Northwind Category and Product tables. We then add a Domain Service class that defines the queries on top of that data model – one for all products, one for all categories, and one for a specific product by ID. The Product entity queries include the corresponding Category entities so that the client doesn’t have to make a separate query for category information.      &lt;br /&gt;&lt;/li&gt;    &lt;div id="codeSnippetWrapper"&gt;     &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;       &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IQueryable&amp;lt;Product&amp;gt; GetProductById( &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; productId )&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #008000"&gt;// Include the category in the product query.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Context.ProductSet.Include( &lt;span style="color: #006080"&gt;&amp;quot;Categories&amp;quot;&lt;/span&gt; ).&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        Where( product =&amp;gt; product.ProductID == productId );&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;

    &lt;br /&gt;&lt;/div&gt;

  &lt;li&gt;The Order Service is implemented in the same way except that the data model pulls in the Northwind Order, Order Details and Product tables. Again, the Order entity queries include the Order Details entities so the client doesn’t have to make a separate query for each Order line item. The Order Detail includes the Product name (rather than the entire Product entity).&lt;/li&gt;

  &lt;li&gt;As you create the ADO.NET Entity Data Models and the Domain Services for each service, an App.Config file is generated which contains the database connection string. You have to copy this connection string to the Web projects Web.config file. This allows the host web application to provide the connects to the databases that the hosted services projects need. Don’t forget to do this otherwise your services won’t be able to connect to the database and it can be difficult to track down the problem (experience talking here!).&lt;/li&gt;

  &lt;li&gt;In addition to including related entities in the data query, you have to provide meta-data to .NRS to tell it to serialize the related entities over to the client. You do this by creating a meta-data class that is associated with the entity class and adding an entry with an [Include] attribute:
    &lt;br /&gt;&lt;/li&gt;

  &lt;div id="codeSnippetWrapper"&gt;
    &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;[MetadataType( &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;( ProductMetadata ) )]&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Product&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sealed&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ProductMetadata&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        [Key]&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; ProductID;&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        [Include]&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Category Categories;&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

      &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
  &lt;/div&gt;

  &lt;div&gt;&amp;#160;&lt;/div&gt;

  &lt;li&gt;The sample shows how you can use .NRS and the client-side classes that it generates to implement the ViewModel pattern. On the client side, .NRS generates classes for the Product, Category, Order, and Order Details entities and for the Service Context classes that provide access to the services themselves. You’ll see that these classes effectively replace the Model and Services classes that were included in the Prism Quick Start Solution. Each Prism module implements one or two ViewModels which use the service context classes to query data via the server. The entities themselves are considered Models. The ViewModel coordinates the query and selection of entities so that the Views can simply data bind to them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The sample application is pretty simple. It’s meant to show how to structure a solution that uses Prism and .NRS together. It does not show how to use some of the more advanced features of .NRS, like data updates and application services for authentication and authorization. I’ll cover those in a future post…&lt;/p&gt;

&lt;p&gt;The sample also uses some of the cool new Silverlight 3.0 features, such as the PagedCollectionView class and some of the new easing functions (for the compulsory gratuitous animation!) and many of the ‘standard’ Prism features, like the RegionManager, EventAggregator, ModuleCatalog, etc.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;.NRS provides a simple way to create data services on top of a database and to expose data entities to the Silverlight client where you can perform CRUD operations on them. Coupled with Prism, it allows you to build flexible applications that compose data services into an rich user experience. To be sure, .NRS isn’t the only way to build and consume data services, and it isn’t suitable for all types of applications, but for some applications it can be very productive and effective.&lt;/p&gt;

&lt;p&gt;A couple of words of caution though. While .NRS is technically independent of the data access technology used, it does make it rather too easy to simply expose tables from your database directly to the client. You will have to &lt;em&gt;very&lt;/em&gt; careful not to couple your client application to your database by inadvertently exposing your database schema via the services. To avoid this, you should think first and foremost about the data model that you’re going to expose as a service to the client, and &lt;em&gt;then&lt;/em&gt; worry about how that maps to persistent storage.&lt;/p&gt;

&lt;p&gt;I would also be careful when using the .NRS DomainDataSource component. You can use this to connect your UI directly to the .NRS data services but I think it does mean that you’re implementing, in some sense, application logic directly in the View where it is difficult to test. Personally I’d rather do this kind of thing in the ViewModel where I can unit test it. YMMV though.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9873200" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/ViewModel/default.aspx">ViewModel</category><category domain="http://blogs.msdn.com/dphill/archive/tags/.NET+Ria+Services/default.aspx">.NET Ria Services</category></item><item><title>Prism Quick Start Kit Update</title><link>http://blogs.msdn.com/dphill/archive/2009/06/15/prism-quick-start-kit-update.aspx</link><pubDate>Mon, 15 Jun 2009 20:36:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9754187</guid><dc:creator>dphill</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9754187.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9754187</wfw:commentRss><description>&lt;p&gt;As promised, I have updated the Prism Quick Start Kit and added a WPF quick-start solution and WPF project templates. You can download the latest release &lt;a href="http://dphill.members.winisp.net/download/PrismQuickStartKit-0.2.zip"&gt;here&lt;/a&gt;. In the zip you’ll find four project templates (Shell and Module templates for WPF and Silverlight) and two quick-start solutions, one each for WPF and Silverlight.&lt;/p&gt;  &lt;p&gt;To install the templates, copy the project template zip files to your Visual Studio C# template folder. On my system the templates go here:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;“My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C#”&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You should also remove the previous Prism templates if you have installed them. Next, register the templates with Visual Studio by running&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;devenv.exe /installvstemplates&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;in a Visual Studio command prompt window (as admin). &lt;/p&gt;  &lt;p&gt;When you run Visual Studio and create a new project, you should see the four templates show up in the Visual C# node.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKitUpdate_8735/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKitUpdate_8735/image_thumb.png" width="470" height="90" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Using the Prism project templates should be pretty straightforward. Couple of things to note though:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;When you create a project with any of these templates you should first of all update the references to point to the Prism assemblies on your system. The quick-start solutions come complete with a Lib folder that contains pre-built Prism binaries so they work out of the box for convenience, but you should try and use the Prism binaries on your system where you can.&lt;/li&gt;    &lt;li&gt;You will of course need the Silverlight Visual Studio tools to be installed before you can use any of the Silverlight project templates or the quick-start solution. See &lt;a href="http://silverlight.net/GetStarted/"&gt;here&lt;/a&gt; for more information on getting started with Silverlight development.&lt;/li&gt;    &lt;li&gt;The WPF shell project comes complete with a module catalog that looks for modules in the local output folder. If you add a WPF module to your project you will have to copy the output module assembly to the shell’s bin/Debug or bin/Release folder. I use a post-build step on each module project to automatically copy the assemblies over after every build:     &lt;br /&gt;      &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKitUpdate_8735/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKitUpdate_8735/image_thumb_2.png" width="470" height="243" /&gt;&lt;/a&gt;      &lt;br /&gt;You’ll need to update this with the name of your shell project.&amp;#160; You can achieve the same thing by simply adding project reference to your modules projects and then Visual Studio will copy over the assemblies for you, but since Prism advocates a&amp;#160; loosely-coupled composite architecture this seems like cheating to me :-).&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The Silverlight and WPF quick-start solutions are essentially the same – the only difference between the two is that the WPF shell includes a menu-like button that’s hooked up the shell’s Exit command. I also updated the quick-start solutions to include a style that can be applied to ContentControl regions so that a banner containing the region name is displayed. This is just to make it easier for folks to see where each region is located within the shell.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKitUpdate_8735/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKitUpdate_8735/image_thumb_1.png" width="454" height="315" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The quick-start solutions are meant to provide a skeletal solution on which you can build real application. They are not very interesting as a standalone app, but if you’re curious to see what it looks like you can run the Silverlight version of the quick-start solution &lt;a href="http://dphill.members.winisp.net/Quickstart/Default.html"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9754187" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Patterns+and+Practices/default.aspx">Patterns and Practices</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Prism Training Course</title><link>http://blogs.msdn.com/dphill/archive/2009/06/08/prism-training-course.aspx</link><pubDate>Mon, 08 Jun 2009 20:06:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9708513</guid><dc:creator>dphill</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9708513.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9708513</wfw:commentRss><description>&lt;p&gt;David Platt of Rolling Thunder has just announced another 3 day Prism training course to be held July 7th-9th. You can find all of the details &lt;a href="http://rollthunder.com/Prism/PrismPublicClass.htm"&gt;here&lt;/a&gt;. It’s web delivered so you don’t even have to travel!&lt;/p&gt;  &lt;p&gt;It looks like it covers a lot of material – there’s a detailed syllabus &lt;a href="http://rollthunder.com/Prism/PrismDetailSyllabus.htm"&gt;here&lt;/a&gt; – from the basic goals and architecture of Prism, all the way through to advanced scenarios with modules, services, loosely-coupled events, and UI composition.&lt;/p&gt;  &lt;p&gt;If you’re looking to use Prism to increase the quality of your WPF &amp;amp; Silverlight applications and to speed up your development it’s definitely worth checking it out.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9708513" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Prism Quick Start Kit</title><link>http://blogs.msdn.com/dphill/archive/2009/05/29/prism-quick-start-kit.aspx</link><pubDate>Sat, 30 May 2009 02:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9661173</guid><dc:creator>dphill</dc:creator><slash:comments>16</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9661173.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9661173</wfw:commentRss><description>&lt;P&gt;Building applications from scratch starting from a blank page or screen in Visual Studio is a frustrating, time consuming and intimidating task. Instead, most developers like to start with a working application that they can modify, tweak and extend to suit their needs.&lt;/P&gt;
&lt;P&gt;Far too often though, developers take a demo or a sample as the starting point for their application, and this often leads to a poor application design that’s complex, difficult to test and debug, and inflexible. Demos and samples have their place of course – they are great for illustrating a single concept or a cool new feature – but they are typically &lt;STRONG&gt;not&lt;/STRONG&gt; designed to provide a solid base for an entire application. &lt;/P&gt;
&lt;P&gt;Prism is a library of design patterns that work together to provide a solid architectural foundation on which you can build real-world Silverlight and WPF applications that are flexible and maintainable. Some of the patterns that Prism contains are fairly simple while others are more complex, but they are designed to work together to solve some of the challenges you face when building these real-world applications.&lt;/P&gt;
&lt;P&gt;We illustrate individual patterns using what we call ‘&lt;STRONG&gt;Quick-Starts&lt;/STRONG&gt;’ which are small focused sample applications. We illustrate how the patterns work together using what we call a ‘&lt;STRONG&gt;Reference Implementation&lt;/STRONG&gt;’, which is a large sample application that implements a real-world scenario (during development, we actually use the RI to help us figure out what challenges a developer faces when building a non-trivial real-world application, and from those challenges we distil the patterns that help to address them and then implement those patterns in a reusable library). For Prism, the RI is a Stock Trader application that allows you buy and sell stocks and to manage your portfolio.&lt;/P&gt;
&lt;P&gt;However, neither the Quick-Starts nor the Reference Implementation that we include in Prism are great for taking as a starting point for a new Prism application. The Quick-Starts are too fine-grained and focused on one specific pattern or technique, while the Reference Implementation is too coarse-grained and includes a lot of application logic that’s specific to the stock trader scenario.&lt;/P&gt;
&lt;H3&gt;The Prism Quick Start Kit&lt;/H3&gt;
&lt;P&gt;To help with this problem, we are considering building a number of solution and project templates for Visual Studio that would give you a simple working app that you could tweak and modify. These would fall somewhere in-between the Quick-Starts and Reference Implementation and provide a basic solution and project structure into which you could add your application specific files.&lt;/P&gt;
&lt;P&gt;I spent a couple of days this week prototyping this approach. I built a couple of project templates (one for a Prism Shell, and one for a Prism Module) and a solution template that provide a complete multi-module working app. You can download these templates from &lt;A href="http://dphill.members.winisp.net/download/PrismQuickStartKit-0.1.zip" mce_href="http://dphill.members.winisp.net/download/PrismQuickStartKit-0.1.zip"&gt;here&lt;/A&gt;. Together, these templates make up what I call the ‘Prism Quick Start Kit’.&lt;/P&gt;
&lt;H4&gt;Installation&lt;/H4&gt;
&lt;P&gt;Installation of the project templates is fairly straightforward:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Unzip the starter kit and copy the ‘Prism Shell.zip’ and ‘Prism Module.zip’ files into your Visual Studio templates folder. They are C# templates so they go here on my system: &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C# &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;To get Visual Studio to display the new project templates in the New Projects dialog, run the following command (as admin) in a Visual Studio Command Prompt window: &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; devenv.exe /installvstemplates &lt;BR&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H4&gt;Getting Started With The Prism Project Templates&lt;/H4&gt;
&lt;P&gt;To see the project templates in action, follow these steps:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Fire up Visual Studio, and click File/New/Web Site. Click on ASP.NET Web Site and enter ‘PrismApp’ as the folder name. This will create the web project that will host our Prism application.&lt;/LI&gt;
&lt;LI&gt;Next, right click on the PrismApp solution and selected Add/New Project. Select the ‘Visual C#’ project types node and you should see the Prism Shell and Prism Module templates in the My Templates section: &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb.png" width=370 height=60 mce_src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb.png"&gt;&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;Click on the Prism Shell template and then click on OK. This will create a Prism Shell project called ‘Prism.Shell1’.&lt;/LI&gt;
&lt;LI&gt;We need to tidy up the project references to point to the Prism and Unity assemblies. If you click on the References node you’ll probably see that these references need updating. If you’ve added these assemblies into your GAC then they should be ok, but if not, you’ll need to remove them and add them again by browsing to wherever you complied them on your system.&lt;/LI&gt;
&lt;LI&gt;Next, we need to link the Prism Shell project to the Web project. Right click on the web project and select Property Pages. Click on the Silverlight Applications node and then click the Add button. In the dialog, select the Prism Shell project and click Add then OK. &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_4.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb_1.png" width=400 height=333 mce_src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb_1.png"&gt;&lt;/A&gt;&amp;nbsp; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;This will link the Prism Shell project to the web project and create a test page. Right click on the Prism.Shell1TestPage.html page and select Set As Start Page. Press F5 and click Ok to enable debugging. You should see the Prism shell in all its glory: &lt;BR&gt;&lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_6.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb_2.png" width=400 height=410 mce_src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb_2.png"&gt;&lt;/A&gt; &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;The shell includes all of the basic things you typically need in a shell – a shell View and ViewModel, a bootstrapper and a module catalog. The shell’s UI includes a simple 3 region layout. [Eventually, you can imagine having a whole gallery of different shell layouts and themes to choose from…]&lt;/LI&gt;
&lt;LI&gt;The next step is to create a Prism module project. Right click on the PrismApp solution, select Add/New Project, choose the Prism Module project template and click OK. This will create a module project called ‘Prism.Module1’. The project template contains all of the basic things you need in a module – a View and ViewModel, a basic data model and a data service.&lt;/LI&gt;
&lt;LI&gt;We need to do the dance with the references as above. [We’ll hopefully figure out a way to make this experience much better in the future…]&lt;/LI&gt;
&lt;LI&gt;Next, link the module project with the web project as above, but this time make sure that the ‘Add a test page’ check box is unchecked – we don’t need a test page for the module. Click Add then OK. This step ensures that the module’s xap file gets copied to the web ClientBin folder.&lt;/LI&gt;
&lt;LI&gt;The last step is to add the module to the shell’s module catalog. Open the ModuleCatalog.xaml file and uncomment the first entry: &lt;BR&gt;&lt;/LI&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;prism:ModuleInfo&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Ref&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Prism.Module1.xap"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #ff0000"&gt;ModuleName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Module1"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #ff0000"&gt;ModuleType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Prism.Module1.ModuleInit, Prism.Module1, Version=1.0.0.0"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #ff0000"&gt;InitializationMode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="WhenAvailable"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;BR&gt;If you used a different name for the module, you’ll have to edit this to use the names that you chose.&lt;/DIV&gt;
&lt;LI&gt;When you press F5, you will see the module get loaded into the shell and the module’s view displayed in the shell’s main region. You’ll also notice that the module includes a simple data model that gives the UI something to display. You can take this as a starting point and modify to suit your needs.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_8.png" mce_href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_8.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb_3.png" width=400 height=410 mce_src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb_3.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;The Prism Quick Start Solution&lt;/H4&gt;
&lt;P&gt;I find the project templates described above pretty useful for creating new Prism projects, but there are way too many steps involved to make it a simple and clean experience. What I’d really like to do is to create a ‘Solution Template’ that includes all of the sub-projects and references all linked up and ready to go.&lt;/P&gt;
&lt;P&gt;Unfortunately Visual Studio doesn’t by itself allow this to be done easily. There are additional tools and frameworks available that enable this, but at this stage I wanted to keep it simple so the next best thing was to just create a baseline sample project that I can manually copy and modify whenever I want to build a Prism multi-module solution. I call this the ‘Prism Quick-Start Solution’.&lt;/P&gt;
&lt;P&gt;The baseline quick-start solution is the third zip file in the Prism quick-start kit. If you unzip it you’ll see that it contains Web and Shell projects, two Module projects and a ‘Common’ class library. The solution has all of these linked together and includes the Prism and Unity assembly so that you don’t have to fix up any references. In other words, you can unzip it and go!&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_10.png" mce_href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_10.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb_4.png" width=500 height=464 mce_src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismQuickStartKit_BBD9/image_thumb_4.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;If you run the app or examine the code, you’ll see that it contains a little more functionality than you get by just using the project templates described above. This is because, in a typical Prism application, there are a couple of common things that you need to do to coordinate the functionality between the Shell and the multiple Modules.&lt;/P&gt;
&lt;P&gt;An example of this is when you implement loosely-coupled events between modules to coordinate context or user actions. The quick-start solution shows how to implement simple cross-module master-detail functionality – when you click on the Master View (from Module 1), the Catalog View (from Module 2) will update. This also shows how you typically coordinate data and context across two modules…&lt;/P&gt;
&lt;P&gt;Another example is the use of a Controller class to programmatically coordinate the display of Views in a region in order to implement navigation or application workflow. The quick-start solution uses a controller class to programmatically display views in the main region when the user clicks on buttons in the master view.&lt;/P&gt;
&lt;P&gt;The quick-start solution is meant to provide a basic structure for a Prism app and to include the most commonly used features of Prism. I find it very useful as a starting point because it contains all of the little code snippets and that you often need and has a basic structure in place making it pretty straightforward to take it and modify it to create many different types of applications. It’s hopefully also a good place to experiment with Prism and to learn about some of its basic features.&lt;/P&gt;
&lt;P align=center&gt;oO------Oo&lt;/P&gt;
&lt;P&gt;I hope you find these templates useful. We’re hoping to provide templates like these in Prism 3.0 but we’d also like to provide item templates, code snippets and some simple in-tool automation to make building Prism apps really simple and straightforward. Let me know what you think, and whatever else you’d like to see in Prism 3.0…&lt;/P&gt;
&lt;P&gt;Download the Prism Quick Start Kit &lt;A href="http://dphill.members.winisp.net/download/PrismQuickStartKit-0.1.zip" mce_href="http://dphill.members.winisp.net/download/PrismQuickStartKit-0.1.zip"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9661173" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Patterns+and+Practices/default.aspx">Patterns and Practices</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>ViewModel and Dependency Injection</title><link>http://blogs.msdn.com/dphill/archive/2009/05/18/viewmodel-and-dependency-injection.aspx</link><pubDate>Mon, 18 May 2009 22:28:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9625816</guid><dc:creator>dphill</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9625816.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9625816</wfw:commentRss><description>&lt;p&gt;In my last post – &lt;a href="http://blogs.msdn.com/dphill/archive/2009/04/28/silverlight-navigation-part-3.aspx"&gt;Silverlight Navigation Part 3&lt;/a&gt; – I outlined a mechanism whereby you could navigate to a View and have the application create and wire up the associated ViewModel automatically. I also showed the inverse of this, where you could navigate to a ViewModel and have the application automatically create and wire up the associated View automatically.&lt;/p&gt;  &lt;p&gt;Whether you prefer the View-First or the ViewModel-First approach, the essential feature that really supports the ViewModel pattern is that the system should be able to create a ViewModel for a View (or vice versa) automatically. Otherwise, the burden falls to the developer to do this in code, which can result in a complicated architecture that’s either inflexible or difficult to understand and maintain.&lt;/p&gt;  &lt;p&gt;Let’s say, for example, that you have adopted a View-First approach. Now, you could just have some code in your application (say, in a controller component or event handler somewhere) that simply creates the required View and it’s associated ViewModel and wires them together like this:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ShowCustomer()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    CustomerView view = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomerView();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    CustomerViewModel viewModel = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomerViewModel();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    view.DataContext = viewModel;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    myContentControl.Content = view;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You can use this approach with a ViewModel-First approach too. Another simple approach is to just get the View to create its own ViewModel, either in its constructor:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CustomerView : UserControl&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CustomerView()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        InitializeComponent();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DataContext = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomerViewModel();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;or via XAML:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl.DataContext&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;CustomerViewModel&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl.DataContext&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;All three of these approaches work great, except that they hard code your application to use specific View and ViewModel types. This may very well not be an issue for you, and if it isn’t, I say go for it!&lt;/p&gt;

&lt;p&gt;However, there are times when you’ll want to have the View and the ViewModel types more loosely coupled. An example might be when you want to decide at run-time which View to display for a particular ViewModel based on, say, the user’s role, chosen UI theme, screen size, or even the type of device that the user is using(!). So, while the approaches above are simple, they are relatively inflexible.&lt;/p&gt;

&lt;h3&gt;Dependency Injection To The Rescue?&lt;/h3&gt;

&lt;p&gt;It is at this point that the Dependency Injection folks will start to gesticulate wildly and remind us that this is &lt;em&gt;exactly&lt;/em&gt; the situation in which DI excels. Remember that with DI, if you have a dependency between one class and another, the system (i.e. the DI container) can automatically fulfill that dependency dynamically at run-time for you. This allows the classes to be more loosely coupled and removes the need for you to manage the creation of dependent classes yourself. Let’s see how this works…&lt;/p&gt;

&lt;p&gt;Say we have a class ‘A’ that depends on (i.e. has a reference to) a class ‘B’. Typical DI containers (including Unity) require that we express the dependency between A and B using a type – typically (but not necessarily) an intermediate interface type, say IB – and that we define a constructor on A that takes a reference to that type. We then register our implementation of the intermediate interface type with the container – so that it knows that whenever anybody wants an implementation of IB it will create an instance of B.&lt;/p&gt;

&lt;p&gt;So, when we want an instance of class A, we just ask the container to create one for us. It spots that class A requires a reference to an IB implementation, so it goes and creates a B for us automatically and passes a reference to it to A’s constructor. The container manages the creation of dependent classes for us!&lt;/p&gt;

&lt;p&gt;It is of course true that in many situations DI is a good solution for this kind of problem. I think though, that for the ViewModel scenario DI is not ideal. To illustrate why, let’s see how DI typically works in View-First and ViewModel-First scenarios…&lt;/p&gt;

&lt;h4&gt;The Perils of IViewModel&lt;/h4&gt;

&lt;p&gt;In our View-First example above, we have a View that wants a reference to (depends on) a ViewModel, so we’d first register an implementation of our ViewModel with the container:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;_container.RegisterType&amp;lt;ICustomerViewModel, CustomerViewModel&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;and we’d design the View so that it gets a reference to the ViewModel implementation in its constructor:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CustomerView( ICustomerViewModel viewModel )&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DataContex = viewModel;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Finally, we’d get the container to create an instance of the View. The container will automatically create an instance of the registered ViewModel type and pass a reference to it into the View’s constructor.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;CustomerView view = _container.Resolve&amp;lt;CustomerView&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Ok this works, but I think there are a number of problems with this approach:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;To create the View we have to use the DI container. We can’t just create the View using ‘new’ and we can’t create it declaratively via XAML (since that will use the default constructor which won’t pass in a reference to the required ViewModel). In other words, we have to have a controller or event handler or some code somewhere that creates the View via the container by calling Resolve.&lt;/li&gt;

  &lt;li&gt;The UI designer (even if the UI designer is really a developer) should not have to write code in the View just to make it work. If there is some complicated UI behavior that can’t be done declaratively, then code &lt;em&gt;may&lt;/em&gt; be required, but this should be a special case and not required every time just to get stuff wired up and working. Even implementing the simple constructor above takes some explanation and can be easily forgotten or incorrectly implemented. &lt;/li&gt;

  &lt;li&gt;We have defined a ‘marker’ interface type that we don’t really need – i.e. the interface has no properties or methods, we’re just using it as a marker. Yes, we &lt;em&gt;could&lt;/em&gt; define some properties and method on it, but the View should not be programmatically calling into the ViewModel. Remember, UI designers should not have to write any code. All interactions between View and ViewModel should be done via bindings and attached behaviors so that the View is just a loosely coupled observer of the ViewModel. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;The Evils of IView&lt;/h4&gt;

&lt;p&gt;So that’s Dependency Injection in a View-First world. What about a ViewModel-First world? Well, things are no better here either. Similar to the process outlined above, we’d probably define an IView interface; register an implementation of it with the container; define a constructor on the ViewModel that accepts an IView reference; then create an instance of the ViewModel using the container:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;_container.RegisterType&amp;lt;ICustomerView, CustomerView&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CustomerViewModel( ICustomerView view )&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    ((FrameworkElement)view).DataContext = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;CustomerViewModel viewModel = _container.Resolve&amp;lt;CustomerViewModel&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Again, a couple of problems with this approach:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Again, we can’t create a View declaratively using XAML – the container will create the View as a result of creating an instance of the ViewModel class – so we’d have to have a controller or event handler or some code somewhere to kick things off. &lt;/li&gt;

  &lt;li&gt;We’d have a marker interface that we’d don’t really need and that won’t define any properties or methods – the ViewModel should &lt;strong&gt;not&lt;/strong&gt; be programmatically calling into a View. &lt;/li&gt;

  &lt;li&gt;The UI designer would have to implement an interface on the View each and every time they create one. It’s not terribly complicated, but the UI designer should not be required to write any code except for advanced scenarios. &lt;/li&gt;

  &lt;li&gt;The ViewModel-First approach is actually slightly worse that the View-First approach because of the nasty cast in the constructor. This is required in order to set the view’s data context to the ViewModel. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Wouldn’t It Be Nice If…&lt;/h3&gt;

&lt;p&gt;In my last post on navigation, I showed a couple of different approaches to the problem of conjuring up a View for a ViewModel (or vice versa) without using a Dependency Injection approach.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For View-First, instead of using DI and defining interfaces and constructors, I just used an attached property on the View to specify the type name of the ViewModel (ViewModel.TypeName) and the system automatically constructed the ViewModel for me and wired it up to the View’s DataContext.&lt;/li&gt;

  &lt;li&gt;Going the other way (ViewModel-First) , I just used a naming convention to infer the name of the View from the ViewModel’s type name, created an instance of that View and set it’s DataContext.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Neither of these approaches are ideal though, so I got to thinking what an ideal approach might look like… The key is that we need a simple way of expressing the relationship between the View and the ViewModel types so that the system can just make the right things happen!&lt;/p&gt;

&lt;p&gt;If you’re familiar with DataTemplates in WPF, you know that it’s possible to define a DataTemplate (somewhere in the application’s resources) for a particular (non UI) type. Whenever the system has to display an object of that type, the DataTemplate is automatically used to visually represent it. Under the covers, the system creates an instance of the DataTemplate, sets its DataContext to the object that it represents, and then displays it in the UI. Silverlight does not yet support implicit data templating – you have to specify the DataTemplate explicitly for each control – but the mechanism is very similar.&lt;/p&gt;

&lt;p&gt;I think this is close to what we want…&lt;/p&gt;

&lt;p&gt;I think of DataTemplates simply as “Thin Views” – i.e. purely declarative Views with no code behind. They are very useful, but sometimes you just need to have some code in the View (for complex visual behavior that can’t be done declaratively). So, if the system could be extended to include Views that could have code behind, it would all fit together in a nice, simple, consistent model. It could look something like this…&lt;/p&gt;

&lt;p&gt;We define a View as usual and simply declare that it is associated with a ViewModel data type:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;UserControl x:Class=&amp;quot;MySample.CustomerView&amp;quot;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;             DataType=&amp;quot;{x:Type MySample.CustomerViewModel}&amp;quot;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;For the ViewModel-First approach, we simple create (or navigate to) an instance of the ViewModel and display it. For example,&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;MyContentControl.Content = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomerViewModel();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The system would then step in and create an instance of the View that corresponds to this type and would wire up the DataContext for us – just like the system does today with DataTemplates!!!&lt;/p&gt;

&lt;p&gt;Similarly, for View-First, where we simply create (or navigate to) a View, the system would automatically create an instance of the associated ViewModel type for us and wire up the DataContext. There would likely be another property to control this behavior.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;I think this approach has a number of benefits:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The system carries the burden of finding and creating corresponding Views and ViewModels, making our application code much, much simpler. And simpler means that it’s faster to write, easier to debug, and easier to unit test!&lt;/li&gt;

  &lt;li&gt;It gives us a single consistent model that works for Views &lt;strong&gt;with&lt;/strong&gt; and &lt;strong&gt;without&lt;/strong&gt; code behind.&lt;/li&gt;

  &lt;li&gt;It works declaratively as well as programmatically giving us a lot of freedom to create Views or ViewModels in code or in XAML as desired. It works great with navigation too.&lt;/li&gt;

  &lt;li&gt;It allows Views to express a dependency on a particular ViewModel, while allowing ViewModels to remain completely View agnostic. This opens up a whole host of interesting design-time tooling possibilities – like you get with DataTemplates today – but with more explicit support for the ViewModel pattern. For example, you can imagine that the UI designers can provide intelli-sense or drag &amp;amp; drop support for binding expressions and behaviors (because the design-time system can determine the ViewModel’s commands, notifications and properties).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You’ll have noticed that we’re not using an intermediate interface type to loosely couple the View and ViewModel. The approach could be extended to support that though, for example by using the upcoming Managed Extensibility Framework (MEF), or by building in some form of simple Dependency Injection mechanism into the XAML loader system.&lt;/p&gt;

&lt;p&gt;Until I prototype this approach more fully, it’s not clear whether it will &lt;em&gt;really&lt;/em&gt; work as well as expected. Also, it’s not clear at this stage when (or if) we could expect it this approach to be implemented in the platform.&lt;/p&gt;

&lt;p&gt;We can but dream though…&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9625816" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Patterns+and+Practices/default.aspx">Patterns and Practices</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Helix/default.aspx">Helix</category><category domain="http://blogs.msdn.com/dphill/archive/tags/ViewModel/default.aspx">ViewModel</category></item><item><title>Silverlight Navigation Part 3</title><link>http://blogs.msdn.com/dphill/archive/2009/04/28/silverlight-navigation-part-3.aspx</link><pubDate>Tue, 28 Apr 2009 23:45:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9574249</guid><dc:creator>dphill</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9574249.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9574249</wfw:commentRss><description>&lt;p&gt;Welcome to the third post in my series on navigation in Silverlight! The goal of this series of posts is to provide a simple to use framework (called Helix) for building Silverlight applications that are based on a flexible navigation mechanism and the ViewModel separated presentation pattern. This post is long and was a tough one to write (which is partly why it took so long to complete!) but this post takes us much closer to our goal.&lt;/p&gt;  &lt;p&gt;If you’ve been reading this series from the beginning, you’ll have noticed that we’re taking something of an agile approach to building Helix. You can think of each post in this series as an iteration. And like all good agile projects, we’re not afraid of a bit of refactoring, or of adding or significantly altering features as we tackle new scenarios. So in the latest version of Helix you’ll find some changes compared the version in part 2.&lt;/p&gt;  &lt;p&gt;Some of these changes are bug fixes, but most are new features or extensions to existing features to support the ViewModel pattern alongside navigation. You’ll also find more samples and unit tests in this drop. There is a summary of the main changes and new features at the end of this post. You can download the latest release from &lt;a href="http://dphill.members.winisp.net/Download/Helix-Navigation-0.3.zip" target="_blank"&gt;here&lt;/a&gt; and you can run all of the latest samples from &lt;a href="http://dphill.members.winisp.net" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;The Story So Far…&lt;/h3&gt;  &lt;p&gt;Before we get into any details, let’s quickly review what we’ve covered in previous posts…&lt;/p&gt;  &lt;p&gt;In the first &lt;a href="http://blogs.msdn.com/dphill/archive/2008/10/07/silverlight-navigation-part-1.aspx"&gt;post&lt;/a&gt; in the series, I introduced the Helix Frame and NavigationLink controls and showed how they could be used together with a simple Journal to implement a simple navigation mechanism between pages in a Silverlight 2.0 application.&lt;/p&gt;  &lt;p&gt;In the second &lt;a href="http://blogs.msdn.com/dphill/archive/2008/11/02/silverlight-navigation-part-2.aspx"&gt;post&lt;/a&gt; in the series, I introduced the Route, NavigationHandler and NavigationController classes and demonstrated how they can be used to implement navigation between pages based on parameterized navigation links. That post also showed two ways of passing parameters via the navigation link to the target page, so that the page can be initialized or have it's context set appropriately.&lt;/p&gt;  &lt;p&gt;One way was to use the NavigationPageController class which passes all of the navigation parameters to the target page's OnNavigate method (through the INavigationPage interface). The other way was to use the PageActionController class which invokes a page action method on the target page by mapping the navigation parameters to the method's name and it's parameters.&lt;/p&gt;  &lt;p&gt;Both of these approaches created an instance of the target page and then passed the navigation parameters directly to it. As noted in the second post, this is clearly not ideal since it means that the page will then contain application logic as well as UI – not good for a lot of reasons!!!&lt;/p&gt;  &lt;p&gt;Separated presentation patterns like the ViewModel pattern help to keep the UI and application logic cleanly separated. I described the ViewModel pattern in a previous &lt;a href="http://blogs.msdn.com/dphill/archive/2009/01/31/the-viewmodel-pattern.aspx"&gt;post&lt;/a&gt;, but to recap, the ViewModel pattern separates UI and presentation logic into View and ViewModel classes, and uses data binding and commands to communicate between them. In &lt;a href="http://blogs.msdn.com/dphill/archive/2009/02/11/collectionviewmodel.aspx"&gt;this&lt;/a&gt; post, I provided an implementation of a generic ViewModel for handling collections, imaginatively called CollectionViewModel. In this &lt;a href="http://blogs.msdn.com/dphill/archive/2008/12/05/ui-composition-patterns.aspx"&gt;post&lt;/a&gt;, I described two strategies in which the View and the ViewModel can get created and linked up. In View-First composition, the view is logically created first. In Presenter-First composition, the presenter (the ViewModel is our case) is logically created first.&lt;/p&gt;  &lt;p&gt;These three additional posts can be considered parts 2a, 2b and 2c of this series, so please check them out if you haven't already done so. We’ll be building on the concepts and features they describe in this post.&lt;/p&gt;  &lt;p&gt;Ok, that’s the background information out of the way. Let’s get started extending the Helix navigation framework so that it works alongside the ViewModel separated presentation pattern…&lt;/p&gt;  &lt;h3&gt;The Challenge: Mixing ViewModels and Navigation&lt;/h3&gt;  &lt;p&gt;One of the challenges with any separated presentation pattern is that you have to have some way of creating, hooking up and managing the additional components that are involved. In our preferred ViewModel pattern these additional components are principally Views, ViewModels and Models.&lt;/p&gt;  &lt;p&gt;Now, if your application is fairly static, it’s fairly straightforward to create and hook up these components. But if your application is more dynamic (for example, when the UI changes constantly because the user is navigating around within the application!) then things are not quite so simple. As well as creating and hooking up these components during navigation, we also have to figure out how the other parts of the application are going to interact and communicate with them.&lt;/p&gt;  &lt;p&gt;In my experience, this issue – the handling of Views, ViewModels and Models in a dynamic application that includes navigation – is the one that causes the most confusion and pain for folks building real-world applications using the ViewModel pattern. It is this very issue that we’re going to tackle in this post…&lt;/p&gt;  &lt;h4&gt;Choosing A Navigation Scheme&lt;/h4&gt;  &lt;p&gt;Before we get into the details on the integration of the ViewModel pattern into the Helix navigation framework, we first have to think about the different ways in which we can structure our application so we can and navigate around within it.&lt;/p&gt;  &lt;p&gt;Helix essentially allows you to design a &lt;strong&gt;navigation scheme&lt;/strong&gt; for your application by allowing you to decide how the various elements in your application are linked together by parameterized Uri's. When you define the format of the navigation links in your application, you are designing the way in which the user will navigate through your application to access its functionality and content by identifying the main navigational elements in your application and identifying which parameters are passed to them. At a high level, there are two basic navigation schemes to choose from.&lt;/p&gt;  &lt;p&gt;Perhaps the simplest navigation scheme is one where the application's navigational links refer directly to the application's visual elements. Using this scheme means that we'll link the application together using Uri's that refer to pages or controls within the application and allow the user to navigate between them. This is the navigation scheme that we used in the last two posts of the series. I think this type of navigation scheme tends to work great for &lt;strong&gt;content-centric&lt;/strong&gt; applications – i.e. when the user &lt;em&gt;expects&lt;/em&gt; to be primarily navigating through &lt;em&gt;content&lt;/em&gt;. Blog readers, news readers, and media sharing apps are good examples of this type of application. &lt;/p&gt;  &lt;p&gt;With Helix you are not limited to using simple page-based navigation schemes. You can link your application together in other interesting ways. In particular, you can structure your application so that it's composed of tasks or actions that the user carries out. I call these types of applications &lt;strong&gt;task-centric&lt;/strong&gt; applications.&lt;/p&gt;  &lt;p&gt;Let's look at a simple example – an expense reporting application. In terms of tasks, the user can create, edit, submit, approve, reject, or archive expense reports, so we could structure our application so that the user naturally navigates between these tasks in sequences that are natural. For example, the user may start by creating a new expense report and then submit it for approval; then they may edit a draft expense report and save it for later submission; then they may review their approved expense reports and archive them away for safe keeping.&lt;/p&gt;  &lt;p&gt;I think this type of navigation scheme is very interesting. It means for instance, that we can align our application’s navigational structure with the application's use-cases and the user’s tasks, rather than having to strictly follow the visual structure of the application. This means that we can more cleanly separate the visual structure of the application from its logical structure and work flow, which in turn means that we can more easily test the application, and have more flexibility when designing a fluid, animated UI for it. In addition, when we consider &lt;strong&gt;deep linking&lt;/strong&gt; (in a future post) we'll see that the user, or other systems, very often will be exposed to the navigational structure of the application, so having a navigation scheme that’s independent of the visual structure can also be important for many other reasons.&lt;/p&gt;  &lt;p&gt;At this point you might be asking: “Yes, but does it really matter what the navigational scheme for an application is since the user never sees it – they just click on links and the UI gets updated?”. This is of course true, up to a point. It’s not clear that one approach is superior to the other – I can see advantages and disadvantages with each – so we’ll explore both approaches to see what each feels like when building an application.&lt;/p&gt;  &lt;p&gt;Whatever your choice of navigation scheme, content-centric or task-centric, the important thing is that you are comfortable with it and use it consistently throughout your application. Using multiple schemes within the same application can lead to user confusion and an application that’s difficult to maintain or extend. Choosing a navigational scheme that's natural for your application will help you build, test and extend it &lt;em&gt;much&lt;/em&gt; more easily and will help to make it easier to use, so it’s important to design your navigation scheme wisely and to stick to it.&lt;/p&gt;  &lt;h4&gt;Ah, But What About The ViewModel?&lt;/h4&gt;  &lt;p&gt;Regardless of the navigation scheme, things get even more interesting when we introduce the ViewModels pattern into the navigational picture. Using the ViewModel pattern means that we'll have a component that encapsulates the UI (the View), and a component that encapsulates the presentation logic and state (the ViewModel). My post &lt;a href="http://blogs.msdn.com/dphill/archive/2009/01/31/the-viewmodel-pattern.aspx" target="_blank"&gt;here&lt;/a&gt; describes the ViewModel pattern in some detail.&lt;/p&gt;  &lt;p&gt;The View and the ViewModel have to get created and hooked up together and this can happen in one of two ways – the view is either logically created first followed by the ViewModel on which is depends, &lt;em&gt;or&lt;/em&gt; the ViewModel is logically created first followed by the View on which it depends. I call these two mechanisms &lt;strong&gt;View-First&lt;/strong&gt; or &lt;strong&gt;ViewModel-First&lt;/strong&gt; composition respectively – see my post &lt;a href="http://blogs.msdn.com/dphill/archive/2008/12/05/ui-composition-patterns.aspx" target="_blank"&gt;here&lt;/a&gt; for more details.&lt;/p&gt;  &lt;p&gt;Now – and this is a key point – if you think about a &lt;strong&gt;content-centric&lt;/strong&gt; navigation scheme as described above, you'll see that this maps very naturally to &lt;strong&gt;View-First&lt;/strong&gt; composition! The user is logically navigating to a View so we construct the View first, followed by the ViewModel on which it depends and that provides a clean separation between UI and presentation logic.&lt;/p&gt;  &lt;p&gt;On the other hand, with a task-centric navigation scheme, the user is logically navigating to a component that manages an activity or task. This component (as we'll see below) maps quite naturally to a ViewModel, so logically we're creating the ViewModel first, followed by the View on which it depends so that it can be visually represented in the UI. In other words, &lt;strong&gt;task-centric&lt;/strong&gt; navigation maps naturally to &lt;strong&gt;ViewModel-First&lt;/strong&gt; composition!&lt;/p&gt;  &lt;p&gt;So, we can clearly identify two distinct navigational styles:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;View-First Navigation&lt;/strong&gt; – Where the user navigates between Views in a content-centric application, &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;ViewModel-First Navigation&lt;/strong&gt; – Where the user navigates between ViewModels that represent tasks or activities within the application. &lt;/li&gt; &lt;/ul&gt;  &lt;div style="border-bottom: #808000 thin solid; border-left: #808000 thin solid; padding-bottom: 1px; background-color: #c8b793; margin: 12px; padding-left: 8px; padding-right: 8px; vertical-align: top; border-top: #808000 thin solid; border-right: #808000 thin solid; padding-top: 1px"&gt;Interestingly, you can also see the correlation between &lt;strong&gt;content-centric navigation and view-first composition&lt;/strong&gt;, and &lt;strong&gt;task-centric navigation and presenter-first composition&lt;/strong&gt;, in ASP.NET web applications.     &lt;p&gt;With traditional ASP.NET web applications, the application consists of a number of pages that are linked together by simple Uri's. In other words, the navigational structure of the application is based on visual elements linked together. With ASP.NET WebForms, the pages can be richly defined using server-side controls, client-side AJAX controls, and with MasterPages and so on, but the navigational structure is always based on pages and the ASP.NET runtime will create the pages as you navigate to them. You may optionally choose to separate the presentation or business logic from the UI by using an MVP pattern, but in this case, the Presenter will be constructed by the page itself.&lt;/p&gt;    &lt;p&gt;On the other hand, using ASP.NET's MVC framework, we can define a navigational scheme that follows the logical structure of our application and that is independent of the visual pages within the application. By defining suitable navigation routes we will logically navigate to a controller component which then allows us to create a suitable view and hook it up to a data model component. We technically have &lt;em&gt;controller-first&lt;/em&gt; composition, but hopefully you can see that this is the moral equivalent of constructing a ViewModel before the View.&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;In this latest drop of Helix, I’ve added support for both View-First navigation and ViewModel-First navigation by implementing a navigation controller for each. The rest of the Helix architecture remains essentially the same (though there are some new features and some fixes as detailed at the end of this post). Remember, you can always implement a custom controller if you want to change the implementation that’s described below.&lt;/p&gt;  &lt;p&gt;Instead of walking through the implementation of these controllers, it’s probably more useful to walk through a sample application for each navigation style so you can see how they are both put together. In the examples below, I’m also using some of the new and improved features in Helix that are common to both styles of navigation.&lt;/p&gt;  &lt;p&gt;Ok, enough theory, let’s see some code!&lt;/p&gt;  &lt;h3&gt;View-First Navigation&lt;/h3&gt;  &lt;p&gt;To illustrate View-First Navigation, I took the Order Entry sample application from the second post and converted it to use ViewModel pattern. You’ll remember that this sample was based on a navigation scheme where the links referred to the pages within the application, so it was relatively straightforward to keep that navigation scheme and introduce the ViewModel pattern into it. You can run the final application &lt;a href="http://dphill.members.winisp.net/OrderEntryVMSample.html" target="_blank"&gt;here&lt;/a&gt;. Let’s walk through the application so you can see how it all fits together…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix1_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 10px 0px; display: inline; border-top: 0px; border-right: 0px" title="Helix1" border="0" alt="Helix1" align="left" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix1_thumb.png" width="209" height="273" /&gt;&lt;/a&gt;The application consists of a number of Models, ViewModels and Views, plus a RootPage and an Application&amp;#160; class. The RootPage is a simple page with a Frame control – as we navigate between pages, they will displayed here.&lt;/p&gt;  &lt;p&gt;The application uses three model classes to represent the customer, sales order and the sales order line items. In this sample these are just simple classes with a number of properties. These are all defined in the Models folder.&lt;/p&gt;  &lt;p&gt;The ViewModels for the application are defined in the ViewModels folder. The ViewModels implement a number of commands and properties that the Views can bind to. The application’s pages are all defined in the Views folder. None of the pages have any code behind; all of the UI is defined declaratively in XAML. The pages bind against the ViewModel’s commands and properties.&lt;/p&gt;  &lt;p&gt;All of these classes are connected together at run-time through navigation. The navigation scheme for the application is defined in App.xaml. With the latest drop of Helix, we can define the navigation routes, and associated controller and default parameter values, as an application resource. This allows us to define the navigation scheme for our application declaratively without having to write any code.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;n:RouteTable&lt;/span&gt; &lt;span class="attr"&gt;x:Key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;GlobalNavigationRoutes&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;n:Route&lt;/span&gt; &lt;span class="attr"&gt;UriTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;/[PageName]&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;n:Route.Controller&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;c:PageController&lt;/span&gt; &lt;span class="attr"&gt;DefaultResourcePath&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Views&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;n:Route.Controller&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;n:Route&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;n:Route&lt;/span&gt; &lt;span class="attr"&gt;UriTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;/[PageName]/[CustomerID]&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;n:Route.Controller&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;c:PageController&lt;/span&gt; &lt;span class="attr"&gt;DefaultResourcePath&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Views&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;n:Route.Controller&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;n:Route&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;n:Route&lt;/span&gt; &lt;span class="attr"&gt;UriTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;/[PageName]/[CustomerID]/[SalesOrderID]&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;n:Route.Controller&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;c:PageController&lt;/span&gt; &lt;span class="attr"&gt;DefaultResourcePath&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Views&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;n:Route.Controller&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;n:Route&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;n:RouteTable&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;In this application we have three navigation routes. The first route defines no parameters just the page name, but the second and third routes add CustomerID and SalesOrderID parameters. Each route uses a PageController. The DefaultResourcePath tells the controller where to look in the application for the pages that we will navigate to.&lt;/p&gt;

&lt;p&gt;The bulk of the application’s logic is defined in the ViewModel classes. The ViewModels implement a number of commands and properties and expose them to the UI for binding. Helix includes a number of features to help with View to ViewModel binding.&lt;/p&gt;

&lt;p&gt;Simple properties exposed by the ViewModel are easy to bind to. In the case where the underlying data managed by the ViewModel is a collection (for example, a collection of customers), the ViewModel creates a CollectionViewModel class to wrap it. This class manages currency, selection and sorting of the underlying collection. The View and CollectionViewModel are kept in sync using the SynchronizeCollectionView attached behavior like this:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ListBox&lt;/span&gt; &lt;span class="attr"&gt;ItemsSource&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding Customers}&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;     &lt;span class="attr"&gt;h:SelectionChanged&lt;/span&gt;.&lt;span class="attr"&gt;SynchronizeCollectionView&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding Customers}&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;My post &lt;a href="http://blogs.msdn.com/dphill/archive/2009/02/11/collectionviewmodel.aspx" target="_blank"&gt;here&lt;/a&gt; on CollectionViewModel describes in detail how this attached behavior works. I have now rolled the CollectionViewModel and the SynchronizeCollectionView attached behavior classes into Helix so everything is in one place.&lt;/p&gt;

&lt;p&gt;The ViewModels also implement commands that the View can bind to. Commands are implemented using the Prism DelegateCommand class – see &lt;a href="http://msdn.microsoft.com/en-us/library/dd458928.aspx" target="_blank"&gt;here&lt;/a&gt; for more information on Prism and Delegate Command pattern. Commands can be bound to UI elements using the Prism Command attached behavior. Command parameters can also be defined using the CommandParameter attached behavior.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edit&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="attr"&gt;prism:Click&lt;/span&gt;.&lt;span class="attr"&gt;Command&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding ViewOrdersCommand}&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="attr"&gt;prism:Click&lt;/span&gt;.&lt;span class="attr"&gt;CommandParameter&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding Customers.CurrentItem}&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;In the example above, we’re binding the Edit button to the ViewOrders command and passing in the currently selected customer as a command parameter. When the user clicks the button, the command’s method will be invoked with the current customer as a parameter. If the Edit command is not available, the button is disabled automatically.&lt;/p&gt;

&lt;p&gt;Many of the commands in the application result in a navigation. Commands which result in navigation are typically implemented like this:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ViewOrders( Customer customer )&lt;/pre&gt;

  &lt;pre&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="rem"&gt;// Navigate to the Orders page.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    Uri navUri = &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri( &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format( &lt;span class="str"&gt;&amp;quot;/Orders/{0}&amp;quot;&lt;/span&gt;, customer.CustomerID ),&lt;/pre&gt;

  &lt;pre class="alt"&gt;                          UriKind.Relative );&lt;/pre&gt;

  &lt;pre&gt;    _navigationContext.Target.RequestNavigate( navUri );&lt;/pre&gt;

  &lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;The Uri above is formatted in accordance with the navigation scheme that we defined in App.xaml. The Uri can include parameters such as the customer ID and these are passed to the target ViewModel when it’s created. This makes it very easy to pass parameters around during navigation. Since we have a View-First navigation application, we could also use the Helix NavigationLink control and navigate directly from the page.&lt;/p&gt;

&lt;p&gt;The navigation context you can see above is passed to the ViewModel by the framework when it is first constructed as a result of navigation. You can use the navigation context class to get access to the navigation parameters, or to ask the navigation target to navigate to another Uri as shown above. The NavigationContext class is discussed in more detail below.&lt;/p&gt;

&lt;p&gt;There are just a couple of final things that we need in order to stitch everything together. Since we’re using a View-First navigation controller, navigation Uris, such as the one above, specify the name of the page to navigate to. In the example above, we’re navigating to the Orders.xaml page in the Views folder. So far so good, but how does the framework know which ViewModel to create for this view?&lt;/p&gt;

&lt;p&gt;There are a number of ways to solve this problem. Ultimately we need to know the Type of the ViewModel class so we can instantiate it. One way to get this type is to infer it from the type of the View – so, for example, a view with a type name of ‘MyApp.MyView’ would infer a ViewModel of type say ‘MyApp.MyViewModel’. This would work but means that we would have to know about the naming convention and the relevant namespaces and we would have to follow both carefully when creating our ViewModel classes.&lt;/p&gt;

&lt;p&gt;Another approach, and the one that is implemented in this sample application, is to allow the View to explicitly specify the type of the ViewModel it was designed for. To do that we just use a simple attached property. The Customers page, for example, specifies that it needs an instance of the CustomersViewModel class like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;NavigationPage&lt;br /&gt;  &lt;/span&gt;&lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.Samples.Helix.OrderEntrySample.CustomersPage&amp;quot;&lt;/span&gt;
  ...
  &lt;span class="attr"&gt;ViewModel&lt;/span&gt;.&lt;span class="attr"&gt;TypeName&lt;/span&gt;&lt;span class="kwrd"&gt;=&lt;br /&gt;    &amp;quot;Microsoft.Samples.Helix.OrderEntrySample.ViewModels.CustomersViewModel&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can imagine some day in the far flung future, when the tooling folks finally embrace the notion of separated presentation patterns, that the ViewModel’s type could be automatically specified by the tool when the user is designing the view – maybe even as a proper Type parameter making the View a generic type, for example MyView&amp;lt;ViewModelType&amp;gt;. We can only hope that that day will come soon…&lt;/p&gt;

&lt;p&gt;In any case, when the framework creates the View it checks to see if there is a ViewModel specified, and if so, it instantiates the ViewModel and sets it as the View’s DataContext. All of this is handled by the PageController which is described in more detail below.&lt;/p&gt;

&lt;p&gt;The last piece of the puzzle is the navigation context. Once the View and ViewModel have been created and hooked up, the controller passes in the navigation context which contains the navigation parameters and a whole bunch of other stuff. The ViewModel (or the View) can opt to receive the navigation context by implementing the INavigationAware interface, which consists of a single method OnNavigate:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="preproc"&gt;#region&lt;/span&gt; INavigationAware Members&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnNavigate( NavigationContext context )&lt;/pre&gt;

  &lt;pre&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="rem"&gt;// Store the navigation context for later.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    _navigationContext = context;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    ...&lt;/pre&gt;

  &lt;pre&gt;}&lt;/pre&gt;

  &lt;pre class="alt"&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;The ViewModel can then retrieve the parameters it’s interested and retrieve the relevant data to initialize itself.&lt;/p&gt;

&lt;h4&gt;The PageController Class Dissected&lt;/h4&gt;

&lt;p&gt;The View-First application described above uses the PageController class to handle navigation. This controller does all of the heavy lifting and stitches everything together. It carries out four steps in sequence:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix2_4.png"&gt;&lt;img style="border-right-width: 0px; margin: 10px auto; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Helix2" border="0" alt="Helix2" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix2_thumb_1.png" width="450" height="64" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The first step is to create the View. The View’s name is specified as a parameter as part of the navigation Uri, as defined in the navigation routes in App.xaml. The View is created by loading the resource, prefixed with the DefaultResourcePath if one is specified. &lt;/li&gt;

  &lt;li&gt;The next step is to create the ViewModel. The ViewModel's type is specified using an attached property value on the View. If the View doesn’t specify a ViewModel type, this step is skipped. &lt;/li&gt;

  &lt;li&gt;If a ViewModel has been created, the next step is to set the View’s DataContext to the it. This allows the View to binding to the ViewModels properties and commands. &lt;/li&gt;

  &lt;li&gt;The final step is to set the navigation context on the View or ViewModel. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The last step probably needs some explanation. In part 2 of this series you may recall that we passed the navigation parameters to the target View using the INavigationPage interface. Now that we have ViewModel support, we probably don’t want to pass the navigation parameters to the page; we want to pass them to the ViewModel instead. In the latest drop of Helix, I have added a new interface INavigationAware that can be implemented by a View or a ViewModel (or both). The PageController checks to see if either the View or the ViewModel implements this interface and if so, calls the OnNavigate method, passing in the NavigationContext.&lt;/p&gt;
&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;NavigationContext is a new class. It provides a single object from which to retrieve all of the information about the current navigation operation, including the navigation parameters, mode, Uri and target, etc. Most of the ViewModels in the sample application store a reference to the NavigationContext to use for initiating further navigation operations later on and for retrieving the parameters that they require.&lt;/p&gt;

&lt;p&gt;The implementation of the PageController class described here is pretty simple. The strategy it implements is the one I settled on during my investigations, but you can easily change the implementation to suit your needs. For example, you can change the way in which the View or ViewModel gets created, or they way in which they get hooked-up, to whatever strategy you prefer. The beauty of the Helix framework is that you can make these changes in a single place without having to make multiple changes throughout the entire application!&lt;/p&gt;

&lt;h3&gt;ViewModel-First Navigation&lt;/h3&gt;

&lt;p&gt;OK, so much for View-First navigation. Let’s see what ViewModel-First navigation looks like…&lt;/p&gt;

&lt;p&gt;To illustrate ViewModel-First navigation, I implemented a sample expense reporting application. You can run the application &lt;a href="http://dphill.members.winisp.net/ExpenseSample.html" target="_blank"&gt;here&lt;/a&gt;. As described above, this application provides a number of tasks that the user can carry out. Each task will be rendered visually, so the user will experience these states through the UI, but to a large extent the tasks exist independently of how they are rendered.&lt;/p&gt;

&lt;p&gt;The following diagram illustrates the tasks and the commands that lead to the transitions (navigation!) between the tasks. From the View Expense Reports task, for example, the user can create, edit, review, submit or archive an expense report; from the Edit Expense Report task the user can save the expense report and the application moves back to the View Expense Reports task.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix5_2.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Helix5" border="0" alt="Helix5" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix5_thumb.png" width="466" height="206" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix3_2.png"&gt;&lt;img style="border-right-width: 0px; margin: 0px 0px 5px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Helix3" border="0" alt="Helix3" align="right" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix3_thumb.png" width="217" height="342" /&gt;&lt;/a&gt;The structure of the project is similar to the Order Entry sample described above. It consists of three folders that contain the application’s Models, ViewModels and Views, a root page and an application class.&lt;/p&gt;

&lt;p&gt;The essential difference between this application and the Order Entry application described above is that navigation occurs between ViewModels. Each ViewModel represents a task so the bulk of the application logic is defined in the ViewModels. Each ViewModel implements properties and commands similar to those described above.&lt;/p&gt;

&lt;p&gt;The ViewModel folder also contains a couple of ViewModel helper classes that perform data formatting for expense amounts and dates. These classes aren’t ViewModels per se, but they are used by the Views to help them render the data correctly.&lt;/p&gt;

&lt;p&gt;There is a corresponding View for each ViewModel, defined in the Views folder. Again, the views contain no code behind.&lt;/p&gt;

&lt;p&gt;Ok, let’s see how all of this fits together. First, the application’s navigation scheme is defined in App.xaml:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RouteTable&lt;/span&gt; &lt;span class="attr"&gt;x:Key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;GlobalNavigationRoutes&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Route&lt;/span&gt; &lt;span class="attr"&gt;UriTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;/[ViewModelTypeName]/[ExpenseID]&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Route.Controller&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ViewModelController&lt;/span&gt; &lt;span class="attr"&gt;DefaultResourcePath&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Views&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;                &lt;span class="attr"&gt;DefaultNamespace&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.Samples.Helix.ExpenseSample.ViewModels&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Route.Controller&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Route.Defaults&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;NavigationParameter&lt;/span&gt; &lt;span class="attr"&gt;ParameterName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ExpenseID&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ParameterValue&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;-1&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Route.Defaults&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Route&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;RouteTable&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;This application defines a single route that has two parameters – the ViewModel type name, and the expense report ID. A default value for the expense report ID is specified, so the navigational Uri’s don’t necessarily have to specify it. This route uses the ViewModelController navigation controller class. This is the class that coordinates how the ViewModels &amp;amp; Views get created, hooked-up, and initialized with the navigation context.&lt;/p&gt;

&lt;p&gt;The ViewModelController has two properties – DefaultResourcePath, which tells it where to look for Views, and DefaultNamespace, which specifies the default namespace for the ViewModel classes. The operation of this controller class is described below, but essentially it works by creating a ViewModel then a suitable View for it, hooks them up via the View’s DataContext and then sets the navigation context.&lt;/p&gt;

&lt;p&gt;The interaction between the Views and the ViewModels is the same as described above and includes commands and the CollectionViewModel sync attached behavior. Navigation between tasks occurs as commands are invoked on the ViewModels. A typical implementation of a command looks like this:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateExpenseReport( ExpenseReport expenseReport )&lt;/pre&gt;

  &lt;pre&gt;{&lt;/pre&gt;

  &lt;pre class="alt"&gt;    ExpenseReport newExpenseReport = _expenseReports.CreateNewExpenseReport();&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;    &lt;span class="rem"&gt;// Navigate to the Edit ViewModel.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    _navigationContext.Target.RequestNavigate( &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;/pre&gt;

  &lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format( &lt;span class="str"&gt;&amp;quot;/EditExpenseReport/{0}&amp;quot;&lt;/span&gt;, newExpenseReport.ExpenseID ),&lt;/pre&gt;

  &lt;pre&gt;                           UriKind.Relative ) );&lt;/pre&gt;

  &lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;The format of the Uri is as defined in the navigation route in App.xaml. In the example above, we’re passing an expense report ID as a parameter to the target EditExpenseReport ViewModel. When that ViewModel is instantiated, the parameter will be passed in as part of the navigation context and the ViewModel can retrieve the corresponding expense report. In this way, we can control not only what gets instantiated during navigation, but also how parameters flow around the system. This really simplifies how applications like this are put together…&lt;/p&gt;

&lt;h4&gt;The ViewModelController Class Dissected&lt;/h4&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Hopefully you won’t be surprised to learn that the ViewModelController creates the ViewModel first and then creates a suitable View for it. The sequence goes like this:&lt;/p&gt;

&lt;p&gt;&lt;img style="border-right-width: 0px; margin: 10px auto; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Helix4" border="0" alt="Helix4" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/SilverlightNavigationPart3_EEB8/Helix4_thumb.png" width="450" height="56" /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;In the first step, the ViewModel is instantiated using the ViewModelTypeName navigation parameter, prefixed with the DefaultNamespace if one is specified. So for a ViewModel type name of ‘EditExpenseReport’, the type ‘Microsoft.Samples.Helix.ExpenseSample.ViewModels.EditExpenseReport’ will be instantiated. &lt;/li&gt;

  &lt;li&gt;The next step is to create a suitable View. The details of this step are described below. If a View can’t be instantiated, an exception is thrown. &lt;/li&gt;

  &lt;li&gt;The next step is to set the View’s DataContext to the ViewModel. This allows the View to binding to the ViewModels properties and commands. &lt;/li&gt;

  &lt;li&gt;The final step is to set the navigation context on the View or ViewModel. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the View-First strategy described above we had the challenge of figuring out which ViewModel to instantiate for a given View. In ViewModel-First navigation we have the opposite problem – given a ViewModel, we have to decide which View to instantiate for it.&lt;/p&gt;

&lt;p&gt;The current implementation takes a simple approach – we just append the ViewModel’s short type name with ‘View’ and load the corresponding View resource. So for the ‘EditExpenseReport’ ViewModel, we’d load the View ‘EditExpenseReportView’ located in the Views folder. This was an experiment to see how a naming-convention based approach would work.&lt;/p&gt;

&lt;p&gt;There are other ways to solve this problem, but for the purposes of this sample, it works pretty well. You can always implement an alternate strategy in a custom controller class if you prefer a different way to create and hook-up the ViewModel or View.&lt;/p&gt;

&lt;h3&gt;End of Part 3&lt;/h3&gt;

&lt;p&gt;Well, that was a long post wasn’t it? We covered a lot of ground though. Since we’re building Helix from the ground up there are a lot of details to grok, and just like sausages and laws, it’s not always pretty seeing how things are made. The final framework, though, should be drop-dead simple to use – that’s the goal anyway!&lt;/p&gt;

&lt;p&gt;We’ve been experimenting with alternate approaches to discover their advantages and disadvantages and to see which one might work as a default approach that will work for most applications. We’ve essentially identified two broad approaches that have potential and we can now build applications with a View-First navigational style, or with a ViewModel-First navigational style.&lt;/p&gt;

&lt;p&gt;Which approach you use depends on your application and which approach feels most natural to you. The implementations described here work pretty well for both approaches but there are few things that need some improvement. The nice thing about Helix, though, is that it’s simple to implement alternate strategies or to tweak the behavior of the navigation scheme in an application. With a few changes here and there we can customize navigation without having to rewrite big chunks of our application.&lt;/p&gt;

&lt;p&gt;Personally, I believe the ViewModel-First approach has a lot of advantages over View-First approach, but it takes some getting used to. The example above doesn’t really highlight the advantages of this approach in terms of testability and UI flexibility. I’ll try and focus on those in the next post in the series, as well as deep linking. I promise that you won’t have to wait as long for that post…&lt;/p&gt;

&lt;p&gt;On another note, whatever approach we choose, there is always the ‘tooling problem’. In other words, what would the ideal tooling experience be like for building applications based on both a separated presentation pattern and a flexible navigation system? It’s not an easy question to answer. I have some ideas but they will have to wait for a future post too…&lt;/p&gt;

&lt;p&gt;As always, please let me know what you think of Helix – what you like or don’t like, etc. If you have any feedback on Helix, please drop me a line.&lt;/p&gt;

&lt;p align="center"&gt;oO------Oo&lt;/p&gt;

&lt;h3&gt;Helix 0.3: Changes and New Features&lt;/h3&gt;

&lt;p&gt;A quick summary of the main changes and new features in this drop of Helix:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Added support for global routes. Global routes are managed by the Navigation Manager and can be defined as an application-level resource in XAML. If not global routes are defined, a default global rout is added automatically. Frame-local routes can also be defined and are checked for a match first during navigation. If a match at the Frame level is not found, then the global routes are checked. This provides a lot of flexibility when implementing hierarchical navigation scenarios in an application. &lt;/li&gt;

  &lt;li&gt;Moved the page loader code to the static Navigation Manager class. Centralizing this code allows for multiple controller classes to take advantage of it (and allows for it’s ultimate replacement by the Silverlight framework itself if and when it supports the ability to load pages by resource name). &lt;/li&gt;

  &lt;li&gt;Removed the need to register the application’s main assembly with the Navigation Manager class. The Navigation Manager now searches all assemblies in the application manifest (except those beginning with System). This also the Navigation Manager to instantiate Views and ViewModels without the developer having to specify which assembly they are defined in, which in turn allows for easier integration between UI and non-UI application layering. &lt;/li&gt;

  &lt;li&gt;Default constructors added for Route and Journal classes. Using the default constructor for a Route object instantiates a default PageController instance. Similarly, using the Journal’s default constructor instantiates a default RouteNavigationHandler instance. These default constructors allow for simpler declarative setup in code or XAML. &lt;/li&gt;

  &lt;li&gt;NavigationParameter and related classes were also changed to support default construction and the ability to declaratively specify default values in Routes. &lt;/li&gt;

  &lt;li&gt;Refactored the regular expressions in the Route class to const strings to allow for easier customization. Also tidied up the regular expression for identifying fields in the navigation Uris. This allows you to more easily change which characters are allowed in navigation fields (e.g. you can now define fields that include period and dash, so you can use GUIDS for example). &lt;/li&gt;

  &lt;li&gt;Refactored all Controller and Journal classes into their own namespaces. &lt;/li&gt;

  &lt;li&gt;NavigationUIVisibility is now in the Helix Controls namespace. &lt;/li&gt;

  &lt;li&gt;Controller parameters – added the ability for a controller to specify its required parameters using an attribute. This allows the controller base class to automatically check incoming parameters to make sure that all required parameters have been provided. This simplifies error handling and the implementation of derived controller classes. This also allows for the associated Route object to check for a compatible controller when the Route is first registered.&lt;/li&gt;

  &lt;li&gt;Navigation Context – Added Navigation Context class which includes all of the information pertaining to the current navigation operation, including the navigation parameters, original Uri and the navigation target. This provides for a simple API, better extensibility and allows ViewModels to store a reference to their navigation context so they can initiate or initiate/cancel/redirect a navigation operation. &lt;/li&gt;

  &lt;li&gt;Added PageController and ViewModelController classes. Removed the NavigationPageController class (this functionality is now provided by the PageController class). The PageActionController class is now derived from the PageController class. &lt;/li&gt;

  &lt;li&gt;Added DefaultResourcePath property on PageController &amp;amp; ViewModelController to allow views to be loaded from a sub-folder in the project. The previous version of Helix required all pages to be defined at the project root level. &lt;/li&gt;

  &lt;li&gt;Added InitialUri dependency property on the Frame Control. This allows the Frame to navigate to the specified Uri when the Frame is first loaded, removing the need for code behind in the root page. &lt;/li&gt;

  &lt;li&gt;Added CollectionViewModel to Helix library. Also added a number of bug fixes in the Refresh and OnModelChanged method. The latter is required due to weird behavior with the Silverlight DataGrid control. &lt;/li&gt;

  &lt;li&gt;Added a unit test project with unit test for Routes, Navigation Manager, Page and ViewModel Controllers, CollectionViewModel, etc.&lt;/li&gt;

  &lt;li&gt;That’s all the changes I can remember… &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A quick note on &lt;strong&gt;Silverlight 3.0 Beta&lt;/strong&gt;: Helix and all of the associated samples are built for Silverlight 2.0. However, you should have no problem using Helix with the Silverlight 3.0 Beta. There are a few known issues in Silverlight 3.0 Beta to do with memory leaks but these probably won’t affect you too much and they’ve been fixed in later versions.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9574249" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Helix/default.aspx">Helix</category></item><item><title>Mix 09!</title><link>http://blogs.msdn.com/dphill/archive/2009/03/18/mix-09.aspx</link><pubDate>Wed, 18 Mar 2009 20:35:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9487435</guid><dc:creator>dphill</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9487435.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9487435</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://live.visitmix.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; margin: 0px 10px 10px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="mix09header" align="left" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/Mix_7428/mix09header_3.jpg" width="109" height="88" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Mix 09 starts today! There have been a number of key announcements made at Mix, especially concerning Silverlight 3.0 and Blend 3.0. If you are at all interested in Web and Silverlight development then be sure to check out the &amp;quot;Gu's&amp;quot; keynote highlights &lt;a href="http://visitmix.com/Opinions/MIX09-Keynote-and-Partner-Highlights" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The next releases of Silverlight and Blend have lots of interesting features. I'll cover them in detail in a future post, but one question that I'm sure is top of mind is how the new version of Silverlight relates to Prism and Helix.&lt;/p&gt;  &lt;p&gt;Silverlight 3.0 provides a lot of new features that are nicely complementary to Prism. These new features help with data validation, data forms, navigation and with accessing business entities over the network. Prism focuses on patterns for flexible, modular, loosely coupled, unit-testable applications. These patterns can of course be used in Silverlight 3.0 just as effectively as in 2.0. The combination of Prism and the new Silverlight features provide a very powerful platform for building line of business RIA applications.&lt;/p&gt;  &lt;p&gt;We're planning the next release of Prism which will target Silverlight 3.0 (and WPF 4.0), so we're beginning to look at how we can evolve Prism to further integrate and complement Silverlight, Blend and WPF. We're especially looking forward to support the new Silverlight out-of-browser feature(!). So if you have any ideas on what you'd like to see in Prism 3.0, please send them our way!&lt;/p&gt;  &lt;p&gt;You'll also see that Silverlight 3.0 now has some support for navigation! I was part of the team behind the navigation features in Silverlight 3.0 last year before moving to the patterns &amp;amp; practices team. My original design for Silverlight navigation was of course very similar to Helix. The design changed quite a bit since I left that team, specifically so that it is more compatible with WPF's navigation model. I'll be posting details on the differences between the two designs, the advantages and disadvantages of each, and how to use them together soon.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9487435" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Helix/default.aspx">Helix</category></item><item><title>Prism 2.0 Refresh</title><link>http://blogs.msdn.com/dphill/archive/2009/03/01/prism-2-0-refresh.aspx</link><pubDate>Mon, 02 Mar 2009 03:17:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9453242</guid><dc:creator>dphill</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9453242.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9453242</wfw:commentRss><description>&lt;p&gt;We just posted a refresh to the Prism 2.0 bits. You can download the latest release from the same location on MSDN &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=fa07e1ce-ca3f-4b9b-a21b-e3fa10d013dd&amp;amp;DisplayLang=en#filelist" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The recent release of the GDR update to Silverlight 2.0 (which takes Silverlight from version 2.0.31005 to version 2.0.40115) causes a problem when building the Composite.Silverlight.Tests project. This issue only affects the unit tests and there is no change required to the core library or any of the quick-starts or the reference implementation. The issue was due to an incorrect path in one of the batch files in the unit test project. You can read more details on the issue &lt;a href="http://www.codeplex.com/CompositeWPF/Wiki/View.aspx?title=Fix%3a%20CAL%20Build%20failure%20with%20Silverlight%20GDR%20update&amp;amp;referringTitle=Known%20Issues%20%2f%20Fixes" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;While we were refreshing the bits, we thought we'd also slip in a fix to a recently reported issue with view activation in tabbed regions. This issue caused a difference in behavior between Prism 1.0 and 2.0. You can read the details &lt;a href="http://www.codeplex.com/CompositeWPF/Wiki/View.aspx?title=Active%20view%20in%20TabControl%20behaves%20differently%20in%20Prism%20V2%20compared%20to%20Prism%20V1" target="_blank"&gt;here&lt;/a&gt;. This issue has been fixed with the refreshed release.&lt;/p&gt;  &lt;p&gt;We also just released a PDF version of the Prism 2.0 documentation so you can print it more easily. You can download the PDF file from &lt;a href="http://www.codeplex.com/CompositeWPF/Release/ProjectReleases.aspx?ReleaseId=14982"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Coming Soon!&lt;/strong&gt; We are working on Visual Basic versions of the quick-starts and documentation. I'll post more details once we've released these in the next week or so...&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9453242" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Patterns+and+Practices/default.aspx">Patterns and Practices</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Prism 2.0 Is Live!</title><link>http://blogs.msdn.com/dphill/archive/2009/02/20/prism-2-0-is-live.aspx</link><pubDate>Sat, 21 Feb 2009 00:11:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9436573</guid><dc:creator>dphill</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9436573.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9436573</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/Prism2.0IsLive_A262/Prism2%20StockTrader_2.png"&gt;&lt;img style="border-right-width: 0px; margin: 0px 10px 10px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Prism2 StockTrader" align="left" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/Prism2.0IsLive_A262/Prism2%20StockTrader_thumb.png" width="200" height="134" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;WooHoo! Prism 2.0 is done and is now live on MSDN! You can access the Prism 2.0 documentation &lt;a href="http://msdn.microsoft.com/en-us/library/cc707819.aspx" target="_blank"&gt;here&lt;/a&gt;, and download the code from &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=fa07e1ce-ca3f-4b9b-a21b-e3fa10d013dd&amp;amp;DisplayLang=en#filelist" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Prism is a library of patterns that help you build robust, flexible and modular WPF and Silverlight applications. These patterns also support unit testing, separation of concerns, loose coupling and the ability to share application logic between Silverlight and WPF applications. The download includes the source code for the library itself, extensive documentation, a sample application that shows how the patterns work together in a real-world application, and a whole bunch of quick-starts and how-to's. There's even a snazzy Visual Studio add-in to help you easily share code between WPF and Silverlight&lt;a title="Adam and Blaine on Channel 9" href="http://channel9.msdn.com/shows/Continuum/Prismv2/" target="_blank"&gt;&lt;img style="border-right-width: 0px; margin: 10px 0px 0px 10px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Blaine and Adam" align="right" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/Prism2.0IsLive_A262/Blaine%20and%20Adam_5.jpg" width="180" height="128" /&gt;&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The Prism team has been busy writing blogs and recording videos to get the word out...&lt;/p&gt;  &lt;p&gt;Blaine Wastell (program manager extraordinaire for Prism) chats to Adam Kinney about Prism on Channel 9 &lt;a href="http://channel9.msdn.com/shows/Continuum/Prismv2/" target="_blank"&gt;here&lt;/a&gt;. He's even written a blog post on Prism &lt;a href="http://blogs.msdn.com/blaine/archive/2009/02/18/prism-2-0-is-live.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you haven't had enough Blaine you can catch even more of &lt;a title="Bob &amp;amp; Blaine on Channel 9" href="http://channel9.msdn.com/posts/akMSFT/What-is-Prism-v2/" target="_blank"&gt;&lt;img style="border-right-width: 0px; margin: 10px 10px 0px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Blaine and Bob" align="left" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/Prism2.0IsLive_A262/Blaine%20and%20Bob_3.jpg" width="200" height="123" /&gt;&lt;/a&gt;him &lt;a href="http://channel9.msdn.com/posts/akMSFT/What-is-Prism-v2/" target="_blank"&gt;here&lt;/a&gt; on Channel 9, alongside Bob Brumfield (one of the developers of Prism), as Ajoy Krishnamoorthy (our product manager) ponders the eternal question - What is Prism? Ajoy's post on the release is &lt;a href="http://blogs.msdn.com/ajoyk/archive/2009/02/18/guidance-for-building-wpf-and-silverlight-applications.aspx" target="_blank"&gt;here&lt;/a&gt; and Bob's is &lt;a href="http://blogs.msdn.com/bobbrum/archive/2009/02/18/composite-guidance-for-silverlight-and-wpf-aka-prism-v2-released.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Still hungry for more information on Prism?&lt;/p&gt;  &lt;p&gt;Check out Erwin's post &lt;a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/02/18/just-released-composite-application-guidance-for-wpf-and-silverlight-february-2008.aspx" target="_blank"&gt;here&lt;/a&gt;, and Julian's post is &lt;a href="http://blogs.southworks.net/jdominguez/2009/02/prism-20-released-composite-application-guidance-for-wpf-and-silverlight-february-2009/" target="_blank"&gt;here&lt;/a&gt;. Erwin and Julian were part of the super-talented Prism development team. Expect more videos and posts from the dev team on how to use the various super-cool features of Prism soon.&lt;/p&gt;  &lt;p&gt;And last but by no means least, Prism's test lead Larry Brader has a post &lt;a href="http://blogs.msdn.com/lbrader/archive/2009/02/18/pround-to-announce-prism-2-ships.aspx" target="_blank"&gt;here&lt;/a&gt;.&amp;#160; Larry's going to be delivering a whole series of posts that will tell you everything you ever wanted to know about unit testing and acceptance testing in WPF and Silverlight, so be sure to check his blog often.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9436573" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Patterns+and+Practices/default.aspx">Patterns and Practices</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/WPF/default.aspx">WPF</category></item><item><title>Master-Detail With CollectionViewModel</title><link>http://blogs.msdn.com/dphill/archive/2009/02/19/master-detail-with-collectionviewmodel.aspx</link><pubDate>Fri, 20 Feb 2009 00:47:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9434991</guid><dc:creator>dphill</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9434991.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9434991</wfw:commentRss><description>&lt;p&gt;Implementing a Master-Detail style UI with the CollectionViewModel I described in my &lt;a href="http://blogs.msdn.com/dphill/archive/2009/02/11/collectionviewmodel.aspx" target="_blank"&gt;previous post&lt;/a&gt; is pretty easy. With a selector control bound to a CollectionViewModel as shown in my previous post, you just need to add a content control to the View and bind its Content property to the current item and define how you want it to be rendered by defining a data template.&lt;/p&gt;  &lt;p&gt;For the sample in my previous post the view's XAML contains this:&lt;/p&gt;  &lt;div&gt;   &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;     &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ContentControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Path=Catalog.CurrentItem}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ContentControl.ContentTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            ...&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ContentControl.ContentTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ContentControl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Note: In WPF, you strictly only need to bind the content control's Content property to the Catalog - WPF automatically binds to the Catalog's current item for you. Not sure why they did it this way. I think an explicit binding to the CurrentItem property is easier to understand, and I don't mind typing the extra characters. Sometimes a little more is definitely more :-)&lt;/p&gt;

&lt;p&gt;You can run the updated sample &lt;a href="http://dphill.members.winisp.net/CollectionViewModel.html" target="_blank"&gt;here&lt;/a&gt; and download the updated source &lt;a href="http://dphill.members.winisp.net/Download/CollectionViewModel2.zip" target="_blank"&gt;here&lt;/a&gt;. I also updated it to use the final release assemblies from Prism 2.0, and fixed a glitch in the Silverlight Unit Testing assembly references...&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9434991" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Patterns+and+Practices/default.aspx">Patterns and Practices</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/WPF/default.aspx">WPF</category></item><item><title>CollectionViewModel</title><link>http://blogs.msdn.com/dphill/archive/2009/02/11/collectionviewmodel.aspx</link><pubDate>Thu, 12 Feb 2009 02:03:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9413640</guid><dc:creator>dphill</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/dphill/comments/9413640.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dphill/commentrss.aspx?PostID=9413640</wfw:commentRss><description>&lt;p&gt;In this post, I'm going to describe an implementation of ICollectionView for Silverlight that allows you to add sorting, filtering, grouping and selection tracking to any Selector based control (such as ListBox or ComboBox). To demonstrate the implementation, I&amp;#8217;ve built a sample application that displays a catalog of items that the user can filter, sort, group and select. You can run the sample &lt;a title="CollectionViewModel Sample" href="http://dphill.members.winisp.net/CollectionViewModel.html" target="_blank"&gt;here&lt;/a&gt;, and you can download the source code, complete with unit tests, from &lt;a title="CollectionViewModel Code" href="http://dphill.members.winisp.net/Download/CollectionViewModel.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In my &lt;a href="http://blogs.msdn.com/dphill/archive/2009/01/31/the-viewmodel-pattern.aspx" target="_blank"&gt;last&lt;/a&gt; post I outlined the key features of the ViewModel pattern and said that WPF's CollectionViews were actually good examples of the ViewModel pattern applied to collection-based models. In this post I explain in more detail why I think of CollectionViews as ViewModels. In fact, the techniques described in this post can be used to implement any kind of ViewModel and are not restricted to just CollectionView scenarios.&lt;/p&gt;  &lt;h3&gt;CollectionViews In WPF&lt;/h3&gt;  &lt;p&gt;Before we get stuck into the Silverlight implementation, let's take a quick look at WPF's CollectionView support. MSDN has a pretty good overview of CollectionViews in WPF &lt;a href="http://msdn.microsoft.com/en-us/library/ms752347.aspx#collection_views"&gt;here&lt;/a&gt;, and a related sample application &lt;a href="http://msdn.microsoft.com/en-us/library/ms771319.aspx"&gt;here&lt;/a&gt; that allows the user to view and edit a collection of items for sale on an auction site. The interesting thing from our point of view is that it shows the basic capabilities of the CollectionViewSource class, the related classes that implement the ICollectionView interface, and shows how they all work together. If you look at the code, you&amp;#8217;ll see that the application&amp;#8217;s UI has a ListBox that&amp;#8217;s bound to a CollectionViewSource, which in turn references a collection of AuctionItems.     &lt;br /&gt;    &lt;br /&gt;&lt;/p&gt;  &lt;div&gt;   &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;     &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Window.Resources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;CollectionViewSource&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;listingDataView&amp;quot;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #ff0000"&gt;Source&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Source={x:Static Application.Current},Path=AuctionItems}&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Window.Resources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Master&amp;quot;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #ff0000"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Source={StaticResource listingDataView}}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;CollectionViewSource just acts as a kind of XAML friendly factory for dishing up objects that implement the ICollectionView interface. You can also bind a control directly to a collection and a default ICollectionView object will automatically be created.&lt;/p&gt;

&lt;p&gt;There are two main implementations of the ICollectionView interface in WPF - BindingListCollectionView, and ListCollectionView for wrapping IBindingListView/IBindingList collections, or IList collections respectively. In the sample above, the underlying collection of AuctionItems is based on IList (it derives from ObservableCollection) so a ListCollectionView object is created automatically and bound through ItemsSource to the ListBox.&lt;/p&gt;

&lt;p&gt;The ListBox control interacts with the CollectionView through the ICollectionView interface so that the UI and the underlying CollectionView are always kept in sync. This interaction is two-way. If the user selects an item in the UI, the CollectionView&amp;#8217;s CurrentItem and CurrentPosition properties are updated automatically. If the CollectionView&amp;#8217;s selected item is changed (say, due to application logic), the UI is updated to show the corresponding item in the UI as selected. If the user decides to filter, sort or group the items through the UI, the CollectionView is updated accordingly. If the CollectionView is filtered, sorted or grouped due to some application logic, then the UI is automatically updated. It&amp;#8217;s this automatic two-way interaction between the control and the CollectionView that makes them so useful.&lt;/p&gt;

&lt;h4&gt;CollectionView == ViewModel&lt;/h4&gt;

&lt;p&gt;Whatever implementation of ICollectionView you use, these classes wrap the underlying collection and provide a &amp;#8216;view&amp;#8217; on top of it that tracks the current selection, and sorts, groups or filters the underlying collection ready for display in a UI of some sort. They sit between the UI (the View) and the underlying collection of objects (the Model) and act as a go-between to manage presentation logic and state. In other words, they are ViewModels!&lt;/p&gt;

&lt;p&gt;Let me elaborate on that a little &amp;#8211; by presentation logic and state I am referring to logic and state that defines the behavior of the application, but which is not specific to the application&amp;#8217;s business logic and data or to the visual representation of the application. In this case, the presentation logic manages the selection, filtering, sorting, grouping of items in a collection. This doesn&amp;#8217;t affect the data in the application or ensure its integrity, and we don&amp;#8217;t want to persist this information to a back-end database, so it&amp;#8217;s clearly not business logic or state.&lt;/p&gt;

&lt;p&gt;It also has nothing to do with the UI &amp;#8211; yes, it &lt;em&gt;drives&lt;/em&gt; the UI, but we can visually represent it in many different ways, so it&amp;#8217;s not &lt;em&gt;specific&lt;/em&gt; to the UI. Some developers mistakenly treat &amp;#8216;Selected Item&amp;#8217; state as specific to the UI but that leads to critical application behavior that is very hard to unit test &amp;#8211; for example, if you had an app that displayed a list of expense reports to approve or deny, wouldn&amp;#8217;t you want to test that the application approves or denies the right expense report?!?&lt;/p&gt;

&lt;h3&gt;CollectionViews In Silverlight&lt;/h3&gt;

&lt;p&gt;Unfortunately Silverlight 2.0 doesn&amp;#8217;t support CollectionViews out of the box. The ICollectionView interface is defined, but there are no public implementations of this interface that you can use out of the box. Also, none of the Silverlight 2.0 controls have any built-in support for ICollectionView so even if there was an implementation that we could use, the controls won&amp;#8217;t automatically track or update the selected item in the CollectionView.&lt;/p&gt;

&lt;p&gt;Note: The DataGrid control (specifically, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=084a1bb2-0078-4009-94ee-e659c6409db0&amp;amp;displaylang=en" target="_blank"&gt;December&lt;/a&gt; release, &lt;strong&gt;NOT&lt;/strong&gt; the one that ships with Silverlight 2.0) is an exception &amp;#8211; if you bind the DataGrid to a collection, it will create an internal CollectionView that tracks and updates the selected item and provides support for sorting the collection by clicking on the column headers. Unfortunately, this implementation is not available for use with other controls.&lt;/p&gt;

&lt;p&gt;So, to have CollectionView support in Silverlight we need two things &amp;#8211; an implementation of the ICollectionView interface, and some way for the controls in our UI to interact with it (without code in the View&amp;#8217;s code-behind file!). The implementation in this post tackles both of these issues. Let&amp;#8217;s take a look at each in turn.&lt;/p&gt;

&lt;h3&gt;The CollectionViewModel Class&lt;/h3&gt;

&lt;p&gt;The CollectionViewModel class in the sample code implements the ICollectionView interface and the required logic to support selection, filtering, sorting and grouping for an underlying collection model. I chose the name &amp;#8216;CollectionViewModel&amp;#8217; because 1) it&amp;#8217;s a ViewModel for collections!!, and 2) so that it wouldn&amp;#8217;t clash horribly with any existing classes in WPF or Silverlight.&lt;/p&gt;

&lt;p&gt;Some notes on the implementation of this class:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It&amp;#8217;s a generic class and can be used to provide a ViewModel for any underlying collection of type IEnumerable&amp;lt;T&amp;gt;. &lt;/li&gt;

  &lt;li&gt;It derives from ObservableCollection&amp;lt;T&amp;gt;, mainly so that I didn&amp;#8217;t have to implement the INotifyCollectionChanged interface from the ground up, and to make it easy for the controls in the View to bind against it. &lt;/li&gt;

  &lt;li&gt;You should be able to use this class in WPF, but I haven&amp;#8217;t test it yet. If you try it, please let me know how it goes. &lt;/li&gt;

  &lt;li&gt;This class is &lt;em&gt;roughly&lt;/em&gt; the equivalent of the ListCollectionView class in WPF, but there are some minor differences in the class hierarchy and the interfaces that it implements. &lt;/li&gt;

  &lt;li&gt;It uses Linq Expressions to implement the filtering, sorting and grouping functionality. I really didn&amp;#8217;t want to implement this functionality myself from the ground up, plus I wanted to play with Linq Expressions so this seemed like a good opportunity. I am not sure that the implementation is efficient or in any way represents best practice for dynamic Linq Expressions though... &lt;/li&gt;

  &lt;li&gt;The CollectionViewModel class implements a number of common commands (see below) that allow next/previous selection and sorting and grouping through the UI, without requiring View code-behind or commands in a parent ViewModel. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let&amp;#8217;s see how this class is used in the sample application.&lt;/p&gt;

&lt;p&gt;The sample displays a shopping catalog and lets the user filter, sort, and group the items in the catalog. The app has a single CatalogView that&amp;#8217;s bound to a CatalogViewModel. The CatalogView has a ListBox control that&amp;#8217;s bound to the Catalog property of the CatalogViewModel. This property is of type ICollectionView and simply returns an instance of the CollectionViewModel class.&lt;/p&gt;

&lt;p&gt;The CatalogView is defined like this: 
  &lt;br /&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Helix.Samples.CollectionViewModel.CatalogView&amp;quot;&lt;/span&gt; ...&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl.DataContext&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;h:CatalogViewModel&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl.DataContext&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    ...&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Catalog}&amp;quot;&lt;/span&gt; ...&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    ...&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The CatalogViewModel looks like this:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CatalogViewModel : INotifyPropertyChanged&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ObservableCollection&amp;lt;CatalogItem&amp;gt; _catalogModel;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ICollectionView _catalogViewModel;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CatalogViewModel()&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _catalogModel = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObservableCollection&amp;lt;CatalogItem&amp;gt;();&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        ...&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _catalogViewModel = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CollectionViewModel&amp;lt;CatalogItem&amp;gt;( _catalogModel );&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ICollectionView Catalog&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _catalogViewModel; }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    ...&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;A couple of things to note: The CatalogViewModel is created by the view and set as the View&amp;#8217;s data context (this is a simple way to implement the &lt;a href="http://blogs.msdn.com/dphill/archive/2008/12/05/ui-composition-patterns.aspx" target="_blank"&gt;View-First composition pattern&lt;/a&gt;). The CatalogViewModel&amp;#8217;s constructor creates the model and fills it with dummy data. In a real application, the model would likely be populated via a web service and created through a data access service component.&lt;/p&gt;

&lt;h4&gt;Under The Covers&lt;/h4&gt;

&lt;p&gt;So how does the CollectionViewModel work? In a way, it&amp;#8217;s a simple enough class because it really just implements the ICollectionView interface. The only complication is the internal implementation of the filtering, sorting and grouping.&lt;/p&gt;

&lt;p&gt;The consumer of the ICollectionView interface can specify a filter, or one or more sorting or grouping criteria. Linq is clearly good at this kind of stuff, but since there can be one or more criteria at runtime we can&amp;#8217;t just write a straightforward Linq query against the underlying collection. We have to build a dynamic query on the fly using Linq Expressions. So if we have multiple sort criteria, for example, the query equates to a &amp;#8216;SortBy + n*(ThenBy)&amp;#8217; style query on the underlying collection. I&amp;#8217;m not sure whether you&amp;#8217;d ever want multiple levels of grouping, but the ICollectionView supports it so it&amp;#8217;s possible I guess&amp;#8230;&lt;/p&gt;

&lt;h3&gt;Interacting With The View&lt;/h3&gt;

&lt;p&gt;OK &amp;#8211; we&amp;#8217;re about half way there. If you run the code described above, you&amp;#8217;ll get the catalog items to show up in the ListBox, and you can programmatically add filtering, sorting and grouping criteria, but as you select items in the ListBox the CurrentItem &amp;amp; CurrentPosition properties on the CollectionViewModel won&amp;#8217;t be updated. In addition, if you want to provide UI that allows the user to choose how to filter, sort or group, you&amp;#8217;ll likely have to add lots of nasty to test code to the code-behind file of the View. Blecch!&lt;/p&gt;

&lt;h4&gt;Selected Item Tracking&lt;/h4&gt;

&lt;p&gt;The next goal is to link the ListBox to the underlying CollectionViewModel that it is bound to, so that as the user selects items in the ListBox the current item in the CollectionViewModel is updated, and vice versa. We could do this hook-up in code behind but it would be much better if we could specify this behavior declaratively in the XAML. Remember, the goal is to reduce or eliminate any code behind in the View.&lt;/p&gt;

&lt;p&gt;Attached Properties are a popular extensibility mechanism in Silverlight. They are used most often to associate a simple value to a control so that some other control can lay it out in some way &amp;#8211; think of the Grid.Column attached property, which is used to assign a column value to a control so that its parent grid control can lay it out appropriately.&lt;/p&gt;

&lt;p&gt;It turns out that attached properties are actually much more powerful than you might think. You can define an attached property that alters the behavior or appearance of the control to which it is attached. This kind of attached properties are often called &lt;a href="http://blogs.msdn.com/johngossman/archive/2008/05/07/the-attached-behavior-pattern.aspx" target="_blank"&gt;attached behaviors&lt;/a&gt;, or just behaviors. The sample implements a behavior called &amp;#8216;SynchronizeCollectionViewBehavior&amp;#8216; that links the ListBox control to the CollectionViewModel so that the two are kept in sync with respect to the currently selected item.&lt;/p&gt;

&lt;p&gt;You use the behavior like this.&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Catalog}&amp;quot;&lt;/span&gt; ...&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;         &lt;span style="color: #ff0000"&gt;h:SelectionChanged&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;SynchronizeCollectionView&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Catalog}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;If you run the code now, as you select items in the ListBox, the current item in the CollectionViewModel is updated. And if you programmatically select an item on the CollectionViewModel (say using the MoveCurrentToPosition method) the corresponding item in the ListBox is selected. And all with no code-behind!&lt;/p&gt;

&lt;h4&gt;Under The Covers&lt;/h4&gt;

&lt;p&gt;How does this work? The SelectionChanged class (in the Selector.SelectionChanged.cs file) defines an attached property SynchronizeCollectionView. This attached property allows the developer to specify the source ICollectionView object to be synchronized with the target control. This class and the attached property it defines together define the SelectionChanged.SynchronizeCollectionView attached property syntax shown above. This naming convention follows an &amp;#8216;event.action&amp;#8217; pattern that we&amp;#8217;ll also be using for commands below.&lt;/p&gt;

&lt;p&gt;When this value is set via XAML, an instance of the SynchronizeCollectionViewBehavior class is created and &amp;#8216;attached&amp;#8217; to the target control. When it is attached, this behavior subscribes to the target control&amp;#8217;s SelectionChanged event (so it can update the CollectionViewModel as the user interacts with the UI) and subscribes to the CurrentChanged event on the source CollectionViewModel (so it can update the target control&amp;#8217;s UI as the underlying CollectionViewModel is changed). The following diagram shows how this works.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/ViewModelandCurrency_B8DA/SyncBehavior_2.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="SyncBehavior" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/ViewModelandCurrency_B8DA/SyncBehavior_thumb.png" width="516" height="219" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;To improve re-use opportunities, the SynchronizeCollectionViewBehavior class derives from a SelectionChangedBehaviorBase class, which in turn derives from a Behavior base class. You can implement other SelectionChanged behaviors, or more general behaviors, using these two base classes.&lt;/p&gt;

&lt;h4&gt;Commands&lt;/h4&gt;

&lt;p&gt;So now that we have the ListBox and CollectionViewModel selected items synchronized, we can turn our attention to commands. In our sample application, the View provides UI that allows the user to show in-stock items only, or to sort by description or price, or to group by rating. The user can also select the next or previous items in the list by clicking buttons. The View defines the UI but we want the behavior to be defined in the ViewModel where we can test it. So the challenge is how to connect the UI in the View to the corresponding behavior defined in the ViewModel(s) without having any code-behind in the View?&lt;/p&gt;

&lt;p&gt;Prism provides a solution to this problem using the exact same attached property/behavior pattern described above. We can use that to hookup controls to command handlers defined in the View&amp;#8217;s ViewModel. Prism provides a Click.Command behavior which can be used to hook any ButtonBase control (essentially all controls that fire a Click event) to a command handler through data binding. For the buttons that allow the user to step forwards or backwards through the catalog, we can simply set the Click.Command attached behavior on them like this:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Next&amp;quot;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #ff0000"&gt;p:Click&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Command&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Path=Catalog.SelectNextCommand}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Note that the Next and Previous commands are actually implemented on the CollectionViewModel for the Catalog. These are pretty useful generic commands to have on a CollectionViewModel and can be useful in any scenario where the user wants to step through the collection.&lt;/p&gt;

&lt;p&gt;The CollectionViewModel class implements two other useful commands &amp;#8211; SortBy and GroupBy. These commands take a string parameter and allow the View to perform simple sorting and grouping quickly and easily without requiring any code in the View&amp;#8217;s ViewModel. The sample uses these two commands like this:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Sort By Description&amp;quot;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #ff0000"&gt;p:Click&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Command&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Path=Catalog.SortByCommand}&amp;quot;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #ff0000"&gt;p:Click&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;CommandParameter&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Description&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Prism provides an out-of-the box solution for binding buttons to commands on a ViewModel. You can extend this to support any control or event by defining a suitable attached property. To show you how to do this, the sample application uses a check box to allow the user to filter the view so that only items that are in stock are shown. The check box control is attached to the ViewModel&amp;#8217;s FilterInStock command using a CheckedCommandBehavior class. Using this, we can hook-up the check box to the command like this:&lt;/p&gt;

&lt;div&gt;
  &lt;div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;
    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;CheckBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Show In Stock Only&amp;quot;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #ff0000"&gt;h:Checked&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Command&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding FilterInStockCommand}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Putting It All Together&lt;/h3&gt;

&lt;p&gt;The following diagram shows how the sample app is put together.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/ViewModelandCurrency_B8DA/CollectionViewModelSample_2.png"&gt;&lt;img border="0" alt="CollectionViewModel Sample" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/ViewModelandCurrency_B8DA/CollectionViewModelSample_thumb.png" width="521" height="294" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You can switch out the ListBox in the View for a ComboBox or a DataGrid (December Release) or any Selector based control and the rest of the application will just work. The XAML in the View is pretty simple and there are no complicated triggers or binding expressions to worry about. Similarly, if you look at the application's code, it&amp;#8217;s also very simple &amp;#8211; all of the complicated code is encapsulated in re-usable classes . This makes it very easy for a UI designer to create an experience on top of a ViewModel, which can be independently developed and tested by an application developer.&lt;/p&gt;

&lt;h4&gt;A Note On Helix&lt;/h4&gt;

&lt;p&gt;You'll notice that the more general purpose classes in the sample application are in the Helix folder. I&amp;#8217;ll be moving these into the Helix library for its next release...&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9413640" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</category><category domain="http://blogs.msdn.com/dphill/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/dphill/archive/tags/WPF/default.aspx">WPF</category></item></channel></rss>