<?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</title><link>http://blogs.msdn.com/b/dphill/</link><description>Iblogyoublogweblog</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>New Download Location</title><link>http://blogs.msdn.com/b/dphill/archive/2012/10/22/new-download-location.aspx</link><pubDate>Mon, 22 Oct 2012 15:48:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10361738</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=10361738</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2012/10/22/new-download-location.aspx#comments</comments><description>&lt;p&gt;A number of folks have contacted me asking where they can download &lt;a href="http://blogs.msdn.com/b/dphill/archive/tags/helix/"&gt;Helix&lt;/a&gt;, the &lt;a href="http://blogs.msdn.com/b/dphill/archive/2011/03/04/prism-template-pack-1-4-now-with-mef-support.aspx"&gt;Prism Template Pack&lt;/a&gt; or the &lt;a href="http://blogs.msdn.com/b/dphill/archive/2011/01/23/closable-tabbed-views-in-prism.aspx"&gt;Prism Tabbed Interface Sample&lt;/a&gt; now that&amp;nbsp;we&amp;nbsp;no longer use the ISP that was hosting these files.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I'm happy to report that I have (at last!) moved these files to Azure so you can download them again. Here are the download links:&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;span style="font-size: small;"&gt;Helix Navigation Framework:&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: small;"&gt;A simple route-based navigation framework for Silverlight and WPF -&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;a href="http://davidhill.azurewebsites.net/Downloads/Helix-Navigation-0.4.zip"&gt;Download&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;strong&gt;Prism Template Pack:&lt;/strong&gt;&amp;nbsp;A&lt;/span&gt;&lt;span style="font-size: small;"&gt; set of Visual Studio solution and project templates to speed up your Prism development -&lt;/span&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;a href="http://davidhill.azurewebsites.net/Downloads/Prism.TemplatePack.1.4.vsix.zip"&gt;Download&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-size: small;"&gt;&lt;span style="color: #ff0000;"&gt;&lt;em&gt;&lt;strong&gt;&lt;span style="font-size: small;"&gt;Be sure to remove the .zip file extension once you've downloaded the template pack (so that it has a .vsix file extension)!&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;span style="font-size: small;"&gt;Prism Tabbed Interface Sample:&lt;/span&gt; &lt;/strong&gt;&lt;span style="font-size: small;"&gt;A Prism sample showing how to implement a tabbed view interface (similar to Visual Studio) - &lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;a href="http://davidhill.azurewebsites.net/Downloads/PrismTabbedViewInterface.zip"&gt;Download&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10361738" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Helix/">Helix</category></item><item><title>Prism Template Pack 1.4: Now with MEF Support!</title><link>http://blogs.msdn.com/b/dphill/archive/2011/03/04/prism-template-pack-1-4-now-with-mef-support.aspx</link><pubDate>Fri, 04 Mar 2011 23:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10137145</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=10137145</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2011/03/04/prism-template-pack-1-4-now-with-mef-support.aspx#comments</comments><description>&lt;p&gt;Quite a few folks have asked for MEF versions of the Prism templates. I&amp;rsquo;m happy to announce that the Prism Template Pack has now been updated to include MEF (as well as Unity) templates.You can download the latest version of the template pack (version 1.4) from &lt;a title="here" href="http://davidhill.azurewebsites.net/Downloads/Prism.TemplatePack.1.4.vsix.zip"&gt;here&lt;/a&gt;&amp;nbsp;[Updated Link]. &lt;span style="text-decoration: line-through;"&gt;You can read the release notes &lt;a href="http://dphill.members.winisp.net/Templates.html" target="_blank"&gt;here&lt;/a&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="font-size: x-small;"&gt;Remember to remove the .zip extension (leaving the .vsix extension!) before double-clicking to install the templates.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://dphill.members.winisp.net/Templates.html"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="NewProject" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/1738.NewProject_5F00_58708F81.png" alt="NewProject" width="576" height="349" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The Prism Template Pack now provides templates for a quick-start solution, a shell and a module, for both Silverlight and WPF, and in C# and Visual Basic.NET. That&amp;rsquo;s a grand total of 24 individual templates (!!), which is one reason why it took so long to release this update.&lt;/p&gt;
&lt;p&gt;To make it easier to find the right template, I&amp;rsquo;ve added MEF and Unity categories under the Prism node. This approach isn&amp;rsquo;t ideal but it means you won&amp;rsquo;t have to parse a large flat list of templates. In the near future I&amp;rsquo;ll investigate moving to a wizard-based approach where you can choose between MEF and Unity, and other configuration options, using a wizard dialog. That should allow the templates to support more variations without exponentially increasing the number of templates &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/2308.wlEmoticon_2D00_smile_5F00_069A656F.png" alt="Smile" /&gt;.&lt;/p&gt;
&lt;p&gt;As always, please let me know what you think.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10137145" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/MEF/">MEF</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Unity/">Unity</category></item><item><title>Closable Tabbed Views in Prism</title><link>http://blogs.msdn.com/b/dphill/archive/2011/01/23/closable-tabbed-views-in-prism.aspx</link><pubDate>Sun, 23 Jan 2011 20:13:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10119175</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=10119175</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2011/01/23/closable-tabbed-views-in-prism.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/6518.image_5F00_2E359407.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 5px 5px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/6082.image_5F00_thumb_5F00_0DAE5455.png" width="267" height="117" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Prism regions make it easy to change the layout of views within an application. A region is a logical placeholder associated with a specific layout control. Displaying a view in a region causes the view to be added to the layout control. But because the region and the layout control are loosely coupled, you can easily swap the layout control for a different one without having to change the modules in the application. For example, you can change from a tabbed view to a single document view.&lt;/p&gt;  &lt;p&gt;While Prism makes it easy to add views to regions, it isn’t obvious how to close and remove a view from a region, especially from the UI. A common scenario is when you have multiple views displayed in tab control and the user can close individual views using a close button on the tab header. You can see this tabbed view style of UI in Internet Explorer and in Visual Studio.&lt;/p&gt;  &lt;p&gt;This &lt;a href="http://dphill.members.winisp.net/Download/PrismTabbedViewInterface.zip"&gt;sample&lt;/a&gt; shows how this can be done. It’s based on the quick start solution that’s provided by the &lt;a href="http://blogs.msdn.com/b/dphill/archive/2011/01/16/prism-4-0-template-pack-now-available.aspx" target="_blank"&gt;Prism 4.0 Template Pack&lt;/a&gt;. There are really only a couple of minor changes to the quick start solution’s shell. All of the real work is done in a new re-usable Blend action class called &lt;font size="2" face="Calibri"&gt;&lt;strong&gt;CloseTabbedViewAction&lt;/strong&gt;&lt;/font&gt;.&lt;/p&gt;  &lt;h3&gt;The Shell View&lt;/h3&gt;  &lt;p&gt;Before we dig into that class, let’s take a look at the changes in the shell’s view. The &lt;font size="2" face="Calibri"&gt;&lt;strong&gt;TabControl&lt;/strong&gt;&lt;/font&gt; that is used to layout views in the Main region is declared as:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;sdk:TabControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;prism:RegionManager&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;RegionName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MainRegion&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;     &lt;span style="color: #ff0000"&gt;prism:TabControlRegionAdapter&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;ItemContainerStyle&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;            &lt;span style="color: #0000ff"&gt;&amp;quot;{StaticResource TabHeaderStyle}&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;sdk:TabControl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;with the item container style defined as:&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Style&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x:Key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TabHeaderStyle&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TargetType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;sdk:TabItem&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Property&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;HeaderTemplate&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter.Value&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&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;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;StackPanel&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Orientation&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Horizontal&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&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;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBlock&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&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;x&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ToolTipService&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;ToolTip&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Close this view.&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ei: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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;               &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ei:EventTrigger&lt;/span&gt; &lt;span style="color: #ff0000"&gt;EventName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Click&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;local:CloseTabbedViewAction&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;               &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ei: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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;ei: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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&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: #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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;StackPanel&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&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;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter.Value&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&gt;   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;The tab header styles defines the header template for each tab item. This template defines a button that’s simply triggers the &lt;font size="2" face="Calibri"&gt;&lt;strong&gt;CloseTabbedViewAction &lt;/strong&gt;&lt;/font&gt;on line 12. That’s all the changes we need in the shell. This approach allows us to keep the logic behind this action nicely encapsulated.&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;h3&gt;The CloseTabbedViewAction Class&lt;/h3&gt;

