<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.dotnetmafia.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>Kevin Williams .NET and Stuff : Silverlight</title><link>http://www.dotnetmafia.com/blogs/kevin/archive/tags/Silverlight/default.aspx</link><description>Tags: Silverlight</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Streaming Video - Silverlight, Sitecore, and Windows Media Services</title><link>http://www.dotnetmafia.com/blogs/kevin/archive/2010/03/04/streaming-video-silverlight-sitecore-and-windows-media-services.aspx</link><pubDate>Thu, 04 Mar 2010 23:51:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:2912</guid><dc:creator>Kevin</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;For quite a while now, I’ve been wanting a simple video streaming solution that I could recommend to clients for whom progressive video downloads won’t cut it and who don’t want to pay to use a CDN like Edgecast or UVault or Limelight.  Clients who don’t need to serve a ton of video on their site, and would be able to host it themselves if it were easy and integrated with their WebCMS.&lt;/p&gt;&lt;p&gt;I’ve started working on just such a solution.  Right now, I’m using &lt;a href="http://www.microsoft.com/windows/windowsmedia/forpros/serve/prodinfo2008.aspx"&gt;Windows Media Services 2008&lt;/a&gt; (an optional component of Windows 2008 Server - Standard and Enterprise editions) to host and stream the videos, Sitecore to manage uploading and publishing of new videos and related content, and a Silverlight video player I found called &lt;a href="http://www.silverlight-blog.it/ontheroad/videoplayer/"&gt;Minoplayer&lt;/a&gt;.  This requires that videos be encoded to WMV format, but I’m already thinking about ways to support Flash video for people who don’t want to use Silverlight (lighttpd’s mod_flv_streaming module looks promising).  And of course, HTML5’s &amp;lt;video&amp;gt; element looks interesting too (although codec support problems may make it more difficult to implement).&lt;/p&gt;&lt;p&gt;You can see an early example of the end result of my work here - &lt;a href="http://www.kevinwilliams.name:8001/Kologarn.aspx"&gt;http://www.kevinwilliams.name:8001/Kologarn.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;(be kind to my server - I’m asking a lot from it running Sitecore, SQL Server, Media Services, and a bunch of other stuff on crappy old hardware)&lt;/p&gt;&lt;p&gt;I will post details of my Media Services installation and configuration experience, some information about the Sitecore solution, etc in the next few days.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=2912" width="1" height="1"&gt;</description><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Sitecore/default.aspx">Sitecore</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Windows+Media+Services/default.aspx">Windows Media Services</category></item><item><title>Using WebService Data With Silverlight</title><link>http://www.dotnetmafia.com/blogs/kevin/archive/2008/03/23/using-webservice-data-with-silverlight.aspx</link><pubDate>Mon, 24 Mar 2008 04:58:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:541</guid><dc:creator>Kevin</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Now, I want to do something a bit more dynamic.&amp;nbsp; How about we call a web service, get some dynamic data back, and render something based on that data?&amp;nbsp; In this post, I will build a simple example in order to clearly illustrate the concepts.&amp;nbsp; But at the end, I will post an example of something a bit more useful to show what can be done!&lt;/p&gt;
&lt;p&gt;First off, let&amp;#39;s define a simple web service.&amp;nbsp; I used VS2008&amp;#39;s New Item wizard and selected &amp;quot;Web Service&amp;quot; from the dialog.&amp;nbsp; Then, I replaced HelloWorld() with my own GetData() method.&amp;nbsp; Here&amp;#39;s what the code behind for MyService.asmx looks like:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;[&lt;span style="COLOR:#2b91af;"&gt;WebService&lt;/span&gt;(Namespace = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;http://tempuri.org/&amp;quot;&lt;/span&gt;)]&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;[&lt;span style="COLOR:#2b91af;"&gt;WebServiceBinding&lt;/span&gt;(ConformsTo = &lt;span style="COLOR:#2b91af;"&gt;WsiProfiles&lt;/span&gt;.BasicProfile1_1)]&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;[&lt;span style="COLOR:#2b91af;"&gt;ToolboxItem&lt;/span&gt;(&lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;)]&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:green;"&gt;// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;[System.Web.Script.Services.&lt;span style="COLOR:#2b91af;"&gt;ScriptService&lt;/span&gt;]&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;class&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;MyService&lt;/span&gt; : System.Web.Services.&lt;span style="COLOR:#2b91af;"&gt;WebService&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR:#2b91af;"&gt;WebMethod&lt;/span&gt;]&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR:#2b91af;"&gt;ScriptMethod&lt;/span&gt;]&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;[] GetData()&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;[] data = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt;[] { &lt;span style="COLOR:#a31515;"&gt;&amp;quot;first data&amp;quot;&lt;/span&gt;, &lt;span style="COLOR:#a31515;"&gt;&amp;quot;second data&amp;quot;&lt;/span&gt;, &lt;span style="COLOR:#a31515;"&gt;&amp;quot;third data&amp;quot;&lt;/span&gt; };&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;return&lt;/span&gt; data;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;}&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Note I also have uncommented the ScriptService attribute on my class and added a ScriptMethod attribute to my method.&amp;nbsp; Calling web services from Javascript is a whole lot easier using ASP.NET AJAX.&amp;nbsp; You&amp;#39;ll need to have the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6&amp;amp;displaylang=en" target="_blank"&gt;ASP.NET AJAX 1.0 Extensions&lt;/a&gt; installed for this to work, but it&amp;#39;s worth it.&amp;nbsp; Oh, I&amp;#39;m also using the new array initialization syntax from C# 3.0 in case you&amp;#39;ve never seen it before.&amp;nbsp; A real world application would probably query a database or something.&lt;/p&gt;
&lt;p&gt;In order to call the web service from Javascript, ASP.NET AJAX requires us to place a ScriptManager on the page with a ServiceReference pointing to the .asmx.&amp;nbsp; Here&amp;#39;s what mine looks like:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;ScriptManager&lt;/span&gt; &lt;span style="COLOR:red;"&gt;ID&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;ScriptManager1&amp;quot;&lt;/span&gt; &lt;span style="COLOR:red;"&gt;runat&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;server&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Services&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;ServiceReference&lt;/span&gt; &lt;span style="COLOR:red;"&gt;Path&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;~/MyService.asmx&amp;quot;&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Services&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;ScriptManager&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Thankfully, VS2008&amp;#39;s web application project template already set up my web.config to use ASP.NET AJAX.&amp;nbsp; If you are not using VS2008, you may need to follow the directions at &lt;a href="http://asp.net/AJAX/Documentation/Live/ConfiguringASPNETAJAX.aspx" target="_blank"&gt;http://asp.net/AJAX/Documentation/Live/ConfiguringASPNETAJAX.aspx&lt;/a&gt; to ensure your web.config is set up properly.&lt;/p&gt;
&lt;p&gt;At this point, I can call my web service from Javascript and react to whatever data comes back.&amp;nbsp; The question is - what should it do?&amp;nbsp; For this post, I think I&amp;#39;ll just put up a Silverlight TextBlock and rotate through the web service data when the user clicks on the text.&amp;nbsp; Here&amp;#39;s the XAML:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Canvas&lt;/span&gt;&lt;span style="COLOR:red;"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/client/2007&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:red;"&gt;x&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;TextBlock&lt;/span&gt;&lt;span style="COLOR:red;"&gt; x&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:red;"&gt;Name&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;MyTextBlock&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; FontSize&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; FontFamily&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;Arial&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Top&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Left&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Loaded&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;MyTextBlockLoaded&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; MouseLeftButtonDown&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;MyTextBlockClick&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Canvas&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;First, I will retrieve the data from the web service once the text block has loaded by using the Loaded event.&amp;nbsp; Let me show you the Javascript and then I will explain it...&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;var&lt;/span&gt; index;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;var&lt;/span&gt; data;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;function&lt;/span&gt; MyTextBlockLoaded( sender, args )&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyService.GetData( GetDataSuccess, GetDataFailed );&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;}&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;function&lt;/span&gt; GetDataSuccess( result )&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data = result;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; index = 0;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UpdateTextBlock();&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;}&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;function&lt;/span&gt; GetDataFailed()&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert( &lt;span style="COLOR:#a31515;"&gt;&amp;#39;Call to MyService.GetData() failed!&amp;#39;&lt;/span&gt; );&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;}&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;function&lt;/span&gt; UpdateTextBlock()&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;var&lt;/span&gt; textblock = document.getElementById( &lt;span style="COLOR:#a31515;"&gt;&amp;#39;&amp;lt;%= Silverlight1.ControlId %&amp;gt;&amp;#39;&lt;/span&gt; ).content.findName( &lt;span style="COLOR:#a31515;"&gt;&amp;#39;MyTextBlock&amp;#39;&lt;/span&gt; );&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; textblock.Text = data[index];&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;}&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;First I declare a variable to hold the current index into the data array and a variable to hold the data itself.&amp;nbsp; The implementation of the MyTextBlockLoaded() event handler is calling the web service using the proxy built by ASP.NET AJAX.&amp;nbsp; Note that because this is an asynchronous call, you have to pass in event handlers for both success and failure - that is where my GetDataSuccess() and GetDataFailed() functions come from.&amp;nbsp; On success, I store the data, set the initial index to 0, and call the function to set the text in the TextBlock.&amp;nbsp; Note I&amp;#39;m using document.getElementById() to find the Silverlight viewer.&amp;nbsp; I&amp;#39;m using some inline server-side script to get the Id of the Silverlight viewer from my control (covered in a previous post) to pass to getElementById().&amp;nbsp; The viewer object has a content property upon which I can call findName() (also covered in a previous blog post) to get a reference to the TextBlock.&lt;/p&gt;
&lt;p&gt;The last thing to do is handle the MouseLeftButtonDown event on the TextBlock so that the text changes when the user clicks on it.&amp;nbsp; Here&amp;#39;s that Javascript function:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;function&lt;/span&gt; MyTextBlockClick( sender, args )&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; ( index &amp;gt;= data.length-1 )&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index = 0;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;else&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index = index + 1;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UpdateTextBlock();&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;}&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Here, I increment the index and when the index reaches the end of the list, I reset it to 0 to go back to the beginning.&amp;nbsp; Then I call UpdateTextBlock() to display the new text.&lt;/p&gt;
&lt;p&gt;You can see this example in action at &lt;a href="http://www.killeverything.com/zak/Silverlight1/WebService1.aspx" target="_blank"&gt;http://www.killeverything.com/zak/Silverlight1/WebService1.aspx&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;At the beginning of this post, I promised to show a more useful example.&amp;nbsp; How about a Silverlight app that displays headlines from an RSS feed and lets you click through to the articles?&amp;nbsp; If you&amp;#39;ve been reading my Silverlight posts, there shouldn&amp;#39;t be anything too new going on here.&amp;nbsp; I have just combined several of the concepts I&amp;#39;ve been learning and blogging about into a single Silverlight app.&amp;nbsp; You can see it running here: &lt;a href="http://www.killeverything.com/zak/Silverlight1/WebService2.aspx" target="_blank"&gt;http://www.killeverything.com/zak/Silverlight1/WebService2.aspx&lt;/a&gt; and the code for both the simple example and the RSS headline viewer are attached to this post.&amp;nbsp; If you&amp;#39;re a .NET head, you might want to look at the source for the web service where I used LINQ to XML to make parsing the RSS feed easy as cake.&amp;nbsp; Oh, and I want to point out the clipping I had to add to the TextBlock.&amp;nbsp; Support for MaxHeight and MaxWidth may be coming in Silverlight 2.0, but clipping is how it&amp;#39;s done for now...&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=541" width="1" height="1"&gt;</description><enclosure url="http://www.dotnetmafia.com/blogs/kevin/attachment/541.ashx" length="32579" type="application/x-zip-compressed" /><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Web+Services/default.aspx">Web Services</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/LINQ+to+XML/default.aspx">LINQ to XML</category></item><item><title>My Silverlight Control</title><link>http://www.dotnetmafia.com/blogs/kevin/archive/2008/03/23/my-silverlight-control.aspx</link><pubDate>Sun, 23 Mar 2008 17:00:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:540</guid><dc:creator>Kevin</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Putting a Silverlight viewer on a web page is a lot of work.&amp;nbsp; You have to import the Silverlight.js file (and make sure it&amp;#39;s deployed to the web server), create a div to contain the viewer, and write some Javascript code to call Silverlight.createObject().&amp;nbsp; To me, this is just begging for an ASP.NET control - so I whipped up one of my own.&lt;/p&gt;
&lt;p&gt;So what do I want my control to do for me?&amp;nbsp; Let&amp;#39;s start at the top with the Silverlight.js file.&amp;nbsp; I want this to be an embedded resource so that I don&amp;#39;t always have to remember to copy it in to a new project.&amp;nbsp; If you&amp;#39;re not familiar with this technique, it&amp;#39;s been around since .NET 2.0 - keep up! :)&amp;nbsp; You just throw the Silverlight.js file into your project and set it&amp;#39;s build action to &amp;quot;Embedded Resource&amp;quot;.&amp;nbsp; Here&amp;#39;s a screenshot:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.killeverything.com/zak/blogimages/MySilverlightControl_A8A6/image.png"&gt;&lt;img style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" height="225" alt="image" src="http://www.killeverything.com/zak/blogimages/MySilverlightControl_A8A6/image_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Add it to your project&amp;#39;s AssemblyInfo.cs like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:green;"&gt;// Embeded Resources&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;[&lt;span style="COLOR:blue;"&gt;assembly&lt;/span&gt;: System.Web.UI.&lt;span style="COLOR:#2b91af;"&gt;WebResource&lt;/span&gt;(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;knw.Silverlight.Silverlight.js&amp;quot;&lt;/span&gt;, &lt;span style="COLOR:#a31515;"&gt;&amp;quot;application/x-javascript&amp;quot;&lt;/span&gt;)]&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Then my control&amp;#39;s code tells the page where to find it like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;Page.ClientScript.RegisterClientScriptInclude(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;Silverlight.js&amp;quot;&lt;/span&gt;, Page.ClientScript.GetWebResourceUrl(&lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.GetType(), &lt;span style="COLOR:#a31515;"&gt;&amp;quot;knw.Silverlight.Silverlight.js&amp;quot;&lt;/span&gt;));&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://www.codeproject.com/KB/aspnet/MyWebResourceProj.aspx" target="_blank"&gt;Here&lt;/a&gt; is a link to an article on Code Project that explains the technique in a bit more detail.&lt;/p&gt;
&lt;p&gt;Next, I want my control to render the container div for the Silverlight viewer.&amp;nbsp; This is pretty straightforward - I just override Render() and use the HtmlTextWriter that&amp;#39;s passed in.&amp;nbsp; Here&amp;#39;s what it looks like:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;protected&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;override&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;void&lt;/span&gt; Render(&lt;span style="COLOR:#2b91af;"&gt;HtmlTextWriter&lt;/span&gt; writer)&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;base&lt;/span&gt;.Render(writer);&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.AddAttribute(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;, ID + &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Div&amp;quot;&lt;/span&gt;);&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.RenderBeginTag(&lt;span style="COLOR:#2b91af;"&gt;HtmlTextWriterTag&lt;/span&gt;.Div);&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.RenderEndTag();&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;}&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Note I&amp;#39;m just concatenating &amp;quot;Div&amp;quot; onto the existing ID of my control when building the div&amp;#39;s id, but that should make it unique.&lt;/p&gt;
&lt;p&gt;The only thing that&amp;#39;s left is the call to Silverlight.createObject().&amp;nbsp; There are a few variables in this call that I thought could be exposed as properties of my control.&amp;nbsp; Specifically, the path to the Xaml document, the height and width of the viewer, and the background color.&amp;nbsp; I&amp;#39;m using C# 3.0, so I took advantage of another language feature - automatic properties.&amp;nbsp; Here&amp;#39;s what that code looks like:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; Xaml { &lt;span style="COLOR:blue;"&gt;get&lt;/span&gt;; &lt;span style="COLOR:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; Height { &lt;span style="COLOR:blue;"&gt;get&lt;/span&gt;; &lt;span style="COLOR:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;int&lt;/span&gt; Width { &lt;span style="COLOR:blue;"&gt;get&lt;/span&gt;; &lt;span style="COLOR:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Color&lt;/span&gt; BackgroundColor { &lt;span style="COLOR:blue;"&gt;get&lt;/span&gt;; &lt;span style="COLOR:blue;"&gt;set&lt;/span&gt;; }&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Lastly, I need to build the actual javascript to create the Silverlight viewer and register it with the page to run as a startup script.&amp;nbsp; Like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;string&lt;/span&gt; createObjectScript = &lt;span style="COLOR:blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;&amp;lt;script&amp;gt;Silverlight.createObject( \&amp;quot;{0}\&amp;quot;, document.getElementById( \&amp;quot;{1}Div\&amp;quot; ), \&amp;quot;{2}Ctrl\&amp;quot;, {{ width:&amp;#39;{3}&amp;#39;, height:&amp;#39;{4}&amp;#39;, inplaceInstallPrompt:false,background:&amp;#39;{5}&amp;#39;, isWindowless:&amp;#39;false&amp;#39;, framerate:&amp;#39;24&amp;#39;, version:&amp;#39;1.0&amp;#39; }},{{ onError:null,onLoad:null }},null );&amp;lt;/script&amp;gt;&amp;quot;&lt;/span&gt;, Xaml, ID, ID, Width, Height, &lt;span style="COLOR:#2b91af;"&gt;ColorTranslator&lt;/span&gt;.ToHtml(BackgroundColor) );&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;Page.ClientScript.RegisterStartupScript( &lt;span style="COLOR:blue;"&gt;this&lt;/span&gt;.GetType(), ID + &lt;span style="COLOR:#a31515;"&gt;&amp;quot;Create&amp;quot;&lt;/span&gt;, createObjectScript );&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;At first glance, that code looks pretty confusing.&amp;nbsp; All it&amp;#39;s actually doing is using string.Format() to build the call to Silverlight.createObject().&amp;nbsp; {0} is the path to the Xaml, {1} is the ID of the control + &amp;quot;Div&amp;quot; (the id of container div), {2} is the ID of the control + &amp;quot;Ctrl&amp;quot; (a unique id for the viewer itself), {3} is the width, {4} is the height, and {5} is the background color (converted from a System.Drawing.Color using the System.Drawing.ColorTranslator class).&amp;nbsp; Oh yeah, and you have to escape curly braces when using string.Format() by doubling them.&lt;/p&gt;
&lt;p&gt;Ok, that was a lot of work - what has it bought me?&amp;nbsp; Well, now when I want to use Silverlight on an .aspx page, all I have to do is add a reference to my DLL, register it at the top of the .aspx page, and put the control on the .aspx page somewhere.&amp;nbsp; Which looks like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;knw&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Silverlight&lt;/span&gt; &lt;span style="COLOR:red;"&gt;id&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;Silverlight1&amp;quot;&lt;/span&gt; &lt;span style="COLOR:red;"&gt;runat&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="COLOR:red;"&gt;Xaml&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;MySilverlight.xaml&amp;quot;&lt;/span&gt; &lt;span style="COLOR:red;"&gt;BackgroundColor&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;Gray&amp;quot;&lt;/span&gt; &lt;span style="COLOR:red;"&gt;Height&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt; &lt;span style="COLOR:red;"&gt;Width&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;I will attach the code for both the control and an example of using it to this post.&amp;nbsp; I&amp;#39;ll be using this control in future Silverlight posts here - plus, I do intend to extend it to do more in the future (as I learn more about Silverlight).&amp;nbsp; So, I&amp;#39;ll try to post updates here from time to time.&amp;nbsp; I hope it&amp;#39;s useful to someone! :)&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=540" width="1" height="1"&gt;</description><enclosure url="http://www.dotnetmafia.com/blogs/kevin/attachment/540.ashx" length="13373" type="application/x-zip-compressed" /><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Silverlight - Simple Animation</title><link>http://www.dotnetmafia.com/blogs/kevin/archive/2008/03/23/silverlight-simple-animation.aspx</link><pubDate>Sun, 23 Mar 2008 07:12:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:539</guid><dc:creator>Kevin</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Seems I&amp;#39;ve fallen way behind on my Silverlight blogging as of late.&amp;nbsp; A few weeks ago, I managed to get some simple animation working.&amp;nbsp; So, I guess I should blog about it.&lt;/p&gt;
&lt;p&gt;Animation is done by transforming your object.&amp;nbsp; Each graphic element has a RenderTransform property to which you can assign a Transform object to modify your element in some way.&amp;nbsp; The different types of Transform objects include RotateTransform, SkewTransform, ScaleTransform, and TranslateTransform.&amp;nbsp; Let&amp;#39;s look at an example.&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse&lt;/span&gt;&lt;span style="COLOR:red;"&gt; MouseLeftButtonDown&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;EllipseClick&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Height&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Width&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Top&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Left&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Fill&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;Black&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse.RenderTransform&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;RotateTransform&lt;/span&gt;&lt;span style="COLOR:red;"&gt; x&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:red;"&gt;Name&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;EllipseXForm&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Angle&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;90&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse.RenderTransform&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;This example is pretty boring - it just renders a 50 pixel high and 100 pixel wide ellipse, rotated 90 degrees (so that it instead appears 100 pixels high and 50 pixels wide).&amp;nbsp; However, it illustrates the effect that a RotateTransform will have on an object.&amp;nbsp; Also note that I have named the transform (the x:Name attribute).&amp;nbsp; The purpose of that will soon become apparent.&lt;/p&gt;
&lt;p&gt;Animations are defined within objects called Storyboards.&amp;nbsp; Basically, a Storyboard defines a timeline of changes that should occur to properties of objects.&amp;nbsp; For my example, I want to change the Angle property of the RotateTransform object over time (so that the Ellipse rotates slowly as we watch).&amp;nbsp; Here is the Storyboard I have defined:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Canvas.Resources&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Storyboard&lt;/span&gt;&lt;span style="COLOR:red;"&gt; x&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:red;"&gt;Name&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;EllipseStoryboard&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;DoubleAnimation&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Storyboard.TargetName&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;EllipseXForm&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Storyboard.TargetProperty&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;Angle&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; To&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Duration&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;00:00:05&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Storyboard&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Canvas.Resources&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;For this example, I have used a DoubleAnimation.&amp;nbsp; This is because the property I want to change (&amp;quot;Angle&amp;quot;) is of type double.&amp;nbsp; There are many other animation objects available such as DecimalAnimation, Int32Animation, and ColorAnimation.&amp;nbsp; The Storyboard.Targetname attribute tells the animation which object it is changing (here&amp;#39;s where I use the name I gave my transform earlier) and Storyboard.TargetProperty indicates what property will be changed.&amp;nbsp; The To attribute is the value the animation should end with and the Duration should be self-explanatory.&amp;nbsp; Note again, I have named my Storyboard so that I can reference it later.&amp;nbsp; Oh yeah, and the Storyboard is a resource, so it&amp;#39;s defined inside the &amp;lt;Canvas.Resources /&amp;gt; element.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m going to need something to trigger the animation to begin.&amp;nbsp; I&amp;#39;ve chosen to do it using a mouse click on the ellipse.&amp;nbsp; So, I will need to add a MouseLeftButtonDown handler to the Ellipse.&amp;nbsp; Now it looks like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse&lt;/span&gt;&lt;span style="COLOR:red;"&gt; MouseLeftButtonDown&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;EllipseClick&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Height&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Width&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Top&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Left&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Fill&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;Black&amp;quot;&amp;gt;...&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;And I need an EllipseClick() function defined in Javascript, so here&amp;#39;s what I came up with:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;script&lt;/span&gt; &lt;span style="COLOR:red;"&gt;type&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;function&lt;/span&gt; EllipseClick( sender, args )&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sender.findName(&lt;span style="COLOR:#a31515;"&gt;&amp;quot;EllipseStoryboard&amp;quot;&lt;/span&gt;).Begin();&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;script&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;I placed this directly in my .aspx file for this example.&amp;nbsp; I don&amp;#39;t think I&amp;#39;ve blogged about findName() before, but Silverlight elements define this method and it allows you to get a reference to any other Silverlight element by name.&amp;nbsp; Here, I am using it to get the &amp;quot;EllipseStoryboard&amp;quot; Storyboard and executing it&amp;#39;s Begin() method.&lt;/p&gt;
&lt;p&gt;You can see this example in action at &lt;a href="http://www.killeverything.com/zak/Silverlight1/EllipseRotate1.aspx" target="_blank"&gt;http://www.killeverything.com/zak/Silverlight1/EllipseRotate1.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s not quite what I wanted, though.&amp;nbsp; The rotation is happening around the top left corner of the ellipse instead of the center.&amp;nbsp; Luckily, this was easy to fix - the RotateTransform has CenterX and CenterY properties that allow you to define the point around which the object rotates.&amp;nbsp; Knowing that the ellipse is 100 wide and 50 tall, this is what I changed the transform to look like:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;RotateTransform&lt;/span&gt;&lt;span style="COLOR:red;"&gt; x&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:red;"&gt;Name&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;EllipseXForm&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Angle&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;90&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; CenterX&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; CenterY&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;25&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;You can see the finished example at &lt;a href="http://www.killeverything.com/zak/Silverlight1/EllipseRotate2.aspx" target="_blank"&gt;http://www.killeverything.com/zak/Silverlight1/EllipseRotate2.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve also attached a ZIP with the files needed for these examples in case you want to play with them yourself.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=539" width="1" height="1"&gt;</description><enclosure url="http://www.dotnetmafia.com/blogs/kevin/attachment/539.ashx" length="5654" type="application/x-zip-compressed" /><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/XAML/default.aspx">XAML</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight Day 2</title><link>http://www.dotnetmafia.com/blogs/kevin/archive/2008/02/22/silverlight-day-2.aspx</link><pubDate>Sat, 23 Feb 2008 02:53:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:515</guid><dc:creator>Kevin</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/kevin/rsscomments.aspx?PostID=515</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/kevin/archive/2008/02/22/silverlight-day-2.aspx#comments</comments><description>&lt;p&gt;Today&amp;#39;s goal is to display an image and react to a mouse click in some way.&amp;nbsp; I actually started by reading the QuickStart that gets installed along with the Silverlight SDK.&amp;nbsp; You can also find it at &lt;a title="http://silverlight.net/quickstarts/silverlight10/default.aspx" href="http://silverlight.net/quickstarts/silverlight10/default.aspx"&gt;http://silverlight.net/quickstarts/silverlight10/default.aspx&lt;/a&gt; if you still don&amp;#39;t have the SDK installed (and why don&amp;#39;t you?&amp;nbsp; Huh?)&lt;/p&gt;
&lt;p&gt;It looks like all I need to display an image is an object set to fill with an ImageBrush.&amp;nbsp; Something like this should work:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Height&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Width&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;200&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Top&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Left&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;10&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse.Fill&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;ImageBrush&lt;/span&gt;&lt;span style="COLOR:red;"&gt; ImageSource&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;lolcat_quadcore.jpg&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse.Fill&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Ellipse&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Bingo, that did the trick.&amp;nbsp; It looks like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.killeverything.com/zak/blogimages/SilverlightDay2_125AC/image.png"&gt;&lt;img height="116" alt="lolcat ellipse" src="http://www.killeverything.com/zak/blogimages/SilverlightDay2_125AC/image_thumb.png" width="216" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Oh wait, I just found the Image object - no brush needed if you do it like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Image&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Source&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;lolcat_quadcore.jpg&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Top&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;120&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Left&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Height&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;100&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Which looks like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.killeverything.com/zak/blogimages/SilverlightDay2_125AC/image_3.png"&gt;&lt;img style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" height="113" alt="lolcat image" src="http://www.killeverything.com/zak/blogimages/SilverlightDay2_125AC/image_thumb_3.png" width="137" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Note that in the first case, the image was automatically stretched to fit the dimensions of the ellipse and in the second, I only specified a height - so the image was automatically scaled proportionally.&amp;nbsp; Cool!&lt;/p&gt;
&lt;p&gt;Now, processing mouse clicks.&amp;nbsp; This appears to be amazingly easy as well.&amp;nbsp; First, you need to declare the event handler in the XAML mark-up like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Image&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Source&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;lolcat_quadcore.jpg&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Top&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;120&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Left&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Height&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; MouseLeftButtonDown&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;ChangeLolcat&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Then you just need a javascript function to handle the event - mine looks like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:courier new;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;function&lt;/span&gt; ChangeLolcat( sender, args )&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;if&lt;/span&gt; ( sender.Source == &lt;span style="COLOR:#a31515;"&gt;&amp;quot;lolcat_quadcore.jpg&amp;quot;&lt;/span&gt; )&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sender.Source = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;lolcat_schroedinger.jpg&amp;quot;&lt;/span&gt;;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;else&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sender.Source = &lt;span style="COLOR:#a31515;"&gt;&amp;quot;lolcat_quadcore.jpg&amp;quot;&lt;/span&gt;;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;}&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;In this case, because the MouseLeftButtonDown event is on the Image object, that&amp;#39;s the object that gets passed in to the javascript function as &amp;quot;sender&amp;quot;.&amp;nbsp; I am simply changing the Source property from how it was defined in the XAML in response to the mouse click.&amp;nbsp; And it works! (sorry I can&amp;#39;t show you - I don&amp;#39;t have a good place to host .NET code at the moment)&amp;nbsp; I think I&amp;#39;m going to like working with Silverlight.&lt;/p&gt;
&lt;p&gt;In case you want to download the code for this project and try it out yourself, I will ZIP it up and attach it to this blog post.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=515" width="1" height="1"&gt;</description><enclosure url="http://www.dotnetmafia.com/blogs/kevin/attachment/515.ashx" length="93593" type="application/x-zip-compressed" /><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/XAML/default.aspx">XAML</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/lolcats/default.aspx">lolcats</category></item><item><title>Silverlight Day 1</title><link>http://www.dotnetmafia.com/blogs/kevin/archive/2008/02/20/silverlight-day-1.aspx</link><pubDate>Thu, 21 Feb 2008 01:16:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:506</guid><dc:creator>Kevin</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/kevin/rsscomments.aspx?PostID=506</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/kevin/archive/2008/02/20/silverlight-day-1.aspx#comments</comments><description>&lt;p&gt;So I finally set out to do something with Silverlight... I set a simple goal for myself tonight - I just wanted to see &amp;quot;Hello World&amp;quot;.&amp;nbsp; That should be easy, right?&lt;/p&gt;
&lt;p&gt;First, I downloaded the Silverlight 1.0 SDK from &lt;a href="http://www.microsoft.com/silverlight"&gt;http://www.microsoft.com/silverlight&lt;/a&gt;&amp;nbsp;and installed it.&lt;/p&gt;
&lt;p&gt;Second, I created a new web site in Visual Studio.&lt;/p&gt;
&lt;p&gt;Third, I grabbed a copy of Silverlight.js and added it to the web site.&amp;nbsp; For me, it was in C:\Program Files\Microsoft Silverlight 1.0 SDK\Tools\Silverlight.js.&lt;/p&gt;
&lt;p&gt;I added a link to Silverlight.js in the HTML head of default.aspx.&amp;nbsp; Like this:&lt;/p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:Courier New;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;script&lt;/span&gt; &lt;span style="COLOR:red;"&gt;type&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span style="COLOR:red;"&gt;src&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;Silverlight.js&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;script&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Next, I added a div in the HTML body of default.aspx and gave it an id.&amp;nbsp; It doesn&amp;#39;t need the runat=server attribute, just an id (it will only be reference from Javascript).&amp;nbsp; Like this:&lt;/p&gt;
&lt;p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:Courier New;"&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;div&lt;/span&gt; &lt;span style="COLOR:red;"&gt;id&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;MySilverlightDiv&amp;quot;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;div&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, I created a XAML file.&amp;nbsp; I know next to nothing about XAML yet, so I just used Google to &amp;quot;borrow&amp;quot; someone else&amp;#39;s example code for now.&amp;nbsp; My XAML file is called MySilverlight.xaml and looks like this:&lt;/p&gt;
&lt;p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:Courier New;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Canvas&lt;/span&gt;&lt;span style="COLOR:red;"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/client/2007&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:red;"&gt;x&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;TextBlock&lt;/span&gt;&lt;span style="COLOR:red;"&gt; FontSize&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;40&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; FontFamily&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;Arial&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Top&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;20&amp;quot;&lt;/span&gt;&lt;span style="COLOR:red;"&gt; Canvas.Left&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;20&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Hello World!&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:#a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;TextBlock&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Canvas&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Last thing I did was add the javascript to my HTML file to actually create the Silverlight object in my div:&lt;/p&gt;
&lt;p&gt;
&lt;div style="FONT-SIZE:10pt;BACKGROUND:white;COLOR:black;FONT-FAMILY:Courier New;"&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;script&lt;/span&gt; &lt;span style="COLOR:red;"&gt;type&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Silverlight.createObject(&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#a31515;"&gt;&amp;quot;MySilverlight.xaml&amp;quot;&lt;/span&gt;, &lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; document.getElementById( &lt;span style="COLOR:#a31515;"&gt;&amp;quot;MySilverlightDiv&amp;quot;&lt;/span&gt;),&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:#a31515;"&gt;&amp;quot;MySilverlightControl&amp;quot;&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { width:&lt;span style="COLOR:#a31515;"&gt;&amp;#39;400&amp;#39;&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; height:&lt;span style="COLOR:#a31515;"&gt;&amp;#39;200&amp;#39;&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; inplaceInstallPrompt:&lt;span style="COLOR:blue;"&gt;false&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; background:&lt;span style="COLOR:#a31515;"&gt;&amp;#39;#DDDDDD&amp;#39;&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; isWindowless:&lt;span style="COLOR:#a31515;"&gt;&amp;#39;false&amp;#39;&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; framerate:&lt;span style="COLOR:#a31515;"&gt;&amp;#39;24&amp;#39;&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; version:&lt;span style="COLOR:#a31515;"&gt;&amp;#39;1.0&amp;#39;&lt;/span&gt; },&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { onError:&lt;span style="COLOR:blue;"&gt;null&lt;/span&gt;,&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; onLoad:&lt;span style="COLOR:blue;"&gt;null&lt;/span&gt; },&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;null&lt;/span&gt; );&lt;/p&gt;
&lt;p style="MARGIN:0px;"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;script&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;That&amp;#39;s the filename of my XAML file, the Id of my div, a unique&amp;nbsp;Id for the Silverlight control itself, and some various parameters for Silverlight that I do not yet fully understand.&lt;/p&gt;
&lt;p&gt;That&amp;#39;s it.&amp;nbsp; I hit my web site with a browser and there was my awesome Hello World!&lt;/p&gt;
&lt;p&gt;Hopefully tomorrow I will have time to research XAML some more and do something a bit more interesting with Silverlight.&amp;nbsp; I hope to extend this simple starter project and continue writing about it here, so if you&amp;#39;re interested - copy/paste the code above and come back tomorrow! :)&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=506" width="1" height="1"&gt;</description><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/XAML/default.aspx">XAML</category><category domain="http://www.dotnetmafia.com/blogs/kevin/archive/tags/Silverlight/default.aspx">Silverlight</category></item></channel></rss>