<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>SilverLight</title>
        <link>http://www.nimblecoder.com/blog/category/21.aspx</link>
        <description>SilverLight</description>
        <language>en-US</language>
        <copyright>Ryan Van Slooten</copyright>
        <generator>Subtext Version 2.1.1.1</generator>
        <item>
            <title>Animated Clocks for SVG and Silverlight</title>
            <link>http://nimblecoder.com/blog/archive/2009/12/30/animated-clocks-for-svg-and-silverlight.aspx</link>
            <description>&lt;p&gt;At one point in time I found a cool clock graphic and I was looking for it again because it gave a fairly detailed explanation on making a nice looking vector based clock (it was the Codeproject article by &lt;a href="http://www.codeproject.com/KB/dotnet/vgclock.aspx"&gt;Marc Clifton&lt;/a&gt;). During my search I found numerous implementations of both SVG and Silverlight clocks and I decided to catalog my findings.&lt;/p&gt;  &lt;p&gt;The animated clocks are not necessarily practical to display on web pages, but an interesting exercise and fun as well.&lt;/p&gt;  &lt;h2&gt;SVG Clocks&lt;/h2&gt;  &lt;h3&gt;&lt;a href="http://www.adobe.com/svg/demos/clock.html" target="_blank"&gt;Adobe SVG Clock&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.adobe.com/svg/demos/clock.html"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="AdobeSvgClock" border="0" alt="AdobeSvgClock" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/AdobeSvgClock.png" width="185" height="217" /&gt;&lt;/a&gt; by Adobe (unknown date)&lt;/p&gt;  &lt;p&gt;A very basic looking clock that uses three &amp;lt;animateTransform type="rotate"&amp;gt; for the hour, minute, and second hands along with a load script to initialize the hands. Note that Adobe has discontinued their SVG Viewer and there are conflicts between SVG and Flash.    &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://realtech.burningbird.net/graphics/svg/experiments-svg-clock" target="_blank"&gt;Experiments: SVG Clock&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/BurningBirdSvgClock.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="BurningBirdSvgClock" border="0" alt="BurningBirdSvgClock" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/BurningBirdSvgClock_thumb.png" width="215" height="213" /&gt;&lt;/a&gt; by Shelley Powers on November 30, 2007&lt;/p&gt;  &lt;p&gt;This is an improvement on a very simple SVG clock by Jason Davis (the original link was not working). This implementation supports displaying time in a different time zone rather than the user’s current time using the statement: &lt;span style="font-family: courier new, fixed"&gt;setInterval("setClock(calcTime(-6))", 1000);&lt;/span&gt;. The code is licensed with LGPL.&lt;/p&gt;  &lt;p&gt;I had to download the file directly as it was not shown in FF 3.5. The author has a rather appropriate statement in the article:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Is the clock worth the extra burden on the client's machine? Yes, and no. As a demonstration of what you can do with SVG and simple animation, I think it's a valuable tool. There is a Catch 22 about SVG: we don't use SVG because browser support is incomplete or inefficient; effort to better incorporate SVG is of secondary importance because SVG is little used. The only way to break this cycle is to actually start using the specification, and pushing a bit at the edges while we go about it.&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;&lt;a href="http://en.wikipedia.org/wiki/File:Binary_clock.svg" target="_blank"&gt;Binary Clock&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/File:Binary_clock.svg"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="200px-Binary_clock_svg" border="0" alt="200px-Binary_clock_svg" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/200pxBinary_clock_svg.png" width="200" height="147" /&gt;&lt;/a&gt; by Alexander Jones &amp;amp; Eric Pierce from Wikipedia on October 14, 2006&lt;/p&gt;  &lt;p&gt;This is Wikipedia entry that I thought was animated but it turns out it is not animated. Bummer. It wouldn’t be hard to animate though.  &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://kamhungsoh.com/000d.xhtml"&gt;SVG + Javascript Analogue Clocks&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://kamhungsoh.com/000d.xhtml"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SvgJavascriptAnalogueClock" border="0" alt="SvgJavascriptAnalogueClock" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SvgJavascriptAnalogueClock.png" width="240" height="118" /&gt;&lt;/a&gt; by Kam-Hung Soh&lt;/p&gt;  &lt;p&gt;This example uses Javascript at the DOM document level rather than inside the SVG document to rotate the clock hands. It also uses a regular expression to change the rotation angle.    &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://tavmjong.free.fr/INKSCAPE/DRAWINGS/clock2.svg" target="_blank"&gt;Animated SVG Clock Gears&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://tavmjong.free.fr/INKSCAPE/DRAWINGS/clock2.svg"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AnimatedClockGears" border="0" alt="AnimatedClockGears" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/AnimatedClockGears.png" width="244" height="87" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;by &lt;a href="http://tavmjong.free.fr/" target="_blank"&gt;Tavmjong Bah&lt;/a&gt; (unknown date)&lt;/p&gt;  &lt;p&gt;This is a really cool example created with &lt;a href="http://www.inkscape.org/" target="_blank"&gt;Inkscape&lt;/a&gt; where every gear is independent and does not interfere with other gears. According to the author, the gears outlines were generated with a Python script by Aaron Spike.     &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://oskamp.dyndns.org/SiemensClock/SVG/" target="_blank"&gt;Siemens Wall Clock&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://oskamp.dyndns.org/SiemensClock/SVG/"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SiemensWallClockSvg" border="0" alt="SiemensWallClockSvg" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SiemensWallClockSvg.png" width="240" height="236" /&gt;&lt;/a&gt; by &lt;a href="http://oskamp.dyndns.org/" target="_blank"&gt;Stefan Oskamp&lt;/a&gt; (unknown date)&lt;/p&gt;  &lt;p&gt;A nice looking clock that uses inline SVG along with a Javascript setInterval function to adjust the rotate attributes for the hour, minute, and second hands. The actual background is a 256 x 256 PNG file, rather than a vector based image.    &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://labs.ibuildstuff.net/?p=svgclock" target="_blank"&gt;An SVG Clock&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://labs.ibuildstuff.net/?p=svgclock"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SvgClockWithCountdown" border="0" alt="SvgClockWithCountdown" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SvgClockWithCountdown.png" width="200" height="209" /&gt;&lt;/a&gt; by Damien Dawber (ibuildstuff.net)&lt;/p&gt;  &lt;p&gt;This clock is a self generated SVG image using JavaScript and the &lt;a href="http://raphaeljs.com/"&gt;Raphael&lt;/a&gt; JavaScript Vector Library.     &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://anomaly.org/wade/projects/svgClocks/" target="_blank"&gt;SVG Clock Gallery&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SimpleAnalogClock.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SimpleAnalogClock" border="0" alt="SimpleAnalogClock" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SimpleAnalogClock_thumb.png" width="220" height="210" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;by &lt;a href="http://anomaly.org/wade/index.html"&gt;G. Wade Johnson&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;A clock with a sunburst effect that uses an external script to drive the animation. The author also has a version that runs backwards by simply changing a parameter in the initialization script.    &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://staticfree.info/projects/24h_clock/" target="_blank"&gt;24-Hour '12'-at-the-top Analog Clock&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://staticfree.info/projects/24h_clock/"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="24h_clock_v2.2" border="0" alt="24h_clock_v2.2" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/24h_clock_v2.2.png" width="240" height="239" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;by &lt;a href="http://staticfree.info/"&gt;Steve Pomery&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;A nice looking clock created using Inkscape. Now at version 2.2.  &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://chriswjohnson.blogspot.com/2008/04/svg-resurgent.html" target="_blank"&gt;SVG Resurgent&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://chriswjohnson.blogspot.com/2008/04/svg-resurgent.html"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SvgResurgentClock" border="0" alt="SvgResurgentClock" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SvgResurgentClock.png" width="200" height="200" /&gt;&lt;/a&gt; by &lt;a href="http://chriswjohnson.blogspot.com/"&gt;Chris W. Johnson&lt;/a&gt; on April 29, 2008&lt;/p&gt;  &lt;p&gt;An inline base64 encoded SVG clock. The SVG has a version of the Google analytics tracking script "because it's nice to know if people care."    &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h2&gt;Silverlight Clocks&lt;/h2&gt;  &lt;h3&gt;&lt;a href="http://silverlight.net/samples/1.0/clock/default.html" target="_blank"&gt;Microsoft Silverlight Clock Samples&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://silverlight.net/samples/1.0/clock/default.html"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="Silverlight1ClockSample" border="0" alt="Silverlight1ClockSample" align="left" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/Silverlight1ClockSample.png" width="240" height="212" /&gt;&lt;/a&gt; by Microsoft&lt;/p&gt;  &lt;p&gt;A &lt;a href="http://silverlight.net/samples/1.0/clock/default.html"&gt;clock sample&lt;/a&gt; from the Silverlight 1.0 SDK which uses clock.xaml and clock.js to create the clock. The result is actually very similar to some of the SVG implementations since Silverlight 1.0 did not have codebehind capability.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://silverlight.net/content/samples/sl2/clock/run/index.html"&gt;Version 2.0&lt;/a&gt; of the clock uses codebehind along with a XAP file. There is also a &lt;a href="http://www.silverlight.net/content/samples/sl2/ruby-clock/index.html"&gt;version using IronRuby&lt;/a&gt; although the XAP file is significantly larger (11KB vs 1MB!) because it includes several assemblies in the XAP. Then there is the &lt;a href="https://silverlight.net/content/samples/sl2/python-clock/index.html"&gt;Python version&lt;/a&gt; as well which is almost identical to the Ruby version except for the language substitution.&lt;/p&gt;  &lt;p&gt;There is also a Microsoft walk-through: &lt;a href="http://msdn.microsoft.com/en-us/library/bb404709%28VS.95%29.aspx"&gt;Creating a Silverlight Clock by Using Expression Blend or Code&lt;/a&gt;, which has a detailed step by step guide for Expression Blend.     &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://www.codeproject.com/KB/dotnet/vgclock.aspx" target="_blank"&gt;A Vector Graphics Rendered Animated Clock&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.codeproject.com/KB/dotnet/vgclock.aspx"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="VectorGraphicsRenderedClock" border="0" alt="VectorGraphicsRenderedClock" align="left" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/VectorGraphicsRenderedClock.png" width="209" height="210" /&gt;&lt;/a&gt; by Marc Clifton on April 18, 2004&lt;/p&gt;  &lt;p&gt;A very nice looking clock complete with a walkthrough on how to create the look and feel of the clock. Technically this isn’t a Silverlight clock as it is intended for the (now defunct) &lt;a href="http://www.myxaml.com/"&gt;MyXaml&lt;/a&gt; and then improved upon by &lt;a href="http://www.vgdotnet.com/"&gt;VG.net&lt;/a&gt;. The graphics should be mostly compatible with Silverlight though I haven’t tested it yet.     &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://www.silverlightshow.net/items/Developing-Silverlight-Analog-Clock-pattern-oriented-approach.aspx" target="_blank"&gt;Developing Silverlight Analog Clock – pattern oriented approach&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.silverlightshow.net/items/Developing-Silverlight-Analog-Clock-pattern-oriented-approach.aspx"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="SilverlightClockPatternOriented" border="0" alt="SilverlightClockPatternOriented" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SilverlightClockPatternOriented.png" width="207" height="204" /&gt;&lt;/a&gt; &lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SilverlightClockPatternOriented2.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SilverlightClockPatternOriented2" border="0" alt="SilverlightClockPatternOriented2" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/SilverlightClockPatternOriented2_thumb.png" width="239" height="240" /&gt;&lt;/a&gt; by Pencho Popadiyn on October 30, 2008&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.silverlightshow.net/items/Developing-Silverlight-Analog-Clock-pattern-oriented-approach.aspx"&gt;Version 1&lt;/a&gt; introduces the MVP design pattern and the design of the clock using the MVP pattern.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.silverlightshow.net/items/Developing-Silverlight-AnalogClock-part-2-Enhancing-the-view.aspx" target="_blank"&gt;Version 2&lt;/a&gt; - This implementation uses VS2008, .NET 3.5, Silverlight 2 using an MVP pattern. The sample has a very nice looking graphic and improves upon the Clock view.     &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://hybridclock.codeplex.com/" target="_blank"&gt;Hybrid Clock in Silverlight 2&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://hybridclock.codeplex.com/"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="HybridClock" border="0" alt="HybridClock" align="left" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/HybridClock.png" width="167" height="155" /&gt;&lt;/a&gt; by &lt;a href="http://www.alexanderbell.us/"&gt;Alex Bell&lt;/a&gt; on November 7, 2008 (based on SVN timestamps)&lt;/p&gt;  &lt;p&gt;A modest clock using Silverlight although the author claims: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Hybrid Clock is, by far, the most sophisticated animated Date/Time visualization control developed for Microsoft Silverlight™ 2.0.      &lt;br clear="left" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;&lt;a href="http://blogs.msdn.com/synergist/archive/2008/05/24/beauty-with-silverlight.aspx" target="_blank"&gt;Beauty with Silverlight: Ball Watch Animation&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/BallWatchSilverlight.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="BallWatchSilverlight" border="0" alt="BallWatchSilverlight" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/BallWatchSilverlight_thumb.png" width="200" height="200" /&gt;&lt;/a&gt;by Michael S. Scherotter on April 24, 2008&lt;/p&gt;  &lt;p&gt;This is a gorgeous clock using Silverlight, Expression Blend, and Expression Design. For some reason this is a Silverlight 1.0 applet instead of 2.0 which means it uses some Javascript event triggering for the loading, but it looks great.    &lt;br clear="left" /&gt;&lt;/p&gt;  &lt;h3&gt;Miscellaneous Silverlight Clocks&lt;/h3&gt;  &lt;p&gt;I was taking way too much time, so here are other implementations without screen shots.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.c-sharpcorner.com/UploadFile/nipuntomar/SilverlightClock08122008132436PM/SilverlightClock.aspx" href="http://www.c-sharpcorner.com/UploadFile/nipuntomar/SilverlightClock08122008132436PM/SilverlightClock.aspx"&gt;http://www.c-sharpcorner.com/UploadFile/nipuntomar/SilverlightClock08122008132436PM/SilverlightClock.aspx&lt;/a&gt; – A good Silverlight clock.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://pixelplastic.de/2008/01/12/ZoomableUltraHighResolutionSilverlightClock.aspx" href="http://pixelplastic.de/2008/01/12/ZoomableUltraHighResolutionSilverlightClock.aspx"&gt;http://pixelplastic.de/2008/01/12/ZoomableUltraHighResolutionSilverlightClock.aspx&lt;/a&gt; – A Silverlight clock that allows the user to drag and move the clock. The applet did not work in IE or FF, so I assume it was developed with a pre-release version and has not been updated on the blog article. You can download the source code though. Marcel Hoyer has an &lt;a href="http://pixelplastic.de/2008/10/20/UpdatedSilverlightDemosClockAttractorBezier.aspx"&gt;older version of the clock&lt;/a&gt; as well as other cool Silverlight examples on his blog.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://weblogs.asp.net/andrewrea/archive/2009/08/12/programmatic-drawing-with-silverlight-2-0-3-0-an-analogue-clock.aspx" href="http://weblogs.asp.net/andrewrea/archive/2009/08/12/programmatic-drawing-with-silverlight-2-0-3-0-an-analogue-clock.aspx"&gt;http://weblogs.asp.net/andrewrea/archive/2009/08/12/programmatic-drawing-with-silverlight-2-0-3-0-an-analogue-clock.aspx&lt;/a&gt; – A basic looking clock although the clock is mostly generated by code (tick marks, etc.) which is cool. The blog post has a lengthy code listing and downloadable code.&lt;/p&gt;  &lt;h2&gt;WPF Clocks&lt;/h2&gt;  &lt;h3&gt;&lt;a href="http://www.charlespetzold.com/blog/2006/04/070132.html" target="_blank"&gt;Another Xamlifferous Experience (an All-XAML Clock)&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/AllXamlClock.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="AllXamlClock" border="0" alt="AllXamlClock" align="left" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SilverlightClocks_12166/AllXamlClock_thumb.png" width="228" height="224" /&gt;&lt;/a&gt; by &lt;a href="http://www.charlespetzold.com/"&gt;Charles Petzold&lt;/a&gt; on April 7, 2006&lt;/p&gt;  &lt;p&gt;This is an all XAML clock without any C# or .NET code. It was based on a Microsoft sample and Charles Petzold improved upon that sample by eliminating the C# code, improved the animation technique, and eliminated the repetition in the XAML. The clock graphic is basic and not fancy, but practical.    &lt;br clear="left" /&gt;&lt;/p&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/78.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2009/12/30/animated-clocks-for-svg-and-silverlight.aspx</guid>
            <pubDate>Wed, 30 Dec 2009 07:17:17 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/78.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2009/12/30/animated-clocks-for-svg-and-silverlight.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/78.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/78.aspx</trackback:ping>
        </item>
        <item>
            <title>Spinning Wait Symbol in Silverlight, Part4</title>
            <link>http://nimblecoder.com/blog/archive/2008/11/06/spinning-wait-symbol-in-silverlight-part4.aspx</link>
            <description>&lt;div&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart4_9F71/SpinningCursor4TestPage.png"&gt;&lt;img height="178" alt="SpinningCursor4-TestPage" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart4_9F71/SpinningCursor4TestPage_thumb.png" width="240" align="right" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;ul&gt; &lt;li&gt;&lt;a title="SpinningCursor3 source code" href="/blog/Samples/Silverlight/SpinningCursor4.zip"&gt;SpinningCursor4.zip&lt;/a&gt; (57 KB): Source (VS2008/Silverlight 2.0)&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Series History&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Part 4: Adding an animation (static XAML) to the slices (in Silverlight/C#)  &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.nimblecoder.com/blog/archive/2008/10/29/spinning-wait-symbol-in-silverlight-part3.aspx"&gt;Part 3: Adding curvature to the slices (in Silverlight/C#)&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.nimblecoder.com/blog/archive/2008/10/20/spinning-wait-symbol-in-silverlight-part-2.aspx"&gt;Part 2: Dynamically building slices (in Silverlight/C#)&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.nimblecoder.com/blog/archive/2008/10/08/spinning-wait-symbol-in-silverlight.aspx"&gt;Part 1: Treo-like wait symbol in static XAML&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart4_9F71/SpinningCursor4TestPage.png"&gt;&lt;/a&gt; &lt;/p&gt; &lt;h4&gt;Introduction&lt;/h4&gt; &lt;p&gt;The goal of these posts is to build a spinning cursor similar to the &lt;a href="http://en.wikipedia.org/wiki/Spinning_wait_cursor_(Mac_OS_X)"&gt;Mac OS X wait cursor&lt;/a&gt; through programmatic means in &lt;a href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt;. The cursor is still very rough and will undergo improvements progrressively. One of the reasons to build the cursor programmatically is to have more control over the output such as changing the number of slices or rotation or other parameters.&lt;/p&gt; &lt;p&gt;For this post, I added an animation to the rotation angle of the canvas which causes the slices to spin. I also added a simple navigation to the previous examples.&lt;/p&gt; &lt;div&gt; &lt;iframe src="/samples/Silverlight/SpinningCursor4.Web/SpinningCursorTestPage.html" width="500" height="280"&gt; &lt;p&gt;Download Silverlight&lt;/p&gt; &lt;/iframe&gt; &lt;/div&gt; &lt;h4&gt;Step 1: Adding the Animation&lt;/h4&gt; &lt;p&gt;In the previous post, I had one canvas for the background image as well as the slices. This time I realized I needed two canvases: one for the background and one for the slices. I needed separate canvases so that I could apply a rotation transform animation to the slices without affecting the background image. I used Expression Blend 2.0 sp1 and selected the "SpinningCanvas" and added an Storyboard named "SpinStoryboard". I then changed the Angle of the RotateTransform from 0 - 360° for the time range 0.0 - 2.0 sec.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart4_9F71/SpinningCursor4BlendAnimation.png"&gt;&lt;img height="369" alt="SpinningCursor4-BlendAnimation" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart4_9F71/SpinningCursor4BlendAnimation_thumb.png" width="640" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;This resulted in the following XAML:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span&gt;    &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;="SpinStoryboard" &lt;/span&gt;&lt;span style="color: red"&gt;RepeatBehavior&lt;/span&gt;&lt;span style="color: blue"&gt;="Forever"&amp;gt;
&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DoubleAnimationUsingKeyFrames
            &lt;/span&gt;&lt;span style="color: red"&gt;BeginTime&lt;/span&gt;&lt;span style="color: blue"&gt;="00:00:00"
            &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetName&lt;/span&gt;&lt;span style="color: blue"&gt;="SpinningCanvas"
            &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetProperty&lt;/span&gt;&lt;span style="color: blue"&gt;="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"&amp;gt;
&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SplineDoubleKeyFrame &lt;/span&gt;&lt;span style="color: red"&gt;KeyTime&lt;/span&gt;&lt;span style="color: blue"&gt;="00:00:02" &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;="360"/&amp;gt;
&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DoubleAnimationUsingKeyFrames&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span&gt;    &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;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;h4&gt;Step 2: Starting the Animation&lt;/h4&gt;
&lt;p&gt;When the control is created or updated, the Update() method is called. I modified the method as follows:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;void &lt;/span&gt;&lt;span style="color: maroon"&gt;Update&lt;/span&gt;()
{
    &lt;span style="color: maroon"&gt;SpinStoryboard&lt;/span&gt;.&lt;span style="color: maroon"&gt;Stop&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;CursorCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Clear&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;SpinningCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Clear&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;CreateOutlineGuides&lt;/span&gt;(&lt;span style="color: maroon"&gt;CursorCanvas&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;CreateBackground&lt;/span&gt;(&lt;span style="color: maroon"&gt;CursorCanvas&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;CreateSlicePaths&lt;/span&gt;(&lt;span style="color: maroon"&gt;SpinningCanvas&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;SpinStoryboard&lt;/span&gt;.&lt;span style="color: maroon"&gt;Begin&lt;/span&gt;();
}
&lt;/pre&gt;
&lt;h4&gt;Step 3: Adding the Sample Navigation&lt;/h4&gt;
&lt;p&gt;I wanted to support future samples, so I used reflection to find all of the UserControls not including App or Page. I used a Dictionary&amp;lt;string, Type&amp;gt; to map the Type.Name with the Type in case I need it for future samples. I then dynamically created a button for each sample.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;void &lt;/span&gt;&lt;span style="color: maroon"&gt;Page_Loaded&lt;/span&gt;(&lt;span style="color: navy"&gt;object &lt;/span&gt;&lt;span style="color: maroon"&gt;sender&lt;/span&gt;, &lt;span style="color: #a65300"&gt;RoutedEventArgs &lt;/span&gt;&lt;span style="color: maroon"&gt;e&lt;/span&gt;)
{
    &lt;span style="color: #a65300"&gt;Assembly &lt;/span&gt;&lt;span style="color: maroon"&gt;assembly &lt;/span&gt;= &lt;span style="color: #a65300"&gt;Assembly&lt;/span&gt;.&lt;span style="color: maroon"&gt;GetExecutingAssembly&lt;/span&gt;();
    &lt;span style="color: #a65300"&gt;Type&lt;/span&gt;[] &lt;span style="color: maroon"&gt;exportedTypes &lt;/span&gt;= &lt;span style="color: maroon"&gt;assembly&lt;/span&gt;.&lt;span style="color: maroon"&gt;GetExportedTypes&lt;/span&gt;();
    &lt;span style="color: navy"&gt;foreach &lt;/span&gt;(&lt;span style="color: #a65300"&gt;Type &lt;/span&gt;&lt;span style="color: maroon"&gt;t &lt;/span&gt;&lt;span style="color: navy"&gt;in &lt;/span&gt;&lt;span style="color: maroon"&gt;exportedTypes&lt;/span&gt;)
    {
        &lt;span style="color: green"&gt;// Testing various inheritance detection methods
        &lt;/span&gt;&lt;span style="color: navy"&gt;bool &lt;/span&gt;&lt;span style="color: maroon"&gt;isNotApp &lt;/span&gt;= (&lt;span style="color: maroon"&gt;t &lt;/span&gt;!= &lt;span style="color: navy"&gt;typeof&lt;/span&gt;(&lt;span style="color: #a65300"&gt;App&lt;/span&gt;));
        &lt;span style="color: navy"&gt;bool &lt;/span&gt;&lt;span style="color: maroon"&gt;isNotSelf &lt;/span&gt;= (&lt;span style="color: maroon"&gt;t &lt;/span&gt;!= &lt;span style="color: navy"&gt;this&lt;/span&gt;.&lt;span style="color: maroon"&gt;GetType&lt;/span&gt;());
        &lt;span style="color: navy"&gt;bool &lt;/span&gt;&lt;span style="color: maroon"&gt;isUserControl &lt;/span&gt;= &lt;span style="color: maroon"&gt;t&lt;/span&gt;.&lt;span style="color: maroon"&gt;IsSubclassOf&lt;/span&gt;(&lt;span style="color: navy"&gt;typeof&lt;/span&gt;(&lt;span style="color: #a65300"&gt;UserControl&lt;/span&gt;));

        &lt;span style="color: navy"&gt;if &lt;/span&gt;(&lt;span style="color: maroon"&gt;isNotApp &lt;/span&gt;&amp;amp;&amp;amp; &lt;span style="color: maroon"&gt;isNotSelf &lt;/span&gt;&amp;amp;&amp;amp; &lt;span style="color: maroon"&gt;isUserControl&lt;/span&gt;)
        {
            &lt;span style="color: maroon"&gt;_implementedTypes&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;t&lt;/span&gt;.&lt;span style="color: maroon"&gt;Name&lt;/span&gt;, &lt;span style="color: maroon"&gt;t&lt;/span&gt;);
        }
    }

    &lt;span style="color: #a65300"&gt;Button &lt;/span&gt;&lt;span style="color: maroon"&gt;lastButton &lt;/span&gt;= &lt;span style="color: navy"&gt;null&lt;/span&gt;;

    &lt;span style="color: green"&gt;// Sort the names of the UserControls to make more sense
    &lt;/span&gt;&lt;span style="color: #a65300"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: navy"&gt;string&lt;/span&gt;&amp;gt; &lt;span style="color: maroon"&gt;sortedKeys &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: navy"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color: maroon"&gt;_implementedTypes&lt;/span&gt;.&lt;span style="color: maroon"&gt;Keys&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;sortedKeys&lt;/span&gt;.&lt;span style="color: maroon"&gt;Sort&lt;/span&gt;();

    &lt;span style="color: navy"&gt;for &lt;/span&gt;(&lt;span style="color: navy"&gt;int &lt;/span&gt;&lt;span style="color: maroon"&gt;index &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;; &lt;span style="color: maroon"&gt;index &lt;/span&gt;&amp;lt; &lt;span style="color: maroon"&gt;_implementedTypes&lt;/span&gt;.&lt;span style="color: maroon"&gt;Count&lt;/span&gt;; ++&lt;span style="color: maroon"&gt;index&lt;/span&gt;)
    {
        &lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;key &lt;/span&gt;= &lt;span style="color: maroon"&gt;sortedKeys&lt;/span&gt;[&lt;span style="color: maroon"&gt;index&lt;/span&gt;];
        &lt;span style="color: #a65300"&gt;Type &lt;/span&gt;&lt;span style="color: maroon"&gt;t &lt;/span&gt;= &lt;span style="color: maroon"&gt;_implementedTypes&lt;/span&gt;[&lt;span style="color: maroon"&gt;key&lt;/span&gt;];
        &lt;span style="color: maroon"&gt;lastButton &lt;/span&gt;= &lt;span style="color: maroon"&gt;AddButton&lt;/span&gt;(&lt;span style="color: maroon"&gt;t&lt;/span&gt;, &lt;span style="color: maroon"&gt;index&lt;/span&gt;);
    }

    &lt;span style="color: green"&gt;// Use the last UserControl for the initial display
    &lt;/span&gt;&lt;span style="color: navy"&gt;if &lt;/span&gt;(&lt;span style="color: maroon"&gt;lastButton &lt;/span&gt;!= &lt;span style="color: navy"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color: maroon"&gt;Button_Click&lt;/span&gt;(&lt;span style="color: maroon"&gt;lastButton&lt;/span&gt;, &lt;span style="color: navy"&gt;null&lt;/span&gt;);
    }
}
&lt;/pre&gt;
&lt;p&gt;To make it simple, I used name of the UserControl for the Button.Content and in the Button_Click event I used System.Activator to create an instance of the class.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;private void &lt;/span&gt;&lt;span style="color: maroon"&gt;Button_Click&lt;/span&gt;(&lt;span style="color: navy"&gt;object &lt;/span&gt;&lt;span style="color: maroon"&gt;sender&lt;/span&gt;, &lt;span style="color: #a65300"&gt;RoutedEventArgs &lt;/span&gt;&lt;span style="color: maroon"&gt;e&lt;/span&gt;)
{
    &lt;span style="color: #a65300"&gt;UIElement &lt;/span&gt;&lt;span style="color: maroon"&gt;control &lt;/span&gt;= &lt;span style="color: navy"&gt;null&lt;/span&gt;;

    &lt;span style="color: navy"&gt;try
    &lt;/span&gt;{
        &lt;span style="color: #a65300"&gt;Button &lt;/span&gt;&lt;span style="color: maroon"&gt;button &lt;/span&gt;= &lt;span style="color: maroon"&gt;sender &lt;/span&gt;&lt;span style="color: navy"&gt;as &lt;/span&gt;&lt;span style="color: #a65300"&gt;Button&lt;/span&gt;;
        &lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;typeName &lt;/span&gt;= &lt;span style="color: maroon"&gt;button&lt;/span&gt;.&lt;span style="color: maroon"&gt;Content &lt;/span&gt;&lt;span style="color: navy"&gt;as string&lt;/span&gt;;
        &lt;span style="color: #a65300"&gt;Type &lt;/span&gt;&lt;span style="color: maroon"&gt;type &lt;/span&gt;= &lt;span style="color: maroon"&gt;_implementedTypes&lt;/span&gt;[&lt;span style="color: maroon"&gt;typeName&lt;/span&gt;];
        &lt;span style="color: navy"&gt;object &lt;/span&gt;&lt;span style="color: maroon"&gt;instance &lt;/span&gt;= &lt;span style="color: maroon"&gt;System&lt;/span&gt;.&lt;span style="color: #a65300"&gt;Activator&lt;/span&gt;.&lt;span style="color: maroon"&gt;CreateInstance&lt;/span&gt;(&lt;span style="color: maroon"&gt;type&lt;/span&gt;);
        &lt;span style="color: maroon"&gt;control &lt;/span&gt;= &lt;span style="color: maroon"&gt;instance &lt;/span&gt;&lt;span style="color: navy"&gt;as &lt;/span&gt;&lt;span style="color: #a65300"&gt;UIElement&lt;/span&gt;;
    }
    &lt;span style="color: navy"&gt;catch &lt;/span&gt;(&lt;span style="color: #a65300"&gt;Exception &lt;/span&gt;&lt;span style="color: maroon"&gt;ex&lt;/span&gt;)
    {
        &lt;span style="color: maroon"&gt;System&lt;/span&gt;.&lt;span style="color: maroon"&gt;Diagnostics&lt;/span&gt;.&lt;span style="color: #a65300"&gt;Debug&lt;/span&gt;.&lt;span style="color: maroon"&gt;WriteLine&lt;/span&gt;(&lt;span style="color: maroon"&gt;ex&lt;/span&gt;.&lt;span style="color: maroon"&gt;ToString&lt;/span&gt;());
    }

    &lt;span style="color: maroon"&gt;WorkArea&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Clear&lt;/span&gt;();
    &lt;span style="color: navy"&gt;if &lt;/span&gt;(&lt;span style="color: maroon"&gt;control &lt;/span&gt;!= &lt;span style="color: navy"&gt;null&lt;/span&gt;)
        &lt;span style="color: maroon"&gt;WorkArea&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;control&lt;/span&gt;);
}&lt;/pre&gt;
&lt;h4&gt;Conclusion&lt;/h4&gt;
&lt;p&gt;The animation looks nice and adds a lot to the overall effect. For the next part, I plan to dynamically create the animation instead of using Blend and perhaps improve the background shape to more closely resemble the Mac OS X spinning cursor.&lt;/p&gt;
&lt;div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f11%2f06%2fspinning-wait-symbol-in-silverlight-part4.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f11%2f06%2fspinning-wait-symbol-in-silverlight-part4.aspx&amp;amp;border=9CCFF&amp;amp;fgcolor=9CCFF&amp;amp;bgcolor=9CCFF&amp;amp;cfgcolor=9CCFF&amp;amp;cbgcolor=9CCFF" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a18b93fb-92fa-4217-9e65-8066a74a613a" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/75.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2008/11/06/spinning-wait-symbol-in-silverlight-part4.aspx</guid>
            <pubDate>Thu, 06 Nov 2008 08:03:05 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/75.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2008/11/06/spinning-wait-symbol-in-silverlight-part4.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/75.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/75.aspx</trackback:ping>
        </item>
        <item>
            <title>Spinning Wait Symbol in Silverlight, Part3</title>
            <link>http://nimblecoder.com/blog/archive/2008/10/29/spinning-wait-symbol-in-silverlight-part3.aspx</link>
            <description>&lt;div&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart3_94A2/SpinningCursor3TestPage.png"&gt;&lt;img height="249" alt="SpinningCursor3-TestPage" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart3_94A2/SpinningCursor3TestPage_thumb.png" width="231" align="right" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;ul&gt; &lt;li&gt;&lt;a title="SpinningCursor3 source code" href="/blog/Samples/Silverlight/SpinningCursor3.zip"&gt;SpinningCursor3.zip&lt;/a&gt; (34 KB): Source (VS2008/Silverlight 2.0)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Series History&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Part 3: Adding curvature to the slices (in Silverlight/C#)  &lt;/li&gt;&lt;li&gt;&lt;a href="/blog/archive/2008/10/20/spinning-wait-symbol-in-silverlight-part-2.aspx"&gt;Part 2: Dynamically building slices (in Silverlight/C#)&lt;/a&gt;  &lt;/li&gt;&lt;li&gt;&lt;a href="/blog/archive/2008/10/08/spinning-wait-symbol-in-silverlight.aspx"&gt;Part 1: Treo-like wait symbol in static XAML&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;In this post, I add curvature to the slices and refactor the code to support upcoming features. The goal of these posts is to build a spinning cursor similar to the &lt;a href="http://en.wikipedia.org/wiki/Spinning_wait_cursor_(Mac_OS_X)"&gt;Mac OS X wait cursor&lt;/a&gt; through programmatic means in &lt;a href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt;. One of the reasons to build the cursor programmatically is to create it will different number of slices or rotation or other parameters. At this point, the cursor is still very rough and just beginning to resemble the final result. In upcoming posts, I will animate the cursor and adjust the appearance to more closely resemble the desired cursor.&lt;/p&gt; &lt;h4&gt;Step 1: Adjust the cursor properties&lt;/h4&gt; &lt;p&gt;I added AlternateSlices and Origin properties, and also DefaultSliceCount and DefaultRotationAngle to the class.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;public static readonly int &lt;/span&gt;&lt;span style="color: maroon"&gt;DefaultSliceCount &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;10&lt;/span&gt;;
&lt;span style="color: navy"&gt;public static readonly double &lt;/span&gt;&lt;span style="color: maroon"&gt;DefaultSliceRotationAngle &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;360.0&lt;/span&gt; / &lt;span style="color: maroon"&gt;DefaultSliceCount&lt;/span&gt;;

&lt;span style="background: #e0e0ff; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="background: #e0e0ff; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: #e0e0ff; color: green"&gt;Show alternating slices (true) or all slices (false) &lt;/span&gt;       
&lt;span style="background: #e0e0ff; color: gray"&gt;/// &amp;lt;/summary&amp;gt; &lt;/span&gt;
&lt;span style="color: navy"&gt;public bool &lt;/span&gt;&lt;span style="color: maroon"&gt;AlternateSlices &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;set&lt;/span&gt;; }

&lt;span style="background: #e0e0ff; color: gray"&gt;/// &amp;lt;summary&amp;gt; &lt;/span&gt;       
&lt;span style="background: #e0e0ff; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: #e0e0ff; color: green"&gt;The origin of the ellipse for the spinning cursor &lt;/span&gt;
&lt;span style="background: #e0e0ff; color: gray"&gt;/// &amp;lt;/summary&amp;gt; &lt;/span&gt;
&lt;span style="color: navy"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;&lt;span style="color: maroon"&gt;Origin &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;private set&lt;/span&gt;; }
&lt;/pre&gt;
&lt;h4&gt;Step 2: Set the default parameter values&lt;/h4&gt;
&lt;p&gt;I specified the default slice count and the radius and origin of the cursor.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;void &lt;/span&gt;&lt;span style="color: maroon"&gt;Page_Loaded&lt;/span&gt;(&lt;span style="color: navy"&gt;object &lt;/span&gt;&lt;span style="color: maroon"&gt;sender&lt;/span&gt;, &lt;span style="color: #a65300"&gt;RoutedEventArgs &lt;/span&gt;&lt;span style="color: maroon"&gt;e&lt;/span&gt;)
{
    &lt;span style="color: maroon"&gt;txtVersion&lt;/span&gt;.&lt;span style="color: maroon"&gt;Text &lt;/span&gt;= &lt;span style="color: navy"&gt;this&lt;/span&gt;.&lt;span style="color: maroon"&gt;GetType&lt;/span&gt;().&lt;span style="color: maroon"&gt;Name&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;AlternateSlices &lt;/span&gt;= &lt;span style="color: navy"&gt;true&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;SliceCount &lt;/span&gt;= &lt;span style="color: maroon"&gt;DefaultSliceCount&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;txtSliceCount&lt;/span&gt;.&lt;span style="color: maroon"&gt;Text &lt;/span&gt;= &lt;span style="color: #a65300"&gt;Convert&lt;/span&gt;.&lt;span style="color: maroon"&gt;ToString&lt;/span&gt;(&lt;span style="color: maroon"&gt;SliceCount&lt;/span&gt;);

    &lt;span style="color: maroon"&gt;SliceRotationAngle &lt;/span&gt;= &lt;span style="color: maroon"&gt;DefaultSliceRotationAngle&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;txtRotation&lt;/span&gt;.&lt;span style="color: maroon"&gt;Text &lt;/span&gt;= &lt;span style="color: #a65300"&gt;Convert&lt;/span&gt;.&lt;span style="color: maroon"&gt;ToString&lt;/span&gt;(&lt;span style="color: maroon"&gt;SliceRotationAngle&lt;/span&gt;);

    &lt;span style="color: maroon"&gt;RadiusX &lt;/span&gt;= &lt;span style="color: maroon"&gt;SpinningCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Width &lt;/span&gt;/ &lt;span style="background: #e6ffff"&gt;2.0&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;RadiusY &lt;/span&gt;= &lt;span style="color: maroon"&gt;SpinningCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Height &lt;/span&gt;/ &lt;span style="background: #e6ffff"&gt;2.0&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;Origin &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(&lt;span style="color: maroon"&gt;RadiusX&lt;/span&gt;, &lt;span style="color: maroon"&gt;RadiusY&lt;/span&gt;);

    &lt;span style="color: maroon"&gt;Update&lt;/span&gt;();
}
&lt;/pre&gt;
&lt;h4&gt;Step 3: Create a background circle (ellipse)&lt;/h4&gt;
&lt;p&gt;I used a simple linear gradient for now because the final gradient looks much more complicated and will take more time.&lt;/p&gt;
&lt;p /&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;void &lt;/span&gt;&lt;span style="color: maroon"&gt;CreateBackground&lt;/span&gt;(&lt;span style="color: #a65300"&gt;Canvas &lt;/span&gt;&lt;span style="color: maroon"&gt;cursorCanvas&lt;/span&gt;)
{
    &lt;span style="color: #a65300"&gt;GradientBrush &lt;/span&gt;&lt;span style="color: maroon"&gt;brush &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;LinearGradientBrush&lt;/span&gt;();
    &lt;span style="color: #a65300"&gt;GradientStop &lt;/span&gt;&lt;span style="color: maroon"&gt;stop1 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;GradientStop&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;stop1&lt;/span&gt;.&lt;span style="color: maroon"&gt;Color &lt;/span&gt;= &lt;span style="color: #2b91af"&gt;Color&lt;/span&gt;.&lt;span style="color: maroon"&gt;FromArgb&lt;/span&gt;(&lt;span style="background: #e6ffff"&gt;255&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;255&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;stop1&lt;/span&gt;.&lt;span style="color: maroon"&gt;Offset &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;0.25&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;brush&lt;/span&gt;.&lt;span style="color: maroon"&gt;GradientStops&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;stop1&lt;/span&gt;);

    &lt;span style="color: #a65300"&gt;GradientStop &lt;/span&gt;&lt;span style="color: maroon"&gt;stop2 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;GradientStop&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;stop2&lt;/span&gt;.&lt;span style="color: maroon"&gt;Color &lt;/span&gt;= &lt;span style="color: #2b91af"&gt;Color&lt;/span&gt;.&lt;span style="color: maroon"&gt;FromArgb&lt;/span&gt;(&lt;span style="background: #e6ffff"&gt;255&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;255&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;stop2&lt;/span&gt;.&lt;span style="color: maroon"&gt;Offset &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;0.5&lt;/span&gt;; &lt;span style="color: green"&gt;// cursorCanvas.Width / 2.0;
    &lt;/span&gt;&lt;span style="color: maroon"&gt;brush&lt;/span&gt;.&lt;span style="color: maroon"&gt;GradientStops&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;stop2&lt;/span&gt;);

    &lt;span style="color: #a65300"&gt;GradientStop &lt;/span&gt;&lt;span style="color: maroon"&gt;stop3 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;GradientStop&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;stop3&lt;/span&gt;.&lt;span style="color: maroon"&gt;Color &lt;/span&gt;= &lt;span style="color: #2b91af"&gt;Color&lt;/span&gt;.&lt;span style="color: maroon"&gt;FromArgb&lt;/span&gt;(&lt;span style="background: #e6ffff"&gt;255&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;255&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;stop3&lt;/span&gt;.&lt;span style="color: maroon"&gt;Offset &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;0.75&lt;/span&gt;; &lt;span style="color: green"&gt;// cursorCanvas.Width;
    &lt;/span&gt;&lt;span style="color: maroon"&gt;brush&lt;/span&gt;.&lt;span style="color: maroon"&gt;GradientStops&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;stop3&lt;/span&gt;);

    &lt;span style="color: #a65300"&gt;Ellipse &lt;/span&gt;&lt;span style="color: maroon"&gt;ellipse &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;Ellipse&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;ellipse&lt;/span&gt;.&lt;span style="color: maroon"&gt;Height &lt;/span&gt;= &lt;span style="color: maroon"&gt;cursorCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Height&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;ellipse&lt;/span&gt;.&lt;span style="color: maroon"&gt;Width &lt;/span&gt;= &lt;span style="color: maroon"&gt;cursorCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Width&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;ellipse&lt;/span&gt;.&lt;span style="color: maroon"&gt;Fill &lt;/span&gt;= &lt;span style="color: maroon"&gt;brush&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;cursorCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;ellipse&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;h4&gt;Step 4: Implement the alternating slices&lt;/h4&gt;
&lt;p /&gt;
&lt;p&gt;Implementing the alternating slices was simple:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="background: #e0e0ff; color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="background: #e0e0ff; color: green"&gt;Create an ellipse using rotated slices to build the ellipse
&lt;/span&gt;&lt;span style="background: #e0e0ff; color: gray"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: navy"&gt;void &lt;/span&gt;&lt;span style="color: maroon"&gt;CreateSlicePaths&lt;/span&gt;(&lt;span style="color: #a65300"&gt;Canvas &lt;/span&gt;&lt;span style="color: maroon"&gt;cursorCanvas&lt;/span&gt;)
{
    &lt;span style="color: green"&gt;// Create Slices
    &lt;/span&gt;&lt;span style="color: navy"&gt;for &lt;/span&gt;(&lt;span style="color: navy"&gt;int &lt;/span&gt;&lt;span style="color: maroon"&gt;index &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;; &lt;span style="color: maroon"&gt;index &lt;/span&gt;&amp;lt; &lt;span style="color: maroon"&gt;SliceCount&lt;/span&gt;; ++&lt;span style="color: maroon"&gt;index&lt;/span&gt;)
    {
        &lt;span style="color: #a65300"&gt;PathFigure &lt;/span&gt;&lt;span style="color: maroon"&gt;pathFigure &lt;/span&gt;= &lt;span style="color: maroon"&gt;CreateSliceFigure&lt;/span&gt;();

        &lt;span style="color: #a65300"&gt;PathGeometry &lt;/span&gt;&lt;span style="color: maroon"&gt;pathGeometry &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;PathGeometry&lt;/span&gt;();
        &lt;span style="color: maroon"&gt;pathGeometry&lt;/span&gt;.&lt;span style="color: maroon"&gt;Figures&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;);

        &lt;span style="color: #a65300"&gt;Path &lt;/span&gt;&lt;span style="color: maroon"&gt;path &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;Path&lt;/span&gt;();
        &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;Stroke &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;SolidColorBrush&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Color&lt;/span&gt;.&lt;span style="color: maroon"&gt;FromArgb&lt;/span&gt;(&lt;span style="background: #e6ffff"&gt;128&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;));
        &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;StrokeThickness &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;1.0&lt;/span&gt;;
        &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;Fill &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;SolidColorBrush&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Color&lt;/span&gt;.&lt;span style="color: maroon"&gt;FromArgb&lt;/span&gt;(&lt;span style="background: #e6ffff"&gt;192&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;128&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;128&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;128&lt;/span&gt;));
        &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;Data &lt;/span&gt;= &lt;span style="color: maroon"&gt;pathGeometry&lt;/span&gt;;

        &lt;span style="color: green"&gt;// Rotate the slice for all slices after the first slice
        &lt;/span&gt;&lt;span style="color: navy"&gt;if &lt;/span&gt;(&lt;span style="color: maroon"&gt;index &lt;/span&gt;&amp;gt; &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;)
        {
            &lt;span style="color: #a65300"&gt;RotateTransform &lt;/span&gt;&lt;span style="color: maroon"&gt;t1 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;RotateTransform&lt;/span&gt;();
            &lt;span style="color: maroon"&gt;t1&lt;/span&gt;.&lt;span style="color: maroon"&gt;CenterX &lt;/span&gt;= &lt;span style="color: maroon"&gt;RadiusX&lt;/span&gt;;
            &lt;span style="color: maroon"&gt;t1&lt;/span&gt;.&lt;span style="color: maroon"&gt;CenterY &lt;/span&gt;= &lt;span style="color: maroon"&gt;RadiusY&lt;/span&gt;;
            &lt;span style="color: maroon"&gt;t1&lt;/span&gt;.&lt;span style="color: maroon"&gt;Angle &lt;/span&gt;= &lt;span style="color: maroon"&gt;SliceCenterAngle &lt;/span&gt;* &lt;span style="color: maroon"&gt;index&lt;/span&gt;;

            &lt;span style="color: #a65300"&gt;TransformGroup &lt;/span&gt;&lt;span style="color: maroon"&gt;transformGroup &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;TransformGroup&lt;/span&gt;();
            &lt;span style="color: maroon"&gt;transformGroup&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;t1&lt;/span&gt;);
            &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;RenderTransform &lt;/span&gt;= &lt;span style="color: maroon"&gt;transformGroup&lt;/span&gt;;
        }

        &lt;span style="color: maroon"&gt;cursorCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;path&lt;/span&gt;);

        &lt;span style="color: navy"&gt;if &lt;/span&gt;(&lt;span style="color: maroon"&gt;AlternateSlices&lt;/span&gt;)
            ++&lt;span style="color: maroon"&gt;index&lt;/span&gt;;
    }
}
&lt;/pre&gt;
&lt;h4&gt;Step 5: Add the curvature to the slices&lt;/h4&gt;
&lt;p&gt;The curvature isn't perfect, but it looks fine with the default settings (10 slices and 36° rotation). I used a Bezier curve, but perhaps the standard arc would work better in the future.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Curve control weighting
&lt;/span&gt;&lt;span style="color: navy"&gt;double &lt;/span&gt;&lt;span style="color: maroon"&gt;curveWeight &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;0.75&lt;/span&gt;;

