<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>C#</title>
        <link>http://www.nimblecoder.com/blog/category/1.aspx</link>
        <description>C-Sharp</description>
        <language>en-US</language>
        <copyright>Ryan Van Slooten</copyright>
        <generator>Subtext Version 2.1.1.1</generator>
        <item>
            <title>Using a delegate and Custom Appender with log4net to display live log text</title>
            <link>http://nimblecoder.com/blog/archive/2009/01/30/using-a-delegate-and-custom-appender-with-log4net-to-display.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/Displayinglivelogtextinapplicationusingl_C7AE/log4netAppender.png" rel="lightbox"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" title="log4netAppender sample" alt="log4netAppender sample" align="right" src="http://www.nimblecoder.com/blog/Images/nimblecoder_com/blog/WindowsLiveWriter/Displayinglivelogtextinapplicationusingl_C7AE/log4netAppender_thumb.png" width="240" height="180" /&gt;&lt;/a&gt; Recently I needed to display the text that was sent to log4net in a TextBox in a Form. It turns out this is very easy to do using a custom appender and the AppenderSkeleton. The custom appender uses a delegate to allow the host program to define a callback function to handle the log text as necessary.&lt;/p&gt; &lt;h4&gt;1. Create a new custom appender class&lt;/h4&gt; &lt;p&gt;I named my appender DelegateAppender because it needed to use a delegate to pass the text to the Form.&lt;/p&gt; &lt;pre class="code"&gt;&lt;span style="color: navy"&gt;using &lt;/span&gt;&lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Core&lt;/span&gt;;

&lt;span style="color: navy"&gt;namespace &lt;/span&gt;&lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Appender
&lt;/span&gt;{
    &lt;span style="color: navy"&gt;public delegate void &lt;/span&gt;&lt;span style="color: #2b91af"&gt;LogTextAppend&lt;/span&gt;(&lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;text&lt;/span&gt;);

    &lt;span style="color: navy"&gt;public class &lt;/span&gt;&lt;span style="color: #a65300"&gt;DelegateAppender &lt;/span&gt;: &lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Appender&lt;/span&gt;.&lt;span style="color: #a65300"&gt;AppenderSkeleton
    &lt;/span&gt;{
        &lt;span style="color: navy"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;LogTextAppend &lt;/span&gt;&lt;span style="color: maroon"&gt;logTextAppend&lt;/span&gt;;

        &lt;span style="color: navy"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;LogTextAppend &lt;/span&gt;&lt;span style="color: maroon"&gt;LogTextMethod
        &lt;/span&gt;{
            &lt;span style="color: navy"&gt;get &lt;/span&gt;{ &lt;span style="color: navy"&gt;return &lt;/span&gt;&lt;span style="color: maroon"&gt;logTextAppend&lt;/span&gt;; }
            &lt;span style="color: navy"&gt;set &lt;/span&gt;{ &lt;span style="color: maroon"&gt;logTextAppend &lt;/span&gt;= &lt;span style="color: navy"&gt;value&lt;/span&gt;; }
        }

        &lt;span style="color: navy"&gt;public &lt;/span&gt;&lt;span style="color: maroon"&gt;DelegateAppender&lt;/span&gt;()
        {
            &lt;span style="color: maroon"&gt;logTextAppend &lt;/span&gt;= &lt;span style="color: maroon"&gt;EmptyAppend&lt;/span&gt;;
        }

        &lt;span style="color: navy"&gt;private void &lt;/span&gt;&lt;span style="color: maroon"&gt;EmptyAppend&lt;/span&gt;(&lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;text&lt;/span&gt;)
        {
            &lt;span style="color: green"&gt;// Do nothing
        &lt;/span&gt;}

        &lt;span style="color: navy"&gt;protected override void &lt;/span&gt;&lt;span style="color: maroon"&gt;Append&lt;/span&gt;(&lt;span style="color: #a65300"&gt;LoggingEvent &lt;/span&gt;&lt;span style="color: maroon"&gt;loggingEvent&lt;/span&gt;)
        {
            &lt;span style="color: navy"&gt;if &lt;/span&gt;(&lt;span style="color: maroon"&gt;logTextAppend &lt;/span&gt;!= &lt;span style="color: navy"&gt;null&lt;/span&gt;)
                &lt;span style="color: maroon"&gt;logTextAppend&lt;/span&gt;(&lt;span style="color: maroon"&gt;RenderLoggingEvent&lt;/span&gt;(&lt;span style="color: maroon"&gt;loggingEvent&lt;/span&gt;));
        }
    }
}
&lt;/pre&gt;
&lt;h4&gt;2. Create and assign the delegate to the appender&lt;/h4&gt;
&lt;p&gt;As far as I could tell, there was no easy way to specify the delegate to use in the configuration of the DelegateAppender. Therefore I added a simple method to assign the delegate in the Form to the DelegateAppender.&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: navy"&gt;public void &lt;/span&gt;&lt;span style="color: maroon"&gt;AddStatus&lt;/span&gt;(&lt;span style="color: navy"&gt;string &lt;/span&gt;&lt;span style="color: maroon"&gt;message&lt;/span&gt;)
{
    &lt;span style="color: maroon"&gt;textBoxStatus&lt;/span&gt;.&lt;span style="color: maroon"&gt;AppendText&lt;/span&gt;(&lt;span style="color: maroon"&gt;message&lt;/span&gt;);
}