&lt;div class="csharpcode"&gt;When the user invokes the &lt;font size="2" face="Calibri"&gt;&lt;strong&gt;CloseTabbedView&lt;/strong&gt;&lt;/font&gt; action, we just want the view to be removed from the region. The Prism Region class defines a &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;Remove&lt;/font&gt;&lt;/strong&gt; method for just this situation. Once we call the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;Remove&lt;/font&gt;&lt;/strong&gt; method, the associated &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;TabControl&lt;/font&gt;&lt;/strong&gt; will be automatically updated and the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;TabItem&lt;/font&gt;&lt;/strong&gt; that’s being used to display the view will be cleanly removed. Pretty easy right? Well, unfortunately it’s not &lt;em&gt;quite&lt;/em&gt; that easy…&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;The &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;Remove&lt;/font&gt;&lt;/strong&gt; method takes a reference to the view to be removed. So in the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;Invoke&lt;/font&gt;&lt;/strong&gt; method of the action class we need to somehow get a reference to the view and to the region that’s (logically) hosting it.&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;The parameter to the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;Invoke&lt;/font&gt;&lt;/strong&gt; method provides a reference to the element that triggered the action (in this case the button defined as part of the tab header template). This element is available through the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;OriginalSource&lt;/font&gt;&lt;/strong&gt; property. From there we can get a reference to the parent &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;TabItem&lt;/font&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;TabControl&lt;/font&gt;&lt;/strong&gt; by traversing up the visual tree. The &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;CloseTabbedViewAction&lt;/font&gt;&lt;/strong&gt; class defines a helper method called &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;FindVisualParent&lt;/font&gt;&lt;/strong&gt; to help us do this:&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; T FindVisualParent&amp;lt;T&amp;gt;( DependencyObject node ) &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; T : DependencyObject&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     DependencyObject parent = VisualTreeHelper.GetParent( node );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( parent == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; || parent &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; T ) &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (T)parent;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Recurse up 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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; FindVisualParent&amp;lt;T&amp;gt;( parent );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;The Content property of the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;TabItem&lt;/font&gt;&lt;/strong&gt; provides a reference to the view that’s being displayed. OK, that gives us the view reference, but what the region? Happily, the Prism &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;RegionManager&lt;/font&gt;&lt;/strong&gt; class provides a method called &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;GetObservabelRegion&lt;/font&gt;&lt;/strong&gt; which returns a reference to the region, if any, associated with a control. We can simply call that method and we now have the references we need. The &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;Invoke&lt;/font&gt;&lt;/strong&gt; method now looks something like this:&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; height: 394px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CloseTabbedViewAction : TriggerAction&amp;lt;FrameworkElement&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt;         RoutedEventArgs args = parameter &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; RoutedEventArgs;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( args == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; ) &lt;span style="color: #0000ff"&gt;return&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;         &lt;span style="color: #008000"&gt;// Find the parent tab item that contains the view to remove.&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;         TabItem tabItem = FindVisualParent&amp;lt;TabItem&amp;gt;( args.OriginalSource &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; DependencyObject );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: #008000"&gt;// Find the parent tab control that represents the region.&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;         TabControl tabControl = FindVisualParent&amp;lt;TabControl&amp;gt;( tabItem );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&lt;/span&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( tabControl != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; tabItem != &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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum16"&gt;  16:&lt;/span&gt;             &lt;span style="color: #008000"&gt;// Get the view.&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum17"&gt;  17:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; view = tabItem.Content;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum18"&gt;  18:&lt;/span&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum19"&gt;  19:&lt;/span&gt;             &lt;span style="color: #008000"&gt;// Get the region associated with the tab control.&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum20"&gt;  20:&lt;/span&gt;             IRegion region = RegionManager.GetObservableRegion( tabControl ).Value;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum21"&gt;  21:&lt;/span&gt;             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( region != &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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum22"&gt;  22:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum23"&gt;  23:&lt;/span&gt;                 region.Remove( view );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum24"&gt;  24:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum25"&gt;  25:&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum26"&gt;  26:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;h3&gt;Integrating with Region Navigation&lt;/h3&gt;