&lt;span style="color: green"&gt;// Create the first line
&lt;/span&gt;&lt;span style="color: #a65300"&gt;BezierSegment &lt;/span&gt;&lt;span style="color: maroon"&gt;seg1 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;BezierSegment&lt;/span&gt;();
&lt;span style="color: maroon"&gt;seg1&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point1 &lt;/span&gt;= &lt;span style="color: maroon"&gt;point0&lt;/span&gt;;
&lt;span style="color: maroon"&gt;seg1&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point2 &lt;/span&gt;= &lt;span style="color: maroon"&gt;CalculatePointOnEllipse&lt;/span&gt;(&lt;span style="background: #e6ffff"&gt;0.0&lt;/span&gt;, &lt;span style="color: maroon"&gt;RadiusX &lt;/span&gt;* &lt;span style="color: maroon"&gt;curveWeight&lt;/span&gt;, &lt;span style="color: maroon"&gt;RadiusY &lt;/span&gt;* &lt;span style="color: maroon"&gt;curveWeight&lt;/span&gt;, &lt;span style="color: maroon"&gt;Origin&lt;/span&gt;);
&lt;span style="color: maroon"&gt;seg1&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point3 &lt;/span&gt;= &lt;span style="color: maroon"&gt;point1&lt;/span&gt;;
&lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;Segments&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;seg1&lt;/span&gt;);