&lt;span style="color: navy"&gt;private void &lt;/span&gt;&lt;span style="color: maroon"&gt;InitializeLogging&lt;/span&gt;()
{
    &lt;span style="color: navy"&gt;bool &lt;/span&gt;&lt;span style="color: maroon"&gt;initialized &lt;/span&gt;= &lt;span style="color: navy"&gt;false&lt;/span&gt;;

    &lt;span style="color: navy"&gt;if &lt;/span&gt;(!&lt;span style="color: maroon"&gt;log&lt;/span&gt;.&lt;span style="color: maroon"&gt;Logger&lt;/span&gt;.&lt;span style="color: maroon"&gt;Repository&lt;/span&gt;.&lt;span style="color: maroon"&gt;Configured&lt;/span&gt;)
    {
        &lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Config&lt;/span&gt;.&lt;span style="color: #a65300"&gt;XmlConfigurator&lt;/span&gt;.&lt;span style="color: maroon"&gt;Configure&lt;/span&gt;();
        &lt;span style="color: maroon"&gt;textBoxStatus&lt;/span&gt;.&lt;span style="color: maroon"&gt;AppendText&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"WARNING: log4net not automatically configured. "&lt;/span&gt; +
            &lt;span style="background: #ffffe6"&gt;"Check AssemblyInfo.cs for - "&lt;/span&gt; +
            &lt;span style="background: #ffffe6"&gt;"[assembly: log4net.Config.XmlConfigurator(Watch=true)]\r\n"&lt;/span&gt;);
    }

    &lt;span style="color: navy"&gt;foreach &lt;/span&gt;(&lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Appender&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;IAppender &lt;/span&gt;&lt;span style="color: maroon"&gt;appender &lt;/span&gt;&lt;span style="color: navy"&gt;in &lt;/span&gt;&lt;span style="color: maroon"&gt;log&lt;/span&gt;.&lt;span style="color: maroon"&gt;Logger&lt;/span&gt;.&lt;span style="color: maroon"&gt;Repository&lt;/span&gt;.&lt;span style="color: maroon"&gt;GetAppenders&lt;/span&gt;())
    {
        &lt;span style="color: navy"&gt;if &lt;/span&gt;(&lt;span style="color: maroon"&gt;appender&lt;/span&gt;.&lt;span style="color: maroon"&gt;GetType&lt;/span&gt;() == &lt;span style="color: navy"&gt;typeof&lt;/span&gt;(&lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Appender&lt;/span&gt;.&lt;span style="color: #a65300"&gt;DelegateAppender&lt;/span&gt;))
        {
            &lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Appender&lt;/span&gt;.&lt;span style="color: #a65300"&gt;DelegateAppender &lt;/span&gt;&lt;span style="color: maroon"&gt;delegateAppender &lt;/span&gt;= (&lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Appender&lt;/span&gt;.&lt;span style="color: #a65300"&gt;DelegateAppender&lt;/span&gt;) &lt;span style="color: maroon"&gt;appender&lt;/span&gt;;
            &lt;span style="color: green"&gt;// .NET 2.0+
            &lt;/span&gt;&lt;span style="color: maroon"&gt;delegateAppender&lt;/span&gt;.&lt;span style="color: maroon"&gt;LogTextMethod &lt;/span&gt;= &lt;span style="color: navy"&gt;this&lt;/span&gt;.&lt;span style="color: maroon"&gt;AddStatus&lt;/span&gt;;
            &lt;span style="color: green"&gt;// .NET 1.1
            //delegateAppender.LogTextMethod = new log4net.Appender.LogTextAppend(this.AddStatus);
            &lt;/span&gt;&lt;span style="color: maroon"&gt;initialized &lt;/span&gt;= &lt;span style="color: navy"&gt;true&lt;/span&gt;;
        }
    }

    &lt;span style="color: navy"&gt;if &lt;/span&gt;(!&lt;span style="color: maroon"&gt;initialized&lt;/span&gt;)
    {
        &lt;span style="color: maroon"&gt;textBoxStatus&lt;/span&gt;.&lt;span style="color: maroon"&gt;AppendText&lt;/span&gt;(&lt;span style="background: #ffffe6"&gt;"ERROR: Unable to add DelegateAppender to logging!\r\n"&lt;/span&gt;);
    }
}
&lt;/pre&gt;
&lt;h4&gt;3. Add the log4net configuration to app.config and AssemblyInfo.cs&lt;/h4&gt;
&lt;p&gt;The code for AssemblyInfo.cs just tells log4net to configure itself and also watch for changes.&lt;/p&gt;
&lt;pre class="code"&gt;[&lt;span style="color: navy"&gt;assembly&lt;/span&gt;: &lt;span style="color: maroon"&gt;log4net&lt;/span&gt;.&lt;span style="color: maroon"&gt;Config&lt;/span&gt;.&lt;span style="color: #a65300"&gt;XmlConfigurator&lt;/span&gt;(&lt;span style="color: maroon"&gt;Watch &lt;/span&gt;= &lt;span style="color: navy"&gt;true&lt;/span&gt;)]
&lt;/pre&gt;