&lt;div class="csharpcode"&gt;The code above removes the view from the region ok, but in a real application we probably want the view (or its view model) to be informed that the user is closing the view. This would allow the view to validate itself, save its state, etc. In some cases the view may want to be able to cancel the close operation entirely.&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;In Prism 4.0, we added support for Region Navigation. This extends Prism’s region concept to provide a Uri based navigation mechanism for displaying views in regions. It also includes support for the MVVM pattern by allowing views and view models to participate in navigation. To enable this, two interfaces were defined: &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;INavigationAware&lt;/font&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;IConfirmNavigationRequest&lt;/font&gt;&lt;/strong&gt;. You can implement these interfaces on your view or view model. The methods they define allow the view or view model to be notified before and after navigation has occurred, and in the latter case, to defer navigation pending confirmation by the user.&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;We can consider the closure of a view a navigation operation. If the view (or it’s view model) implements one of these interfaces, then we can allow them to participate in the operation by calling the appropriate methods. To do this, we need a helper method to find out whether the view or the view model implements the interface and, if so, return a reference to the implementor:&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; T Implementor&amp;lt;T&amp;gt;( &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; content ) &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; T : &lt;span style="color: #0000ff"&gt;class&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     T impl = content &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; T;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( impl == &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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;         FrameworkElement element = content &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; FrameworkElement;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( element != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; ) impl = element.DataContext &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; T;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; impl;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;If either the view or view model implement the specific interface, we need to call the appropriate method on it. We’ll define another helper method for that:&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; NotifyIfImplements&amp;lt;T&amp;gt;( &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; content,&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt;                  Action&amp;lt;T&amp;gt; action ) &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; T : &lt;span style="color: #0000ff"&gt;class&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; notified = &lt;span style="color: #0000ff"&gt;false&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Get the implementor of the specified interface -&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// either the view or the view model.&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;     T target = Implementor&amp;lt;T&amp;gt;( content );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( target != &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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;         action( target );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt;         notified = &lt;span style="color: #0000ff"&gt;true&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum13"&gt;  13:&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; notified;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum15"&gt;  15:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;Ok, so far so good. Now all we need to do is to modify the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;Invoke&lt;/font&gt;&lt;/strong&gt; method to call the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;NotifyIfImplements&lt;/font&gt;&lt;/strong&gt; helper method for the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;INavigationAware&lt;/font&gt;&lt;/strong&gt; interface.&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; NavigationContext context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NavigationContext( region.NavigationService, &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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: #008000"&gt;// See if the view (or its view model) supports the INavigationAware interface.&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: #008000"&gt;// If so, call the OnNavigatedFrom method.&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; NotifyIfImplements&amp;lt;INavigationAware&amp;gt;( view, i =&amp;gt; i.OnNavigatedFrom( context ) );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;The code above causes the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;OnNavigatedFrom&lt;/font&gt;&lt;/strong&gt; method to be called on the view or view model when it is closed. This allows it to do whatever it needs to do to save its state, etc.&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;We make a similar call to the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;NotifyIfImplements&lt;/font&gt;&lt;/strong&gt; helper method for the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;IConfirmNavigationRequest&lt;/font&gt;&lt;/strong&gt; interface:&lt;/div&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #008000"&gt;// See if the view (or its view model) supports the&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: #008000"&gt;// IConfirmNavigation interface.&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: #008000"&gt;// If so, call the ConfirmNavigationRequest method.&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: #008000"&gt;// If not, just remove the view from the region. &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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( !NotifyIfImplements&amp;lt;IConfirmNavigationRequest&amp;gt;( view,&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     i =&amp;gt; i.ConfirmNavigationRequest( context,&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     canNavigate =&amp;gt; { &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( canNavigate ) &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( region != &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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum8"&gt;   8:&lt;/span&gt;                                region.Remove( view ); } ) ) )&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum9"&gt;   9:&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; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Remove the view.&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; background-color: white; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     region.Remove( view );&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; 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; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #606060" id="lnum12"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="csharpcode"&gt;This is a little more complicated because we have to allow the view to prompt the user before closing the view. To do that we defer the removal of the view from the region by defining it within a delegate which gets called once the user interaction is completed. In the quick start template, the Edit View allows you to choose whether or not to confirm navigation away from the view using a check box. If you check it, you will be prompted to confirm the view’s closure.&lt;/div&gt;

&lt;div class="csharpcode"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode"&gt;Ok, so there you have it. By using the &lt;strong&gt;&lt;font size="2" face="Calibri"&gt;CloseTabbedViewAction&lt;/font&gt;&lt;/strong&gt; class you can easily implement a tabbed view style interface using Prism. This action class works with both Silverlight and WPF. Both samples are provided &lt;a href="http://dphill.members.winisp.net/Download/PrismTabbedViewInterface.zip" target="_blank"&gt;here&lt;/a&gt;. Let me know what you think!&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10119175" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category></item><item><title>Prism 4.0 Template Pack Now Available</title><link>http://blogs.msdn.com/b/dphill/archive/2011/01/16/prism-4-0-template-pack-now-available.aspx</link><pubDate>Sun, 16 Jan 2011 23:21:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10116384</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>16</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=10116384</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2011/01/16/prism-4-0-template-pack-now-available.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/4520.QuickStart.Silverlight.2_2D00_300_5F00_32649B50.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 5px 5px 5px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="QuickStart.Silverlight.2-300" border="0" alt="QuickStart.Silverlight.2-300" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/5706.QuickStart.Silverlight.2_2D00_300_5F00_thumb_5F00_234DBC76.png" width="119" height="119" /&gt;&lt;/a&gt;The updated version of the Prism Template Pack for Prism 4.0 is now available &lt;a href="http://dphill.members.winisp.net/Download/Prism.TemplatePack.1.3.vsix.zip"&gt;here&lt;/a&gt;!&lt;/p&gt;  &lt;p&gt;The Prism 4.0 Template Pack contains Prism shell and module project templates and a quick-start solution template which creates a multi-project solution with a shell and two modules. All templates are available for both Silverlight and WPF and for C# or Visual Basic.NET.&lt;/p&gt;  &lt;p&gt;The templates are deployed as a vsix package. Downloaded the template pack from &lt;a href="http://dphill.members.winisp.net/Download/Prism.TemplatePack.1.3.vsix.zip"&gt;here&lt;/a&gt; and then rename the file to remove the .zip file extension. Double click on the &lt;strong&gt;&lt;font face="Courier New"&gt;Prism.TemplatePack.1.3.vsix&lt;/font&gt;&lt;/strong&gt; file, review and accept the license agreement, and the templates will be installed and available in the Visual Studio New Project Dialog under the Prism node. Release notes for the template pack are available &lt;a href="http://dphill.members.winisp.net/Templates.html"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://compositewpf.codeplex.com/releases/view/55576"&gt;Prism 4.0&lt;/a&gt; (also available on MSDN &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=3453ab2b-2067-41e4-b087-312d8385cf1b&amp;amp;displaylang=en"&gt;here&lt;/a&gt;) ships with signed binary assemblies. You can register these assemblies with Visual Studio by running the &lt;strong&gt;&lt;font face="Courier New"&gt;RegisterPrismBinaries.bat&lt;/font&gt;&lt;/strong&gt; batch file. This allows Visual Studio to automatically resolve all assembly references in the newly generated projects. If you have built the Prism assemblies yourself you will have to manually fix up the project references to point to the Prism assembly locations on your system. Remember, for Silverlight projects, you will have to manually create Silverlight Application References in the Web project so that the shell and two modules XAP files are deployed to the hosting web site.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To use the Quick Start Solution templates, you will need to have the Expression Blend SDK for Silverlight (&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&amp;amp;FamilyID=d197f51a-de07-4edf-9cba-1f1b4a22110d"&gt;here&lt;/a&gt;) and/or WPF (&lt;a href="http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&amp;amp;FamilyID=75e13d71-7c53-4382-9592-6c07c6a00207"&gt;here&lt;/a&gt;) installed.&lt;/p&gt;  &lt;h3&gt;A Quick Tour&lt;/h3&gt;  &lt;p&gt;The templates provide boiler-plate code that demonstrates many of the features provided by Prism, including:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The Model-View-ViewModel (MVVM) Pattern &lt;/li&gt;    &lt;li&gt;Dependency Injection using Unity &lt;/li&gt;    &lt;li&gt;Modularity &lt;/li&gt;    &lt;li&gt;Commands &lt;/li&gt;    &lt;li&gt;Interaction Requests &lt;/li&gt;    &lt;li&gt;Regions &lt;/li&gt;    &lt;li&gt;Navigation &lt;/li&gt;    &lt;li&gt;Loosely coupled events using the Event Aggregator &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/6278.image_5F00_3BDD59C6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 5px 10px 10px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/4532.image_5F00_thumb_5F00_219CF0A2.png" width="328" height="247" /&gt;&lt;/a&gt;The quick start solution templates creates a simple multi-module Prism solution that shows all of these features working together. You can use this template to create a simple but working end-to-end application which you can evolve to your own requirements. For this release, I have updated the quick start solution quite a bit to illustrate some of the new features available in Prism 4.0, including those that support the MVVM pattern and region-based navigation.&lt;/p&gt;  &lt;p&gt;The solution consists of two modules that are loaded into a shell that uses a tab control to organize views in the main region on the right. Module 1 provides a collection of data items that are displayed in a list box using a collection view. The user can use commands to navigate to views which are then displayed as tabs in the main region. Module 2 provides a single view that responds to loosely-coupled events that are fired when the user selects an item in Module 1’s list view.&lt;/p&gt;  &lt;p&gt;The solution shows how to use some of the more advanced features of Prism’s region navigation support. Clicking on the arrow button for an item causes an Edit View for that item to be displayed in the main region. The Edit View uses an interaction request to prompt the user if they decide to navigate away from that view. The other button causes the Details View to be displayed. This view is re-used and updated to display the corresponding item. The navigational behavior of the views are defined by the &lt;font face="Courier New"&gt;&lt;strong&gt;INavigationAware&lt;/strong&gt;&lt;/font&gt; and &lt;strong&gt;&lt;font face="Courier New"&gt;IConfirmNavigationRequest&lt;/font&gt;&lt;/strong&gt; interfaces implemented by the view model classes.&lt;/p&gt;  &lt;p&gt;I’ve tested the templates extensively but if you find anything that needs fixing or improving, please let me know. If everything is ok, I’ll put the template pack in the Visual Studio Code Gallery to make them available from within Visual Studio’s Extension Manager directly…&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10116384" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category></item><item><title>Updated Prism Template Pack for Visual Studio 2010 RTM</title><link>http://blogs.msdn.com/b/dphill/archive/2010/06/08/updated-prism-template-pack-for-visual-studio-2010-rtm.aspx</link><pubDate>Tue, 08 Jun 2010 18:34:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10021817</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=10021817</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2010/06/08/updated-prism-template-pack-for-visual-studio-2010-rtm.aspx#comments</comments><description>&lt;p&gt;Well it took longer than I thought it would, but I’ve finally managed to update the Prism Template Pack for Visual Studio 2010 RTM!!!&lt;/p&gt;  &lt;p&gt;To install the templates, download the template pack from &lt;a href="http://dphill.members.winisp.net/Download/Prism.TemplatePack.zip" target="_blank"&gt;here&lt;/a&gt;, &lt;strong&gt;rename the file extension from .zip to .vsix&lt;/strong&gt;, then double click it. You’ll be presented with the license. Once you accept everything will be installed into the Visual Studio Extension Manager. If you already have the RC version installed, it should be updated automatically.&lt;/p&gt;  &lt;p&gt;If you used the Release Candidate release of the Template Pack, you’ll notice a few updates in this version:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Both Visual C# and Visual Basic templates are now provided!!! &lt;/li&gt;    &lt;li&gt;The templates have been updated to target Prism 2.2 (available &lt;a href="http://compositewpf.codeplex.com/releases/view/46046" target="_blank"&gt;here&lt;/a&gt;), which uses the latest Unity 2.0 and EntLib 5.0 releases. &lt;/li&gt;    &lt;li&gt;Some folks reported problems installing the templates. It seems these problems were due to long path names in the vsix package. I’ve shortened the paths so hopefully this issue is now resolved. (Many thanks to &lt;a href="http://silverlightdude.wordpress.com/2010/06/07/installing-the-prism-template-pack-for-visual-studio-2010/" target="_blank"&gt;Silverlight Dude&lt;/a&gt; for figuring this out!!!) &lt;/li&gt;    &lt;li&gt;I’ve also fixed a few minor bugs, and updated the readme files to cover the use of Unity 2.0 and EntLib 5.0. Apart from that, everything should work as before… &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Now With Visual Basic Templates!!!&lt;/h4&gt;  &lt;p&gt;The biggest new feature of course, is that the Template Pack now provides Visual Basic .NET templates as well as C#. This was one of the reasons why it took me so long to update the templates – my VB was a bit rusty :-)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/8838.image_5F00_0290BC98.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/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-29-42-metablogapi/2313.image_5F00_thumb_5F00_01B856AE.png" width="539" height="280" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Please give them a whirl and let me know what you think. If there are no problems, I’ll post them up onto the Visual Studio Gallery.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10021817" width="1" height="1"&gt;</description></item><item><title>Prism 4.0 – Have Your Say!</title><link>http://blogs.msdn.com/b/dphill/archive/2010/04/28/prism-4-0-have-your-say.aspx</link><pubDate>Wed, 28 Apr 2010 17:59:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10004027</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=10004027</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2010/04/28/prism-4-0-have-your-say.aspx#comments</comments><description>&lt;p&gt;We are just about to officially kick off the Prism 4.0 project. As we’ve done for previous Prism projects, we’ve put together a short survey to try and get community input on the focus and direction of the project. You can find the survey &lt;a href="http://www.zoomerang.com/Survey/WEB22AK39NFHMT" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;One of the key questions that we’d like to get feedback on, is whether we should solely target .NET 4.0 and Silverlight 4.0, or whether we should also target .NET 3.5 SP1 and Silverlight 3.0. I’m sure there are many folks who have existing solutions and would like to take advantage of Prism 4.0. But, there are significant new features in .NET/SL 4.0 (such as the Managed Extensibility Framework) that greatly simplify app development.&lt;/p&gt;  &lt;p&gt;Focusing on .NET/SL 4.0 would also allow us to greatly simplify Prism, which in turn would allow us to cover additional areas of guidance. The survey describes a number of these potential areas, including security, data/service access, designer-developer workflow, design-time support, out-of-browser applications, UI patterns, navigation, etc.&lt;/p&gt;  &lt;p&gt;As you can see, there are a lot of areas that we could provide guidance on but we can’t tackle them all. We need to hear from you so that we can prioritize appropriately. So please take the survey and let us know what you think are the most important aspects for us to focus on.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10004027" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category></item><item><title>Prism Template Pack for Visual Studio 2010</title><link>http://blogs.msdn.com/b/dphill/archive/2010/03/25/prism-template-pack-for-visual-studio-2010.aspx</link><pubDate>Thu, 25 Mar 2010 20:33:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9985306</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>16</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9985306</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2010/03/25/prism-template-pack-for-visual-studio-2010.aspx#comments</comments><description>&lt;p&gt;Now that we have Release Candidate versions of Visual Studio 2010, as well as WPF and Silverlight 4.0, I’ve updated the Prism Templates so that you can more easily develop Prism applications that target these latest releases.&lt;/p&gt;  &lt;p&gt;The templates themselves are similar to those I released a while back – there are templates for Shell and Module projects, as well as ‘QuickStart Solution’ templates that provide a complete, pre-configured, multi-module solution that you can use as a starting point for a complete Prism application. All templates are available for both WPF and Silverlight. They are all in C# at the moment. I’ll work on VB.NET versions soon…&lt;/p&gt;  &lt;p&gt;I’ve modified the templates a little to use some of the features that have been introduced since Silverlight 2.0. In particular, I updated the QuickStart Solution to use the Silverlight PagedCollectionView class so that the ViewModel can keep track of the current selection automatically.&lt;/p&gt;  &lt;p&gt;The biggest change, though, is that the templates now come in a VSIX package and use the Visual Studio 2010 Extension Manager. This dramatically simplifies the installation and management of the templates!! You can download the VSIX package &lt;a href="http://dphill.members.winisp.net/Download/Prism.TemplatePack.RC.zip" target="_blank"&gt;here&lt;/a&gt; – &lt;strong&gt;&lt;em&gt;note that you will have to change the file extension from .zip to .vsix in order to install it&lt;/em&gt;&lt;/strong&gt; – or you can find it in the Visual Studio Code Gallery. You can also read the Getting Started release notes &lt;a href="http://dphill.members.winisp.net/Templates.html" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You can install the VSIX package by simply double-clicking it (once you’ve changed the file extension to .vsix). You’ll be prompted to accept the license but two clicks is pretty much all it takes. When you run Visual Studio 2010 and open the Extension Manager (from the Tools menu) you’ll see the Prism Template Pack is installed. You can uninstall it or disable it from here too.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismTemplatePackforVisualStudio2010_A42A/ExtensionManager_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ExtensionManager" border="0" alt="ExtensionManager" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismTemplatePackforVisualStudio2010_A42A/ExtensionManager_thumb.png" width="504" height="286" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The templates show up in the Visual Studio 2010 New Project dialog under the Prism category. There are Shell and Module project templates, as well as the QuickStart Solution templates, for Silverlight and WPF.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismTemplatePackforVisualStudio2010_A42A/NewProject_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NewProject" border="0" alt="NewProject" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismTemplatePackforVisualStudio2010_A42A/NewProject_thumb.png" width="504" height="350" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Once you’ve created a project using the templates, a ReadMe file will be shown that details the remaining steps you will need to take before the solution will compile and run. This mainly involves updating the project’s references to point to the Prism assemblies on your system. In some cases, you might also have to add Silverlight App References to the Web project so that the projects are linked together properly. I haven’t yet figured out how to do this automatically without requiring some kind of complicated Visual Studio automation but I’m still working on it…&lt;/p&gt;  &lt;p&gt;These templates target the Release Candidate versions of Visual Studio 2010, and WPF and Silverlight 4.0. Once they are fully released, I will update the templates with any changes that are required. I’m also hoping that templates like these will be included ‘in the box’ for Prism 4.0.&lt;/p&gt;  &lt;p&gt;In the meantime, I hope you find them useful. Let me know what you think!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9985306" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/VS2010/">VS2010</category></item><item><title>Prism – A Look Ahead</title><link>http://blogs.msdn.com/b/dphill/archive/2010/03/15/prism-a-look-ahead.aspx</link><pubDate>Mon, 15 Mar 2010 20:16:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9978997</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9978997</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2010/03/15/prism-a-look-ahead.aspx#comments</comments><description>&lt;p&gt;We (meaning the Patterns &amp;amp; Practices Client Team) have have just published a post (&lt;a href="http://blogs.msdn.com/simplifying_patterns_and_practices/archive/2010/03/15/prism-a-look-ahead.aspx" target="_blank"&gt;here&lt;/a&gt;) on the P&amp;amp;P team blog that describes our plans for Prism. The post answers two of the most frequently asked questions that we get on Prism:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Can I use Prism for WPF/Silverlight 4.0 development?&lt;/li&gt;    &lt;li&gt;What’s going to be in Prism 4.0?&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;To answer the first question we’ve started to test Prism 2.1 against the Release Candidates of WPF 4.0 and Silverlight 4.0. Apart from a couple of very minor things in the Reference Implementation and some of the unit tests, we’ve found no issues with using Prism 2.1 for WPF 4.0 and Silverlight 4.0 development. Once .NET 4.0 and Silverlight 4.0 are released, we’ll complete our testing and release an updated version of Prism (which we’ll probably call Prism 2.2). This is an interim release to allow folks to continue to use Prism when targeting the latest and greatest versions of WPF and Silverlight.&lt;/p&gt;  &lt;p&gt;In the meantime, we’re going to start work on the next version of Prism (which we’re going to call Prism 4.0) with a target release date around September 2010. As you know, we run a pretty agile ship here in patterns &amp;amp; practices, and we rely heavily on the community to help us guide our projects as we go along. What this means is that we won’t know exactly what’s going to be in Prism 4.0 until we ship it, but of course we do have a pretty good idea on the technical areas that we’d like to address.&lt;/p&gt;  &lt;p&gt;For Prism 4.0 the four key technical areas that we’d like to cover are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Managed Extensibility Framework (MEF) Integration&lt;/b&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Extended Support for Model-View-ViewModel (MVVM)&lt;/b&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Data Access &amp;amp; Application Services&lt;/b&gt;&lt;/li&gt;    &lt;li&gt;&lt;b&gt;Design-Time Support&lt;/b&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The &lt;a href="http://blogs.msdn.com/simplifying_patterns_and_practices/archive/2010/03/15/prism-a-look-ahead.aspx" target="_blank"&gt;post&lt;/a&gt; provides much more detail on each of these areas. We’re looking to you folks to help us prioritize which aspects of these areas we should focus on. If you’d like to get involved, make sure you visit the Prism &lt;a href="http://compositewpf.codeplex.com/"&gt;CodePlex&lt;/a&gt; site regularly and let us know what you think. We’ll be dropping code and updates there often once the project gets underway next month.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9978997" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/MEF/">MEF</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Unity/">Unity</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/-NET+Ria+Services/">.NET Ria Services</category></item><item><title>Custom Content Loaders in Silverlight 4.0</title><link>http://blogs.msdn.com/b/dphill/archive/2009/12/24/custom-content-loaders-in-silverlight-4-0.aspx</link><pubDate>Thu, 24 Dec 2009 15:51:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9940972</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9940972</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/12/24/custom-content-loaders-in-silverlight-4-0.aspx#comments</comments><description>&lt;p&gt;Silverlight 3.0 supports navigation by providing a Frame control into which you can load various pages as the user clicks on hyperlink controls in the application’s UI. Each page is specified by a Uri. As navigation takes place, the browser’s history and address bar is updated with this Uri. This allows the user to use the browser’s forward and back buttons to navigate around within the Silverlight application or to use deep links. You can map ‘friendly’ Uri’s to real page Uri’s so that the browser’s address bar doesn’t display the internal details of your application’s UI structure.&lt;/p&gt;  &lt;p&gt;The Silverlight 3.0 navigation framework has some very interesting capabilities, but it does have some limitations too. One of these limitations is that all of the pages that can be navigated to have to be defined in the application’s primary XAP file. For composite applications, that typically consist of multiple XAP files, this has proven to be quite a problem. Various workarounds have been proposed but they are all pretty clunky. The underlying problem is that the Silverlight 3.0 navigation framework doesn’t provide any extensibility hooks to implement this capability properly.&lt;/p&gt;  &lt;h4&gt;The Good News&lt;/h4&gt;  &lt;p&gt;Happily, this is about to change in Silverlight 4.0, which will allow you to specify a &lt;strong&gt;Content Loader &lt;/strong&gt;for each Frame instance:&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: #606060" id="lnum1"&gt;   1:&lt;/span&gt; myFrame.ContentLoader = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomContentLoader();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The content loader is responsible for loading whatever content is associated with the target Uri. By giving folks the ability to create custom content loaders of their own, Silverlight 4.0’s navigation framework opens up some very interesting extensibility options. A custom content loader, for example, can remove the need for clunky shims and pass-through loader pages when navigating to pages located in other XAP files. They can also allow you to use navigation Uri’s which don’t necessarily have to map directly to UI content, or allow you to control the target page’s construction (so you can hook up it’s ViewModel), etc.&lt;/p&gt;

&lt;h4&gt;The Bad News&lt;/h4&gt;

&lt;p&gt;There is a rather large drawback with custom content loaders though: they are executed &lt;strong&gt;&lt;em&gt;asynchronously&lt;/em&gt;&lt;/strong&gt;. This makes them quite tricky to implement. A custom content loader implements the INavigationContentLoader interface which includes Begin and End methods and uses an IAsyncResult object to coordinate the asynchronous interaction between the Frame and the content loading logic. This asynchronous call pattern is known as the .NET Asynchronous Programming Model (APM). It’s &lt;em&gt;notoriously&lt;/em&gt; tricky to implement properly – not least of which because you have to account for the 3 or 4 ways in which the caller can execute the call, and you have to handle exceptions, cancellations and wait handles very carefully.&lt;/p&gt;

&lt;p&gt;So why is navigation executed asynchronously you may ask. That’s a very good question! I was involved in the early design discussions for the Silverlight navigation framework and argued against an asynchronous model for a couple of reasons. My main argument was that navigation invariably means you have to construct the new UI to which you’re navigating, and this has to happen &lt;em&gt;synchronously&lt;/em&gt; on the UI thread. My other argument&amp;#160; was to do with user experience – more on this later.&lt;/p&gt;

&lt;p&gt;Ah, yes, (so the counter-argument went) but what happens if you want to download some content/data from the host web site, or make a web service call, or load data from a database, or maybe do some complex calculation – you can’t tie up the UI thread! These are all valid things to do in an application of course, &lt;em&gt;just not within the navigation operation itself!!!&lt;/em&gt; Apart from anything else, these are pretty advanced scenarios and &lt;em&gt;by far &lt;/em&gt;the majority of navigation scenarios will just involve mapping Uri’s to UI content which just needs to be loaded (on the UI thread!!). In addition, all of these scenarios can be achieved fairly easily on top of a synchronous navigation model, &lt;em&gt;and &lt;/em&gt;in a way that makes for a better user experience too.&lt;/p&gt;

&lt;p&gt;Ok, rant over. I feel much better now :-) INavigationContentLoader is what it is. The Silverlight folks have worked hard to open up the navigation framework a little and given us a key extensibility point. We just have to try and leverage it as best we can…&lt;/p&gt;