&lt;span style="color: green"&gt;// Use an arc for the circular side
&lt;/span&gt;&lt;span style="color: #a65300"&gt;ArcSegment &lt;/span&gt;&lt;span style="color: maroon"&gt;seg2 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;ArcSegment&lt;/span&gt;();
&lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point &lt;/span&gt;= &lt;span style="color: maroon"&gt;point2&lt;/span&gt;;
&lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;Size &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Size&lt;/span&gt;(&lt;span style="color: maroon"&gt;RadiusX&lt;/span&gt;, &lt;span style="color: maroon"&gt;RadiusY&lt;/span&gt;);
&lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;RotationAngle &lt;/span&gt;= &lt;span style="color: maroon"&gt;SliceCenterAngle&lt;/span&gt;;
&lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;IsLargeArc &lt;/span&gt;= (&lt;span style="color: maroon"&gt;SliceCenterAngle &lt;/span&gt;&amp;gt; &lt;span style="background: #e6ffff"&gt;180.0&lt;/span&gt;);
&lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;SweepDirection &lt;/span&gt;= &lt;span style="color: #2b91af"&gt;SweepDirection&lt;/span&gt;.&lt;span style="color: maroon"&gt;Counterclockwise&lt;/span&gt;;
&lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;Segments&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;seg2&lt;/span&gt;);