&lt;p&gt;The app.config is as follows:  &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;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;1.0&lt;/span&gt;" &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;" &lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;configSections&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;section
   &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;log4net&lt;/span&gt;"
   &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;log4net.Config.Log4NetConfigurationSectionHandler, log4net&lt;/span&gt;"
  &lt;span style="color: blue"&gt;/&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;configSections&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

 &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;log4net&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;logger &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;log4netAppender.LogTestForm&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;level &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;ALL&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;logger&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;root&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;level &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;ALL&lt;/span&gt;" &lt;span style="color: blue"&gt;/&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;appender-ref &lt;/span&gt;&lt;span style="color: red"&gt;ref&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;DelegateAppender&lt;/span&gt;" &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;root&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;appender
    &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;DelegateAppender&lt;/span&gt;"
    &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;log4net.Appender.DelegateAppender&lt;/span&gt;" &lt;span style="color: blue"&gt;&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layout &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;log4net.Layout.PatternLayout&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;param
     &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;ConversionPattern&lt;/span&gt;"
     &lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;%m%n&lt;/span&gt;"
    &lt;span style="color: blue"&gt;/&amp;gt;
   &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layout&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;appender&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;log4net&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;And there is a simple example of how to create a custom appender with log4net and hook it into an application.&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:96ab4fb1-d58f-447e-b5a9-214dd4b0e2f7" class="wlWriterEditableSmartContent"&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/log4net" rel="tag"&gt;log4net&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/76.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2009/01/30/using-a-delegate-and-custom-appender-with-log4net-to-display.aspx</guid>
            <pubDate>Fri, 30 Jan 2009 18:42:19 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/76.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2009/01/30/using-a-delegate-and-custom-appender-with-log4net-to-display.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/76.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/76.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>3</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>
        <item>
            <title>Automatically setting the Specified property in WSDL Generated files</title>
            <link>http://nimblecoder.com/blog/archive/2008/04/01/automatically-setting-the-specified-property-in-wsdl-generated-files.aspx</link>
            <description>&lt;p&gt;The wsdl.exe tool with Visual Studio can be used to manually generate a code file to use with a project. If you use the nillable or minOccurs attributes in the XSD though, the wsdl.exe tool generates a boolean 'Specified' field that must be set to true in order to transmit the data through the web service. For example:&lt;/p&gt; &lt;h3&gt;WSDL File (myfile.wsdl)&lt;/h3&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;xs:element&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="duedate"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="xs:dateTime"&lt;/span&gt; &lt;span class="attr"&gt;nillable&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;minOccurs&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;maxOccurs&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;Generated CS File (wsdl.exe myfile.wsdl)&lt;/h3&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// ...&lt;/span&gt;