&lt;p&gt;So, in this post I’ll describe the implementation of a base class (&lt;strong&gt;ContentLoaderBase&lt;/strong&gt;) that can be used to easily implement custom content loaders in Silverlight 4.0. You can use this base class to implement any number of different content loaders, including &lt;strong&gt;synchronous&lt;/strong&gt; content loaders or &lt;strong&gt;asynchronous&lt;/strong&gt; content loaders that download content in the background or that use a background thread for background processing. Hopefully this base class will provide you with a reasonable starting point for implementing whatever type of content loader you need in your application. At the end of this post I’ll talk briefly about how the &lt;strong&gt;ContentLoaderBase&lt;/strong&gt; base class works.&lt;/p&gt;

&lt;p&gt;You can download the sample code &lt;a href="http://dphill.members.winisp.net/Download/ContentLoaderSample.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It’s built on Visual Studio 2010 Beta 2 and Silverlight 4.0 Beta. The sample shows how to configure and use various synchronous and asynchronous content loaders and their effect on navigation. You can switch between the sample content loaders in MainPage.xaml.cs.&lt;/p&gt;

&lt;h4&gt;Implementing a Synchronous Content Loader&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;ContentLoaderBase&lt;/strong&gt; base class provides a small number of virtual methods. You can implement a synchronous or an asynchronous custom content loader simply by overriding the right methods. In the simple (and most common) case of an synchronous content loader, you simply need to override a single method – &lt;strong&gt;LoadContentSync&lt;/strong&gt; – which looks 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: #606060" id="lnum1"&gt;   1:&lt;/span&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;object&lt;/span&gt; LoadContentSync( Uri targetUri,&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: #606060" id="lnum2"&gt;   2:&lt;/span&gt;                                            Uri currentUri )&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: #606060" id="lnum3"&gt;   3:&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: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ControlOrPage();&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: #606060" id="lnum5"&gt;   5:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In this method you simply create or load whatever UI content you need based on the new (and maybe the current) Uri. You can do this in any number of ways – using a switch statement or using a lookup table for example. The important thing to note is that this method is called on the UI thread so you don’t have to worry about creating UI content or making cross-thread calls.&lt;/p&gt;

