<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The MossyBlog Times Archives 2007 - 2009 : JavaScript</title><link>http://blogs.msdn.com/msmossyblog/archive/tags/JavaScript/default.aspx</link><description>Tags: JavaScript</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How To: Using AjaxControlToolkit to animate Silverlight.</title><link>http://blogs.msdn.com/msmossyblog/archive/2007/10/03/how-to-using-ajaxcontroltoolkit-to-animate-silverlight.aspx</link><pubDate>Wed, 03 Oct 2007 10:47:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5256824</guid><dc:creator>scbarnes</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/msmossyblog/comments/5256824.aspx</comments><wfw:commentRss>http://blogs.msdn.com/msmossyblog/commentrss.aspx?PostID=5256824</wfw:commentRss><wfw:comment>http://blogs.msdn.com/msmossyblog/rsscomments.aspx?PostID=5256824</wfw:comment><description>&lt;p&gt;In my Silverlight travels, I was thinking on how one is able to animate a &amp;quot;PullDown&amp;quot; menu, in that it comes down and then goes back up upon triggered events.&lt;/p&gt;  &lt;h4&gt;Approach A.&lt;/h4&gt;  &lt;p&gt;I decided to approach this using simplistic rules, where I'd create two animations inside Expression Blend using the KeyFrame Recorder.&amp;#xA0; I'd simply move the &amp;quot;Canvas&amp;quot; in question to where I want it to rest, and then within a 1 second interval, animate it upwards. I'd call this &amp;quot;&lt;strong&gt;PLMoveUp&lt;/strong&gt;&amp;quot;. I'd then take the exact concept and reverse it through a separate KeyFrame Resource (KeyFrame Resources are basically XAML code that await you to trigger their animation sequence via play/stop methods) called &amp;quot;&lt;strong&gt;PLMoveDown&lt;/strong&gt;&amp;quot;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/msmossyblog/WindowsLiveWriter/HowToUsingAjaxControlToolkittoanimateSi_FA13/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="174" alt="image" src="http://blogs.msdn.com/blogfiles/msmossyblog/WindowsLiveWriter/HowToUsingAjaxControlToolkittoanimateSi_FA13/image_thumb.png" width="516" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This works, don't get me wrong, but sadly this approach is flawed. As how do you know where the current phase in the Storyboard is at? there aren't any &amp;quot;onStoryBoardStep&amp;quot; style events to subscribe to, resulting in &amp;quot;assuming&amp;quot; the animations end naturally. This means that if a user were to click on a button repeatedly you'd kind of get this flicker look (bad experience).&lt;/p&gt;  &lt;h4&gt;Approach B.&lt;/h4&gt;  &lt;p&gt;Instead of having two Canvas.Resource Storyboards, you consolidate into one. Then using the Silverlight API, you would utilse the power of Storyboard.AutoReverse and Storyboard.Seek(amt).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/msmossyblog/WindowsLiveWriter/HowToUsingAjaxControlToolkittoanimateSi_FA13/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="83" alt="image" src="http://blogs.msdn.com/blogfiles/msmossyblog/WindowsLiveWriter/HowToUsingAjaxControlToolkittoanimateSi_FA13/image_thumb_2.png" width="523" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This works, but again, you've got to do a lot of work to poll where the animation is at, and that requires an outside &amp;quot;timer&amp;quot;. In that in order to poll the current point in time of an animation, you'd create a &amp;quot;timer&amp;quot; that would constantly ping/pong the Storyboard for an update. Yet you'd need to further assign an x:Name attribute to one of the SplineDoubleKeyFrames for this as well, as you'll want to extract the KeyTime.Seconds amount in order to determine what the latest value is currently sitting at.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/msmossyblog/WindowsLiveWriter/HowToUsingAjaxControlToolkittoanimateSi_FA13/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="20" alt="image" src="http://blogs.msdn.com/blogfiles/msmossyblog/WindowsLiveWriter/HowToUsingAjaxControlToolkittoanimateSi_FA13/image_thumb_3.png" width="597" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Overall, bad.&lt;/p&gt;  &lt;h4&gt;Approach C.&lt;/h4&gt;  &lt;p&gt;Using the ASP.NET &lt;strong&gt;AjaxControlToolkit&lt;/strong&gt;, I was able to leverage the existing animation libraries to do my bidding for me. &lt;/p&gt;  &lt;p&gt;First I created a project using the &lt;strong&gt;ASP.NET AJAX Futures Web application (.NET Framework 3.5)&lt;/strong&gt; template.&lt;/p&gt;  &lt;p&gt;I then added a Project to this Solution, using the JavaScript Silverlight Project (I'm not going to use the managed code (C#) approach to Silverlight, instead I'm choosing to use JavaScript + Silverlight).&lt;/p&gt;  &lt;p&gt;I setup my GUI assets, using Microsoft Expression Blend. Positioned them to where I want them, and began then saved the project.&lt;/p&gt;  &lt;p&gt;Then inside Visual Studio 2008, I added a &amp;quot;Add Silverlight Link..&amp;quot; via the &lt;strong&gt;Solution Explorer&lt;/strong&gt;. Connected the two together.&lt;/p&gt;  &lt;p&gt;Now, I must confess it's at this point where I had to figure out how to bring in the AjaxControlToolkit. As I've never really had a need to use it up until today. I downloaded the 3.5 Framework version of it and installed it (Basically follow the Install Videos to the letter and you should be fine).&lt;/p&gt;  &lt;p&gt;Now comes the code.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt; &lt;span class="rem"&gt;&amp;lt;!-- -----------------------------------------------------------------------------------&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;&lt;span class="rem"&gt; SILVERLIGHT CONTROL&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;&lt;span class="rem"&gt; ----------------------------------------------------------------------------------- --&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SilverlightHost&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Xaml&lt;/span&gt; &lt;span class="attr"&gt;XamlUrl&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;~/Page.xaml&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SilverlightControl&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Windowless&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1000&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;750&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

  &lt;br /&gt;Using the Xaml tag, i created a pointer to my Page.xaml file (which has my assets housed within). Note the name &amp;quot;&lt;strong&gt;SilverlightControl&lt;/strong&gt;&amp;quot; (important).&lt;/p&gt;

