<?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>Southworks Blogs &#187; Navigation</title>
	<atom:link href="http://blogs.southworks.net/category/navigation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.southworks.net</link>
	<description>Powered by Southworks</description>
	<lastBuildDate>Tue, 14 May 2013 19:36:02 +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>Why Silverlight 3 Navigation cannot be fully leveraged when loading modules remotely with Prism 2</title>
		<link>http://blogs.southworks.net/dschenkelman/2009/11/05/why-silverlight-3-navigation-cannot-be-fully-leveraged-when-loading-modules-remotely-with-prism-2/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2009/11/05/why-silverlight-3-navigation-cannot-be-fully-leveraged-when-loading-modules-remotely-with-prism-2/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 09:36:35 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Composite Application Guidance for WPF & SL]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Patterns & Practices]]></category>
		<category><![CDATA[Prism-v2]]></category>
		<category><![CDATA[Remote Module Loading]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Windows Presentation Foundation]]></category>
		<category><![CDATA[p&p]]></category>

		<guid isPermaLink="false">http://15.145</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2009/11/05/why-silverlight-3-navigation-cannot-be-fully-leveraged-when-loading-modules-remotely-with-prism-2/" class="more-link">read more<img src="http://blogs.southworks.net/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Now that <a href="http://blogs.southworks.net/dschenkelman/2009/11/02/prism-v21-composite-application-guidance-just-released-updated-version-for-silverlight-3/" target="_blank">the Prism team has shipped a new version of the guidance</a>, I thought it would be a good time to blog on this subject, based on some research we did with <a href="http://blogs.southworks.net/ejadib/" target="_blank">Ezequiel</a>, <a href="http://blogs.southworks.net/matiasb/" target="_blank">Matias</a> and <a href="http://blogs.southworks.net/jdominguez/" target="_blank">Julian</a>. This article will not focus on how to workaround the limitations of using Silverlight 3 Navigation with Prism (as the guys who wrote the posts mentioned below have done a good job on that) instead it will focus on the why of these limitations:</p>
<ul>
<li><a href="http://blogs.southworks.net/mconverti/2009/04/12/how-to-integrate-a-prism-v2-application-with-the-silverlight-3-navigation-framework/">How To: Integrate a Prism v2 application with the Silverlight 3 Navigation Framework </a></li>
<li><a href="http://www.davidpoll.com/?p=92" target="_blank">Silverlight 3 Navigation: Navigating to Pages in dynamically-loaded assemblies</a></li>
</ul>
<table border="1" cellspacing="0" cellpadding="2" width="267" align="center">
<tbody>
<tr>
<td width="265" valign="top"><strong>Warning:</strong> Technical explanation coming below.</td>
</tr>
</tbody>
</table>
<p>The Silverlight team is aware of the limitations mentioned below, so they <span style="text-decoration: underline">might</span> be taken into account for a future version.</p>
<h2>Issue Description</h2>
<p><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.page(VS.95).aspx">Pages</a> with code behind, from remotely loaded modules cannot be navigated to, calling the Frame&#8217;s <a href="http://msdn.microsoft.com/en-us/library/ms602275(VS.95).aspx">Navigate</a> method. This prevents having functional views since they neither have code behind nor a <strong>ViewModel</strong> attached.</p>
<h2>Cause of Issue</h2>
<table border="1" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td width="1086" valign="top"><strong>Note: </strong>To be able to perform the research below, add the following line in the <strong>LoadAssemblyFromStream</strong> method placed in the <strong>XapModuleTypeLoader</strong> class from the CAL:<br />
<span style="font-family: Courier New;font-size: x-small">Deployment.Current.Parts.Add(assemblyPart);</span></td>
</tr>
</tbody>
</table>
<p><strong></strong></p>
<p>The Silverlight 3 Navigation framework goes over every <strong>AssemblyPart </strong>in the <strong>Deployment.Current.Parts</strong> collection if the Page to navigate to has code behind, as shown in the code below (<strong>PageResourceContentLoader</strong> class reflected code in the <strong>System.Windows.Navigation</strong> namespace from the <strong>System.Windows.Controls.Navigation</strong> assembly):</p>
<pre><span style="color: blue">private static </span><span style="color: #2b91af">Type </span>GetTypeFromAnyLoadedAssembly(<span style="color: blue">string </span>typeName)
        {
            <span style="color: #2b91af">Type </span>type = <span style="color: blue">null</span>;
            <span style="color: blue">foreach </span>(<span style="color: #2b91af">AssemblyPart </span>part <span style="color: blue">in </span><span style="color: #2b91af">Deployment</span>.Current.Parts)
            {
                <span style="color: green">/*THE LINE BELOW RETURNS NULL FOR REMOTELY LOADED ASSEMBLIES, BECAUSE THEY ARE NOT IN THE APPLICATION'S XAP*/
                </span><span style="color: #2b91af">StreamResourceInfo </span>resourceStream = <span style="color: #2b91af">Application</span>.GetResourceStream(<span style="color: blue">new </span><span style="color: #2b91af">Uri</span>(part.Source, <span style="color: #2b91af">UriKind</span>.Relative));
                <span style="color: blue">if </span>(resourceStream != <span style="color: blue">null</span>)
                {
                    <span style="color: #2b91af">Assembly </span>assembly = <span style="color: blue">new </span><span style="color: #2b91af">AssemblyPart</span>().Load(resourceStream.Stream);
                    <span style="color: blue">if </span>(assembly != <span style="color: blue">null</span>)
                    {
                        type = <span style="color: #2b91af">Type</span>.GetType(typeName + <span style="color: #a31515">"," </span>+ assembly, <span style="color: blue">false</span>);
                    }
                }
                <span style="color: blue">if </span>(type != <span style="color: blue">null</span>)
                {
                    <span style="color: blue">return </span>type;
                }
            }
            <span style="color: blue">return </span>type;
        }</pre>
<p>As the above code shows, even if the <strong>AssemblyPart</strong> is in the collection it is not found by the <strong>Application.GetReourceStream</strong> method. From the <a href="http://msdn.microsoft.com/en-us/library/ms596994(VS.95).aspx">method&#8217;s MSDN site</a>, the cause is:</p>
<p><em></em></p>
<p><em>&#8220;The </em><a href="http://msdn.microsoft.com/en-us/library/system.windows.application.getresourcestream(VS.95).aspx"><em>GetResourceStream</em></a><em> method allows you to load an arbitrary resource file from one of the following locations:</em></p>
<ul>
<li><em>Embedded in the application assembly in the application package.</em></li>
<li><em>Embedded in a library assembly that is included in the application package.</em></li>
<li><em>Included in the application package.&#8221;</em></li>
</ul>
<p>So only assemblies in the application&#8217;s original .xap file are found and not for other modules.</p>
<p>I hope the above explanation was useful.</p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/Why-Silverlight-3-Navigation-cannot-be-fully-leveraged-when-loading-modules-remotely-with-Prism-2"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2009%2F11%2F05%2Fwhy-silverlight-3-navigation-cannot-be-fully-leveraged-when-loading-modules-remotely-with-prism-2%2F"></a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.southworks.net%2fdschenkelman%2f2009%2f11%2f05%2fwhy-silverlight-3-navigation-cannot-be-fully-leveraged-when-loading-modules-remotely-with-prism-2%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.southworks.net%2fdschenkelman%2f2009%2f11%2f05%2fwhy-silverlight-3-navigation-cannot-be-fully-leveraged-when-loading-modules-remotely-with-prism-2%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