&lt;p&gt;Of course, since the call is made on the UI thread, you shouldn’t do crazy things like make a network call or do a lengthy calculation in this method. If you need to do anything like that then you &lt;em&gt;may&lt;/em&gt; need an asynchronous content loader (though I’ll argue later that even if you do need to do anything like this you shouldn’t do it during navigation). In the meantime here’s how you can do it using the &lt;strong&gt;ContentLoaderBase&lt;/strong&gt; class…&lt;/p&gt;

&lt;h4&gt;Implementing an Asynchronous Content Loader&lt;/h4&gt;

&lt;p&gt;You can implement an asynchronous content using the &lt;strong&gt;ContentLoaderBase&lt;/strong&gt; class by overriding two virtual methods (and implementing one or two callbacks). The first method to override is the &lt;strong&gt;GetLoadBehavior&lt;/strong&gt; method which defines whether the navigation operation for a particular Uri is synchronous or asynchronous (the default value is synchronous which is why we didn’t need to override this method in the synchronous case above).&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: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; LoadBehavior GetLoadBehavior( Uri targetUri )&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: #606060" id="lnum2"&gt;   2:&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: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Content is loaded asynchronously for all Uris.&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: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; LoadBehavior.Asynchronous;&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: #606060" id="lnum5"&gt;   5:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In this example, navigation for all Uri’s is asynchronous, though we could of course have some Uri’s handled synchronously and some handled asynchronously (which is useful when, for example, we’ve cached content that was previously downloaded asynchronously so that subsequent navigations can be handled synchronously).&lt;/p&gt;

