<?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>Silverlight &#124; WPF &#124; Microsoft.Net &#187; RegisterScriptableObject</title>
	<atom:link href="http://joel.neubeck.net/tag/registerscriptableobject/feed/" rel="self" type="application/rss+xml" />
	<link>http://joel.neubeck.net</link>
	<description>Simplifing structure without changing results</description>
	<lastBuildDate>Fri, 01 Apr 2011 21:34:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Communicating between two Silverlight objects on a single page</title>
		<link>http://joel.neubeck.net/2008/07/communicating-between-sl2-objects/</link>
		<comments>http://joel.neubeck.net/2008/07/communicating-between-sl2-objects/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 08:35:00 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[RegisterScriptableObject]]></category>
		<category><![CDATA[ScriptableMember]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/07/communicating-between-sl2-objects/</guid>
		<description><![CDATA[Not sure where I stumbled on it, but recently I watched video online where as the video was playing, a banner ad on the same page changed as the context of the video changed.&#160; I was intrigued by the potential this technique had in interactive marketing.&#160; As I was watching the video I was envisioning [...]]]></description>
			<content:encoded><![CDATA[<p>Not sure where I stumbled on it, but recently I watched video online where as the video was playing, a banner ad on the same page changed as the context of the video changed.&#160; I was intrigued by the potential this technique had in interactive marketing.&#160; As I was watching the video I was envisioning a character picking up a can of Pepsi and at that moment a corresponding banner ad somewhere else on the page switching to an ad for Pepsi.&#160; This could be a very powerful way to create interactive calls to action.</p>
<p>This got me thinking about how I might duplicate that technique in Silverlight 2. I figured that the first step was to figure out a simple way communicate between two distinct Silverlight object which exists on the same page.&#160; For this example I am going to have one SL object contain a series of <strong>Buttons</strong>, while the other SL object contains a single <strong>TextBlock.</strong></p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-1.png"><img title="slobjects_1" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="216" alt="slobjects_1" src="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-1-thumb.png" width="417" align="left" border="0" /></a> </p>
<p>  <br style="clear: both" />
<p>In the image above the red box I refer to as <strong>slObject1</strong>, where the blue box I refer to as <strong>slObject2</strong>.&#160; Both of these &lt;objects&gt; have unique id’s and point to their own respective Silverlight Project and both have been placed in a single html file.&#160; </p>
<p>In this example my <strong>slObject1</strong> will be executing a Javascript function, which in turn will be calling an internal function inside of <strong>slObject2</strong>.&#160; To do this I simply add a reference to the “System.Windows.Browser” namespace and call the Invoke method of the Window object.&#160; here is what my button click handler looks like.&#160; </p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-2.png"><img title="slobjects_2" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="120" alt="slobjects_2" src="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-2-thumb.png" width="445" align="left" border="0" /></a></p>
<p>  <br style="clear: both" />
<p>Once I have this defined I can now go back into my default.html file and define this Javascript function.&#160; The function finds the appropriate html object and calls the internal function in <strong>slObject2</strong>.&#160; </p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-3.png"><img title="slobjects_3" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="90" alt="slobjects_3" src="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-3-thumb.png" width="509" align="left" border="0" /></a> </p>
<p>  <br style="clear: both" />
<p>To create my “UpdateTextBlock function I need to add a few things to the <strong>slObject2</strong> project.&#160; First I have to go into my App.xaml.cs file and enter the following in my Application_Startup handler.&#160; <strong>“HtmlPage.RegisterScriptableObject(&quot;Page&quot;, page);”</strong>&#160; This registers a managed object for scriptable access by JavaScript code.&#160; Once registered I can create my methods as follows.</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-4.png"><img title="slobjects_4" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="103" alt="slobjects_4" src="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-4-thumb.png" width="331" align="left" border="0" /></a></p>
<p>  <br style="clear: both" />
<p>That is all there is to it.&#160; Now that I have the ability to communicate between the two SL object I can go after a more complicated implementation.</p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview(&#39;/code/SLObjects.zip&#39;);" href="/wp-content/uploads/2008/07/SLObjects/SLObjects.zip">SLObjects.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/07/communicating-between-sl2-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

