<?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 : XAML, Silverlight</title><link>http://www.dotnetmafia.com/blogs/kevin/archive/tags/XAML/Silverlight/default.aspx</link><description>Tags: XAML, Silverlight</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><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>