&lt;p&gt;The other method you need to override is the &lt;strong&gt;LoadContentAsync&lt;/strong&gt; method. This is where you initiate whatever asynchronous operation you need. When that operation is completed, you simply need to call the &lt;strong&gt;LoadContentAsyncComplete &lt;/strong&gt;method in the base class to complete the navigation operation.&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: #606060" id="lnum1"&gt;   1:&lt;/span&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; LoadContentAsync(&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: #606060" id="lnum2"&gt;   2:&lt;/span&gt;                     ContentLoaderAsyncResult asyncResult )&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: #606060" id="lnum3"&gt;   3:&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: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Initiate asynchronous operation here...&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: #606060" id="lnum5"&gt;   5:&lt;/span&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: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// When the asynchronous operation is completed, call the&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: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// LoadContentAsyncComplete method on the base class to&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: #606060" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// complete the navigation operation.&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: #606060" id="lnum9"&gt;   9:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Broadly speaking, there are two types of asynchronous operations that you &lt;em&gt;might &lt;/em&gt;want to do when loading content during a navigation operation. The first involves downloading some form of content, data or configuration from the host web site. The second involves performing some form of processing or calculation on a background thread.&lt;/p&gt;

&lt;p&gt;Either way, once the async operation is completed you will still need to load or create the actual UI content to which you’re navigating on the UI thread. The way you do that in each of these two scenarios are slightly different and may require you to implement one or more callbacks. Let’s look at each of these scenarios in turn…&lt;/p&gt;

&lt;h4&gt;Downloading Content During Navigation&lt;/h4&gt;

&lt;p&gt;Retrieving or sending data from the host web site is a common scenario in Silverlight. The Silverlight WebClient class makes this fairly straightforward by providing an asynchronous event-based callback mechanism – you can start the download or upload process and the WebClient class will call you back when its complete. They key feature of this class is that the callback happens on the &lt;em&gt;UI thread&lt;/em&gt;, which in turn means that you don’t have to worry about cross-thread UI access. It’s a pity that the navigation framework didn’t adopt the same event-driven approach… Ho hum…&lt;/p&gt;

&lt;p&gt;To use the WebClient class in a content loader, we simply need to start a download process (or whatever we need) in the LoadContentAsync method and specify a callback method. Since the callback method is called on the UI thread we can load or create whatever UI content we need there. The completed sample looks something 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: #606060" id="lnum1"&gt;   1:&lt;/span&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; LoadContentAsync(&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: #606060" id="lnum2"&gt;   2:&lt;/span&gt;                             ContentLoaderAsyncResult asyncResult )&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: #606060" id="lnum3"&gt;   3:&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: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Use the WebClient class to download a file from the&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: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// web server. This is an asynchronous method call and&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: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// will return immediately.&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: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     webClient.OpenReadAsync(&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: #606060" id="lnum8"&gt;   8:&lt;/span&gt;                 &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Uri( &lt;span style="color: #006080"&gt;&amp;quot;NavigationData.xml&amp;quot;&lt;/span&gt;, UriKind.Relative ),&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: #606060" id="lnum9"&gt;   9:&lt;/span&gt;                 asyncResult );&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: #606060" id="lnum10"&gt;  10:&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: #606060" id="lnum11"&gt;  11:&lt;/span&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: #606060" id="lnum12"&gt;  12:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnOpenReadCompleted( Object sender,&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: #606060" id="lnum13"&gt;  13:&lt;/span&gt;                                   OpenReadCompletedEventArgs e )&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: #606060" id="lnum14"&gt;  14:&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: #606060" id="lnum15"&gt;  15:&lt;/span&gt;     ContentLoaderAsyncResult asyncResult =&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: #606060" id="lnum16"&gt;  16:&lt;/span&gt;                     (ContentLoaderAsyncResult)e.UserState;&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: #606060" id="lnum17"&gt;  17:&lt;/span&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: #606060" id="lnum18"&gt;  18:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Since the WebClient callback is on the UI thread,&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: #606060" id="lnum19"&gt;  19:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// we can create the UI we're navigating to here.&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: #606060" id="lnum20"&gt;  20:&lt;/span&gt;     Object content = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ControlOrPage();&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: #606060" id="lnum21"&gt;  21:&lt;/span&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: #606060" id="lnum22"&gt;  22:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Inform the base class that the async request has&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: #606060" id="lnum23"&gt;  23:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// been completed.&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: #606060" id="lnum24"&gt;  24:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.LoadContentAsyncComplete( content, asyncResult );&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: #606060" id="lnum25"&gt;  25:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Notice how the UI content&amp;#160; that was created in the callback method is passed back to the base class via the LoadContentAsyncComplete method call. The base class then completes the asynchronous navigation operation and passes the content to the Frame.&lt;/p&gt;

&lt;h4&gt;Background Processing During Navigation&lt;/h4&gt;

&lt;p&gt;The other scenario where you might want to use an asynchronous content loader is where you want to use a background thread to perform some kind of calculation or background process. In this case, the &lt;strong&gt;LoadContentAsync&lt;/strong&gt; method might look something 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: #606060" id="lnum1"&gt;   1:&lt;/span&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; LoadContentAsync(&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: #606060" id="lnum2"&gt;   2:&lt;/span&gt;                             ContentLoaderAsyncResult asyncResult )&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: #606060" id="lnum3"&gt;   3:&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: #606060" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Use the thread pool to queue up a background operation.&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: #606060" id="lnum5"&gt;   5:&lt;/span&gt;     ThreadPool.QueueUserWorkItem( BackgroundTask, asyncResult );&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: #606060" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Where BackgroundTask is the method that defines the background process. This method will of course be called on the background thread, not the UI thread, so when the calculation is finished how do we load the UI content that we need to navigate to? To do that, when we inform the base class that the calculation has finished, we provide &lt;em&gt;another &lt;/em&gt;callback. The base class makes sure that this callback will be called on the UI thread so we can load our UI content there. The completed sample looks something 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: #606060" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; BackgroundTask( Object state )&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: #606060" id="lnum2"&gt;   2:&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: #606060" id="lnum3"&gt;   3:&lt;/span&gt;     ContentLoaderAsyncResult asyncResult =&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: #606060" id="lnum4"&gt;   4:&lt;/span&gt;                 (ContentLoaderAsyncResult)state;&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: #606060" id="lnum5"&gt;   5:&lt;/span&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: #606060" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Simulate some lengthy calculation or process.&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: #606060" id="lnum7"&gt;   7:&lt;/span&gt;     Thread.Sleep( 4000 );&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: #606060" id="lnum8"&gt;   8:&lt;/span&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: #606060" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// We can't create the necessary UI content&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: #606060" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// here because we're on a background thread.&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: #606060" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// So we create the UI in a callback method.&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: #606060" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// The base class will call the callback on the UI thread.&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: #606060" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.LoadContentAsyncComplete( LoadContentUICallback,&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: #606060" id="lnum14"&gt;  14:&lt;/span&gt;                                    asyncResult, asyncResult );&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: #606060" id="lnum15"&gt;  15:&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: #606060" id="lnum16"&gt;  16:&lt;/span&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: #606060" id="lnum17"&gt;  17:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Object LoadContentUICallback( Object callbackState )&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: #606060" id="lnum18"&gt;  18:&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: #606060" id="lnum19"&gt;  19:&lt;/span&gt;     Debug.WriteLine( &lt;span style="color: #006080"&gt;&amp;quot;LoadContentUICallback&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: #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: #606060" id="lnum20"&gt;  20:&lt;/span&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: #606060" id="lnum21"&gt;  21:&lt;/span&gt;     ContentLoaderAsyncResult asyncResult =&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: #606060" id="lnum22"&gt;  22:&lt;/span&gt;                 (ContentLoaderAsyncResult)callbackState;&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: #606060" id="lnum23"&gt;  23:&lt;/span&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: #606060" id="lnum24"&gt;  24:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// Since THIS callback is on the UI thread, we can&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: #606060" id="lnum25"&gt;  25:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// create the UI we're navigating to here.&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: #606060" id="lnum26"&gt;  26:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ControlOrPage();&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: #606060" id="lnum27"&gt;  27:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h4&gt;TODO: Cancelation&lt;/h4&gt;