&lt;span style="color: green"&gt;// Close shape by going back to the starting point
&lt;/span&gt;&lt;span style="color: #a65300"&gt;BezierSegment &lt;/span&gt;&lt;span style="color: maroon"&gt;seg3 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;BezierSegment&lt;/span&gt;();
&lt;span style="color: maroon"&gt;seg3&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point1 &lt;/span&gt;= &lt;span style="color: maroon"&gt;point2&lt;/span&gt;;
&lt;span style="color: maroon"&gt;seg3&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point2 &lt;/span&gt;= &lt;span style="color: maroon"&gt;CalculatePointOnEllipse&lt;/span&gt;(&lt;span style="color: maroon"&gt;SliceCenterAngle&lt;/span&gt;, &lt;span style="color: maroon"&gt;RadiusX &lt;/span&gt;* &lt;span style="color: maroon"&gt;curveWeight&lt;/span&gt;, &lt;span style="color: maroon"&gt;RadiusY &lt;/span&gt;* &lt;span style="color: maroon"&gt;curveWeight&lt;/span&gt;, &lt;span style="color: maroon"&gt;Origin&lt;/span&gt;);
&lt;span style="color: maroon"&gt;seg3&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point3 &lt;/span&gt;= &lt;span style="color: maroon"&gt;point0&lt;/span&gt;;
&lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;Segments&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;seg3&lt;/span&gt;);
&lt;/pre&gt;
&lt;p /&gt;
&lt;h4&gt;Conclusion&lt;/h4&gt;
&lt;p&gt;The spinning cursor now has a dynamic number of slices and rotation angle, and it is starting to look more like the desired result. In the next post, I will animate the cursor to give it the spinning effect.&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:88d816bf-b129-4f1d-8932-0f80148948d6" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f10%2f29%2fspinning-wait-symbol-in-silverlight-part3.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f10%2f29%2fspinning-wait-symbol-in-silverlight-part3.aspx" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/74.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2008/10/29/spinning-wait-symbol-in-silverlight-part3.aspx</guid>
            <pubDate>Wed, 29 Oct 2008 16:16:42 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/74.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2008/10/29/spinning-wait-symbol-in-silverlight-part3.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/74.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/74.aspx</trackback:ping>
        </item>
        <item>
            <title>Spinning Wait Symbol in Silverlight, Part 2</title>
            <link>http://nimblecoder.com/blog/archive/2008/10/20/spinning-wait-symbol-in-silverlight-part-2.aspx</link>
            <description>&lt;p&gt;After my &lt;a href="http://www.nimblecoder.com/blog/archive/2008/10/08/spinning-wait-symbol-in-silverlight.aspx"&gt;previous spinning wait symbol&lt;/a&gt;, I decided to see how difficult it would be to create a &lt;a href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt; version of the &lt;a href="http://en.wikipedia.org/wiki/Spinning_wait_cursor_(Mac_OS_X)"&gt;Mac OSX wait cursor&lt;/a&gt; that I referenced in the &lt;a href="http://www.nimblecoder.com/blog/archive/2008/10/08/spinning-wait-symbol-in-silverlight.aspx"&gt;previous post&lt;/a&gt;. The Mac OSX cursor is commonly referred to as the "Spinning Pizza of Death" or the "Marble of Doom" and in fact there is a &lt;a href="http://marbleofdoom.com/"&gt;Marble of Doom&lt;/a&gt; web site dedicated to the amount of time spent waiting while watching the spinning cursor. The Marble of Doom web site has a very nice and large version of the cursor using Flash although it doesn't have any vector information but is using video frames (they probably just published the final product and did not include the vector/animation information). The purpose of this post is to programmatically build the cursor and then in later posts to animate it.&lt;/p&gt; &lt;h4&gt;Step 1: Decide on the initial interface properties&lt;/h4&gt; &lt;p&gt;I realized quickly that I would need a little geometry to programmatically build the cursor, but the first step was to build the interface requirements. The essential properties were:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;public int &lt;/span&gt;&lt;span style="color: maroon"&gt;SliceCount &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;set&lt;/span&gt;; }
