<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>davidpoll.com &#187; Silverlight 3</title>
	<atom:link href="http://www.davidpoll.com/tag/silverlight-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidpoll.com</link>
	<description>Silverlight, RIA development, and other goofy geeky goodness.</description>
	<lastBuildDate>Mon, 26 Jul 2010 02:17:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Silverlight Toolkit November 2009: Activity Control &#8211;&gt; BusyIndicator (a.k.a. Update 3: Displaying background activity in a Silverlight RIA application)</title>
		<link>http://www.davidpoll.com/2009/11/19/silverlight-toolkit-november-2009-activity-control-busyindicator-a-k-a-update-3-displaying-background-activity-in-a-silverlight-ria-application/</link>
		<comments>http://www.davidpoll.com/2009/11/19/silverlight-toolkit-november-2009-activity-control-busyindicator-a-k-a-update-3-displaying-background-activity-in-a-silverlight-ria-application/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 06:14:45 +0000</pubDate>
		<dc:creator>david.poll</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Activity Control]]></category>
		<category><![CDATA[BusyIndicator]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[Silverlight 4 Beta]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.davidpoll.com/2009/11/19/silverlight-toolkit-november-2009-activity-control-busyindicator-a-k-a-update-3-displaying-background-activity-in-a-silverlight-ria-application/</guid>
		<description><![CDATA[Wow!&#160; What a week!&#160; PDC, the Silverlight 4 Beta, and now the November 2009 release of the Silverlight Toolkit!&#160; There’s been a ton of great news and exciting announcements, and now I can share with you that the Activity control, first blogged here, is now a part of the Silverlight Toolkit! Awesome!&#160; What does that [...]]]></description>
			<content:encoded><![CDATA[<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_start --><!-- AdSense Now! V1.90 -->
<!-- Post[count: 3] -->
<div class="adsense adsense-leadin" style="float:right;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-0397559301561409";
/* 234x60, created 9/21/09 */
google_ad_slot = "7066877373";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Wow!&#160; What a week!&#160; <a href="http://www.microsoftpdc.com" target="_blank">PDC</a>, the <a href="http://www.silverlight.net/getstarted/silverlight-4-beta" target="_blank">Silverlight 4 Beta</a>, and now the November 2009 release of the <a href="http://silverlight.codeplex.com/" target="_blank">Silverlight Toolkit</a>!&#160; There’s been a ton of great news and exciting announcements, and now I can share with you that the Activity control, <a href="http://www.davidpoll.com/tag/activity-control/" target="_blank">first blogged here</a>, is now a part of the Silverlight Toolkit!</p>
<h3>Awesome!&#160; What does that mean for the Activity control?</h3>
<p>During this transition, the Activity control underwent a few changes (thanks to my colleagues working on the Toolkit – <a href="http://blogs.msdn.com/delay/" target="_blank">David Anson</a> and <a href="http://www.jeff.wilcox.name" target="_blank">Jeff Wilcox</a>) to make it more generally palatable:</p>
<ul>
<li>The control has been renamed from “Activity” to “BusyIndicator” in order to avoid confusion with the concept of an Activity (sounds a lot like “Task”)</li>
<ul>
<li>Similarly, “IsActive” is now “IsBusy”, and the visual states have been renamed appropriately as well.</li>
</ul>
<li>AutoBind and related properties have been removed once and for all.&#160; They were a performance hog in the original versions, and they really only hit a very, very narrow scenario.&#160; Instead, bind to a property that represents your busyness.</li>
<li>MinDisplayTime has gone away.&#160; If you’re looking to change the minimum display time, you can re-template the control and add a duration to the transition from visible back to hidden.</li>
<li>OverlayBrush and OverlayOpacity have been replaced with a single OverlayStyle property where you can set the color/opacity of the overlay easily.</li>
<li>DisplayAfter now defaults to 0.1s instead of 0.05s</li>
</ul>
<p>Otherwise, the control is basically the same!&#160; Give it a shot!</p>
<p>With this transition, the BusyIndicator control truly becomes accessible to anyone who’s using the Silverlight Toolkit.&#160; You can <a href="http://silverlight.codeplex.com/WorkItem/List.aspx" target="_blank">report bugs through that project on codeplex</a>, and we’ll make sure to keep an eye on any feedback we get from you on the control.</p>
<h3>Great… So where can I find it?</h3>
<p>It’s simple!&#160; Just download the November 2009 Silverlight Toolkit for either Silverlight 3 or Silverlight 4.&#160; There are a few ways to get it:</p>
<ul>
<li><a href="http://silverlight.codeplex.com" target="_blank">Silverlight Toolkit Codeplex Page</a></li>
<li><a href="http://www.jeff.wilcox.name/2009/11/toolkit-webpi/" target="_blank">Web Platform Installer</a></li>
</ul>
<p>The BusyIndicatorControl can be found in the <strong>System.Windows.Controls</strong> namespace in the <strong>System.Windows.Controls.Toolkit.dll</strong> assembly in the toolkit.</p>
<h3></h3>
<h3>And… can I see it in action?</h3>
<p>Yep!&#160; David Anson created some awesome samples in the Toolkit Sample Browser for the BusyIndicator.&#160; I’m a big fan of his work! <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://silverlight.net/content/samples/sl3/toolkitcontrolsamples/run/default.html" target="_blank"><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="BusyIndicator is now in the Silverlight Toolkit sample browser!" border="0" alt="BusyIndicator is now in the Silverlight Toolkit sample browser!" src="http://www.davidpoll.com/Images/Sil.Update3Displayingbackgroundactivityi_138BA/image.png" width="644" height="435" /></a> </p>
<p>I hope you all enjoy using the BusyIndicator control in your applications!&#160; Let me know what you think!</p>
<p>P.S. Thanks to Jeff Wilcox, who <a href="http://www.jeff.wilcox.name/2009/11/busy-indicator-control/" target="_blank">beat me to explaining this change</a> <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#160; I’ve been super-busy with PDC, so it was good to have someone start getting the word out early.&#160; Jeff gives a great overview of what the control is meant to do and has lots of resources regarding the Silverlight Toolkit.&#160; Check out his <a href="http://www.jeff.wilcox.name" target="_blank">blog</a>!</p>
<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.davidpoll.com/2009/11/19/silverlight-toolkit-november-2009-activity-control-busyindicator-a-k-a-update-3-displaying-background-activity-in-a-silverlight-ria-application/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Relative hyperlinks with Silverlight navigation</title>
		<link>http://www.davidpoll.com/2009/09/20/relative-hyperlinks-with-silverlight-navigation/</link>
		<comments>http://www.davidpoll.com/2009/09/20/relative-hyperlinks-with-silverlight-navigation/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 05:39:00 +0000</pubDate>
		<dc:creator>david.poll</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Dynamic Navigation]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Relative Links]]></category>
		<category><![CDATA[Silverlight 3]]></category>

		<guid isPermaLink="false">http://www.davidpoll.com/2009/09/20/relative-hyperlinks-with-silverlight-navigation/</guid>
		<description><![CDATA[If you haven’t noticed already, I happen to like the Navigation feature in Silverlight quite a bit (I wonder why? ).  In my other posts on Navigation, I’ve spent some time exploring how you can navigate to Pages in assemblies other than the main application assembly and how those assemblies can be loaded on-demand (granted, [...]]]></description>
			<content:encoded><![CDATA[<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_start --><p>If you haven’t noticed already, I happen to like the Navigation feature in Silverlight quite a bit (I wonder why? <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).  In my <a href="http://www.davidpoll.com/tag/navigation/">other posts on Navigation</a>, I’ve spent some time exploring how you can navigate to Pages in assemblies other than the main application assembly and how those assemblies can be loaded on-demand (granted, it uses some workarounds, but it gets us where we want to go!).</p>
<p>This is all well and good, but it presents an annoying problem that impacts the maintainability of such code.  Specifically, it forces every hyperlink within each of the external assemblies to know how to refer to its assembly by name (this is akin to the problem with absolute URLs in hyperlinks on web pages – those links become tightly coupled to the page for which they were created, and can’t be copied into other projects).</p>
<p>Technically, almost all Uris used by the navigation framework today are relative Uris (unless UriMappings are used to turn absolute ones into relative ones), but they are application-relative and never Page-relative.  This means that if you have a page at “/Views/Page1.xaml” and want to link to another page at “/Views/Page2.xaml” from within Page1, you must refer to the entire path (“/Views/Page2.xaml”) rather than just the relative path to the other page (e.g. “Page2.xaml” or “./Page2.xaml”).</p>
<p>In this post, we’ll look at a way to allow Page-relative navigation within your Silverlight Pages.  The approach I’ll use will take advantage of the INavigate interface that was added in Silverlight 3 and the HyperlinkButton control that uses this interface to perform navigation when clicked.</p>
<p>The INavigate interface looks like this:</p>
<pre class="code"><span style="color: blue">public interface </span><span style="color: #2b91af">INavigate
</span>{
    <span style="color: green">// Methods
    </span><span style="color: blue">bool </span>Navigate(<span style="color: #2b91af">Uri </span>source);
}</pre>
<p>It’s a simple interface with a simple purpose: allow a component to provide a way to handle navigation to a Uri.  Right now, the only component built into Silverlight that actually takes advantage of it is the HyperlinkButton control.  We use this control quite often in Navigation-enabled applications, since it allows us to target a particular Frame control to navigate to a Page by Uri.  In the Silverlight Navigation Application project template, you’ll see XAML like this:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="<strong><em><span style="text-decoration: underline;">ContentFrame</span></em></strong>" </span><span style="color: red">Style</span><span style="color: blue">="{</span><span style="color: #a31515">StaticResource </span><span style="color: red">ContentFrameStyle</span><span style="color: blue">}"
                  </span><span style="color: red">Source</span><span style="color: blue">="/Home" </span><span style="color: red">Navigated</span><span style="color: blue">="ContentFrame_Navigated" </span><span style="color: red">NavigationFailed</span><span style="color: blue">="ContentFrame_NavigationFailed"&gt;
&lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>And:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">="Link2" </span><span style="color: red">Style</span><span style="color: blue">="{</span><span style="color: #a31515">StaticResource </span><span style="color: red">LinkStyle</span><span style="color: blue">}"
                 </span><span style="color: red">NavigateUri</span><span style="color: blue">="/About" </span><span style="color: red"><strong><em><span style="text-decoration: underline;">TargetName</span></em></strong></span><span style="color: blue"><strong><em><span style="text-decoration: underline;">="ContentFrame</span></em></strong>" </span><span style="color: red">Content</span><span style="color: blue">="about"/&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This all works because the Frame control implements INavigate.  In other words, there’s no magic there – you can use it too!  Here’s the way the HyperlinkButton works when you’re trying to target an INavigate (approximately <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ):</p>
<ul>
<li>For each parent FrameworkElement going up the visual tree from the HyperlinkButton…
<ul>
<li>Check to see if the FrameworkElement is an INavigate and that its name matches TargetName (ignored if TargetName is null or empty)
<ul>
<li>If so, call INavigate.Navigate() on the FrameworkElement</li>
<li>Otherwise, recursively search for an INavigate that’s properly named within each of the children of the FrameworkElement</li>
</ul>
</li>
<li>If no properly named INavigate was found, keep moving up the visual tree</li>
</ul>
</li>
</ul>
<p>In other words, the HyperlinkButton will search its way up and down the visual tree (technically doing a pre-order breadth-first search from each parent of the HyperlinkButton, working its way up the visual tree) for an appropriate INavigate to call.</p>
<h2>So, what does all this INavigate stuff mean to me?</h2>
<p>With that technical detail out of the way, the question that arises is: how can we use this to enable Page-relative navigation?  Well, the reason navigation of a Frame works within Pages today is because the Frame control implements INavigate, and the HyperlinkButton works its way up the visual tree until it finds this.</p>
<p>For our purposes, this is great, since it means we can intercept the call to INavigate.Navigate() by implementing the interface somewhere between the HyperlinkButton and the Frame.  There’s a convenient place for this, since applications that use Page/Frame and HyperlinkButtons within those pages have a visual tree like this:</p>
<ul>
<li>Application
<ul>
<li>Layout
<ul>
<li><strong><em>Frame</em></strong>
<ul>
<li><strong><em><span style="text-decoration: underline;">Page</span></em></strong>
<ul>
<li><strong><em>HyperlinkButton</em></strong></li>
<li>Other controls</li>
</ul>
</li>
</ul>
</li>
<li>Other Controls</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>What I’m suggesting is that the Page we navigate to implement INavigate and turn page-relative Uri’s into application-relative Uri’s before handing them off the NavigationService (or the Frame) to actually perform the navigation.</p>
<p>I’ve gone ahead and extended my DynamicNavigation library to make DynamicPage implement INavigate to do what we want, but you could do the same on any subclass of Page (including every one of your Pages if you didn’t want a common base class).  Here’s my simple implementation (with a switch to turn off this feature on DynamicPages):</p>
<pre class="code"><span style="color: blue">public bool </span>RelativeLinks
{
    <span style="color: blue">get </span>{ <span style="color: blue">return </span>(<span style="color: blue">bool</span>)GetValue(RelativeLinksProperty); }
    <span style="color: blue">set </span>{ SetValue(RelativeLinksProperty, <span style="color: blue">value</span>); }
}

<span style="color: blue">public static readonly </span><span style="color: #2b91af">DependencyProperty </span>RelativeLinksProperty =
    <span style="color: #2b91af">DependencyProperty</span>.Register(<span style="color: #a31515">"RelativeLinks"</span>, <span style="color: blue">typeof</span>(<span style="color: blue">bool</span>), <span style="color: blue">typeof</span>(<span style="color: #2b91af">DynamicPage</span>), <span style="color: blue">new </span><span style="color: #2b91af">PropertyMetadata</span>(<span style="color: blue">true</span>));

<span style="color: blue">private static readonly </span><span style="color: #2b91af">Uri </span>basePlaceHolderUri = <span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(<span style="color: #a31515">"none:///"</span>, <span style="color: #2b91af">UriKind</span>.Absolute);

<span style="color: blue">#region </span>INavigate Members

<span style="color: blue">public bool </span>Navigate(<span style="color: #2b91af">Uri </span>navigateUri)
{
    <span style="color: blue">string </span>original = navigateUri.OriginalString;
    <span style="color: blue">if </span>(RelativeLinks &amp;&amp; !navigateUri.IsAbsoluteUri &amp;&amp; !original.StartsWith(<span style="color: #a31515">"/"</span>))
    {
        <span style="color: #2b91af">Uri </span>result;
        <span style="color: blue">if </span>(NavigationService.CurrentSource.IsAbsoluteUri)
        {
            result = <span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(NavigationService.CurrentSource, navigateUri);
        }
        <span style="color: blue">else
        </span>{
            <span style="color: #2b91af">Uri </span>baseUri = <span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(basePlaceHolderUri, NavigationService.CurrentSource);
            result = <span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(<span style="color: #a31515">"/" </span>+ basePlaceHolderUri.MakeRelativeUri(<span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(baseUri, navigateUri)).OriginalString,
                <span style="color: #2b91af">UriKind</span>.Relative);
        }
        <span style="color: blue">return </span>NavigationService.Navigate(result);
    }
    <span style="color: blue">else
    </span>{
        <span style="color: blue">return </span>NavigationService.Navigate(navigateUri);
    }
}

<span style="color: blue">#endregion</span></pre>
<p>Now, within the page, you can use Page-relative Uri’s on HyperlinkButtons.  All you need to do is avoid setting a TargetName (either through a style or directly on the HyperlinkButton), and the Page will handle the navigation!</p>
<p>Page-relative Uri’s can take a variety of forms.  Assuming the Page you’re currently on is “/MyLibrary;component/Views/Main/Page1.xaml”, the following transformations will occur (as an example):</p>
<ul>
<li>“Page2.xaml” –&gt; “/MyLibrary;component/Views/Main/Page2.xaml”</li>
<li>“./Page2.xaml” –&gt; “/MyLibrary;component/Views/Main/Page2.xaml”</li>
<li>“../Page3.xaml” –&gt; “/MyLibrary;component/Views/Page3.xaml”</li>
<li>“../Secondary/Page3.xaml” –&gt; “/MyLibrary;component/Views/Secondary/Page3.xaml”</li>
<li>“../../BasePage.xaml” –&gt; “/MyLibrary;component/BasePage.xaml”</li>
<li>“SubMain/Page4.xaml” –&gt; “/MyLibrary;component/Views/Main/SubMain/Page4.xaml”</li>
<li>“SubMain/Page4.xaml?a=b&amp;c=d” –&gt; “/MyLibrary;component/Views/Main/SubMain/Page4.xaml?a=b&amp;c=d”</li>
<li>“/MyLibrary;component/Views/Main/Page5.xaml” –&gt; “/MyLibrary;component/Views/Main/Page5.xaml” (no change)</li>
</ul>
<h2>Cool!  Can I see it in action?</h2>
<p>Of course! <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   As always, you can play around with a running app that does this here:</p>
<p><a href="http://www.davidpoll.com/Samples/RelativeNavigation/DynamicNavigationApplicationTestPage.html#/DynamicallyLoadedLibrary;component/CSDynamicPage.dyn.xaml" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Live sample of page-relative navigation" src="http://www.davidpoll.com/Images/RelativehyperlinkswithSilverlightnavigat_1274C/image.png" border="0" alt="Live sample of page-relative navigation" width="644" height="479" /></a></p>
<p>Click the link at the bottom of that page to peform a relative navigation that should take you on a journey between a number of pages – all of which navigate using relative navigation.</p>
<p>For reference, here is the file structure for the sample application.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="File structure of the sample application." src="http://www.davidpoll.com/Images/RelativehyperlinkswithSilverlightnavigat_1274C/image_3.png" border="0" alt="File structure of the sample application." width="268" height="255" /> </p>
<h2>So, what’s your point?</h2>
<p>Well, to sum it up – being able to do page-relative navigation increases the portability of your Pages.  It’s especially useful if you use it in conjunction with UriMapping.  With the technique above, the “relative-ness” refers to the user-facing Uri.  This means that you can create UriMappings in order to create a “virtual” file structure, and all of your relative links should continue to work (and new ones might be possible!).  Give it a shot and let me know what you think!  I’m continuing to experiment with Navigation, always on the lookout for things that might improve the experience when working with it.</p>
<h2>Enough already!  Give me the goods!</h2>
<p>Patience!  You didn’t really think I’d leave you hanging, did you?  Here you go:</p>
<ul>
<li><a href="http://www.davidpoll.com/Download/DynamicNavigation.zip">DynamicNavigation libraries</a> (see my other posts for an introduction to what it provides and how to use it – <a href="http://www.davidpoll.com/2009/07/14/silverlight-3-navigation-navigating-to-pages-in-dynamically-loaded-assemblies/">1</a>, <a href="http://www.davidpoll.com/2009/07/20/on-demand-loading-of-assemblies-with-silverlight-navigation/">2</a>)</li>
<li><a href="http://www.davidpoll.com/Download/RelativeNavigationSample.zip">Sample Source</a></li>
</ul>
<h2>Stop talking to yourself!</h2>
<p>Okay. <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.davidpoll.com/2009/09/20/relative-hyperlinks-with-silverlight-navigation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Update 2: Displaying background activity in a Silverlight RIA application</title>
		<link>http://www.davidpoll.com/2009/09/14/update-2-displaying-background-activity-in-a-silverlight-ria-application/</link>
		<comments>http://www.davidpoll.com/2009/09/14/update-2-displaying-background-activity-in-a-silverlight-ria-application/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 07:45:50 +0000</pubDate>
		<dc:creator>david.poll</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[.NET RIA Services]]></category>
		<category><![CDATA[Activity Control]]></category>
		<category><![CDATA[BusyIndicator]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[WCF RIA Services]]></category>

		<guid isPermaLink="false">http://www.davidpoll.com/2009/09/14/update-2-displaying-background-activity-in-a-silverlight-ria-application/</guid>
		<description><![CDATA[Hi folks!&#160; It’s been a little while since I’ve blogged, but fear not, I’m still watching and hoping to blog more in the coming weeks. In the meantime, it’s been brought to my attention by a few people now that there are a few issues with the Activity control, and I wanted to address them. [...]]]></description>
			<content:encoded><![CDATA[<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_start --><p>Hi folks!&#160; It’s been a little while since I’ve blogged, but fear not, I’m still watching and hoping to blog more in the coming weeks.</p>
<p>In the meantime, it’s been brought to my attention by a few people now that there are a few issues with the Activity control, and I wanted to address them.</p>
<ol>
<li>Performance – A bit of a mea culpa on my part.&#160; I included a feature for the control that I’ve called “AutoBind”, whereby it would watch for changes to the visual tree of its contents and subscribe to any control that has a property whose name matches “ActivityPropertyName”.&#160; By default, this is great when working with .NET RIA Service’s DomainDataSource, since ActivityPropertyName is “IsBusy” by default, but it also turns out to be a hefty amount of work, constantly searching the visual tree and registering/unregistering event handlers.&#160; This wouldn’t be so bad, except that AutoBind defaults to true, meaning even if you’re not using this functionality, the Activity control is doing the work.&#160; Below, you’ll find a new version of the Activity control that amends the situation, making AutoBind default to false.&#160; This is the only change to the control since my last post on the matter, but I’d love to hear if you have thoughts about the control, this feature, or other requests!</li>
<li>.NET RIA Services’ Business Application Template – So, the .NET RIA Services guys included with their <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;displaylang=en">July Preview</a> a project template to help you get started with a RIA Services application.&#160; In this template, they included a dll with the Activity control in it.&#160; A few people have noted that it has a slightly different API than they’re used to seeing with the control, which is due to their use of the original version of the control that I posted (its API has changed a bit since then, and a number of bugs were fixed, including some layout issues).&#160; Anyhoo, feel free to pick up the latest version below!</li>
</ol>
<p>So there you have it – just a few changes and things to note.&#160; You can find the control here:</p>
<ul>
<li><a href="http://www.davidpoll.com/Download/ActivityControl9-14.zip">Activity Control</a></li>
<li><a href="http://www.davidpoll.com/Download/ActivityControlDemo9-14.zip">Activity control demo project</a></li>
</ul>
<p>Thanks for all the great feedback since I first posted this control.&#160; As usual, let me know if you have questions or issues!</p>
<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.davidpoll.com/2009/09/14/update-2-displaying-background-activity-in-a-silverlight-ria-application/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>On-demand loading of assemblies with Silverlight Navigation</title>
		<link>http://www.davidpoll.com/2009/07/20/on-demand-loading-of-assemblies-with-silverlight-navigation/</link>
		<comments>http://www.davidpoll.com/2009/07/20/on-demand-loading-of-assemblies-with-silverlight-navigation/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 22:01:00 +0000</pubDate>
		<dc:creator>david.poll</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[BusyIndicator]]></category>
		<category><![CDATA[Dynamic Navigation]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Silverlight 3]]></category>

		<guid isPermaLink="false">http://www.davidpoll.com/2009/07/21/on-demand-loading-of-assemblies-with-silverlight-navigation/</guid>
		<description><![CDATA[As those of you who’ve been reading my blog may know, I’ve been spending a bit of time with some enhancements to navigation in Silverlight surrounding the use of dynamically-loaded assemblies.&#160; I’ve still got a bunch of things I’d like to try to implement, but in the meantime I thought I’d share what I’ve got [...]]]></description>
			<content:encoded><![CDATA[<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_start --><p>As those of you who’ve been reading my blog may know, I’ve been spending a bit of time with some enhancements to navigation in Silverlight surrounding the use of dynamically-loaded assemblies.&#160; I’ve still got a bunch of things I’d like to try to implement, but in the meantime I thought I’d share what I’ve got so far.</p>
<p>Now that I have a mechanism for navigating to Pages in dynamically-loaded assemblies in Silverlight, the question arises: how can I improve the user and developer experience around partitioning applications in this way?</p>
<p>In particular, this is the flow I’d like to be able to create:</p>
<ul>
<li>Developer knows the set of Pages his user will be able to navigate to, and partitions them into assemblies that he will load at runtime </li>
<li>Furthermore, the developer knows the dependencies those assemblies have on other dynamically-loaded assemblies (e.g. multiple assemblies contain Pages that use DataGrid, but System.Windows.Controls.Data should be shared/downloaded when the first of those assemblies is downloaded) </li>
<li>The user is presented with some sort of navigation UI (e.g. HyperlinkButtons, buttons that call Frame.Navigate(), etc.) </li>
<li>When the user requests a page in an assembly that has not yet been downloaded, it should be automatically downloaded, and navigation with the Frame should only complete once the Page can be loaded. </li>
</ul>
<p>With this on-demand loading behavior, deep-linking into applications with dynamically-loaded assemblies can be re-enabled (you’ll notice if you try to deep-link into my sample from my <a href="http://www.davidpoll.com/?p=92">previous post</a> about dynamically-loaded assemblies, you get an exception, since the assembly hasn’t been loaded yet).</p>
<p>I’m developing some utilities that will make this flow easier to accomplish.&#160; Please note that at this point all of the API, etc. is subject to change, and I’m definitely not making any assurances around bugs, quality, or anything of the sort, but I thought I’d share what I’ve been working on and start getting some feedback from you folks!</p>
<p>Anyhoo, let’s take this step by step:</p>
<p><strong><span style="font-size: medium">Dividing an application into multiple assemblies</span></strong></p>
<p>This is fairly straightforward, and something I’m sure most of you have been doing for a long time.&#160; For our purposes, there are a number of things to consider:</p>
<ul>
<li>Pages in these assemblies that will be dynamically loaded should use the DynamicPage and DynamicPageShim (or some other workaround you may have come up with) described in my <a href="http://www.davidpoll.com/?p=92">earlier post</a> </li>
<li>Any dynamically-loaded assemblies need to be in a place accessibly using the WebRequest APIs in Silverlight.&#160; I usually put them in my ClientBin folder, and I used a post-build task to copy any dlls for those assemblies into the correct folder (feel free to see my Sample project for an example of this) </li>
<li>The libraries I’ve built support loading DLLs as well as XAP and ZIP files with dlls in them. Just using DLLs is probably the easiest way to go, but using ZIP or XAP files will keep the transfer time/size small. </li>
<li>Remember to take careful note of any dependencies between the libraries.&#160; You’ll need to make sure they’re all loaded into your application before attempting to use the assemblies. </li>
</ul>
<p>One thing I might do in the future is (attempt to) make a project template that will create a XAP class library that places the XAP in the ClientBin folder for you.&#160; I’m still experimenting with how to do this, but it’s still worth noting that using XAPs can be problematic if you’re sharing libraries (VS will automatically package shared assemblies into your XAP, so you might end up with copies of System.Windows.Controls.Navigation.dll in 3 or 4 XAPs, and since they’re all packaged up with the rest of the assemblies, you’ll end up downloading the same DLL multiple times.</p>
<p><strong><span style="font-size: medium">Describing how to load assemblies dynamically</span></strong></p>
<p>I’ve created a little utility that I call “DynamicLoader,” which allows you to declare, in XAML, where your dynamic DLLs can be downloaded from and their interdependencies.&#160; In my App.xaml, I specify the various libraries that may be loaded dynamically (incidentally, some of these libraries are also in my XAP, and the loader will use the ones built into the XAP rather than re-downloading them automatically).&#160; I also describe the various interdependencies between my libraries.&#160; Some are unnecessary (because the dependencies are already in the XAP), but I chose to be explicit for some of the more complex ones to remove all doubt.&#160; An example (from my sample project) can be seen below.</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">DynamicLoader </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">=&quot;loader&quot;&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;DynamicallyLoadedLibrary&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./DynamicallyLoadedLibrary.dll&quot; /&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;DynamicallyLoadedLibraryVB&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./DynamicallyLoadedLibraryVB.dll&quot; /&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;LargeDynamicallyLoadedLibrary&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./LargeDynamicallyLoadedLibrary.dll&quot;&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Data&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Data.DataForm.Toolkit&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Data.Input&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.DataVisualization.Toolkit&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Navigation&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Data&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.ComponentModel.DataAnnotations&quot; /&gt;
    &lt;/</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./System.Windows.Controls.dll&quot; /&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Data&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./System.Windows.Controls.Data.dll&quot;&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.ComponentModel.DataAnnotations&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Data.Input&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Data&quot; /&gt;
    &lt;/</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Data.DataForm.Toolkit&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./System.Windows.Controls.Data.DataForm.Toolkit.dll&quot;&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.ComponentModel.DataAnnotations&quot; /&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Data&quot; /&gt;
    &lt;/</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Data.Input&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./System.Windows.Controls.Data.Input.dll&quot;&gt;
        &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">Dependency </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.ComponentModel.DataAnnotations&quot; /&gt;
    &lt;/</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.DataVisualization.Toolkit&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./System.Windows.Controls.DataVisualization.Toolkit.dll&quot; /&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Controls.Navigation&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./System.Windows.Controls.Navigation.dll&quot; /&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.Windows.Data&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;./System.Windows.Data.dll&quot; /&gt;
    &lt;</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">AssemblyDescription </span><span style="color: red">AssemblyName</span><span style="color: blue">=&quot;System.ComponentModel.DataAnnotations&quot;
                              </span><span style="color: red">Location</span><span style="color: blue">=&quot;System.ComponentModel.DataAnnotations.dll&quot; /&gt;
&lt;/</span><span style="color: #a31515">load</span><span style="color: blue">:</span><span style="color: #a31515">DynamicLoader</span><span style="color: blue">&gt;</span></pre>
<p>The Location specified in each AssemblyDescription is a URI.&#160; In this case, all of my dlls are in my ClientBin directory, so they all begin with “./”, but these could be any URI that can be reached by the Silverlight application.&#160; Furthermore, if you wish to use the new ClientHttp networking stack to do the downloading, you can choose to do so (as part of the AssemblyDescription).</p>
<p>The loader will asynchronously load any requested library (by name), and will only fire Loaded events once all of each assembly’s dependencies have been loaded.&#160; This allows us to know when it’s safe to try to navigate to a Page in a dynamically-loaded assembly.</p>
<p><strong><span style="font-size: medium">Creating Navigation UI</span></strong></p>
<p>Nothing too special to share here.&#160; HyperlinkButtons use the exact same URI scheme as before (for navigating to pages in <a href="http://www.davidpoll.com/2009/07/12/silverlight-3-navigation-navigating-to-pages-in-referenced-assemblies/">referenced</a>/<a href="http://www.davidpoll.com/?p=92">dynamically-loaded</a> assemblies).&#160; Here’s what my XAML for my navigation bar looks like:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">Border </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LinksBorder&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">LinksBorderStyle</span><span style="color: blue">}&quot;&gt;
    &lt;</span><span style="color: #a31515">StackPanel </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LinksStackPanel&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">LinksStackPanelStyle</span><span style="color: blue">}&quot;&gt;

        &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Link1&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">LinkStyle</span><span style="color: blue">}&quot;
                     </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/Home&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;home&quot;/&gt;

        &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Divider1&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">DividerStyle</span><span style="color: blue">}&quot;/&gt;

        &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Link2&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">LinkStyle</span><span style="color: blue">}&quot;
                     </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/About&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;about&quot;/&gt;

        &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Divider2&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">DividerStyle</span><span style="color: blue">}&quot;/&gt;

        &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;csharp&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">LinkStyle</span><span style="color: blue">}&quot; </span><span style="color: red">IsEnabled</span><span style="color: blue">=&quot;True&quot;
                     </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/DynamicallyLoadedLibrary;component/CSDynamicPage.dyn.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;C# Class Library&quot;/&gt;

        &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Divider3&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">DividerStyle</span><span style="color: blue">}&quot;/&gt;

        &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;vb&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">LinkStyle</span><span style="color: blue">}&quot; </span><span style="color: red">IsEnabled</span><span style="color: blue">=&quot;True&quot;
                     </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/DynamicallyLoadedLibraryVB;component/VBDynamicPage.dyn.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;VB Class Library&quot;/&gt;

        &lt;</span><span style="color: #a31515">Rectangle </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;Divider4&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">DividerStyle</span><span style="color: blue">}&quot;/&gt;

        &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;large&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">LinkStyle</span><span style="color: blue">}&quot; </span><span style="color: red">IsEnabled</span><span style="color: blue">=&quot;True&quot;
                     </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/LargeDynamicallyLoadedLibrary;component/LargeDynamicPage.dyn.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;Large Class Library&quot;/&gt;
    &lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Again, nothing too scary here – the XAML remains identical to its form without the dynamically-loaded libraries.</p>
<p><strong><span style="font-size: medium">Adding on-demand navigation</span></strong></p>
<p>The other important piece of this puzzle is a Frame control that uses the loader to ensure that dynamically-loaded libraries are loaded into the AppDomain before attempting to navigate to pages within those libraries.&#160; I’ve provided a derived Frame class (DynamicNavigation.Utilities.Controls.Frame) that does precisely this.&#160; As with my DynamicPage class, you should expect a few quirks, since the Frame class from which it derives doesn’t have any virtual methods.&#160; Don’t cast my Frame to a System.Windows.Controls.Frame if you don’t want to get a bunch of extra events for Loading, Loaded, etc.&#160; Also, since I couldn’t replace the NavigationService, if you subscribe to events on that service, you’ll see a large number of extra events being raised.&#160; Neither of these eccentricities should hamper functionality, but you may see some unexpected activity if you watch those events!</p>
<p>My Frame class takes an DynamicLoader and delegates all loading of dynamic libraries to it.&#160; Here’s what my XAML declaration of the Frame looks like (plus or minus some extraneous attributes):</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">dnav</span><span style="color: blue">:</span><span style="color: #a31515">Frame </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">ContentFrameStyle</span><span style="color: blue">}&quot;
            </span><span style="color: red">DynamicLoader</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">loader</span><span style="color: blue">}&quot;
            </span><span style="color: red">Source</span><span style="color: blue">=&quot;/Home&quot;&gt;
    &lt;</span><span style="color: #a31515">dnav</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
            &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/Views/Home.xaml&quot;/&gt;
            &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;/{a};component/{p}&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/{a};component/{p}&quot; /&gt;
            &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;/{pageName}&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/Views/{pageName}.xaml&quot;/&gt;
        &lt;/</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">dnav</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">dnav</span><span style="color: blue">:</span><span style="color: #a31515">Frame</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>And that’s it!&#160; With my custom Frame class, it take <strong>*zero*</strong> code to get dynamic loading up and running – only XAML is necessary.&#160; Attach an Activity control to the loader, and you’re hot to trot!</p>
<p><strong><span style="font-size: medium">In Conclusion</span></strong></p>
<p>Well, there you have it!&#160; I’d like to remind folks that none of the APIs here are intended to be concrete, and I make no guarantees of quality – I’m just trying to demonstrate how it can be done, and if the interest is there, I’ll keep investing some time in exploring this.&#160; I’ve got a bunch of ideas for where I can go from here, things I’d like to change/improve, and I look forward to playing some more with these prototypes.</p>
<p>Without further ado, here are the links I’m sure you’re all waiting for:</p>
<ul>
<li><a href="http://www.davidpoll.com/Download/DynamicNavigation.zip">DynamicNavigation libraries</a> (for your consumption) </li>
<li><a href="http://www.davidpoll.com/Samples/OnDemandDownload/DynamicNavigationApplicationTestPage.html">Live Sample</a> </li>
<li><a href="http://www.davidpoll.com/Samples/Download/OnDemandNavigationSample.zip">Sample Source</a> </li>
</ul>
<p><strong><span style="font-size: medium">What’s next?</span></strong></p>
<p>Well, I’ve got a lot of ideas, and I’d love to hear some from you all.&#160; Here are some of mine (not making any promises – I’m just experimenting with these):</p>
<ul>
<li>Cache to IsoStore – downloaded libraries could be stored in Isolated Storage and loaded from there if they’re already on the machine </li>
<li>Install – When the application is taken out of browser, automatically download the assemblies to Isolated Storage and load from there, allowing the entire application to be run offline </li>
<li>URI scheme/custom loading – I’d love to be able to just specify the whole deal in a URI to a page, such as “pack://http:,,www.davidpoll.com,Samples,ClientBin,MyLibrary.dll;component/Page2.dyn.xaml” and not need the big manifest with assembly name/location mappings and dependencies. </li>
<li>Dependencies for particular URIs – allows the Frame control to pre-load assemblies before a particular page is loaded, even if the page is a local one (thanks, Austin, for this idea!) </li>
</ul>
<p>Anyway, I’ve got a thousand other ideas racing through my mind right now, but those are just a few.&#160; What do you think?&#160; Is there anything you dislike about my approach or anything you particularly like?&#160; Speak up!</p>
<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.davidpoll.com/2009/07/20/on-demand-loading-of-assemblies-with-silverlight-navigation/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Silverlight 3 Navigation: Adding transitions to the Frame control</title>
		<link>http://www.davidpoll.com/2009/07/19/silverlight-3-navigation-adding-transitions-to-the-frame-control/</link>
		<comments>http://www.davidpoll.com/2009/07/19/silverlight-3-navigation-adding-transitions-to-the-frame-control/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 22:03:26 +0000</pubDate>
		<dc:creator>david.poll</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.davidpoll.com/2009/07/19/silverlight-3-navigation-adding-transitions-to-the-frame-control/</guid>
		<description><![CDATA[Continuing with my recent theme of enhancing the built-in support for Navigation in Silverlight 3, I thought I’d use this post to look briefly at enhancing user experience during navigation.&#160; On the surface, the Frame control is pretty unexciting from a UX perspective – its job is really just to display pages as a result [...]]]></description>
			<content:encoded><![CDATA[<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_start --><p>Continuing with my recent theme of enhancing the built-in support for Navigation in Silverlight 3, I thought I’d use this post to look briefly at enhancing user experience during navigation.&#160; On the surface, the Frame control is pretty unexciting from a UX perspective – its job is really just to display pages as a result of requests to navigate (either through the browser’s address bar, responding to HyperlinkButton clicks, or direct calls to Frame.Navigate()).&#160; It has barely any UI of its own, and can usually be thought of as an enhanced ContentControl (incidentally, it is one!).</p>
<p>Most of the time, all the Frame is doing is displaying a Page, and this (in my opinion at least) is an appropriate presentation – the Frame shouldn’t get in the way of displaying my Pages.&#160; Where I do want the Frame to intervene now and then is during page changes, allowing me to provide rich transitions when navigating from Page to Page.&#160; The Frame control provided in the Silverlight 3 SDK doesn’t do anything for us as far as transitions go out of the box, but with a little templating magic and the <a href="http://silverlight.codeplex.com/">Silverlight Toolkit</a>’s TransitioningContentControl (which Jesse Liberty has a <a href="http://silverlight.net/blogs/jesseliberty/archive/2009/04/29/animated-visual-state-transitions-with-the-transitioning-content-control.aspx">great blog post on</a>), I think we can get the desired effect!</p>
<p>Let’s begin by taking a peek at the ControlTemplate for the Frame control:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">ControlTemplate </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;navigation:Frame&quot;&gt;
    &lt;</span><span style="color: #a31515">Border </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">}&quot;
            </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">}&quot;
            </span><span style="color: red">Background</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Background</span><span style="color: blue">}&quot;
            </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">BorderBrush</span><span style="color: blue">}&quot;
            </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">BorderThickness</span><span style="color: blue">}&quot;&gt;
        &lt;</span><span style="color: #a31515">ContentPresenter </span><span style="color: red">Cursor</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Cursor</span><span style="color: blue">}&quot;
                          </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">}&quot;
                          </span><span style="color: red">Margin</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Padding</span><span style="color: blue">}&quot;
                          </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">}&quot;
                          </span><span style="color: red">Content</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Content</span><span style="color: blue">}&quot;/&gt;
    &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">ControlTemplate</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>As you can see, there’s very little to it: a Border and a ContentPresenter – with all the appropriate TemplateBindings.</p>
<p>All we have to do to get transitions on the Frame control is replace that ContentPresenter with the TransitioningContentControl:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">ControlTemplate </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">=&quot;TransitioningFrame&quot; </span><span style="color: red">TargetType</span><span style="color: blue">=&quot;navigation:Frame&quot;&gt;
    &lt;</span><span style="color: #a31515">Border </span><span style="color: red">Background</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Background</span><span style="color: blue">}&quot;
            </span><span style="color: red">BorderBrush</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">BorderBrush</span><span style="color: blue">}&quot;
            </span><span style="color: red">BorderThickness</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">BorderThickness</span><span style="color: blue">}&quot;
            </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">}&quot;
            </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">}&quot;&gt;
        &lt;</span><span style="color: #a31515">toolkit</span><span style="color: blue">:</span><span style="color: #a31515">TransitioningContentControl </span><span style="color: red">Content</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Content</span><span style="color: blue">}&quot;
                                             </span><span style="color: red">Cursor</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Cursor</span><span style="color: blue">}&quot;
                                             </span><span style="color: red">Margin</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">Padding</span><span style="color: blue">}&quot;
                                             </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">}&quot;
                                             </span><span style="color: red">VerticalAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">}&quot;
                                             </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">HorizontalContentAlignment</span><span style="color: blue">}&quot;
                                             </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">TemplateBinding </span><span style="color: red">VerticalContentAlignment</span><span style="color: blue">}&quot;
                                             </span><span style="color: red"><strong><u><em>Transition</em></u></strong></span><span style="color: blue"><strong><u><em>=&quot;&lt;Transition Name&gt;&quot;</em></u></strong> /&gt;
    &lt;/</span><span style="color: #a31515">Border</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">ControlTemplate</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The “toolkit:” xml namespace uses the following definition (since you can find the TransitioningContentControl in the System.Windows.Controls namespace and the System.Windows.Controls.Layout.Toolkit assembly): xmlns:toolkit=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit&quot;</p>
<p>To change the type of transition the Frame will use, just change the value of the Transition property on the TransitioningContentControl.</p>
<p>There’s not much more to it!&#160; Short, sweet, and to the point <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Check out the live sample and source if you’re curious:</p>
<ul>
<li><a href="http://www.davidpoll.com/Samples/TransitioningNavigation/TestPage.html">Sample</a> </li>
<li><a href="http://www.davidpoll.com/Download/TransitioningNavigation.zip">Sample Source</a> </li>
</ul>
<p>&#160;</p>
<p><strong><font size="4">Caveats and Questions</font></strong></p>
<p>I know you’d be disappointed if I really left it at that, so here’s the one caveat I’ve observed with this technique:</p>
<p>My <a href="http://www.davidpoll.com/?p=92">dynamically-loaded libraries with navigation workaround</a> will cause a few problems with this technique, since it sets the Frame’s Content property twice (once to load the DynamicPageShim, the other to load the DynamicPage itself).&#160; The result is that you will see the Frame transition to a blank page and then to the DynamicPage with your content.&#160; So here’s the question: how important is this transitioning behavior to you?&#160; There are two options for how I proceed here, neither of which are truly ideal:</p>
<ol>
<li>Leave DynamicPage and DynamicPageShim as-is and live with the slight wonkiness during transitions. </li>
<li>Make DynamicPageShim avoid changing the content of the Frame twice (making transitions work just fine <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).&#160; This will mean that you won’t be able to use the DynamicPage<strong><em>exactly</em></strong> as you would the standard Page (e.g. binding to &quot;Frame.Content.MyCustomPropertyOnMyPage” won’t be possible… instead you’d have to bind to “Frame.Content.<strong><em>Content</em></strong>.MyCustomPropertyOnMyPage”). </li>
</ol>
<p>Neither of these options significantly hampers functionality – just impacts either user experience or developer experience, but I’d love to hear your thoughts!&#160; Do you prefer option 1 or option 2?</p>
<p>In the meantime, I’m working on some fun little utilities that will make dynamically loading assemblies with navigation much simpler and more declarative, and am looking forward to blogging it when it’s ready!</p>
<p>&#160;</p>
<p><strong><font size="4">Update: Credit where credit is due</font></strong></p>
<p>About 10 minutes after I posted this, I came across someone (<a href="http://firstfloorsoftware.com/blog/">Koen Zwikstra</a>) who posted almost the exact same thing before me, and I want to make sure he gets fair mention for getting there before me <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You can find his post here: <a title="http://firstfloorsoftware.com/blog/animated-page-navigation-in-sl3/" href="http://firstfloorsoftware.com/blog/animated-page-navigation-in-sl3/">http://firstfloorsoftware.com/blog/animated-page-navigation-in-sl3/</a></p>
<p>Sorry for duplicating!&#160; Great stuff!</p>
<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.davidpoll.com/2009/07/19/silverlight-3-navigation-adding-transitions-to-the-frame-control/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Silverlight 3 Navigation: Navigating to Pages in dynamically-loaded assemblies</title>
		<link>http://www.davidpoll.com/2009/07/14/silverlight-3-navigation-navigating-to-pages-in-dynamically-loaded-assemblies/</link>
		<comments>http://www.davidpoll.com/2009/07/14/silverlight-3-navigation-navigating-to-pages-in-dynamically-loaded-assemblies/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 06:47:11 +0000</pubDate>
		<dc:creator>david.poll</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Silverlight 3]]></category>

		<guid isPermaLink="false">http://www.davidpoll.com/?p=92</guid>
		<description><![CDATA[In my last post on the new navigation feature in Silverlight, I explored how you can navigate to pages in assemblies/projects referenced by your main application.&#160; Almost immediately, a number of you asked how you can navigate to pages in assemblies that have been dynamically loaded, allowing you to delay downloading certain pieces of your [...]]]></description>
			<content:encoded><![CDATA[<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_start --><p>In my <a href="http://www.davidpoll.com/?p=88">last post on the new navigation feature in Silverlight</a>, I explored how you can navigate to pages in assemblies/projects referenced by your main application.&#160; Almost immediately, a number of you asked how you can navigate to pages in assemblies that have been dynamically loaded, allowing you to delay downloading certain pieces of your application until users request them.&#160; This allows you to reduce the initial size (and thereby load/download time) of your application to something more appropriate for your users and avoid using bandwidth to download components to users’ machines that they may never actually user/encounter.</p>
<p>Out of the box, Silverlight 3’s navigation feature only allows navigating to Pages in assemblies referenced by your application project and packaged in your XAP.&#160; There are a number of technical reasons behind this that I know we’d like to explore and hopefully address in future versions, but I won’t go into the details here.&#160; There is, however, one exception to this rule that prevents us from navigating to Pages in dynamically-loaded assemblies: you <strong><em>can</em></strong> load Pages with no code behind that live in such assemblies.</p>
<p>After a few months of thinking about this problem in the back of my mind, it finally clicked for me: this exception is the way in!&#160; All of the other workarounds I was able to think of required Pages located in the XAP that would load their contents dynamically and didn’t really take advantage of the Navigation feature at all.</p>
<p>Anyway, I think I finally found a reasonably good workaround, and while it’s a little hacky-er than I would’ve liked, it doesn’t fundamentally change the feel of using Silverlight navigation.&#160; Here’s the gist of my strategy:</p>
<ul>
<li>Load an assembly containing a Page dynamically </li>
<li>Include in this assembly a “shim” Page with no code behind.&#160; In its XAML, reference the <em>real</em> page <strong>with</strong> code behind, and forward any navigation-related information (events, title, query strings, etc.) to that Page </li>
<li>When that page is navigated to, replace the Frame’s content with the <em>real</em> page. </li>
<li>From the application, navigate to the “shim” page in the dynamically-loaded assembly </li>
</ul>
<p>Ok, I know that sounds a little roundabout, but I think I’ve made it pretty easy to accomplish for a developer now.&#160; More importantly – it works!</p>
<p>Let me go into a little more detail…</p>
<p><strong><span style="font-size: medium">The Library</span></strong></p>
<p>I’ve created a tiny little assembly that I’ve called “DynamicNavigation”.&#160; It contains two classes, both of which are made for use in XAML:</p>
<ul>
<li><strong>DynamicPage</strong>: A descendant of the Page class that allows the Shim to communicate with it.&#160; If I did my job correctly, for 99% of cases, you can navigate directly to this page (rather than its Shim) if you haven’t dynamically loaded the assembly.&#160; There shouldn’t really be any new public interface (except for some “new” properties that hide the original Page properties, since they aren’t virtual). </li>
<li><strong>DynamicPageShim</strong>:&#160; Another descendant of the Page class, meant to be used in XAML with no code behind.&#160; This class will forward any navigation events, etc., to the DynamicPage it takes as its content.&#160; The goal here was to minimize the XAML so that the additional size due to these files is small.&#160; There may be further optimizations I can do, but it’s getting pretty close <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </li>
</ul>
<p><strong><span style="font-size: medium">The Developer Experience</span></strong></p>
<p>Ok, that’s all great, but what do I have to do to use it?</p>
<p>Well, instead of 2 files (&lt;PageName&gt;.xaml and &lt;PageName&gt;.xaml.cs/vb), creating a Page now takes 3 files:</p>
<ul>
<li><em>&lt;PageName&gt;.dyn.xaml:</em> </li>
</ul>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">dyn</span><span style="color: blue">:</span><span style="color: #a31515">DynamicPageShim </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
           </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">dyn</span><span style="color: blue">=&quot;clr-namespace:DynamicNavigation;assembly=DynamicNavigation&quot;
           </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">my</span><span style="color: blue">=&quot;clr-namespace:DynamicallyLoadedLibrary;<span style="text-decoration: underline"><strong><em>assembly=DynamicallyLoadedLibrary</em></strong></span>&quot;&gt;
    &lt;</span><span style="color: #a31515">my</span><span style="color: blue">:</span><span style="color: #a31515"><strong><em><span style="text-decoration: underline">PageName</span></em></strong> </span><span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">dyn</span><span style="color: blue">:</span><span style="color: #a31515">DynamicPageShim</span><span style="color: blue">&gt;</span></pre>
<p>I’ve underlined two important lines here.&#160; First, “assembly=DynamicallyLoadedLibrary” – normally, this would be unnecessary in an xmlns definition, since I can refer to the library in which the XAML file exists without the “assembly=” syntax.&#160; For the same technical reasons that we normally can’t load a Page in a dynamically-loaded assembly, this name needs to be fully specified, since it allows the XAML loader to find the dynamically-loaded assembly in which your DynamicPage resides.&#160; Next, you can see that this Shim takes an instance of the DynamicPage as its content.&#160; This allows it to forward navigation-related information to the Page and ensure that the Frame has the correct content.</p>
<ul>
<li><em>&lt;PageName&gt;.xaml</em> </li>
</ul>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">dyn</span><span style="color: blue">:</span><span style="color: #a31515">DynamicPage </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;DynamicallyLoadedLibrary.CSDynamicPage&quot;
           </span><span style="color: red">xmlns</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
           </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
           </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">d</span><span style="color: blue">=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
           </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">mc</span><span style="color: blue">=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
           </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">dyn</span><span style="color: blue">=&quot;clr-namespace:DynamicNavigation;assembly=DynamicNavigation&quot;
           </span><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">navigation</span><span style="color: blue">=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation&quot;
           </span><span style="color: red">mc</span><span style="color: blue">:</span><span style="color: red">Ignorable</span><span style="color: blue">=&quot;d&quot;
           </span><span style="color: red">d</span><span style="color: blue">:</span><span style="color: red">DesignWidth</span><span style="color: blue">=&quot;640&quot; </span><span style="color: red">d</span><span style="color: blue">:</span><span style="color: red">DesignHeight</span><span style="color: blue">=&quot;480&quot;
           </span><span style="color: red">Title</span><span style="color: blue">=&quot;Page Title&quot;&gt;
    &lt;</span><span style="color: #a31515">Grid </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LayoutRoot&quot;&gt;</span>

<span style="color: blue">       ...</span>

<span style="color: blue">    &lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">dyn</span><span style="color: blue">:</span><span style="color: #a31515">DynamicPage</span><span style="color: blue">&gt;
</span></pre>
<p>As you can see, there’s really nothing special about the DynamicPage except that the open/close tags are of type DynamicPage rather than Page.&#160; Gotta love it!</p>
<ul>
<li><em>&lt;PageName&gt;.xaml.cs/vb</em> </li>
</ul>
<p>I won’t show an example here, but there’s really nothing special about this.&#160; You’ll develop exactly as though the DynamicPage were a real Page.&#160; The only thing to watch out for: please don’t cast the DynamicPage to a Page, since this will cause it to refer to hidden properties that may not be set.&#160; Again, for 99% of cases, this is probably not an issue, but it bears a little bit of consideration.</p>
<p>The last piece of the puzzle is actually navigating to the page.&#160; Well, it’s pretty straightforward: navigate just as we did in <a href="http://www.davidpoll.com/?p=88">my other post</a> (using “;component” pack URI syntax).&#160; The only difference: <em>instead of navigating to &lt;PageName&gt;.xaml, you’ll navigate to &lt;PageName&gt;.dyn.xaml</em>.</p>
<p>And that’s it!&#160; The rest should just work!</p>
<p>So, without further ado, I’ve got some tools for you!</p>
<p><strong><span style="font-size: medium">The Goods</span></strong></p>
<ul>
<li><a href="http://www.davidpoll.com/Download/DynamicNavigation.zip">DynamicNavigation Download</a> </li>
</ul>
<p>The download above is a zip containing 3 things:</p>
<ol>
<li>DynamicNavigation.dll – an assembly you should reference in both your application project (and include in your xap) as well as any assemblies you wish to dynamically load (so that you can include the XAML files above) </li>
<li>DynamicPageCS.zip – this is a Visual Studio item template that will help get you started.&#160; Drop this zip (without extracting) in <em>“&lt;My Documents&gt;\Visual Studio 2008\Templates\Item Templates\Visual C#”</em>.&#160; Now, if you open Visual Studio and a C# Silverlight 3 project, right-click the project (in the solution explorer) and choose “Add new…”.&#160; Select “Silverlight Dynamic Page” and choose a name for your page.&#160; The item template will create the 3 files for you.&#160; Open up “&lt;PageName&gt;.xaml” and start editing! </li>
<li>DynamicPageVB.zip – I didn’t forget about you VB guys!&#160; Follow the same instructions above (but placing the item template in the VB folder instead of the C# one), and you should be set to go! </li>
</ol>
<p>I’m sure there are some bugs and issues with what I did (for example, the item templates don’t add a reference to DynamicNavigation.dll to your project yet… I hope to fix this once I figure out how!).&#160; Let me know if something’s causing you problems, and I’ll see if I can work it out in my (not so) copious free time <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong><span style="font-size: medium">The Sample</span></strong></p>
<p>You know me – I can’t leave you without a live sample of this thing in action!&#160; Take a look here (for your viewing pleasure):</p>
<ul>
<li><a href="http://www.davidpoll.com/Samples/DynamicNavigationApplication/DynamicNavigationApplicationTestPage.html">Sample</a> </li>
<li><a href="http://www.davidpoll.com/Samples/Download/DynamicNavigationSample.zip">Sample Source</a> </li>
</ul>
<p>Enjoy!&#160; You may even find a cameo from a previous post in there!</p>
<p><strong><span style="font-size: medium">The Tips</span></strong></p>
<p>When using my DynamicNavigation tools, there are a few things you should keep in mind.&#160; Hopefully this list will get smaller going forward, but in the meantime, these are some things to remember:</p>
<ul>
<li>It’s still up to you to load the assemblies dynamically into your AppDomain before attempting to navigate to them.&#160; A super-simple example of how to do this can be found in the code-behind of my MainPage.xaml.&#160; You can also use tools like <a href="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">Prism</a> to accomplish something similar.&#160; There are definitely some tricks that would make this feel more on-demand than what I’ve done in the sample, but that’s a topic for a future post! <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </li>
<li>Along those lines, please make sure any assemblies your dynamically-loaded assembly is dependent upon are loaded before trying to navigate.&#160; I don’t do anything to try to resolve those dependencies. </li>
<li>Try to avoid casting your DynamicPage to its parent type – Page.&#160; If you do, you’ll find some properties aren’t set to your desired values (such as Title, NavigationCacheMode, etc.). </li>
<li>My libraries should replace Frame’s Content with the intended page, so feel free to bind into Frame.Content just as you would otherwise.&#160; You may find that Frame.Content does change twice during a navigation rather than just once, but otherwise, you should get the same events/virtual methods called/etc. on your Page. </li>
<li>Expect Caching and Title to still be honored properly on your page! </li>
<li>Once you’ve created your &lt;PageName&gt;.dyn.xaml file, you should rarely, if ever, need to modify it.&#160; It’s just a shim, and any other work you’d like to do should be possible directly through the DynamicPage files (.xaml and .xaml.cs/vb) </li>
</ul>
<p>I tried to keep the library as small as possible.&#160; Anything I build on top of this, I intend to put in a separate library, so that you’re not forced to take additional overhead for the simplest of cases, where you’ve already done your dynamic loading and just want to navigate to pages in those libraries.</p>
<p><strong><span style="font-size: medium">The Conclusion</span></strong></p>
<p>My hope is that this will get you started down the road to navigating to dynamically-loaded assemblies.&#160; I know it’s a bit obtuse, and still harder to do than it ought to be, but what I’d like to do going forward is take this development and create an SL3 library that will make it really simple to download assemblies from your server on-demand during navigation (and perhaps devise some other nifty features).</p>
<p>Please, let me know what you think.&#160; Should I spend more time on these things?&#160; How valuable is using navigation in this way to you?&#160; What kinds of scenarios would you still like to see enabled?</p>
<p>If I’ve confused the heck out of you, I sincerely apologize.&#160; I know I found myself struggling to describe this adequately, so please, ask questions!&#160; I’m happy to share my thoughts/experiences.</p>
<p>Comment away!</p>
<p><strong><em>P.S.</em></strong> I’m finally on Twitter (at least partially to my dismay <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).&#160; You can find me at @depoll</p>
<p>&#160;</p>
<p><strong><em>Update: </em></strong><a href="http://anoriginalidea.wordpress.com/">Julian Biddle</a> has posted a wholly different strategy that would allow you to divide your Silverlight application across multiple XAPs on his blog: <a title="http://anoriginalidea.wordpress.com/2009/07/22/how-to-build-huge-dynamic-cross-platform-silverlight-business-applications/" href="http://anoriginalidea.wordpress.com/2009/07/22/how-to-build-huge-dynamic-cross-platform-silverlight-business-applications/">http://anoriginalidea.wordpress.com/2009/07/22/how-to-build-huge-dynamic-cross-platform-silverlight-business-applications/</a>.&#160; Take a look – it’s an interesting read/approach <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.davidpoll.com/2009/07/14/silverlight-3-navigation-navigating-to-pages-in-dynamically-loaded-assemblies/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Silverlight 3 Navigation: Navigating to Pages in referenced assemblies</title>
		<link>http://www.davidpoll.com/2009/07/12/silverlight-3-navigation-navigating-to-pages-in-referenced-assemblies/</link>
		<comments>http://www.davidpoll.com/2009/07/12/silverlight-3-navigation-navigating-to-pages-in-referenced-assemblies/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 08:58:18 +0000</pubDate>
		<dc:creator>david.poll</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[BusyIndicator]]></category>
		<category><![CDATA[Dynamic Navigation]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Silverlight 3]]></category>

		<guid isPermaLink="false">http://www.davidpoll.com/?p=88</guid>
		<description><![CDATA[At long last, Silverlight 3 has arrived!&#160; That, in and of itself, is worth a thousand blog posts, but since there’s a plethora of folks out there doing precisely that as I type, I’ll start right out with some content on one of the new features of Silverlight 3 – Navigation. In this post, I’ll [...]]]></description>
			<content:encoded><![CDATA[<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_start --><p>At long last, <a href="http://silverlight.net/GetStarted/" target="_blank">Silverlight 3</a> has arrived!&#160; That, in and of itself, is worth a thousand blog posts, but since there’s a plethora of folks out there doing precisely that as I type, I’ll start right out with some content on one of the <a href="http://silverlight.net/getstarted/silverlight3/default.aspx" target="_blank">new features</a> of Silverlight 3 – Navigation.</p>
<p>In this post, I’ll look at some basic navigation functionality in Silverlight 3.&#160; Silverlight 3 navigation is based on navigating a Frame control to a particular Page control.&#160; On top of allowing non-linear navigation throughout your Silverlight application, the Frame control will integrate with your browser’s history and address bar, allowing you to provide deep-links to Pages within your application and provide a more web-like experience within Silverlight applications.</p>
<p>Using Pages and Navigation in this way allows you to structure your application much like you would a web page, with various pages providing differing functionality.&#160; Like web pages, Silverlight 3 navigation allows you to pass data through query strings, perform fragment navigation, and so on – great topics for another post <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Basic navigation to pages in your main (application) project is simple – HyperlinkButtons can target a Frame, and specify the path to the Page’s XAML file, like so:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Source</span><span style="color: blue">=&quot;/Views/Home.xaml&quot;</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame</span><span style="color: blue">&gt;</span><span style="color: blue">
&lt;</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/Views/Home.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;home&quot;/&gt;
</span><span style="color: blue">    &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/Views/About.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;about&quot;/&gt;
&lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>In this case, my Pages are “Home” and “About”, located in a Views folder within my Silverlight Application project.&#160; Clicking on the links results in changes to the address bar in my web browser, as you can see in the image below.&#160; The path in the hyperlink is displayed after the hash mark (#) in the URL.&#160; I could send someone this link to bring them right back to the specified page in my application.</p>
<p><a href="http://www.davidpoll.com/Samples/MultiAssemblyNavigation/TestPage.html#/Views/About.xaml"><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="Address bar after navigating" border="0" alt="Address bar after navigating" src="http://davidpoll.com/Images/Silverlight3NavigationNavigatingtoPagesi_19C1/image.png" width="604" height="84" /></a>This navigation functionality is very valuable in and of itself, but what happens if I want to put my pages in a separate assembly, ripe for reuse in other applications?&#160; You’ll notice that the URIs for the Pages were relative to the application project (i.e. “/Views/Home.xaml” represents “&lt;ApplicationProject&gt;/Views/Home.xaml”).&#160; This actually comes from the short form of the <a href="http://msdn.microsoft.com/en-us/library/aa970069.aspx" target="_blank">pack URI syntax in WPF</a> (note: the full syntax is not supported in Silverlight, just a narrow subset).&#160; If you want to access Pages in referenced assemblies, you can do so using the same “short” syntax: “/&lt;ReferencedAssemblyName&gt;;component/&lt;PathToPage&gt;/&lt;PageName&gt;.xaml”</p>
<p>With this syntax, I can place (and reference) pages in a class library that will be referenced by my Silverlight application, allowing me to create a structure like the one in the image below (a simplified example, I know, but it does illustrate the point!).</p>
<p><a href="http://davidpoll.com/Images/Silverlight3NavigationNavigatingtoPagesi_19C1/image_3.png"><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="Solution structure showing /Pages/PageInLibrary.xaml in a class library called PageClassLibrary" border="0" alt="Solution structure showing /Pages/PageInLibrary.xaml in a class library called PageClassLibrary" src="http://davidpoll.com/Images/Silverlight3NavigationNavigatingtoPagesi_19C1/image_thumb.png" width="288" height="362" /></a>For this project structure, my hyperlinks look like this:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Source</span><span style="color: blue">=&quot;/Views/Home.xaml&quot;</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame</span><span style="color: blue">&gt;
</span><span style="color: blue">&lt;</span><span style="color: #a31515">StackPanel </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LinksStackPanel&quot;</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/Views/Home.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;home&quot;/&gt;</span><span style="color: blue">
    &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/Views/About.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;about&quot;/&gt;</span><span style="color: blue">
    &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/PageClassLibrary;component/Pages/PageInLibrary.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;page in a class library&quot;/&gt;
&lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;</span></pre>
<p>Upon running and clicking on the “page in a class library” link, you’ll notice that the address bar shows a rather long and ugly URI:</p>
<p><a href="http://www.davidpoll.com/Samples/MultiAssemblyNavigation/TestPage.html#/PageClassLibrary;component/Pages/PageInLibrary.xaml"><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="http://www.davidpoll.com/Samples/MultiAssemblyNavigation/TestPage.html#/PageClassLibrary;component/Pages/PageInLibrary.xaml" border="0" alt="http://www.davidpoll.com/Samples/MultiAssemblyNavigation/TestPage.html#/PageClassLibrary;component/Pages/PageInLibrary.xaml" src="http://davidpoll.com/Images/Silverlight3NavigationNavigatingtoPagesi_19C1/image_4.png" width="604" height="74" /></a></p>
<p>Thankfully, we’ve supplied a great feature for the Frame control that helps you deal with ungainly URIs – the UriMapper.&#160; UriMappers allow you to write code that takes a URI as input and produces a different URI as output.&#160; The output URI will be used to locate the page, while the input URI is what the user will see.&#160; In the SDK, we’ve supplied a default UriMapper that allows you to use some basic pattern matching to map URIs and keep your deep-links nice and tidy.</p>
<p>In my case, I’d be quite happy if I could get rid of the “/PageClassLibrary;component&quot; that I had to add to my URI to reference Pages in a class library altogether.&#160; Instead, I’d like my URI to look like this: “/Pages/PageInLibrary.xaml”.&#160; To accomplish this, I add a UriMapper to my Frame:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame </span><span style="color: red">Source</span><span style="color: blue">=&quot;/Views/Home.xaml&quot;</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
            &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;/Pages/{path}&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/PageClassLibrary;component/Pages/{path}&quot; /&gt;
        &lt;/</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame</span><span style="color: blue">&gt;</span><span style="color: blue">
</span><span style="color: blue">&lt;</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">HyperlinkButton</span><span style="color: blue"> </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/Views/Home.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;home&quot;/&gt;</span><span style="color: blue">
    &lt;</span><span style="color: #a31515">HyperlinkButton</span><span style="color: blue"> </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/Views/About.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;about&quot;/&gt;</span><span style="color: blue">
    &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/PageClassLibrary;component/Pages/PageInLibrary.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;page in a class library&quot;/&gt;</span><span style="color: blue">
    &lt;</span><span style="color: #a31515">HyperlinkButton </span><span style="color: red">NavigateUri</span><span style="color: blue">=&quot;/Pages/PageInLibrary.xaml&quot; </span><span style="color: red">TargetName</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Content</span><span style="color: blue">=&quot;(mapped URI) page in a class library&quot;/&gt;
&lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now, users who navigate to the page are greeted with this, much “prettier” URL:</p>
<p><a href="http://www.davidpoll.com/Samples/MultiAssemblyNavigation/TestPage.html#/Pages/PageInLibrary.xaml"><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="http://www.davidpoll.com/Samples/MultiAssemblyNavigation/TestPage.html#/Pages/PageInLibrary.xaml" border="0" alt="http://www.davidpoll.com/Samples/MultiAssemblyNavigation/TestPage.html#/Pages/PageInLibrary.xaml" src="http://davidpoll.com/Images/Silverlight3NavigationNavigatingtoPagesi_19C1/image_5.png" width="604" height="86" /></a></p>
<p>And there you have it!&#160; Dividing your pages across multiple assemblies doesn’t have to degrade user experience, and once you’re familiar with the style of URI that the navigation framework expects for such pages, it’s no more complex than standard navigation within your Silverlight application.</p>
<p><strong><em>One last thought…</em></strong></p>
<p>Before I leave you, I think it’s important to point something out: the Silverlight 3 SDK ships with a project template for Navigation for Visual Studio.&#160; This template makes it really easy to get started with a styleable, Navigation-enabled Silverlight application, and does quite a lot for you, including specifying some default UriMappings:</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">ContentFrameStyle</span><span style="color: blue">}&quot;
                  </span><span style="color: red">Source</span><span style="color: blue">=&quot;/Home&quot; </span><span style="color: red">Navigated</span><span style="color: blue">=&quot;ContentFrame_Navigated&quot; </span><span style="color: red">NavigationFailed</span><span style="color: blue">=&quot;ContentFrame_NavigationFailed&quot;&gt;
    &lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/Views/Home.xaml&quot;/&gt;
        &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;/{pageName}&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/Views/{pageName}.xaml&quot;/&gt;
      &lt;/</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This is great – it makes the common case of having Pages within your “Views” folder in your application project really clean, allowing developers to reference “/Home” instead of “/Views/Home.xaml”.&#160; However, if you look closely at the UriMappings, you’ll notice that “/{pageName}” will match our “/&lt;AssemblyName&gt;;component” syntax, mapping it to something else entirely, and preventing any attempts to link directly to such URIs.</p>
<p>There are a number of ways to address this issue, depending on your desired URI scheme, such as:</p>
<ul>
<li>Delete the UriMappings entirely and go back to the full paths for all of the hyperlinks </li>
<li>Modify the existing UriMappings so that the “catch-all” doesn’t match the desired syntax </li>
<li>Add UriMappings for each referenced library <strong><em>before</em></strong> the catch-all mapping, like so: </li>
</ul>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">ContentFrameStyle</span><span style="color: blue">}&quot;
                  </span><span style="color: red">Source</span><span style="color: blue">=&quot;/Home&quot; </span><span style="color: red">Navigated</span><span style="color: blue">=&quot;ContentFrame_Navigated&quot; </span><span style="color: red">NavigationFailed</span><span style="color: blue">=&quot;ContentFrame_NavigationFailed&quot;&gt;
    &lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/Views/Home.xaml&quot;/&gt;
<strong><em>        &lt;</em></strong></span><strong><em><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;/Pages/{path}&quot; </span><span style="color: red">MappedUri</span></em></strong><span style="color: blue"><strong><em>=&quot;/PageClassLibrary;component/Pages/{path}&quot; /&gt;</em></strong>
        &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;/{pageName}&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/Views/{pageName}.xaml&quot;/&gt;
      &lt;/</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<ul>
<li>Add a UriMapping to restore the original syntax <strong><em>before</em></strong> the catch-all mapping, like so: </li>
</ul>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;ContentFrame&quot; </span><span style="color: red">Style</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">StaticResource </span><span style="color: red">ContentFrameStyle</span><span style="color: blue">}&quot;
                  </span><span style="color: red">Source</span><span style="color: blue">=&quot;/Home&quot; </span><span style="color: red">Navigated</span><span style="color: blue">=&quot;ContentFrame_Navigated&quot; </span><span style="color: red">NavigationFailed</span><span style="color: blue">=&quot;ContentFrame_NavigationFailed&quot;&gt;
    &lt;</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/Views/Home.xaml&quot;/&gt;
<strong><em>        &lt;</em></strong></span><strong><em><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;/{assemblyName};component/{path}&quot; </span><span style="color: red">MappedUri</span></em></strong><span style="color: blue"><strong><em>=&quot;/{assemblyName};component/{path}&quot; /&gt;</em></strong>
        &lt;</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapping </span><span style="color: red">Uri</span><span style="color: blue">=&quot;/{pageName}&quot; </span><span style="color: red">MappedUri</span><span style="color: blue">=&quot;/Views/{pageName}.xaml&quot;/&gt;
      &lt;/</span><span style="color: #a31515">uriMapper</span><span style="color: blue">:</span><span style="color: #a31515">UriMapper</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame.UriMapper</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">navigation</span><span style="color: blue">:</span><span style="color: #a31515">Frame</span><span style="color: blue">&gt;</span></pre>
<p>This list is certainly not exhaustive, but some combination of these options is likely to help you re-enable navigation to Pages in referenced assemblies.</p>
<p>If you’re still having trouble getting this to work, let me know, and I’ll try to help you troubleshoot!</p>
<p><strong><em>Last, but not least…</em></strong></p>
<p>You thought I might leave you without source and a link to the sample, didn’t you?!&#160; Well, guess I showed you!&#160; Oh, wait, I haven’t linked them yet.&#160; Uhhh… pretend I didn’t say that <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ul>
<li><a href="http://www.davidpoll.com/Samples/MultiAssemblyNavigation/TestPage.html" target="_blank">Sample</a> </li>
<li><a href="http://www.davidpoll.com/Download/MultiAssemblyNavigation.zip">Source code</a> </li>
</ul>
<p>More posts will come now that Silverlight 3 is out!&#160; I’ve been waiting with bated breath!&#160; Thankfully, you folks aren’t around to suggest I use a mint <img src='http://www.davidpoll.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong><em>P.S.</em></strong>&#160; Now that Silverlight 3 <em>is</em> out, I’ve updated all of my samples/source to work with <a href="http://silverlight.net/GetStarted/">Silverlight 3</a>, the <a href="http://silverlight.codeplex.com/">July 2009 Silverlight Toolkit</a>, and <a href="http://silverlight.net/forums/t/108916.aspx">.NET RIA Services July 2009 CTP</a>.&#160; You’ll find my Konami Code control and Activity control should both work out-of-the-box with Silverlight 3 RTM, and the rest only needed minor updates.&#160; If folks are curious about my experiences updating those projects, let me know and I’ll do a short post.</p>
<!-- Advanced AdSense by Jim Gaudet --><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://www.davidpoll.com/2009/07/12/silverlight-3-navigation-navigating-to-pages-in-referenced-assemblies/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