&lt;p&gt;The above code snippets are simplified a little to show you the essentials. If you have an asynchronous content loader you will find that a navigation operation will often be canceled. To implement an asynchronous content loader properly you will therefore have to account for cancelation.&lt;/p&gt;

&lt;p&gt;Why is navigation canceled so often? Because the navigation framework does not provide any built-in mechanism to give feedback to the user during an asynchronous navigation operation. Since the user &lt;em&gt;expects &lt;/em&gt;navigation to be instantaneous, they have a tendency to click the navigate button or hyperlink control multiple times, and each time they do, the previous navigation operation will be cancelled. So it’s very important to handle cancellations properly, otherwise you can easily run into tricky-to-handle exceptions during navigation. The irony of course, is that asynchronous navigation was meant to improve the user experience…&lt;/p&gt;

&lt;p&gt;To illustrate the effects of network latency or lengthy processing during navigation, the sample code includes artificial delays. For the download sample, a HTTP handler is used to introduce an artificial delay during the download of the dummy file. Similarly, the background thread sample includes a 3 second Thread.Sleep in the background task method.&lt;/p&gt;

&lt;p&gt;When navigation is asynchronous, you’ll quickly notice that clicking on the navigation links during an existing navigation operation will cause the previous navigation operation to be canceled. The sample code shows how you might handle this situation but there are some complications that have not yet been ironed out (see the comments in the code for more details). In the download case you will need to somehow cancel the previous download operation. In the background thread case you will have to find a way to abort or cancel the calculation or background process gracefully if navigation is cancelled…&lt;/p&gt;

&lt;h4&gt;ContentLoaderBase Class Implementation Details&lt;/h4&gt;