&lt;span style="color: navy"&gt;public double &lt;/span&gt;&lt;span style="color: maroon"&gt;SliceCenterAngle &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;private set&lt;/span&gt;; }
&lt;span style="color: navy"&gt;public double &lt;/span&gt;&lt;span style="color: maroon"&gt;SliceRotationAngle &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;set&lt;/span&gt;; }
&lt;span style="color: navy"&gt;public double &lt;/span&gt;&lt;span style="color: maroon"&gt;RadiusX &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;set&lt;/span&gt;; }
&lt;span style="color: navy"&gt;public double &lt;/span&gt;&lt;span style="color: maroon"&gt;RadiusY &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;
&lt;p&gt;The &lt;span style="color: maroon"&gt;SliceCount&lt;/span&gt; determines how many slices or divisions to create, and the &lt;span style="color: maroon"&gt;SliceCenterAngle&lt;/span&gt; is simply 360° / &lt;span style="color: maroon"&gt;SliceCount&lt;/span&gt;. The &lt;span style="color: maroon"&gt;SliceRotationAngle&lt;/span&gt; is the angle to twist or bend the slice. I decided to have a &lt;span style="color: maroon"&gt;RadiusX&lt;/span&gt; and &lt;span style="color: maroon"&gt;RadiusY&lt;/span&gt; to support ellipses in the future as well.&lt;/p&gt;
&lt;h4&gt;Step 2: Manually create a slice&lt;/h4&gt;
&lt;p&gt;&lt;a href="http://nimblecoder.com/blog/images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart2_96B0/SpinningCursor1-SliceInBlend.png"&gt;&lt;img height="147" alt="Manual slice in Blend" src="http://nimblecoder.com/blog/images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart2_96B0/SpinningCursor1-SliceInBlend_thumb.png" width="240" align="right" /&gt;&lt;/a&gt; Before I could programmatically create a slice, I needed to find out how to create a slice using XAML and Blend. The points on the slice would be in the center of the circle, and then two points on the circle determined by the &lt;span style="color: maroon"&gt;SliceCenterAngle&lt;/span&gt;. The biggest question was how to create the arc and maintain the circular appearance. Fortunately, the &lt;a href="http://msdn.microsoft.com/en-us/library/ms751808.aspx"&gt;Geometry Overview&lt;/a&gt; on MSDN was very helpful and got me started on the right track with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.pathgeometry.aspx"&gt;PathGeometry&lt;/a&gt;. I was able to create the simplest scenario with a single slice from a circle with four slices:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Path &lt;/span&gt;&lt;span style="color: red"&gt;Stroke&lt;/span&gt;&lt;span style="color: blue"&gt;="Black" &lt;/span&gt;&lt;span style="color: red"&gt;StrokeThickness&lt;/span&gt;&lt;span style="color: blue"&gt;="1"&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Path.Data&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathGeometry&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathGeometry.Figures&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure &lt;/span&gt;&lt;span style="color: red"&gt;StartPoint&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50"&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure.Segments&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LineSegment &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="0,50" /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ArcSegment &lt;/span&gt;&lt;span style="color: red"&gt;Size&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50" &lt;/span&gt;&lt;span style="color: red"&gt;IsLargeArc&lt;/span&gt;&lt;span style="color: blue"&gt;="False"
                            &lt;/span&gt;&lt;span style="color: red"&gt;RotationAngle&lt;/span&gt;&lt;span style="color: blue"&gt;="90" &lt;/span&gt;&lt;span style="color: red"&gt;SweepDirection&lt;/span&gt;&lt;span style="color: blue"&gt;="CounterClockwise" &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="50,100" /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LineSegment &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50" /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure.Segments&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathGeometry.Figures&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathGeometry&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Path.Data&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The next step was to create the same quarter-circle except with two slices:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Path &lt;/span&gt;&lt;span style="color: red"&gt;Stroke&lt;/span&gt;&lt;span style="color: blue"&gt;="Black" &lt;/span&gt;&lt;span style="color: red"&gt;StrokeThickness&lt;/span&gt;&lt;span style="color: blue"&gt;="1"&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Path.Data&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathGeometry&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathGeometry.Figures&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure &lt;/span&gt;&lt;span style="color: red"&gt;StartPoint&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50"&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure.Segments&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LineSegment &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="0,50" /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ArcSegment
                            &lt;/span&gt;&lt;span style="color: red"&gt;Size&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50"
                            &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="14.645,85.355" 
                            &lt;/span&gt;&lt;span style="color: red"&gt;RotationAngle&lt;/span&gt;&lt;span style="color: blue"&gt;="45" 
                            &lt;/span&gt;&lt;span style="color: red"&gt;IsLargeArc&lt;/span&gt;&lt;span style="color: blue"&gt;="False"
                            &lt;/span&gt;&lt;span style="color: red"&gt;SweepDirection&lt;/span&gt;&lt;span style="color: blue"&gt;="CounterClockwise" 
                        /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LineSegment &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50" /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure.Segments&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                
                &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure &lt;/span&gt;&lt;span style="color: red"&gt;StartPoint&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50"&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure.Segments&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LineSegment &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="14.645,85.355" /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ArcSegment
                            &lt;/span&gt;&lt;span style="color: red"&gt;Size&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50"
                            &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="50, 100" 
                            &lt;/span&gt;&lt;span style="color: red"&gt;RotationAngle&lt;/span&gt;&lt;span style="color: blue"&gt;="45" 
                            &lt;/span&gt;&lt;span style="color: red"&gt;IsLargeArc&lt;/span&gt;&lt;span style="color: blue"&gt;="False"
                            &lt;/span&gt;&lt;span style="color: red"&gt;SweepDirection&lt;/span&gt;&lt;span style="color: blue"&gt;="CounterClockwise" 
                        /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LineSegment &lt;/span&gt;&lt;span style="color: red"&gt;Point&lt;/span&gt;&lt;span style="color: blue"&gt;="50,50" /&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure.Segments&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;                &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathFigure&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathGeometry.Figures&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;PathGeometry&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Path.Data&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;h4&gt;Step 3: Create a slice programmatically&lt;/h4&gt;
&lt;p&gt;The general idea is to create one slice and then rotate the slice around the circle to create the complete circle.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Create an ellipse using rotated slices to build the ellipse
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: navy"&gt;void &lt;/span&gt;&lt;span style="color: maroon"&gt;CreateSlicePaths&lt;/span&gt;(&lt;span style="color: #a65300"&gt;Canvas &lt;/span&gt;&lt;span style="color: maroon"&gt;cursorCanvas&lt;/span&gt;)
{
    &lt;span style="color: maroon"&gt;SliceCenterAngle &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;360.0&lt;/span&gt; / &lt;span style="color: maroon"&gt;SliceCount&lt;/span&gt;;

    &lt;span style="color: green"&gt;// Create Slices
    &lt;/span&gt;&lt;span style="color: navy"&gt;for &lt;/span&gt;(&lt;span style="color: navy"&gt;int &lt;/span&gt;&lt;span style="color: maroon"&gt;index &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;; &lt;span style="color: maroon"&gt;index &lt;/span&gt;&amp;lt; &lt;span style="color: maroon"&gt;SliceCount&lt;/span&gt;; ++&lt;span style="color: maroon"&gt;index&lt;/span&gt;)
    {
        &lt;span style="color: #a65300"&gt;PathFigure &lt;/span&gt;&lt;span style="color: maroon"&gt;pathFigure &lt;/span&gt;= &lt;span style="color: maroon"&gt;CreateSliceFigure&lt;/span&gt;();

        &lt;span style="color: #a65300"&gt;PathGeometry &lt;/span&gt;&lt;span style="color: maroon"&gt;pathGeometry &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;PathGeometry&lt;/span&gt;();
        &lt;span style="color: maroon"&gt;pathGeometry&lt;/span&gt;.&lt;span style="color: maroon"&gt;Figures&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;);

        &lt;span style="color: #a65300"&gt;Path &lt;/span&gt;&lt;span style="color: maroon"&gt;path &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;Path&lt;/span&gt;();
        &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;Stroke &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;SolidColorBrush&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Color&lt;/span&gt;.&lt;span style="color: maroon"&gt;FromArgb&lt;/span&gt;(&lt;span style="background: #e6ffff"&gt;255&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;));
        &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;StrokeThickness &lt;/span&gt;= &lt;span style="background: #e6ffff"&gt;1.0&lt;/span&gt;;
        &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;Data &lt;/span&gt;= &lt;span style="color: maroon"&gt;pathGeometry&lt;/span&gt;;

        &lt;span style="color: green"&gt;// Rotate the slice for all slices after the first slice
        &lt;/span&gt;&lt;span style="color: navy"&gt;if &lt;/span&gt;(&lt;span style="color: maroon"&gt;index &lt;/span&gt;&amp;gt; &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;)
        {
            &lt;span style="color: #a65300"&gt;RotateTransform &lt;/span&gt;&lt;span style="color: maroon"&gt;t1 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;RotateTransform&lt;/span&gt;();
            &lt;span style="color: maroon"&gt;t1&lt;/span&gt;.&lt;span style="color: maroon"&gt;CenterX &lt;/span&gt;= &lt;span style="color: maroon"&gt;RadiusX&lt;/span&gt;;
            &lt;span style="color: maroon"&gt;t1&lt;/span&gt;.&lt;span style="color: maroon"&gt;CenterY &lt;/span&gt;= &lt;span style="color: maroon"&gt;RadiusY&lt;/span&gt;;
            &lt;span style="color: maroon"&gt;t1&lt;/span&gt;.&lt;span style="color: maroon"&gt;Angle &lt;/span&gt;= &lt;span style="color: maroon"&gt;SliceCenterAngle &lt;/span&gt;* &lt;span style="color: maroon"&gt;index&lt;/span&gt;;

            &lt;span style="color: #a65300"&gt;TransformGroup &lt;/span&gt;&lt;span style="color: maroon"&gt;transformGroup &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;TransformGroup&lt;/span&gt;();
            &lt;span style="color: maroon"&gt;transformGroup&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;t1&lt;/span&gt;);
            &lt;span style="color: maroon"&gt;path&lt;/span&gt;.&lt;span style="color: maroon"&gt;RenderTransform &lt;/span&gt;= &lt;span style="color: maroon"&gt;transformGroup&lt;/span&gt;;
        }

        &lt;span style="color: maroon"&gt;cursorCanvas&lt;/span&gt;.&lt;span style="color: maroon"&gt;Children&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;path&lt;/span&gt;);
    }
}