&lt;span class="kwrd"&gt;private&lt;/span&gt; System.Nullable&amp;lt;System.DateTime&amp;gt; duedateField;

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; duedateFieldSpecified;

&lt;span class="rem"&gt;// ...&lt;/span&gt;

&lt;span class="rem"&gt;/// &amp;lt;remarks/&amp;gt;&lt;/span&gt;
[System.Xml.Serialization.XmlElementAttribute(IsNullable=&lt;span class="kwrd"&gt;true&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; System.Nullable&amp;lt;System.DateTime&amp;gt; duedate {
    get {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.duedateField;
    }
    set {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.duedateField = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
    }
}

&lt;span class="rem"&gt;/// &amp;lt;remarks/&amp;gt;&lt;/span&gt;
[System.Xml.Serialization.XmlIgnoreAttribute()]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; duedateSpecified {
    get {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.duedateFieldSpecified;
    }
    set {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.duedateFieldSpecified = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
    }
}
&lt;/pre&gt;
&lt;h3&gt;"Breaking Change"&lt;/h3&gt;
&lt;p&gt;What I wanted was simply add the line to the 'duedate' setter to check if the newly assigned value was null or not (the assumption is that a non-null value would mean the field is 'specified'):&lt;/p&gt;&lt;pre class="csharpcode"&gt;    set {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.duedateField = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
&lt;span style="background-color: #ecf6f9"&gt;        &lt;span class="kwrd"&gt;this&lt;/span&gt;.duedateFieldSpecified = (&lt;span class="kwrd"&gt;value&lt;/span&gt; != &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;/span&gt;
    }

&lt;/pre&gt;
&lt;p&gt;I looked around for a solution, but all I found a &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=90727" target="_blank"&gt;very good suggestion&lt;/a&gt; to add this functionality to the wsdl.exe tool. Unfortunately the status was "Closed (Won't Fix)" and the comment was:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Thank you for the suggestion.&lt;br /&gt;This would be nice enhancement, but unfortunately this also is a breaking change: in the previous versions of the .net framework setting value of 'xxx' field did not toggle the xxxSepcified value, so if we change this runtime behavior of some existing applications may change and will require user code change to run the same way as before.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;On the contrary, I contend it would not be difficult or breaking to simply add the functionality through optional parameters, such as: 
&lt;/p&gt;&lt;p&gt;wsdl.exe /autospecified:1 myfile.wsdl 
&lt;/p&gt;&lt;p&gt;The optional parameters would not affect default operation nor break existing code, but instead we have to deal with a short-sighted decision. 
&lt;/p&gt;&lt;h3&gt;Quick and Dirty Solution&lt;/h3&gt;
&lt;p&gt;I decided to write a quick script to try and automatically generate the extra line of code for each setter. I decided to use awk (there are a number of sources for a Windows awk/gawk - &lt;a href="http://www.cygwin.com/" target="_blank"&gt;cygwin&lt;/a&gt;, &lt;a href="http://unxutils.sourceforge.net/" target="_blank"&gt;unxutils&lt;/a&gt;, and more) as it is very quick to implement and script. The following script is the result:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;#!/usr/bin/awk -f&lt;/span&gt;

&lt;span class="rem"&gt;# This is a quick and dirty script to add automatically set the&lt;/span&gt;
&lt;span class="rem"&gt;# 'myFieldSpecified' variables generated from the Visual Studio&lt;/span&gt;
&lt;span class="rem"&gt;# wsdl.exe tool. The script searches for System.Nullable types &lt;/span&gt;
&lt;span class="rem"&gt;# (myField) and verifies a specified variable exists &lt;/span&gt;
&lt;span class="rem"&gt;# (myFieldSpecified). It then searches for the setter and adds&lt;/span&gt;
&lt;span class="rem"&gt;# the line: this.myFieldSpecified = (value != null);&lt;/span&gt;
&lt;span class="rem"&gt;#&lt;/span&gt;
&lt;span class="rem"&gt;# Copyright (C) 2008 Ryan Van Slooten&lt;/span&gt;
&lt;span class="rem"&gt;#&lt;/span&gt;
&lt;span class="rem"&gt;# Version:&lt;/span&gt;
&lt;span class="rem"&gt;#   1.0     2008-04-01      Initial release&lt;/span&gt;
&lt;span class="rem"&gt;#&lt;/span&gt;

BEGIN { FS = &lt;span class="str"&gt;" "&lt;/span&gt;; }

&lt;span class="rem"&gt;# Match the nullable types in the file: int, DateTime, etc.&lt;/span&gt;
/[ \t]*&lt;span class="kwrd"&gt;private&lt;/span&gt; System.Nullable/ {
    print $0;

    &lt;span class="rem"&gt;# Add name of field to nullable array&lt;/span&gt;
    name = substr($3, 1, length($3)-1);
    nullable[name] = &lt;span class="str"&gt;""&lt;/span&gt;;
    next; 
}

&lt;span class="rem"&gt;# Match the xxxFieldSpecified variables&lt;/span&gt;
/[ \t]*&lt;span class="kwrd"&gt;private&lt;/span&gt; .*FieldSpecified;/ {
    print $0;

    &lt;span class="rem"&gt;# Increment value of 'specified' null field to nullable array&lt;/span&gt;
    name = substr($3, 1, length($3)-10);
    specified = substr($3, 1, length($3)-1);
    nullable[name] = specified;
    next; 
}

&lt;span class="rem"&gt;# Match the field setter and check if it is nullable and specified&lt;/span&gt;
/[ \t]*this.* = value;/ {
    print $0;

    &lt;span class="rem"&gt;# Check if field is nullable and has a specified property&lt;/span&gt;
    name = substr($1, 6);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (name &lt;span class="kwrd"&gt;in&lt;/span&gt; nullable) {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (length(nullable[name]) &amp;gt; 0) {
            &lt;span class="rem"&gt;# Fix lost indentation level&lt;/span&gt;
            indent = substr($0, 1, index($0, $1)-1);

            &lt;span class="rem"&gt;# Adjust the xxxFieldSpecified value&lt;/span&gt;
            $1 = $1 &lt;span class="str"&gt;"Specified"&lt;/span&gt;;
            $3 = &lt;span class="str"&gt;"("&lt;/span&gt; substr($3, 1, length($3)-1) &lt;span class="str"&gt;" != null);"&lt;/span&gt;;
            print indent $0;

            &lt;span class="rem"&gt;# Remove element from array&lt;/span&gt;
            delete nullable[name];
        }
    }
    next;
}

&lt;span class="rem"&gt;# default line handler&lt;/span&gt;
{ print $0; }

&lt;/pre&gt;
&lt;div&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fnimblecoder.com%2fblog%2farchive%2f2008%2f04%2f01%2fautomatically-setting-the-specified-property-in-wsdl-generated-files.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fnimblecoder.com%2fblog%2farchive%2f2008%2f04%2f01%2fautomatically-setting-the-specified-property-in-wsdl-generated-files.aspx" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:874bc33b-2c0b-430a-8b9b-8e9d17ea1460" 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/awk" rel="tag"&gt;awk&lt;/a&gt;, &lt;a href="http://technorati.com/tags/c#" rel="tag"&gt;c#&lt;/a&gt;, &lt;a href="http://technorati.com/tags/wsdl" rel="tag"&gt;wsdl&lt;/a&gt;, &lt;a href="http://technorati.com/tags/web%20services" rel="tag"&gt;web services&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/61.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2008/04/01/automatically-setting-the-specified-property-in-wsdl-generated-files.aspx</guid>
            <pubDate>Tue, 01 Apr 2008 20:51:15 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/61.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2008/04/01/automatically-setting-the-specified-property-in-wsdl-generated-files.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/61.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/61.aspx</trackback:ping>
        </item>
        <item>
            <title>Best Practice for Verbatim String Text Block</title>
            <link>http://nimblecoder.com/blog/archive/2007/11/23/best-practice-for-verbatim-string-text-block.aspx</link>
            <description>&lt;p&gt;I was browsing various blogs today and I came across a good example for using a verbatim string instead of a StringBuilder object. The code I came across looked like this (I mean absolutely no disrespect to the author, so I won't include the original link):&lt;/p&gt;&lt;pre class="c#" name="code"&gt;private void ClientScript()
{
   StringBuilder sb_Script = new StringBuilder();
   sb_Script.Append("&amp;lt;script language=\"javascript\"&amp;gt;");
   sb_Script.Append("\r");
   sb_Script.Append("\r");
   sb_Script.Append("function cb_verify(sender) {");
   sb_Script.Append("\r");
   sb_Script.Append("var val = document.getElementById(document.getElementById"
			+"(sender.id).controltovalidate);");
   sb_Script.Append("\r");
   sb_Script.Append("var col = val.getElementsByTagName(\"*\");");
   sb_Script.Append("\r");
   sb_Script.Append("if ( col != null ) {");
   sb_Script.Append("\r");
   sb_Script.Append("for ( i = 0; i &amp;lt; col.length; i++ ) {");
   sb_Script.Append("\r");
   sb_Script.Append("if (col.item(i).tagName == \"INPUT\") {");
   sb_Script.Append("\r");
   sb_Script.Append("if ( col.item(i).checked ) {");
   sb_Script.Append("\r");
   sb_Script.Append("\r");
   sb_Script.Append("return true;");
   sb_Script.Append("\r");
   sb_Script.Append("}");
   sb_Script.Append("\r");
   sb_Script.Append("}");
   sb_Script.Append("\r");
   sb_Script.Append("}");
   sb_Script.Append("\r");
   sb_Script.Append("\r");
   sb_Script.Append("\r");
   sb_Script.Append("return false;");
   sb_Script.Append("\r");
   sb_Script.Append("}");
   sb_Script.Append("\r");
   sb_Script.Append("}");
   sb_Script.Append("\r");
   sb_Script.Append("&amp;lt;/script&amp;gt;");

   //Inject the script into the page

   Page.ClientScript.RegisterClientScriptBlock(GetType(), SCRIPTBLOCK,
					sb_Script.ToString());
   //Registering validator clientside javascript function
   Page.ClientScript.RegisterExpandoAttribute(ClientID, "evaluationfunction",
					"cb_verify");
}
&lt;/pre&gt;
&lt;p&gt;There are many articles on the performance of string concatenation compared to StringBuilder, but this is an example where the verbatim string is significantly better in terms of performance and maintenance. The modified code with the verbatim string looks like this:&lt;/p&gt;&lt;pre class="c#" name="code"&gt;private void ClientScript()
{
   string sb_Script = @"
&amp;lt;script language=""javascript""&amp;gt;
function cb_verify(sender) {
   var val = document.getElementById(document.getElementById(sender.id).controltovalidate);
   var col = val.getElementsByTagName(""*"");
   if ( col != null ) {
       for ( i = 0; i &amp;lt; col.length; i++ ) {
           if (col.item(i).tagName == ""INPUT"") {
               if ( col.item(i).checked ) {
                   return true;
               }
           }
       }
       return false;
    }
}
&amp;lt;/script&amp;gt;";

   //Inject the script into the page
   Page.ClientScript.RegisterClientScriptBlock(GetType(), SCRIPTBLOCK,
                    sb_Script);
   //Registering validator clientside javascript function
   Page.ClientScript.RegisterExpandoAttribute(ClientID, "evaluationfunction",
                    "cb_verify");
}
&lt;/pre&gt;
&lt;p&gt;The indentation is optional if you wish to &lt;a href="http://javascript.crockford.com/jsmin.html" target="_blank"&gt;minimize the javascript&lt;/a&gt;, but the end result is code that is easier to maintain. (I'm still evaluating the &lt;a href="http://code.google.com/p/syntaxhighlighter/" target="_blank"&gt;dp.SyntaxHighlighter&lt;/a&gt; and I see it has an issue with the verbatim string markup.)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:472d6560-f12e-4bdb-a9b2-03618cba6216" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; 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/javascript" rel="tag"&gt;javascript&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/50.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2007/11/23/best-practice-for-verbatim-string-text-block.aspx</guid>
            <pubDate>Fri, 23 Nov 2007 06:05:51 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/50.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2007/11/23/best-practice-for-verbatim-string-text-block.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/50.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/50.aspx</trackback:ping>
        </item>
        <item>
            <title>Efficient String Blocks</title>
            <link>http://nimblecoder.com/blog/archive/2007/11/09/efficient-string-blocks.aspx</link>
            <description>&lt;p&gt;One of the things that bothers me a lot is using a lot of string concatenation when you can just use the verbatim string literal (@"") to define a large block of text. For example, I saw some code on a blog the other day that looked something like this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; strValue = &lt;span class="str"&gt;"&amp;lt;div id='test'&amp;gt;"&lt;/span&gt;;
strValue += &lt;span class="str"&gt;"&amp;lt;input type='text' id='name' value='"&lt;/span&gt; + strName + &lt;span class="str"&gt;"/&amp;gt;"&lt;/span&gt;;
strValue += &lt;span class="str"&gt;"&amp;lt;input type='submit' /&amp;gt;"&lt;/span&gt;;
strValue += &lt;span class="str"&gt;"&amp;lt;/div&amp;gt;"&lt;/span&gt;;
&lt;span class="rem"&gt;// Many more lines before it finally&lt;/span&gt;
&lt;span class="rem"&gt;// finished building the string&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;There are many things wrong with the code sample above including not using StringBuilder. I have seen the same type of code extensively with VB and VBScript mostly due to the lack of a multi-line string and VB and VBScript don't have the concatenation operator either so you end up using strValue = strValue + "stuff".&lt;/p&gt;
&lt;p&gt;The issue I have with code like this is both efficiency and maintainability and significant difficulty supporting translations. I once had to maintain a SharePoint 2003 server-side control (not a lot of fun!) that built a lot of html that was sent to the browser. The code was even originally developed by a Microsoft consultant, but it was a mess of string concatenation similar to the first example. I converted the string html to use the verbatim string literal like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="str"&gt;@"&amp;lt;div id='test'&amp;gt;
&amp;lt;input type='text' id='name' value='"&lt;/span&gt; + strName + &lt;span class="str"&gt;@"/&amp;gt;
&amp;lt;input type='submit' /&amp;gt;
&amp;lt;/div&amp;gt;"&lt;/span&gt;;
&lt;/pre&gt;
&lt;p&gt;But even this is hard to pick out the variable assignments in the string. A more generic version is desired, such as:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="str"&gt;@"&amp;lt;div id='test'&amp;gt;
&amp;lt;input type='text' id='name' value='${name}' /&amp;gt;
&amp;lt;input type='submit' /&amp;gt;
&amp;lt;/div&amp;gt;"&lt;/span&gt;;
&lt;/pre&gt;
&lt;p&gt;At this point, it is easy to use Replace or a RegEx to specify the variable values. The downside is potential performance issues with Replace or RegEx, but the upside is less string concatenation and maintainability. It is easy to place the string in a resource or in configuration where it can be maintained outside of code.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:57a0d948-5184-4f02-a231-2eff920a5429" 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/strings" rel="tag"&gt;strings&lt;/a&gt;&lt;/div&gt;&lt;img src="http://nimblecoder.com/blog/aggbug/44.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Van Slooten</dc:creator>
            <guid>http://nimblecoder.com/blog/archive/2007/11/09/efficient-string-blocks.aspx</guid>
            <pubDate>Fri, 09 Nov 2007 21:18:51 GMT</pubDate>
            <wfw:comment>http://nimblecoder.com/blog/comments/44.aspx</wfw:comment>
            <comments>http://nimblecoder.com/blog/archive/2007/11/09/efficient-string-blocks.aspx#feedback</comments>
            <wfw:commentRss>http://nimblecoder.com/blog/comments/commentRss/44.aspx</wfw:commentRss>
            <trackback:ping>http://nimblecoder.com/blog/services/trackbacks/44.aspx</trackback:ping>
        </item>
    </channel>
</rss>