&lt;p&gt;In my UI I have a &lt;strong&gt;PullDownMenu&lt;/strong&gt;, which I want to now animate up and down.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/msmossyblog/WindowsLiveWriter/HowToUsingAjaxControlToolkittoanimateSi_FA13/image_12.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="292" alt="image" src="http://blogs.msdn.com/blogfiles/msmossyblog/WindowsLiveWriter/HowToUsingAjaxControlToolkittoanimateSi_FA13/image_thumb_5.png" width="475" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now comes the code:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt; &amp;lt;script type=&lt;span class="str"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt; Sys.Application.add_init(appInitHandler);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;function&lt;/span&gt; appInitHandler() {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="rem"&gt;// Silverlight is Ready, now proceed...&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; &lt;span class="kwrd"&gt;function&lt;/span&gt; appOnLoad() {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; &lt;span class="rem"&gt;//$create(Demo.Person,null,null,null,null);&lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; &lt;span class="kwrd"&gt;var&lt;/span&gt; animator = &lt;span class="kwrd"&gt;new&lt;/span&gt; AjaxControlToolkit.Animation.FadeAnimation($get(&lt;span class="str"&gt;&amp;quot;Overlay&amp;quot;&lt;/span&gt;), 0.5, 20, &lt;span class="str"&gt;&amp;quot;FadeOut&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; &lt;span class="kwrd"&gt;var&lt;/span&gt; customanim = &lt;span class="kwrd"&gt;new&lt;/span&gt; AjaxControlToolkit.Animation.ScriptAction(&lt;span class="str"&gt;&amp;quot;overlay&amp;quot;&lt;/span&gt;, 0.5, 40, &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; animator.play(); &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; customanim.onStep = onCustomStep;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; customanim.play();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; }&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; &lt;span class="rem"&gt;// Custom Animation Sequence &lt;/span&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; &lt;span class="kwrd"&gt;function&lt;/span&gt; onCustomStep(percentage) {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; &lt;span class="kwrd"&gt;var&lt;/span&gt; o = $get(&lt;span class="str"&gt;&amp;quot;SilverlightControl&amp;quot;&lt;/span&gt;).content.FindName(&lt;span class="str"&gt;&amp;quot;pulldown&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 19: &lt;/span&gt; &lt;span class="kwrd"&gt;var&lt;/span&gt; amt = Math.round(456*percentage/100);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 20: &lt;/span&gt; o.SetValue(&lt;span class="str"&gt;&amp;quot;Canvas.Top&amp;quot;&lt;/span&gt;, amt + -456);&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 21: &lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 22: &lt;/span&gt; &amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;It's that Simple! I also had a &amp;lt;DIV&amp;gt; tag called &amp;quot;overlay&amp;quot; which represents a screenout overaly.&lt;/p&gt;

&lt;p&gt;I need my hosting provider on &lt;a href="http://www.beyondTheBrowser.NET"&gt;http://www.beyondTheBrowser.NET&lt;/a&gt; to move me over to the .NET 3.5 hosting plan in order to show you, but essentially using the&lt;strong&gt; &lt;a href="http://asp.net/AJAX/AjaxControlToolkit/Samples/Walkthrough/AnimationReference.aspx#ScriptAction" target="_blank"&gt;AjaxControlToolkit.Animation.ScriptAction&lt;/a&gt;&lt;/strong&gt; library, I'm able to empower it to control the Silverlight Animation sequence.&lt;/p&gt;

&lt;p&gt;If you're confused? don't worry, I'll be &lt;strong&gt;videocasting&lt;/strong&gt; this later this month.&lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:B3E14793-948F-49af-A347-D19C374A7C4F:5bd54441-a13a-4b60-8ec8-bf365b62d825" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;
&lt;script type="text/javascript"&gt;&lt;!--
digg_url = 'http://digg.com/programming/How_To_Using_AjaxControlToolkit_to_animate_Silverlight';
digg_title = 'How To: Using AjaxControlToolkit to animate Silverlight.';
digg_bodytext = 'In my Silverlight travels, I was thinking on how one is able to animate a "PullDown" menu, in that it comes down and then goes back up upon triggered events.';
//--&gt;&lt;/script&gt;
&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5256824" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Animation/default.aspx">Animation</category></item><item><title>JavaScript brings balance back to the force.</title><link>http://blogs.msdn.com/msmossyblog/archive/2007/09/01/javascript-brings-balance-back-to-the-force.aspx</link><pubDate>Sat, 01 Sep 2007 06:31:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4680887</guid><dc:creator>scbarnes</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/msmossyblog/comments/4680887.aspx</comments><wfw:commentRss>http://blogs.msdn.com/msmossyblog/commentrss.aspx?PostID=4680887</wfw:commentRss><wfw:comment>http://blogs.msdn.com/msmossyblog/rsscomments.aspx?PostID=4680887</wfw:comment><description>&lt;p&gt;It's funny how you sometimes take something so simple for granted until you one day suddenly realise the answer has been staring you in the face all along.&lt;/p&gt; &lt;p&gt;JavaScript is that answer,it's now become this language widely used, mostly understood and pushed to the point where i doubt there is anything left undiscovered about it. It's now become the bridge between disparate technologies from most of the major software giants (Microsoft, Google, Adobe etc). It's being used in a number of creative ways and it doesn't appear to be stopping either.&lt;/p&gt; &lt;p&gt;You could use JavaScript to write a Windows Vista SideBar Gadget, Yahoo! Widget and whatever the next piece of technology of this kind can be inserted here.&lt;/p&gt; &lt;p&gt;You could use JavaScript to bridge the gap between Adobe AIR and Adobe Acrobat, to empower electronic forms to carryout out tasks dictated by Adobe AIR&amp;nbsp;(via FLEX / AJAX). &lt;/p&gt; &lt;p&gt;You could use JavaScript to control and manipulate Microsoft Silverlight XAML, shape and bend it to suite your will, using it to hold the fort while we build and produce the application framework that's yet to come.&lt;/p&gt; &lt;p&gt;You could use JavaScript to write data to your hard-drive through the use of Google Gears.&lt;/p&gt; &lt;p&gt;You could use JavaScript to hijack other peoples HTML code and make it do some interesting things, much like how I don't have FTP access to this blogs code, but I can bring-in JavaScript to manipulate the DOM should I wish.&lt;/p&gt; &lt;p&gt;You could use JavaScript to fuse two&amp;nbsp;competing technologies (Flash, Silverlight etc)&amp;nbsp;together, and force them to bow to you, the developers will should you so desire.&lt;/p&gt; &lt;p&gt;There is much you can do with JavaScript that typically it was never imagined when it was first produced. It's quite a unique language to admire and utilize, as it's got one thing going for it that we all are somewhat envious about.&lt;/p&gt; &lt;p&gt;Everyone simply knows it. It's been around for far to long, hasn't had any changes really to it and combined with HTML + Browser Agents it can be quite a powerful ally to have.&lt;/p&gt; &lt;p&gt;I have new found respect for JavaScript the more I see it being used in variety of ways. It just keeps getting stronger and stronger, yet no actual changes are made to it?&lt;/p&gt; &lt;p&gt;JavaScript is what keeps the RIA dream alive today, so we can build better tomorrow!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4680887" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/RIA/default.aspx">RIA</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Google+Gears/default.aspx">Google Gears</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/RIA+Handbook/default.aspx">RIA Handbook</category></item><item><title>Performing a hitTest with Silverlight</title><link>http://blogs.msdn.com/msmossyblog/archive/2007/06/16/performing-a-hittest-with-silverlight.aspx</link><pubDate>Sat, 16 Jun 2007 05:55:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3328091</guid><dc:creator>scbarnes</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/msmossyblog/comments/3328091.aspx</comments><wfw:commentRss>http://blogs.msdn.com/msmossyblog/commentrss.aspx?PostID=3328091</wfw:commentRss><wfw:comment>http://blogs.msdn.com/msmossyblog/rsscomments.aspx?PostID=3328091</wfw:comment><description>&lt;p&gt;In my Silverlight coding travels, I've found the urgent need to carry out a &lt;strong&gt;&lt;u&gt;hitTest&lt;/u&gt;&lt;/strong&gt; to determine where my end-users mouse is currently located but also what elements are underneath it within Silverlight.&lt;/p&gt; &lt;p&gt;So what's a &lt;strong&gt;&lt;u&gt;&lt;a href="http://search.live.com/results.aspx?q=hitTest+&amp;amp;src=IE-SearchBox" target="_blank"&gt;hitTest&lt;/a&gt;&lt;/u&gt;&lt;/strong&gt; you ask? well essentially&amp;nbsp;it's when you ask "&lt;em&gt;Is this&amp;nbsp;object colliding or in contact with that object?&lt;/em&gt;". It's used majority of the time in Flash world to determine where a relationship stops and starts with a MovieClip and Mouse (X/Y) coordinates. It can also be commonly used for collision detection with other MovieClips when you make a point and click "fire" game (ie shoot bullets via your mouse at other objects on screen).&lt;/p&gt; &lt;p&gt;Silverlight at present doesn't have a hitTest method, well it does but it's only found within &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tpcsdk10/lonestar/Microsoft.Ink/Classes/ink/Methods/hittest.asp" target="_blank"&gt;Inking&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;Well before one and all start to curse Silverlight for limited functionality compared to Flash (heh), it's not all doom and gloom. Thanks to the hierarchy index within Silverlight, one is able to ask objects individually where the mouse currently resides, but also where it currently is within the elements themselves.&lt;/p&gt; &lt;h4&gt;Now for some code..&lt;/h4&gt; &lt;p&gt;An example, say you had a &lt;strong&gt;Rectangle1&lt;/strong&gt; within &lt;strong&gt;Canvas1&lt;/strong&gt;, and you want to find out where the mouse currently is, but also where that mouse is within the actual Rectangle1 that's relative to the Rectangle1 itself (ie if the Mouse x is 30px in from the Rectangle1's edge?).&lt;/p&gt; &lt;p&gt;To do this you would do the following (this is JScript Code btw):&lt;/p&gt;&lt;pre&gt;    	&lt;span style="color: #008000"&gt;// Commit Default Properties.&lt;/span&gt;
    	private_commitProperties : &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() {
	      &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; local_owner = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; cnvs = $get("&lt;span style="color: #8b0000"&gt;slControl&lt;/span&gt;").Content.FindName("&lt;span style="color: #8b0000"&gt;Canvas1&lt;/span&gt;");
		&lt;span style="color: #008000"&gt;// EVENT: onMouseMove&lt;/span&gt;
        	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; local_onMouseMove = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(sender, eventArgs) {
            	local_owner.MouseObj = eventArgs;
            	local_owner.private_updateDisplayList();
        	}
		
        	&lt;span style="color: #008000"&gt;// Create Events&lt;/span&gt;
       	cnvs.addEventListener("&lt;span style="color: #8b0000"&gt;MouseMove&lt;/span&gt;",  local_onMouseMove);
    	},	

    	&lt;span style="color: #008000"&gt;// Update the DisplayList.    &lt;/span&gt;
    	private_updateDisplayList : &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() {
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; cnvs = $get("&lt;span style="color: #8b0000"&gt;slControl&lt;/span&gt;").Content.FindName("&lt;span style="color: #8b0000"&gt;Canvas1&lt;/span&gt;");	
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; rect = cnvs.FindName("&lt;span style="color: #8b0000"&gt;Rectangle1&lt;/span&gt;");

		&lt;span style="color: #008000"&gt;// Determine where the X/Y Mouse Co-ordinates are &lt;/span&gt;
		&lt;span style="color: #008000"&gt;// within Silverlight itself.&lt;/span&gt;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; currentX = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MouseObj.GetPosition(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;).x;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; currentY = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MouseObj.GetPosition(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;).y;
		
		&lt;span style="color: #008000"&gt;// Determine where the X/Y Mouse is within the Canvas&lt;/span&gt;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; cnvsX = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MouseObj.GetPosition( cnvs ).x;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; cnvsY = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MouseObj.GetPosition( cnvs ).y;

		&lt;span style="color: #008000"&gt;// Determine where the X/Y Mouse is within the Rectangle&lt;/span&gt;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; rectX = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MouseObj.GetPosition( rect ).x;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; rectY = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MouseObj.GetPosition( rect ).y;


		&lt;span style="color: #008000"&gt;// IsMouseInsideRect ?&lt;/span&gt;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; isMouseInsideRect = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;( rectX &amp;gt;=0 &amp;amp;&amp;amp; rectX &amp;lt;= rect.GetValue("&lt;span style="color: #8b0000"&gt;Width&lt;/span&gt;")) {
			isMouseInsideRect  = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
		} 

		&lt;span style="color: #008000"&gt;// IsMouseInsideCanvas ?&lt;/span&gt;
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; IsMouseInsideCanvas = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;( cnvsX &amp;gt;=0 &amp;amp;&amp;amp; cnvsX &amp;lt;= cnvs.GetValue("&lt;span style="color: #8b0000"&gt;Width&lt;/span&gt;")) {
			IsMouseInsideCanvas = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
		} 
		
		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;( IsMouseInsideCanvas  &amp;amp; IsMouseInsideCanvas ) {
			&lt;span style="color: #0000ff"&gt;window&lt;/span&gt;.&lt;span style="color: #0000ff"&gt;status&lt;/span&gt; = "&lt;span style="color: #8b0000"&gt;Mouse is Inside Rectangle&lt;/span&gt;";
		} &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {
			&lt;span style="color: #0000ff"&gt;window&lt;/span&gt;.&lt;span style="color: #0000ff"&gt;status&lt;/span&gt; = "&lt;span style="color: #8b0000"&gt;Mouse is Outside Rectangle&lt;/span&gt;";
		}
    },
&lt;/pre&gt;
&lt;p&gt;So what's happening here? Firstly I'm using &lt;a href="http://ajax.asp.net/docs/" target="_blank"&gt;ASP.NET AJAX ToolKit&lt;/a&gt; so the &lt;strong&gt;&lt;a href="http://ajax.asp.net/docs/ClientReference/Global/GetShortCutMethod.aspx" target="_blank"&gt;$get()&lt;/a&gt;&lt;/strong&gt; is found within this framework. I'm also wiring up a local object to react to the &lt;strong&gt;MouseMove&lt;/strong&gt; event, which in turn invokes &lt;strong&gt;private_updateDisplayList()&lt;/strong&gt; method. &lt;/p&gt;
&lt;p&gt;I then inside JavaScript create two variables (&lt;strong&gt;cnvs&lt;/strong&gt; &amp;amp; &lt;strong&gt;rect&lt;/strong&gt;) as pointers to XAML elements within Silverlight.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;MouseObj&lt;/strong&gt; you'll note was declared inside the &lt;strong&gt;local_onMouseMove&lt;/strong&gt; method, which essentially translates to Silverlights &lt;strong&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.forms.mouseeventargs(VS.71).aspx" target="_blank"&gt;MouseEventArgs&lt;/a&gt;&lt;/strong&gt; and inside this object, you have a method &lt;strong&gt;GetPosition()&lt;/strong&gt; which returns a Pointer (&lt;strong&gt;x/y&lt;/strong&gt;).&lt;/p&gt;
&lt;p&gt;Using this, I'm able to then determine in the first round (&lt;strong&gt;currentX&lt;/strong&gt;/&lt;strong&gt;currentY&lt;/strong&gt;) where the Cursor inside Silverlight currently is (why, not important in the above example but thought it's worth noting you can achieve this simply by providing null as your reference object).&lt;/p&gt;
&lt;p&gt;The second round, I then determine where the &lt;strong&gt;Cursor&lt;/strong&gt; is currently at in relation to the &lt;strong&gt;Canvas1&lt;/strong&gt; (&lt;strong&gt;cnvsX&lt;/strong&gt;/&lt;strong&gt;cnvsY&lt;/strong&gt;), which should return the same results as &lt;strong&gt;currentX&lt;/strong&gt; (seen as though &lt;strong&gt;Canvas1&lt;/strong&gt; is the root element).&lt;/p&gt;
&lt;p&gt;I then determine where the&amp;nbsp;&lt;strong&gt;Cursor&lt;/strong&gt; is located within the &lt;strong&gt;Rectangle1&lt;/strong&gt; element itself. Now, what will happen here is if the &lt;strong&gt;Rectanle1.x&lt;/strong&gt; is located on &lt;em&gt;100 pixels&lt;/em&gt; from the left, and the Cursor is located &lt;em&gt;150 pixels&lt;/em&gt; from the left, the &lt;strong&gt;rectX&lt;/strong&gt; will return "&lt;em&gt;50&lt;/em&gt;" as its result. &lt;/p&gt;
&lt;p&gt;Ahhh so now you see, that the &lt;strong&gt;GetPosition()&lt;/strong&gt; method returns the appropriate &lt;strong&gt;x/y&lt;/strong&gt; coordinates relative to the reference object in question and local &lt;strong&gt;x/y&lt;/strong&gt; as the result. Important to know this one!&lt;/p&gt;
&lt;p&gt;Lastly, I then determine if the Cursor is within the &lt;strong&gt;Rectangle1&lt;/strong&gt; boundaries, and to do this it's a simple case of asking "&lt;em&gt;Does the &lt;strong&gt;rectX&lt;/strong&gt; sit between 0 and the width of Rectangle1?, if so then it's within&lt;/em&gt;" &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note&lt;/u&gt;&lt;/strong&gt;: If &lt;strong&gt;Rectangle1&lt;/strong&gt; has a width of &lt;u&gt;200px&lt;/u&gt; and the &lt;strong&gt;Cursor&lt;/strong&gt; is located at &lt;u&gt;400px&lt;/u&gt; from the edge of &lt;strong&gt;Rectangle1&lt;/strong&gt;,&amp;nbsp;&lt;strong&gt;rectX&lt;/strong&gt; will still return a positive integer which is essentially cursor's actual position (&lt;span style="color: #0000ff"&gt;Math&lt;/span&gt;.round(&lt;strong&gt;currentX&lt;/strong&gt;-&lt;strong&gt;rectX&lt;/strong&gt;)) relative to the &lt;strong&gt;Rectangle1&lt;/strong&gt; (&lt;u&gt;Summary&lt;/u&gt;: &lt;strong&gt;rectX&lt;/strong&gt; will always return positive integer never a negative one).&lt;/p&gt;&lt;/blockquote&gt;
&lt;h4&gt;Where to from here? &lt;/h4&gt;
&lt;p&gt;Don't be afraid, Silverlight 1.1 is basically alpha and all this shows is that with enough brain power a &lt;strong&gt;CursorManager Class&lt;/strong&gt; could be put together quite easily and managed code approach to using &lt;strong&gt;hitTest&lt;/strong&gt; logic could apply here. The overall walk-away point for all is that, Silverlight has a lot of powerful primitives in place, enough for anyone to build upwards from and create their own approach to Silverlight. Combining this effort with AJAX and one could get some interesting HTML/Silverlight offerings on the table.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3328091" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Flash/default.aspx">Flash</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/DHTML/default.aspx">DHTML</category></item><item><title>Some minor Silverlight assumptions/queries.</title><link>http://blogs.msdn.com/msmossyblog/archive/2007/06/08/some-minor-silverlight-assumptions-queries.aspx</link><pubDate>Fri, 08 Jun 2007 14:17:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3159931</guid><dc:creator>scbarnes</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/msmossyblog/comments/3159931.aspx</comments><wfw:commentRss>http://blogs.msdn.com/msmossyblog/commentrss.aspx?PostID=3159931</wfw:commentRss><wfw:comment>http://blogs.msdn.com/msmossyblog/rsscomments.aspx?PostID=3159931</wfw:comment><description>&lt;p&gt;It's been an interesting couple of days for me, as I've meet some developers in both business meeting setting and via social setting (aka &lt;a href="http://webjam.com.au/" target="_blank"&gt;WebJam&lt;/a&gt;).&lt;/p&gt; &lt;p&gt;In my chats with these developers, they all seem very keen to learn more about Silverlight but have hesitations on it that range from "Isn't it bleeding edge?" to "It looks good but I'm not a .NET developer".&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;strong&gt;I'm not a .NET developer, so I guess Silverlight isn't for me.&lt;/strong&gt;&lt;br&gt;Wrong, it can be, you can use Silverlight with HTML as if you would with Flash and HTML. Having zero .NET experience won't hamper you in anyway from building applications in future with Silverlight. You can do a lot with Silverlight today + HTML + AJAX. Microsoft wasn't kidding around with it being a natural progression from AJAX To the next step. You can control the entire Silverlight SDK from JavaScript (no .NET assembly required). So "&lt;em&gt;Silverlight bots, transform and roll out!&lt;/em&gt;"&lt;br&gt;&lt;/li&gt; &lt;li&gt;&lt;strong&gt;What does Silverlight do differently to Flash&lt;br&gt;&lt;/strong&gt;Lots, none and some. Wrong question, what does Silverlight do for you going forward and if you are a .NET developer it compliments your skill set (removing the need to learn new tooling &amp;amp; languages together. Expression Studio isn't that bad of an effort to be honest, as it took me 2 days of playing and I got it).&lt;br&gt;&lt;br&gt;If you are a budding Flash Developer and are looking for a reason to take it on as an extra piece to your portfolio, do so with that in mind. It's another hammer for your tool kit, another piece of clay to sculpt with and so on. It approaches things differently to Adobe Flash, but that is because the roadmap beyond its release has different visions of where RIA is likely to go thus Microsoft's approach. Rich Web, Rich Client &amp;amp; Rich Device is your mantra.&lt;br&gt;&lt;/li&gt; &lt;li&gt;&lt;strong&gt;How do I combine ASP.NET AJAX with Silverlight then?&lt;/strong&gt;&lt;br&gt;That's easy, you create a Project Solution in &lt;a href="http://go.microsoft.com/fwlink/?LinkID=89146&amp;amp;clcid=0x409" target="_blank"&gt;Visual Studio Orcas&lt;/a&gt;, you nominate &lt;a href="http://go.microsoft.com/fwlink/?LinkID=89147&amp;amp;clcid=0x409" target="_blank"&gt;ASP.NET Futures&lt;/a&gt;&amp;nbsp;(with &lt;a href="http://blogs.msdn.com/publicsector/archive/2007/06/07/new-asp-net-ajax-control-toolkit-version-released.aspx" target="_blank"&gt;AJAX Toolkit installed&lt;/a&gt;)&amp;nbsp;as your chosen template. You then create a Silverlight Project within the same solution.&lt;br&gt;&lt;br&gt;Now comes the really hard part.&lt;br&gt;&lt;br&gt;You then right click on the ASP.NET AJAX Futures project and hit the "Add Silverlight Link" to this project.&lt;br&gt;&lt;br&gt;Congratulations you've just linked the two projects together and every time you make changes to your Silverlight project, it will reflect into your ASP.NET AJAX Futures project. "Look mah, no hands".&lt;br&gt;&lt;/li&gt; &lt;li&gt;&lt;strong&gt;What would you tell me that's cool about Silverlight?&lt;/strong&gt;&lt;br&gt;Honestly, so far I've found (even after today) the Brush Fills to be the sexiest thing in this round of releases. I like it for it's simplicity and allow me to demonstrate&lt;/li&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Rectangle&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
	&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
		&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Image&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Source&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"myimage.jpg"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
	&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Rectangle.Fill&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Rectangle&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/ul&gt;
&lt;p&gt;I'll post more of these leading up to ReMIX as it amazes me some of the questions being asked (hey you don't know what you don't know, no harm, no foul) and if these are all that are stopping folks from having a go, then consider it greenlight time hehe.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3159931" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Flash/default.aspx">Flash</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Visual+Studio+2005/default.aspx">Visual Studio 2005</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Expression+Blend/default.aspx">Expression Blend</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/RIA/default.aspx">RIA</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/DHTML/default.aspx">DHTML</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Expression+Design/default.aspx">Expression Design</category></item><item><title>Going Flex to Silverlight: Understanding our DisplayList API.</title><link>http://blogs.msdn.com/msmossyblog/archive/2007/05/27/going-flex-to-silverlight-understanding-our-displaylist-api.aspx</link><pubDate>Sun, 27 May 2007 12:49:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2912920</guid><dc:creator>scbarnes</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/msmossyblog/comments/2912920.aspx</comments><wfw:commentRss>http://blogs.msdn.com/msmossyblog/commentrss.aspx?PostID=2912920</wfw:commentRss><wfw:comment>http://blogs.msdn.com/msmossyblog/rsscomments.aspx?PostID=2912920</wfw:comment><description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Disclaimer:&lt;/u&gt;&lt;/strong&gt; This is part two of my &lt;strong&gt;&lt;/strong&gt;&lt;a href="http://blogs.msdn.com/msmossyblog/archive/tags/Going+Flex+to+Silverlight/default.aspx" target="_blank"&gt;Going Flex to Silverlight series,&lt;/a&gt; where I'll be talking about how one is able to transfer concepts they have learnt in Flex world but are looking to explore what Silverlight also has to offer. Whatever reason they have chosen, is entirely up to them and this isn't to be taken as a feature for feature comparison.&lt;/p&gt; &lt;p&gt;In the Adobe Flex (ActionScript) to create a child element/object within the code base, you would punch out something like this:&lt;/p&gt; &lt;p&gt;&lt;pre&gt;	var txt:TextField = new TextField();
	txt.x = 100;
	txt.y = 0;
	txt.text = "Click for more info...";
	addChild(txt)
&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Which would then render &lt;strong&gt;MyButton&lt;/strong&gt; onto the &lt;strong&gt;DisplayObjectContainer&lt;/strong&gt; in question (provided it derives from a DisplayObject).&lt;/p&gt;
&lt;p&gt;Inside Silverlight, there is a similar approach but instead of just limiting to syntax code, one is able to piece together elements within elements through loading XAML at runtime. In that, you can access XAML pieces parked on your host, bring them in at runtime and instantiate them (children and all) through the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb412361.aspx" target="_blank"&gt;CreateFromXAML&lt;/a&gt;.&amp;nbsp; example:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;    // Retrieve a reference to the control.
    var control = sender.getHost();
    
    // Define a XAML fragment and create it.
    var xamlFragment = '&amp;lt;TextBlock Canvas.Top="200" Text="Click for more info..." /&amp;gt;&lt;textblock text="Click for more info..." canvas.top="100"&gt;';
    textBlock = control.content.createFromXaml(xamlFragment);

    // Add the XAML fragment as a child of the root Canvas object.
    sender.children.add(textBlock);

&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;As you can see, there are some similarities in approach, suffice to say that one is mode of approach. It's also important to note that you are also able to create child elements through managed code such as C# using Flex style syntax - which - can be found in both WPF and Silverlight. Yet, if you prefer JavaScript you can use the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb412363.aspx" target="_blank"&gt;CreateObject(type)&lt;/a&gt; approach, which is similar I guess to the Coldfusion approach to life as well (CreateObject is used to instantiate Coldfusion Classes inside managed code).&lt;/p&gt;
&lt;p&gt;Another cool feature within the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb412361.aspx" target="_blank"&gt;CreateFromXAML&lt;/a&gt; bag of tricks, is that you can also create XAML pieces loaded in via .ZIP files themselves similar to I guess Flex Modules API. This is done via &lt;a href="http://msdn2.microsoft.com/en-us/library/bb412362.aspx" target="_blank"&gt;CreateFromXamlDownloader Method&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;&lt;pre&gt;function onDownloadCompleted(sender, eventArgs)
{
    // Determine whether the download was successful.
    if (currentDownloadProgress != 1)
    {
    	alert("Failed to succesfully download zip file");
        return;
    }

    // Retrieve the XAML content from the downloaded package file.
    var jacketBrowserXaml = sender.getResponseText("jacketBrowser.xaml");

    // Create the objects from the XAML content.
    var jacketBrowser = control.content.createFromXaml(jacketBrowserXaml);

    // Add downloaded XAML content to the control.
    sender.findName("root").children.insert(0, jacketBrowser);

    // Retrieve a reference to the Image object representing the jacket.
    var jacketImageSlice = sender.findName("jacketSlice");

    // Set the Source property of the Image object to the specific jacket image
    // within the downloaded Zip package file.
    jacketImageSlice.setSource(sender, "rotation01_green.png");
}


&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://msdn2.microsoft.com/en-us/library/Bb412362.VisualTree_05(en-us,MSDN.10).png"&gt; &lt;/p&gt;
&lt;p&gt;The children collection there after has also all the typically Method calls made available for you then to find different elements by various means. Yet, if you are unsure of where an element exists within the XAML DOM itself but do remember it's name, one is able to then use the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb188297.aspx" target="_blank"&gt;FindName&lt;/a&gt; Method&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;function onLoaded(sender, eventArgs)
{
    // Retrieve a reference to the control.
    var control = sender.getHost();

    // Retrieve a reference to the specified object.
    var object = control.content.findName("myTextBlock");

    // If a valid object reference, display an alert dialog box.
    if (object != null)
    {
        alert(object.toString() + " found");
    }
}
&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is also the very similar to the way Flex does it inside &lt;strong&gt;Flash.display.DisplayObjectContainer's&lt;/strong&gt; in that it would allow something along the lines of:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;	var target:DisplayObject = container.getChildByName("myTextBlock"); 
	trace(container.getChildIndex(target)); // 0
&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This however would be done on the same node level as the actual Parent of the child. The &lt;a href="http://msdn2.microsoft.com/en-us/library/bb188297.aspx" target="_blank"&gt;FindName&lt;/a&gt; method however searches the entire Silverlight hierarchy for the element that have the name you provided.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Summary&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;There is a lot that Silverlight has on offer and when you dig deeper into what it has today, even in it's alpha state, there is a lot of goodness to be found. I'll continue to expose some of these gems going forward, and if you want me to discuss a topic of some kind, drop me an email on it. That being said, one thing I'd like you all to take away from this post is that the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb412362.aspx" target="_blank"&gt;CreateXAMLFromDownloader&lt;/a&gt; is a massive step forward if you ask me in terms of performance / architecture design &amp;amp; development for applications should they enter the Silverlight path post its release.&lt;/p&gt;
&lt;p&gt;More Info: &lt;a title="http://msdn2.microsoft.com/en-us/library/bb412361.aspx" href="http://msdn2.microsoft.com/en-us/library/bb412361.aspx"&gt;http://msdn2.microsoft.com/en-us/library/bb412361.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2912920" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Flex/default.aspx">Flex</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Flash/default.aspx">Flash</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Going+Flex+to+Silverlight/default.aspx">Going Flex to Silverlight</category></item><item><title>Silverlight + AJAX eh?</title><link>http://blogs.msdn.com/msmossyblog/archive/2007/04/26/silverlight-ajax-eh.aspx</link><pubDate>Wed, 25 Apr 2007 17:51:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2272882</guid><dc:creator>scbarnes</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/msmossyblog/comments/2272882.aspx</comments><wfw:commentRss>http://blogs.msdn.com/msmossyblog/commentrss.aspx?PostID=2272882</wfw:commentRss><wfw:comment>http://blogs.msdn.com/msmossyblog/rsscomments.aspx?PostID=2272882</wfw:comment><description>&lt;p&gt;&lt;a href="http://blog.jonudell.net/2007/04/24/rewriting-the-enriched-web/trackback/" target="_blank"&gt;John Udell&lt;/a&gt; has posted a few things around Silverlight, specifically the standout is around how you can use the &lt;a href="http://blog.jonudell.net/2007/04/24/rewriting-the-enriched-web/trackback/" target="_blank"&gt;XAML DOM within JavaScript&lt;/a&gt; much like you would with the HTML version. That's an excited thing to celebrate to those of you out there that are happy to play in the AJAX space (which seems to be a large portion). This now empowers you initially to combine your existing AJAX applications and Video in the one space using JavaScript.&lt;/p&gt; &lt;p&gt;This is pretty damn cool, as you're using your existing skill set in AJAX development, but having access to Silverlight's features with minimal effort, as most generally in this space have a pretty average (minimum) understanding of how to use things like "&lt;em&gt;getElementById()&lt;/em&gt;" to traverse the DOM. Silverlight in this scenario, is about extending AJAX experience using Video, that's pretty cool right?&lt;/p&gt; &lt;p&gt;Wonder what else we could do in this space? ;)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2272882" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://blogs.msdn.com/msmossyblog/archive/tags/JavaScript/default.aspx">JavaScript</category></item></channel></rss>