&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Create the base shape for the slice
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: navy"&gt;private &lt;/span&gt;&lt;span style="color: #a65300"&gt;PathFigure &lt;/span&gt;&lt;span style="color: maroon"&gt;CreateSliceFigure&lt;/span&gt;()
{
    &lt;span style="color: green"&gt;// Start at the center of the ellipse
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;&lt;span style="color: maroon"&gt;point0 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(&lt;span style="color: maroon"&gt;RadiusX&lt;/span&gt;, &lt;span style="color: maroon"&gt;RadiusY&lt;/span&gt;);

    &lt;span style="color: green"&gt;// Next point is the left side of the ellipse
    //Point point1 = new Point(0.0, RadiusY); // if no rotation
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;&lt;span style="color: maroon"&gt;point1 &lt;/span&gt;= &lt;span style="color: maroon"&gt;CalculatePointOnEllipse&lt;/span&gt;(&lt;span style="color: maroon"&gt;SliceRotationAngle&lt;/span&gt;);

    &lt;span style="color: green"&gt;// Calculate the bottom point on the ellipse
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;&lt;span style="color: maroon"&gt;point2 &lt;/span&gt;= &lt;span style="color: maroon"&gt;CalculatePointOnEllipse&lt;/span&gt;(&lt;span style="color: maroon"&gt;SliceRotationAngle &lt;/span&gt;+ &lt;span style="color: maroon"&gt;SliceCenterAngle&lt;/span&gt;);

    &lt;span style="color: green"&gt;// Starting point
    &lt;/span&gt;&lt;span style="color: #a65300"&gt;PathFigure &lt;/span&gt;&lt;span style="color: maroon"&gt;pathFigure &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;PathFigure&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;StartPoint &lt;/span&gt;= &lt;span style="color: maroon"&gt;point0&lt;/span&gt;;

    &lt;span style="color: green"&gt;// Create the first line
    &lt;/span&gt;&lt;span style="color: #a65300"&gt;LineSegment &lt;/span&gt;&lt;span style="color: maroon"&gt;seg1 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;LineSegment&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;seg1&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point &lt;/span&gt;= &lt;span style="color: maroon"&gt;point1&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;Segments&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;seg1&lt;/span&gt;);

    &lt;span style="color: green"&gt;// Use an arc for the circular side
    &lt;/span&gt;&lt;span style="color: #a65300"&gt;ArcSegment &lt;/span&gt;&lt;span style="color: maroon"&gt;seg2 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;ArcSegment&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point &lt;/span&gt;= &lt;span style="color: maroon"&gt;point2&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;Size &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Size&lt;/span&gt;(&lt;span style="color: maroon"&gt;RadiusX&lt;/span&gt;, &lt;span style="color: maroon"&gt;RadiusY&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;RotationAngle &lt;/span&gt;= &lt;span style="color: maroon"&gt;SliceCenterAngle&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;IsLargeArc &lt;/span&gt;= (&lt;span style="color: maroon"&gt;SliceCenterAngle &lt;/span&gt;&amp;gt; &lt;span style="background: #e6ffff"&gt;180.0&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;seg2&lt;/span&gt;.&lt;span style="color: maroon"&gt;SweepDirection &lt;/span&gt;= &lt;span style="color: #2b91af"&gt;SweepDirection&lt;/span&gt;.&lt;span style="color: maroon"&gt;Counterclockwise&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;Segments&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;seg2&lt;/span&gt;);

    &lt;span style="color: green"&gt;// Close shape by going back to the starting point
    &lt;/span&gt;&lt;span style="color: #a65300"&gt;LineSegment &lt;/span&gt;&lt;span style="color: maroon"&gt;seg3 &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;LineSegment&lt;/span&gt;();
    &lt;span style="color: maroon"&gt;seg3&lt;/span&gt;.&lt;span style="color: maroon"&gt;Point &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(&lt;span style="color: maroon"&gt;point0&lt;/span&gt;.&lt;span style="color: maroon"&gt;X&lt;/span&gt;, &lt;span style="color: maroon"&gt;point0&lt;/span&gt;.&lt;span style="color: maroon"&gt;Y&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;Segments&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: maroon"&gt;seg3&lt;/span&gt;);

    &lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;IsClosed &lt;/span&gt;= &lt;span style="color: navy"&gt;true&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;.&lt;span style="color: maroon"&gt;IsFilled &lt;/span&gt;= &lt;span style="color: navy"&gt;true&lt;/span&gt;;

    &lt;span style="color: navy"&gt;return &lt;/span&gt;&lt;span style="color: maroon"&gt;pathFigure&lt;/span&gt;;
}

&lt;span style="color: gray"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color: green"&gt;Returns a point on the ellipse based on the rotationAngle, using
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &lt;/span&gt;&lt;span style="color: green"&gt;RadiusX/Y as the center (0, 0).
&lt;/span&gt;&lt;span style="color: gray"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: navy"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;&lt;span style="color: maroon"&gt;CalculatePointOnEllipse&lt;/span&gt;(&lt;span style="color: navy"&gt;double &lt;/span&gt;&lt;span style="color: maroon"&gt;rotationAngle&lt;/span&gt;)
{
    &lt;span style="color: navy"&gt;double &lt;/span&gt;&lt;span style="color: maroon"&gt;angleRadians &lt;/span&gt;= &lt;span style="color: maroon"&gt;rotationAngle &lt;/span&gt;* &lt;span style="color: #a65300"&gt;Math&lt;/span&gt;.&lt;span style="color: maroon"&gt;PI &lt;/span&gt;/ &lt;span style="background: #e6ffff"&gt;180.0&lt;/span&gt;;
    &lt;span style="color: navy"&gt;double &lt;/span&gt;&lt;span style="color: maroon"&gt;x &lt;/span&gt;= &lt;span style="color: #a65300"&gt;Math&lt;/span&gt;.&lt;span style="color: maroon"&gt;Cos&lt;/span&gt;(&lt;span style="color: maroon"&gt;angleRadians&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;x &lt;/span&gt;= &lt;span style="color: maroon"&gt;RadiusX &lt;/span&gt;* &lt;span style="color: maroon"&gt;x&lt;/span&gt;;
    &lt;span style="color: navy"&gt;double &lt;/span&gt;&lt;span style="color: maroon"&gt;y &lt;/span&gt;= &lt;span style="color: #a65300"&gt;Math&lt;/span&gt;.&lt;span style="color: maroon"&gt;Sin&lt;/span&gt;(&lt;span style="color: maroon"&gt;angleRadians&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;y &lt;/span&gt;= &lt;span style="color: maroon"&gt;RadiusY &lt;/span&gt;* &lt;span style="color: maroon"&gt;y&lt;/span&gt;;

    &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;&lt;span style="color: maroon"&gt;result &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(&lt;span style="color: maroon"&gt;x&lt;/span&gt;, &lt;span style="color: maroon"&gt;y&lt;/span&gt;);
    &lt;span style="color: maroon"&gt;result&lt;/span&gt;.&lt;span style="color: maroon"&gt;X &lt;/span&gt;= &lt;span style="color: maroon"&gt;RadiusX &lt;/span&gt;- &lt;span style="color: maroon"&gt;x&lt;/span&gt;;
    &lt;span style="color: maroon"&gt;result&lt;/span&gt;.&lt;span style="color: maroon"&gt;Y &lt;/span&gt;= &lt;span style="color: maroon"&gt;RadiusY &lt;/span&gt;+ &lt;span style="color: maroon"&gt;y&lt;/span&gt;;
    &lt;span style="color: navy"&gt;return &lt;/span&gt;&lt;span style="color: maroon"&gt;result&lt;/span&gt;;
}
&lt;/pre&gt;
&lt;h4&gt;Step 4: Going Forward&lt;/h4&gt;
&lt;p&gt;&lt;a href="http://nimblecoder.com/blog/images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart2_96B0/SpinningCursor1-TestPage_1.png"&gt;&lt;img height="181" alt="SpinningCursor1-TestPage" src="http://nimblecoder.com/blog/images/nimblecoder_com/blog/WindowsLiveWriter/SpinningWaitSymbolinSilverlightPart2_96B0/SpinningCursor1-TestPage_thumb_1.png" width="240" align="right" /&gt;&lt;/a&gt; Obviously this still needs a lot of improvement before it approaches the appeal of the Marble of Doom, which I will work on in the coming posts. However, the initial effort to create the "pizza" slices has been achieved and it is easier to build upon a base.&lt;/p&gt;
&lt;p&gt;I added a grid in the background when I had some difficulty with the path geometry, but it is useful to I added two text boxes for the number of slices and rotation angle so that I could see the shape update dynamically.&lt;/p&gt;
&lt;p&gt;Since I just used LineSegments to connect the slice points, the shape does not have the swirl or twist effect yet. Next time I will add the twist as well as rotation.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f5e14260-1dfe-4501-958f-a487a74b5e5d" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f10%2f20%2fspinning-wait-symbol-in-silverlight-part-2.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f10%2f20%2fspinning-wait-symbol-in-silverlight-part-2.aspx" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/73.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2008/10/20/spinning-wait-symbol-in-silverlight-part-2.aspx</guid>
            <pubDate>Mon, 20 Oct 2008 20:08:58 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/73.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2008/10/20/spinning-wait-symbol-in-silverlight-part-2.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/73.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/73.aspx</trackback:ping>
        </item>
        <item>
            <title>Spinning Wait Symbol in Silverlight</title>
            <link>http://nimblecoder.com/blog/archive/2008/10/08/spinning-wait-symbol-in-silverlight.aspx</link>
            <description>&lt;ul&gt; &lt;li&gt;Download: &lt;a href="/blog/Samples/Silverlight/RotatingHourGlass.zip"&gt;RotatingHourGlass&lt;/a&gt; VS2008 Source/Silverlight beta 2 (503 KB)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;My wife has a Treo with Windows Mobile and I when I was using it I noticed it had a cool rotating wait symbol, so I wondered how difficult it would be to build the symbol in &lt;a href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt;. The symbol is similar to the old &lt;a href="http://en.wikipedia.org/wiki/Beos"&gt;BeOS&lt;/a&gt; wait cursor and has as well as the &lt;a href="http://en.wikipedia.org/wiki/Spinning_wait_cursor_(Mac_OS_X)"&gt;Mac OS X wait cursor&lt;/a&gt; which I've always thought looks nice. At one point in time I created a Windows cursor that duplicated the look of the BeOS cursor but I don't use it anymore. If I found a really nice looking 24-bit cursor then I might use it again.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/CircularRotatingWaitSymbolinSilverlight_C269/Quadrant1.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="172" alt="Quadrant1" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/CircularRotatingWaitSymbolinSilverlight_C269/Quadrant1_thumb_3.png" width="177" align="right" border="0" /&gt;&lt;/a&gt;The first step is to create the four quadrants. I used the path geometry to create each quadrant, for example the first quadrant is: &lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: red"&gt;Data&lt;/span&gt;&lt;span style="color: blue"&gt;="M0,0 C0,0 100,0 100,100 L0,100 z"&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;For reference , the &lt;a title="Path Markup Syntax" href="http://msdn.microsoft.com/en-us/library/ms752293.aspx"&gt;path markup syntax&lt;/a&gt; is documented at MSDN. The shape starts at (0,0) and creates a curve point with a control point at (100,0) and end point at (100,100). Then there is a LineTo (0,100) and finally the close ("z") marker to complete the shape. While this is fairly easy through a graphical editor such as &lt;a href="http://www.microsoft.com/expression/"&gt;Expression Blend&lt;/a&gt; (&lt;a href="http://blogs.msdn.com/expression/default.aspx"&gt;blog&lt;/a&gt;), I created this manually so that I could have more control over the exact coordinates rather than relying on the graphical editor.&lt;/p&gt;
&lt;p&gt;I repeated the shape for each quadrant by adjusting the coordinates as necessary. It is also possible to simply apply a rotation to the shape so you have rotations of 90, 180, and 270 degrees, but remember to set the RenderTransformOrigin to the correct corner such as (0,1) to rotate by the bottom left corner.&lt;/p&gt;
&lt;p&gt;Once the quadrants are built, then I placed a rotating quadrant named 'Spinner' over the combined shape. I used an alpha mask on the spinner to differentiate it from the other quadrants. Finally, I added a Storyboard to rotate the 'Spinner' 360 degrees every two seconds:&lt;/p&gt;&lt;pre class="code"&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;="SpinStoryboard" &lt;/span&gt;&lt;span style="color: red"&gt;RepeatBehavior&lt;/span&gt;&lt;span style="color: blue"&gt;="Forever"&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DoubleAnimationUsingKeyFrames &lt;/span&gt;&lt;span style="color: red"&gt;BeginTime&lt;/span&gt;&lt;span style="color: blue"&gt;="00:00:00" &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetName&lt;/span&gt;&lt;span style="color: blue"&gt;="Spinner"
      &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetProperty&lt;/span&gt;&lt;span style="color: blue"&gt;="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SplineDoubleKeyFrame &lt;/span&gt;&lt;span style="color: red"&gt;KeyTime&lt;/span&gt;&lt;span style="color: blue"&gt;="00:00:02" &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;="360"/&amp;gt;
&lt;/span&gt;&lt;span style="background: #ffffe6"&gt;  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DoubleAnimationUsingKeyFrames&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;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;/pre&gt;
&lt;p&gt;The end result is a nice looking animation that is fairly simple. I'm tempted to try to duplicate the Mac OS X wait cursor, but that will have to wait until I have more time.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/CircularRotatingWaitSymbolinSilverlight_C269/SpinningCursorBlend.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Spinning Cursor in Blend" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/CircularRotatingWaitSymbolinSilverlight_C269/SpinningCursorBlend_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f10%2f08%2fspinning-wait-symbol-in-silverlight.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f10%2f08%2fspinning-wait-symbol-in-silverlight.aspx" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:15bb7f99-5d4f-4383-a8b5-f79f539a6bd1" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/72.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2008/10/08/spinning-wait-symbol-in-silverlight.aspx</guid>
            <pubDate>Wed, 08 Oct 2008 13:03:49 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/72.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2008/10/08/spinning-wait-symbol-in-silverlight.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/72.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/72.aspx</trackback:ping>
        </item>
        <item>
            <title>Bouncing Balls in Silverlight Part 1</title>
            <link>http://nimblecoder.com/blog/archive/2008/09/14/bouncing-balls-in-silverlight-part-1.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SimpleBouncingBallinSilverlight_13872/BounceTest.png" rel="lightbox"&gt;&lt;img height="200" alt="BounceTest" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/SimpleBouncingBallinSilverlight_13872/BounceTest_thumb_3.png" width="240" align="right" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="/blog/Samples/Silverlight/BounceTest1.zip"&gt;BounceTest1&lt;/a&gt; (104 KB): Source (VS2008) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Recently I wanted to make a very simple sample in &lt;a href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt; that used a little code to animate bouncing balls. The overall effect is fairly simple, but getting the sample down to the basics took a little time. As part of my research, I looked at several old bouncing ball demos using JavaScript and it was an eye-opening reminder of the dark ages of browsers and JavaScript.&lt;/p&gt;  &lt;p&gt;For the sample, I wanted to keep everything very simple. I started with a circle (ellipse with the same height and width) in a canvas. In order to move the ball, I chose to position the ball at (0, 0) and use a TranslateTransform to adjust the position. You could easily move the ball around with Left and Top, but I also plan to use RotateTransform in later samples so it makes sense to use a TransformGroup to manipulate the object.&lt;/p&gt;  &lt;p&gt;The XAML for the base page is just a Canvas and a rectangle that acts as a border. The ball is placed on the canvas using the common TransformGroup that is created by Expression Blend when you add a transform to an object. Expression Blend also uses the same order for the transforms (ScaleTransform, SkewTransform, RotateTransform, TranslateTransform) and will reorder the transforms back to this order if you adjust any transform using Blend (at least as of Blend 2.5 June 2008 Preview). Here is the XAML for the page:&lt;/p&gt;  &lt;pre class="xml" name="code"&gt;&amp;lt;UserControl x:Class="BounceTest.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300"&amp;gt;
    &amp;lt;Canvas x:Name="LayoutRoot"&amp;gt;
        &amp;lt;Rectangle x:Name="Boundary" Height="300" Width="400" 
            Canvas.Left="0" Canvas.Top="0"
            Fill="#FFFFFFFF" Stroke="#FF000000" /&amp;gt;
        &amp;lt;Ellipse x:Name="Ball01" Height="25" Width="25"
            Canvas.Left="0" Canvas.Top="0"
            Fill="#FFEE3131" Stroke="#FF000000"
            RenderTransformOrigin="0.5,0.5"&amp;gt;
            &amp;lt;Ellipse.RenderTransform&amp;gt;
                &amp;lt;TransformGroup&amp;gt;
                    &amp;lt;ScaleTransform/&amp;gt;
                    &amp;lt;SkewTransform/&amp;gt;
                    &amp;lt;RotateTransform/&amp;gt;
                    &amp;lt;TranslateTransform X="50" Y="50"/&amp;gt;
                &amp;lt;/TransformGroup&amp;gt;
            &amp;lt;/Ellipse.RenderTransform&amp;gt;
        &amp;lt;/Ellipse&amp;gt;
    &amp;lt;/Canvas&amp;gt;
&amp;lt;/UserControl&amp;gt;&lt;/pre&gt;

&lt;p&gt;I created a small class to manage the position and velocity of the ball. The constructor takes the source shape (the ball), the velocity, and the boundary shape. For this scenario, I assume that the ball already has the RotateTransform otherwise it throws an exception. The code could easily create a RotateTransform if it isn't present. The Update method takes the elapsed time since the previous method call. The boundary checking is extremely simple and just changes the direction of the motion when the ball hits a boundary edge. This obviously needs a lot of work for more complex scenarios, but it will do for this simple case.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;public class ShapeVelocity
{
	public Shape shape;
	public Vector velocity;
	public TranslateTransform translate;
	public Size bounds;
	public Size container;

	public ShapeVelocity(Shape AShape, Vector AVelocity, Shape BoundsContainer)
	{
		this.shape = AShape;
		this.velocity = AVelocity;

		var renderTransform = this.shape.RenderTransform;
		if (renderTransform is TransformGroup)
		{
			TransformGroup transformGroup = (TransformGroup)renderTransform;
			foreach (Transform transform in transformGroup.Children)
				if (transform is TranslateTransform)
					this.translate = (TranslateTransform)transform;
		}
		if (this.translate == null)
			throw new ArgumentException("Shape must have a TranslateTransform in it");

		container = new Size(BoundsContainer.Width, BoundsContainer.Height);
		bounds = new Size(
			this.shape.ActualWidth + this.shape.StrokeThickness,
			this.shape.ActualHeight + this.shape.StrokeThickness);
	}

	public void Update(TimeSpan Interval)
	{
		Rect pos = new Rect(
			translate.X,
			translate.Y,
			bounds.Width,
			bounds.Height);

		if ((velocity.X &amp;lt; 0.0) &amp;amp;&amp;amp; (pos.Left &amp;lt; 0.0))
			velocity.X = -velocity.X;
		else if ((velocity.X &amp;gt; 0.0) &amp;amp;&amp;amp; (pos.Right &amp;gt; container.Width))
			velocity.X = -velocity.X;
		if ((velocity.Y &amp;lt; 0.0) &amp;amp;&amp;amp; (pos.Top &amp;lt; 0.0))
			velocity.Y = -velocity.Y;
		else if ((velocity.Y &amp;gt; 0.0) &amp;amp;&amp;amp; (pos.Bottom &amp;gt; container.Height))
			velocity.Y = -velocity.Y;

		translate.X += velocity.X * (double) Interval.Milliseconds / 1000.0;
		translate.Y += velocity.Y * (double) Interval.Milliseconds / 1000.0;
	}
}&lt;/pre&gt;

&lt;p&gt;In anticipation of future examples, I used a List&amp;lt;Shape&amp;gt; collection to store the ball shape to updae the position. For the motion, I used the StoryBoard instead of a DispatcherTimer based on the &lt;a title="Procedural Animation in Silverlight 2" href="http://adamkinney.com/blog/339/default.aspx"&gt;recommendation&lt;/a&gt; of &lt;a href="http://adamkinney.com/"&gt;Adam Kinney&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;public partial class Page : UserControl
{
    private DateTime _lastTime = DateTime.MinValue;
    private double _initialSpeed = 50.0;
    private Storyboard _storyboard;
    private List&amp;lt;ShapeVelocity&amp;gt; _shapes;

    public Page()
    {
        InitializeComponent();
        _shapes = new List&amp;lt;ShapeVelocity&amp;gt;();
        _storyboard = new Storyboard();
        _storyboard.Duration = TimeSpan.FromMilliseconds(10);
        _storyboard.Completed += new EventHandler(storyboard_Tick);
        this.Loaded += new RoutedEventHandler(Page_Loaded);
    }

    void Page_Loaded(object sender, RoutedEventArgs e)
    {
        _shapes.Add(new ShapeVelocity(Ball01, new Vector(_initialSpeed, _initialSpeed), Boundary));
        _lastTime = System.DateTime.Now;
        _storyboard.Begin();
    }

    void storyboard_Tick(object sender, EventArgs e)
    {
        DateTime now = System.DateTime.Now;
        TimeSpan interval = now - _lastTime;
        foreach (ShapeVelocity s in _shapes)
        {
            s.Update(interval);
        }
        _lastTime = now;
        _storyboard.Begin();
    }
}&lt;/pre&gt;

&lt;p&gt;So that is the very simple bouncing ball sample.&lt;/p&gt;

&lt;div id="silverlightControlHost"&gt;&lt;object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="400px" height="300px"&gt;
    &lt;param name="source" value="ClientBin/BounceTest1.xap" /&gt;
    &lt;param name="background" value="white" /&gt;

    &lt;a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;"&gt;
      &lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt;
    &lt;/a&gt;
  &lt;/object&gt;&lt;iframe style="border-top-width: 0px; border-left-width: 0px; visibility: hidden; border-bottom-width: 0px; width: 0px; height: 0px; border-right-width: 0px" /&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f09%2f14%2fbouncing-balls-in-silverlight-part-1.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.nimblecoder.com%2fblog%2farchive%2f2008%2f09%2f14%2fbouncing-balls-in-silverlight-part-1.aspx" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:4f75fff4-67d0-445c-aaea-3d26857c8525" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/71.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2008/09/14/bouncing-balls-in-silverlight-part-1.aspx</guid>
            <pubDate>Mon, 15 Sep 2008 04:28:30 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/71.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2008/09/14/bouncing-balls-in-silverlight-part-1.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/71.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/71.aspx</trackback:ping>
        </item>
        <item>
            <title>On Sample Simplicity</title>
            <link>http://nimblecoder.com/blog/archive/2008/06/13/on-sample-simplicity.aspx</link>
            <description>&lt;p&gt;I was working through a Communications sample of connecting &lt;a href="http://silverlight.net/" target="_blank"&gt;SilverLight&lt;/a&gt; to &lt;a href="http://en.wikipedia.org/wiki/Plain_Old_XML" target="_blank"&gt;POX&lt;/a&gt;, then &lt;a href="http://en.wikipedia.org/wiki/Web_services" target="_blank"&gt;Web Services&lt;/a&gt;, and finally &lt;a href="http://msdn.microsoft.com/en-us/library/ms735119.aspx" target="_blank"&gt;WCF&lt;/a&gt; and I came across the following instructions:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;(Part 1: POX) The Generic handler will process an incoming request using the code declared in the &lt;em&gt;ProcessRequest&lt;/em&gt; function. This function should create some new instances of CityData and add them to the myCities list. Here are some examples of cities with longitude and latitude { (London, 51.5, 0), (Stratford-upon-Avon, 52.3, -1.71), (Edinburgh, 55.95, -3.16) }. See if you can write the code to do this.&lt;/p&gt; &lt;p&gt;(And later in the lab...)&lt;/p&gt; &lt;p&gt;In this example your ASHX served up hard-coded data for 1 city. Can you build it so that it can accept parameters on the URI string (i.e. http://localhost:8001/Sample1Web/GetData.ashx?city=whatever)?&lt;/p&gt; &lt;p&gt;(And even further in the lab...)&lt;/p&gt; &lt;p&gt;Write a function that takes in a country and builds a List&amp;lt;CityData&amp;gt; of several cities for that country. Here are some cities and their latitudes and longitudes:&lt;/p&gt;&lt;pre class="code"&gt;(&lt;span style="background: #ffffe6"&gt;"Paris"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.87&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;2.33&lt;/span&gt;);
(&lt;span style="background: #ffffe6"&gt;"Lourdes"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.1&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0.05&lt;/span&gt;);
(&lt;span style="background: #ffffe6"&gt;"Toulouse"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.6&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;1.38&lt;/span&gt;);
(&lt;span style="background: #ffffe6"&gt;"London"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;51.5&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;);
(&lt;span style="background: #ffffe6"&gt;"Stratford-Upon-Avon"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;52.3&lt;/span&gt;, -&lt;span style="background: #e6ffff"&gt;1.71&lt;/span&gt;);
(&lt;span style="background: #ffffe6"&gt;"Edinburgh"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;55.95&lt;/span&gt;, -&lt;span style="background: #e6ffff"&gt;3.16&lt;/span&gt;);
(&lt;span style="background: #ffffe6"&gt;"Berlin"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;52.52&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;13.42&lt;/span&gt;);
(&lt;span style="background: #ffffe6"&gt;"Munich"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.13&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;11.57&lt;/span&gt;);
(&lt;span style="background: #ffffe6"&gt;"Hamburg"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;53.58&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;9.98&lt;/span&gt;);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/blockquote&gt;
&lt;h3&gt;Provided Solution&lt;/h3&gt;
&lt;p&gt;The sample provided "solution" code at the end of the instructions. The code is basic and unimaginative, but perhaps that is all the is needed of sample code (I would offer that samples are the perfect to push the boundaries -- lead by example).&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// File: CityData.cs
&lt;/span&gt;&lt;span style="color: navy"&gt;public class &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData
&lt;/span&gt;{
    &lt;span style="color: navy"&gt;public string &lt;/span&gt;&lt;span style="color: maroon"&gt;CityName &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;set&lt;/span&gt;; }
    &lt;span style="color: navy"&gt;public double &lt;/span&gt;&lt;span style="color: maroon"&gt;Latitude &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;set&lt;/span&gt;; }
    &lt;span style="color: navy"&gt;public double &lt;/span&gt;&lt;span style="color: maroon"&gt;Longitude &lt;/span&gt;{ &lt;span style="color: navy"&gt;get&lt;/span&gt;; &lt;span style="color: navy"&gt;set&lt;/span&gt;; }

    &lt;span style="color: navy"&gt;public &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;strCityName&lt;/span&gt;, &lt;span style="color: navy"&gt;double &lt;/span&gt;&lt;span style="color: maroon"&gt;nLatitude&lt;/span&gt;, &lt;span style="color: navy"&gt;double &lt;/span&gt;&lt;span style="color: maroon"&gt;nLongitude&lt;/span&gt;)
    {
        &lt;span style="color: maroon"&gt;CityName &lt;/span&gt;= &lt;span style="color: maroon"&gt;strCityName&lt;/span&gt;;
        &lt;span style="color: maroon"&gt;Latitude &lt;/span&gt;= &lt;span style="color: maroon"&gt;nLatitude&lt;/span&gt;;
        &lt;span style="color: maroon"&gt;Longitude &lt;/span&gt;= &lt;span style="color: maroon"&gt;nLongitude&lt;/span&gt;;
    }

    &lt;span style="color: navy"&gt;public &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;()
    {
    }
}

&lt;span style="color: green"&gt;// File: GetData.ashx
&lt;/span&gt;&lt;span style="color: navy"&gt;public class &lt;/span&gt;&lt;span style="color: maroon"&gt;GetData &lt;/span&gt;: &lt;span style="color: maroon"&gt;IHttpHandler
&lt;/span&gt;{
    &lt;span style="color: navy"&gt;private &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt; &lt;span style="color: maroon"&gt;getCities&lt;/span&gt;(&lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;)
    {
        &lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt; &lt;span style="color: maroon"&gt;ret &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt;();

        &lt;span style="color: navy"&gt;switch &lt;/span&gt;(&lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;)
        {
        &lt;span style="color: navy"&gt;case &lt;/span&gt;&lt;span style="background: #ffffe6"&gt;"france"&lt;/span&gt;:
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Paris"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.87&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;2.33&lt;/span&gt;));
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Lourdes"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.1&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0.05&lt;/span&gt;));
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Toulouse"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.6&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;1.38&lt;/span&gt;));
            &lt;span style="color: navy"&gt;break&lt;/span&gt;;

        &lt;span style="color: navy"&gt;case &lt;/span&gt;&lt;span style="background: #ffffe6"&gt;"uk"&lt;/span&gt;:
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"London"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;51.5&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;));
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Stratford-Upon-Avon"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;52.3&lt;/span&gt;, -&lt;span style="background: #e6ffff"&gt;1.71&lt;/span&gt;));
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Edinburgh"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;55.95&lt;/span&gt;, -&lt;span style="background: #e6ffff"&gt;3.16&lt;/span&gt;));
            &lt;span style="color: navy"&gt;break&lt;/span&gt;;

        &lt;span style="color: navy"&gt;case &lt;/span&gt;&lt;span style="background: #ffffe6"&gt;"germany"&lt;/span&gt;:
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Berlin"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;52.52&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;13.42&lt;/span&gt;));
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Munich"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.13&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;11.57&lt;/span&gt;));
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Hamburg"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;53.58&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;9.98&lt;/span&gt;));
            &lt;span style="color: navy"&gt;break&lt;/span&gt;;

        &lt;span style="color: navy"&gt;default&lt;/span&gt;:
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"London"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;51.5&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;));
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Stratford-Upon-Avon"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;52.3&lt;/span&gt;, -&lt;span style="background: #e6ffff"&gt;1.71&lt;/span&gt;));
            &lt;span style="color: maroon"&gt;ret&lt;/span&gt;.&lt;span style="color: maroon"&gt;Add&lt;/span&gt;(&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Edinburgh"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;55.95&lt;/span&gt;, -&lt;span style="background: #e6ffff"&gt;3.16&lt;/span&gt;));
            &lt;span style="color: navy"&gt;break&lt;/span&gt;;
        }
        &lt;span style="color: navy"&gt;return &lt;/span&gt;&lt;span style="color: maroon"&gt;ret&lt;/span&gt;;
    }
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;h3&gt;Alternative 1&lt;/h3&gt;
&lt;p&gt;I wanted to explore alternatives to the supplied code, so I decided to initialize the CityData list with the data instead of using "Add". In C++ this was more efficient (it set the initial list size instead of using the default capacity sizing algorithm among other things), but I'm not sure of performance in terms of C#. I would not expect any significant performance difference with this small sample though.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;public &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt; &lt;span style="color: maroon"&gt;getCities&lt;/span&gt;(&lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;)
{
    &lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt; &lt;span style="color: maroon"&gt;ret &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt;();

    &lt;span style="color: navy"&gt;switch &lt;/span&gt;( &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;.&lt;span style="color: maroon"&gt;ToLower&lt;/span&gt;() )
    {
        &lt;span style="color: navy"&gt;case &lt;/span&gt;&lt;span style="background: #ffffe6"&gt;"france"&lt;/span&gt;:
            &lt;span style="color: maroon"&gt;ret &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt;() {
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Paris"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.87&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;2.33&lt;/span&gt;),
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Lourdes"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.1&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0.05&lt;/span&gt;),
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Toulouse"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.6&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;1.38&lt;/span&gt;)
            };
            &lt;span style="color: navy"&gt;break&lt;/span&gt;;

        &lt;span style="color: navy"&gt;case &lt;/span&gt;&lt;span style="background: #ffffe6"&gt;"germany"&lt;/span&gt;:
            &lt;span style="color: maroon"&gt;ret &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt;() {
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Berlin"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;52.52&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;13.42&lt;/span&gt;),
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Munich"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.13&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;11.57&lt;/span&gt;),
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Hamburg"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;53.58&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;9.98&lt;/span&gt;)
            };
            &lt;span style="color: navy"&gt;break&lt;/span&gt;;

        &lt;span style="color: navy"&gt;case &lt;/span&gt;&lt;span style="background: #ffffe6"&gt;"uk"&lt;/span&gt;:
        &lt;span style="color: navy"&gt;default&lt;/span&gt;:
            &lt;span style="color: maroon"&gt;strCountry &lt;/span&gt;= &lt;span style="background: #ffffe6"&gt;"UK"&lt;/span&gt;;
            &lt;span style="color: maroon"&gt;ret &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt;() {
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"London"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;51.5&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0&lt;/span&gt;),
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Stratford-Upon-Avon"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;52.3&lt;/span&gt;, -&lt;span style="background: #e6ffff"&gt;1.71&lt;/span&gt;),
                &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Edinburgh"&lt;/span&gt;, &lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;55.95&lt;/span&gt;, -&lt;span style="background: #e6ffff"&gt;3.16&lt;/span&gt;)
            };
            &lt;span style="color: navy"&gt;break&lt;/span&gt;;
    }
    &lt;span style="color: navy"&gt;return &lt;/span&gt;&lt;span style="color: maroon"&gt;ret&lt;/span&gt;;
}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;h3&gt;Alternative 2&lt;/h3&gt;
&lt;p&gt;I haven't worked very much with LINQ, so I wanted to compare the same functionality using LINQ. I added a string "Country" to the CityData class and here is the result:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;private static &lt;/span&gt;&lt;span style="color: #a65300"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt; &lt;span style="color: maroon"&gt;cityList &lt;/span&gt;= &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: #a65300"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt;()
{
    &lt;span style="color: green"&gt;// UK
    &lt;/span&gt;&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Paris"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"UK"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.87&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;2.33&lt;/span&gt;),
    &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Lourdes"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"UK"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.1&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0.05&lt;/span&gt;),
    &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Toulouse"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"UK"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.6&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;1.38&lt;/span&gt;),

    &lt;span style="color: green"&gt;// France
    &lt;/span&gt;&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Paris"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"France"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.87&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;2.33&lt;/span&gt;),
    &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Lourdes"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"France"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.1&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;0.05&lt;/span&gt;),
    &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Toulouse"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"France"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;43.6&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;1.38&lt;/span&gt;),

    &lt;span style="color: green"&gt;// Germany
    &lt;/span&gt;&lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Berlin"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"Germany"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;52.52&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;13.42&lt;/span&gt;),
    &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Munich"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"Germany"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;48.13&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;11.57&lt;/span&gt;),
    &lt;span style="color: navy"&gt;new &lt;/span&gt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"Hamburg"&lt;/span&gt;, &lt;span style="background: #ffffe6"&gt;"Germany"&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;53.58&lt;/span&gt;, &lt;span style="background: #e6ffff"&gt;9.98&lt;/span&gt;)
};