&lt;p&gt;The key to the ContentLoaderBase Class is the object that implements the IAsyncResult interface. For that I leveraged the excellent coding skills of Jeffery Richter and his MSDN magazine article (&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163467.aspx" target="_blank"&gt;here&lt;/a&gt;) from a few years back. That article and the accompanying code, describes many of the subtle details that you have to worry about when implementing the APM. With the IAsycnResult object implemented properly, the ContentLoaderBase class ‘simply’ has to make sure that the right virtual methods are called in the right order and that the LoadContentUICallback is executed on the UI thread.&lt;/p&gt;

&lt;h4&gt;An Easier Approach&lt;/h4&gt;

&lt;p&gt;The ContentLoaderBase class simplifies things quite a bit, especially when implementing a synchronous content loader. But I think you can probably see that asynchronous content loaders are still a little complicated to implement properly. I’m sure that I have not even begun to iron out all of the subtle issues that inevitably show up when you’re doing anything asynchronously (e.g. cancelation as noted above).&lt;/p&gt;

&lt;p&gt;For reasons of complexity, plus the bad user experience that can result, I would recommend using only &lt;em&gt;synchronous&lt;/em&gt; content loaders wherever possible. But what about those situations where you &lt;em&gt;absolutely &lt;/em&gt;need to download or calculate something during navigation? My advice is to do these things &lt;em&gt;outside&lt;/em&gt; of the navigation framework and to do them &lt;em&gt;in the target page itself&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So for example, for the two scenarios above, you would navigate to a page (synchronously) that will then download the content or perform the calculation (in its ViewModel of course). Furthermore, while the page is downloading the content or performing the calculation, it can provide visual feedback to the user! To the user, the navigation is instantaneous, even though the target page might take a while to initialize itself. By providing visual feedback while this happens you will likely prevent the user from getting frustrated and repeatedly clicking the navigate button or link.&lt;/p&gt;

&lt;p&gt;I’ll explore this approach, plus some other interesting things you can do with a custom content loader, in a future post…&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9940972" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Helix/">Helix</category></item><item><title>Prism and MEF</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>22</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9934539</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/12/09/prism-and-mef.aspx#comments</comments><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/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/MEF/">MEF</category></item><item><title>Prism &amp; WCF RIA Services</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9928297</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/11/24/prism-wcf-ria-services.aspx#comments</comments><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/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/-NET+Ria+Services/">.NET Ria Services</category></item><item><title>The Breadcrumb Navigation Pattern</title><link>http://blogs.msdn.com/b/dphill/archive/2009/10/15/the-breadcrumb-navigation-pattern.aspx</link><pubDate>Thu, 15 Oct 2009 22:16:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9907866</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9907866</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/10/15/the-breadcrumb-navigation-pattern.aspx#comments</comments><description>&lt;p&gt;The Breadcrumb Navigation pattern provides a visual representation of the path the user took as they navigated to a particular state in an application. It provides context so the user can see where they are logically within the application structure, and it allows them to quickly navigate that structure by jumping straight to previous breadcrumbs.&lt;/p&gt;  &lt;p&gt;Perhaps the most common example of the breadcrumb navigation pattern is Windows Explorer – as you navigate the file system, the breadcrumb control at the top of window displays the path to the current folder, with each folder in the chain displayed as a button. You can jump directly to any of the parent folders by clicking on it.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/TheBreadcrumbNavigationPattern_8E11/clip_image001_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/TheBreadcrumbNavigationPattern_8E11/clip_image001_thumb.jpg" width="454" height="114" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You often see the pattern used in web sites, especially ones where the user is navigating through a lot of hierarchical data. For example, a lot of ecommerce site allows the user to browse the product catalog by drilling into product categories and by specifying search criteria and filters. Here’s a good example from &lt;a href="http://www.guitarcenter.com/" target="_blank"&gt;GuitarCenter.com&lt;/a&gt; – you can navigate around within the product catalog by product category and filter the view by price or manufacturer.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/TheBreadcrumbNavigationPattern_8E11/clip_image002_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/TheBreadcrumbNavigationPattern_8E11/clip_image002_thumb.jpg" width="454" height="32" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;The Breadcrumb Navigation Pattern in Helix&lt;/h3&gt;  &lt;p&gt;This post describes how you can implement the breadcrumb navigation pattern in Helix, my prototype navigation framework for Silverlight. You can download the latest version of Helix from &lt;a href="http://dphill.members.winisp.net/Download/Helix-Navigation-0.4.zip" target="_blank"&gt;here&lt;/a&gt;, and run the sample described below &lt;a href="http://dphill.members.winisp.net/BreadcrumbSample.html" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;h4&gt;The BreadcrumbBar Control&lt;/h4&gt;  &lt;p&gt;Implementing the Breadcrumb Navigation pattern in Helix turned out to be quite straightforward. The main element is the BreadcrumbBar control. This control displays the breadcrumbs as the user navigates within an associated Frame. The user can click on any of the breadcrumbs causing the associated Frame to navigate back to the corresponding point in the navigation history. &lt;/p&gt;  &lt;p&gt;The BreadcrumbBar control is actually a sub-classed and re-templated ListBox control that is bound to the target Frame's journal. As the user navigates between Pages in the target Frame, journal entries are added to the journal. Each journal entry is represented in the BreadcrumbBar control as a ListBox item. The BreadcrumbBar control's template displays each item horizontally as a chevron, along with the corresponding page title. The most difficult part to getting this to work is the control template itself. I used Blend 3.0 to edit the template so even that wasn't that difficult. I also made a couple of changes to the Helix library itself to support breadcrumb style navigation in the Journal. More details on this below.&lt;/p&gt;  &lt;h4&gt;The Sample Application&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/TheBreadcrumbNavigationPattern_8E11/clip_image004_2.jpg"&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/TheBreadcrumbNavigationPattern_8E11/clip_image004_thumb.jpg" width="454" height="175" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Patterns &amp;amp; practices guidance is organized by four high-level focus areas – Fundamentals, Client, Server and Services. Within each area there can be a number of sub-categories (such as security, performance, etc), and within sub-categories there is the guidance itself. Since the catalog is hierarchical, it’s a natural fit for the breadcrumb navigation pattern. I’ll describe a simple application that uses the BreadcrumbBar control and Helix to allow the user to browse through the patterns &amp;amp; practices guidance catalog. You can see the completed application and the BreadcrumbBar control in action &lt;a href="http://dphill.members.winisp.net/BreadcrumbSample.html" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;This is a simple application that has a simple shell that contains a BreadCrumbBar control and a Frame control in a grid:&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;BreadcrumbBar&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;       &lt;span class="attr"&gt;NavigationTarget&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{Binding ElementName=frame}&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;       &lt;span class="attr"&gt;ClearForwardStack&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;False&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&amp;#160;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Frame&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;frame&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;    &lt;span class="attr"&gt;NavigationUIVisibility&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Hidden&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;InitialUri&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;HomePage&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;The BreadcrumbBar control is connected to the target Frame through simple data binding. Since we’re using the BreadcrumbBar control we don’t need the Frame’s back/forward buttons so we can hide the Frame’s navigation UI. The Frame navigates to the HomePage on startup. That’s pretty much it. I’ll talk about the ClearForwardStack below. You can tweak some of the visual aspects of the BreadcrumbBar control, or even replace the control template, to suit your application’s UI style.&lt;/p&gt;

&lt;h4&gt;How Does It Work?&lt;/h4&gt;

&lt;p&gt;The BreadcrumbBar control is just a sub-classed and re-templated ListBox. When the NavigationTarget property value is set, it sets the base class ItemSource to the journal back stack.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.ItemsSource = NavigationTarget.Journal.BackStack;&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;If the user changes the current selection (i.e. by clicking on a previous breadcrumb), the target Frame is navigated to the associated Uri. To support this I added two new methods to the IJournal interface – GoBackTo and GoForwardTo. These two methods allow the journal to navigate directly to an entry that’s in the back stack or the forward stack, without having to navigate backwards or forwards multiple times.&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;NavigationTarget.Journal.GoBackTo( entry, ClearForwardStack );&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;Two other things to note:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The current selection of the underlying ListBox tracks the last entry in the journal. In other words, as the user navigates to new pages within the Frame, a journal entry for it is added and it becomes the current selection in the BreadcrumbBar control. 
    &lt;br /&gt;&lt;/li&gt;

  &lt;li&gt;The ClearForwardStack parameter is used to control how the journal’s forward stack is affected when the user clicks on a previous breadcrumb. Most often you’ll want the forward stack to be cleared, and this is the default. Sometimes you might want to keep the forward stack intact so the user can go forward again. To enable this, just set the ClearForwardStack parameter to false. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;What’s Next For Helix?&lt;/h3&gt;

&lt;p&gt;Now that Silverlight 3.0 supports navigation, the need for Helix is not as great as it was. I actually wrote the original specs for the Silverlight 3.0 Navigation feature. The original design in fact was very similar to Helix, but due to a number of constraints the design evolved and became a little less extensible than originally planned. There are key extensibility points that Helix provides which enable a whole host of interesting scenarios that are difficult or impossible to achieve with the current Silverlight navigation implementation. I’ve really only scraped the surface of these in this series so I’ll continue to evolve Helix in order to explore these scenarios. I’m working with the Silverlight team to explore ways in which these key extensibility points can be opened up in upcoming Silverlight releases.&lt;/p&gt;

&lt;p&gt;In the meantime, if you’re building a Silverlight application that requires navigation functionality, you should use the Silverlight 3.0 navigation framework since it’s robust and fully supported. Hopefully, the need for Helix will go away altogether once the Silverlight navigation framework is more extensible.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9907866" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Helix/">Helix</category></item><item><title>The Application Architecture Guide 2.0 Is Here!</title><link>http://blogs.msdn.com/b/dphill/archive/2009/10/14/the-application-architecture-guide-2-0-is-here.aspx</link><pubDate>Wed, 14 Oct 2009 17:13:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9907244</guid><dc:creator>David Hill [Microsoft]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9907244</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/10/14/the-application-architecture-guide-2-0-is-here.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/ApplicationArchitectureGuide2.0IsHere_B63D/AAG2FrontCover-Small_2.png"&gt;&lt;img style="border-right-width: 0px; margin: 0px 15px 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AAG2FrontCover-Small" border="0" alt="AAG2FrontCover-Small" align="left" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/ApplicationArchitectureGuide2.0IsHere_B63D/AAG2FrontCover-Small_thumb.png" width="164" height="200" /&gt;&lt;/a&gt; The Application Architecture Guide 2&lt;sup&gt;nd&lt;/sup&gt; Edition is finally available! The complete guide is hosted on MSDN &lt;a href="http://www.microsoft.com/architectureguide"&gt;here&lt;/a&gt;. We’ve sent the guide off to MS Press for printing, so the printed version should be available from your favorite bookstore soon.&lt;/p&gt;  &lt;p&gt;Since the final draft of guide was published on CodePlex early this year, we’ve been busy driving the guide through a final set of reviews and polishing the content. Based on community and p&amp;amp;p team feedback we’ve restructured the guide to make it easier to read and understand. We’ve also removed some of the duplication and made it easier to find your way around so you can more easily find the information that’s relevant to you. We’ve also incorporated a lot of the feedback that we’ve received from the community on topics like Domain Driven Design and Cloud Computing. It’s taken us a little longer than we thought, but we hope you’ll agree that the wait was worth it.&lt;/p&gt;  &lt;p&gt;Of course, there are so many elements that go into producing a guide of this scope that it clearly represents a team effort. In particular, the many members of the community and the p&amp;amp;p team who brought their technical expertise and experience to the guide deserve a special mention, along with our esteemed writer &lt;a href="http://blogs.msdn.com/alexhomer/" target="_blank"&gt;Alex Homer&lt;/a&gt; and the rest of our content team who drove the guide through the edit, layout, indexing, and publishing phases.&lt;/p&gt;  &lt;p&gt;What’s next for the guide? Well, that’s up to you! We designed the guide so that it could be more easily updated; for new architectural techniques and approaches, for new technologies, and for new application types and scenarios. For example, we could add a Windows Azure application archetype, or update the technology matrices for the .NET 4.0 wave of technologies. In order for us to prioritize where we go next with the guide we need your feedback, so please send it along and let us know what you think.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9907244" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category></item><item><title>Blend Behaviors</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9899750</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/09/25/blend-behaviors.aspx#comments</comments><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/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Helix/">Helix</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Blend/">Blend</category></item><item><title>Prism Training Classes</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9896859</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/09/18/prism-training-classes.aspx#comments</comments><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/b/dphill/archive/tags/Prism/">Prism</category></item><item><title>Prism And .Net RIA Services</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9873200</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/08/17/prism-and-net-ria-services.aspx#comments</comments><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/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/ViewModel/">ViewModel</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/-NET+Ria+Services/">.NET Ria Services</category></item><item><title>Prism Quick Start Kit Update</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9754187</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/06/15/prism-quick-start-kit-update.aspx#comments</comments><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/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category></item><item><title>Prism Training Course</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9708513</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/06/08/prism-training-course.aspx#comments</comments><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/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category></item><item><title>Prism Quick Start Kit</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>16</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9661173</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/05/29/prism-quick-start-kit.aspx#comments</comments><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/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category></item><item><title>ViewModel and Dependency Injection</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9625816</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/05/18/viewmodel-and-dependency-injection.aspx#comments</comments><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/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Helix/">Helix</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/ViewModel/">ViewModel</category></item><item><title>Silverlight Navigation Part 3</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9574249</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/04/28/silverlight-navigation-part-3.aspx#comments</comments><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/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Helix/">Helix</category></item><item><title>Mix 09!</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9487435</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/03/18/mix-09.aspx#comments</comments><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/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Helix/">Helix</category></item><item><title>Prism 2.0 Refresh</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9453242</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/03/01/prism-2-0-refresh.aspx#comments</comments><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/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category></item><item><title>Prism 2.0 Is Live!</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9436573</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/02/20/prism-2-0-is-live.aspx#comments</comments><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/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category></item><item><title>Master-Detail With CollectionViewModel</title><link>http://blogs.msdn.com/b/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>David Hill [Microsoft]</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/dphill/rsscomments.aspx?WeblogPostID=9434991</wfw:commentRss><comments>http://blogs.msdn.com/b/dphill/archive/2009/02/19/master-detail-with-collectionviewmodel.aspx#comments</comments><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/b/dphill/archive/tags/Patterns+and+Practices/">Patterns and Practices</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Prism/">Prism</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/dphill/archive/tags/WPF/">WPF</category></item></channel></rss>