&lt;span style="color: navy"&gt;public &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt; &lt;span style="color: maroon"&gt;getCities&lt;/span&gt;(&lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;strCountry&lt;/span&gt;)
{
    &lt;span style="color: maroon"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt; &lt;span style="color: maroon"&gt;data &lt;/span&gt;= &lt;span style="color: maroon"&gt;from city &lt;/span&gt;&lt;span style="color: navy"&gt;in &lt;/span&gt;&lt;span style="color: maroon"&gt;cityList
                                 where city&lt;/span&gt;.&lt;span style="color: maroon"&gt;Country &lt;/span&gt;== &lt;span style="color: maroon"&gt;strCountry
                                 select city&lt;/span&gt;;
    &lt;span style="color: navy"&gt;return new &lt;/span&gt;&lt;span style="color: maroon"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: maroon"&gt;CityData&lt;/span&gt;&amp;gt;(&lt;span style="color: maroon"&gt;data&lt;/span&gt;);
}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;This is still not the most efficient or optimal method, but I think it looks nice and is helps introduce LINQ in an understandable manner.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Samples and labs should be simple and yet it is a perfect time to include new technologies and push the boundaries so to speak. One thing I certainly don't want to see in samples are basic programming inefficiencies (things that make you cringe) due to lack of effort by the sample creator. That was not necessarily the case with this sample, but it would have been better to present alternatives such as the examples I listed.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:673666a2-582b-4be1-983b-acae922063a9" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;, &lt;a href="http://technorati.com/tags/LINQ" rel="tag"&gt;LINQ&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/69.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2008/06/13/on-sample-simplicity.aspx</guid>
            <pubDate>Fri, 13 Jun 2008 21:08:44 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/69.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2008/06/13/on-sample-simplicity.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/69.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/69.aspx</trackback:ping>
        </item>
    </channel>
</rss>
