<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.smips.com/smip/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Code Badger (Brad Tutterow's Blog)</title><subtitle type="html">Brad Tutterow is a consultant that likes Microsoft development technologies.</subtitle><id>http://www.smips.com/smip/blogs/codebadger/atom.aspx</id><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/default.aspx" /><link rel="self" type="application/atom+xml" href="http://www.smips.com/smip/blogs/codebadger/atom.aspx" /><generator uri="http://communityserver.org" version="2.1.60809.935">Community Server</generator><updated>2009-09-10T10:46:10Z</updated><entry><title>IOC with StructureMap : Presentation Materials</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2010/02/24/IOC-with-StructureMap-_3A00_-Presentation-Materials.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2010/02/24/IOC-with-StructureMap-_3A00_-Presentation-Materials.aspx</id><published>2010-02-24T18:40:37Z</published><updated>2010-02-24T18:40:37Z</updated><content type="html">&lt;p&gt;For those that might be interested, here are the presentation materials from my talk at the &lt;a href="http://stlnet.org/DesktopDefault.aspx" target="_blank"&gt;St Louis .NET User’s group&lt;/a&gt; last night.&amp;#160; We talked about the need for managing our code dependencies, how to apply the dependency inversion principle, how to use dependency injection, and finally, how to use &lt;a href="http://structuremap.sourceforge.net/Default.htm" target="_blank"&gt;StructureMap&lt;/a&gt; to wire up our dependency injection for us.&lt;/p&gt;  &lt;p&gt;A few key definitions from the talk&lt;/p&gt;  &lt;p&gt;What is a dependency?&amp;#160; Any thing the code I’m working on needs to work that is not the code I’m working on.&amp;#160; Remember that dependencies may very well be your OTHER code sitting in the same project that you’re working in.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/IOCwithStructureMapPresentationMaterials_120A0/image.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/IOCwithStructureMapPresentationMaterials_120A0/image_thumb.png" width="454" height="342" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The dependency inversion principle tells us that high-level modules should not depend on low-level modules.&amp;#160; Rather, both should depend on abstractions.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/IOCwithStructureMapPresentationMaterials_120A0/image_3.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/IOCwithStructureMapPresentationMaterials_120A0/image_thumb_3.png" width="454" height="342" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;One very effective way to pull this off is through the use of interfaces.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/IOCwithStructureMapPresentationMaterials_120A0/image_4.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/IOCwithStructureMapPresentationMaterials_120A0/image_thumb_4.png" width="454" height="342" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Materials&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/IOCwithStructureMapFull.pptx"&gt;Download the slides&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/Sprockets%20(IOC%20with%20StructureMap).zip"&gt;Download the code samples&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.slideshare.net/codebadger/inversion-of-control-with-structuremap" target="_blank"&gt;View the slides at SlideShare.net&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email IOC+with+StructureMap+%3a+Presentation+Materials" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2010/02/24/IOC-with-StructureMap-_3A00_-Presentation-Materials.aspx&amp;subject=IOC+with+StructureMap+%3a+Presentation+Materials"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/24/IOC-with-StructureMap-_3A00_-Presentation-Materials.aspx&amp;title=IOC+with+StructureMap+%3a+Presentation+Materials" title="Submit IOC+with+StructureMap+%3a+Presentation+Materials to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/24/IOC-with-StructureMap-_3A00_-Presentation-Materials.aspx&amp;phase=2" title="Submit IOC+with+StructureMap+%3a+Presentation+Materials to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/24/IOC-with-StructureMap-_3A00_-Presentation-Materials.aspx&amp;title=IOC+with+StructureMap+%3a+Presentation+Materials" title="Submit IOC+with+StructureMap+%3a+Presentation+Materials to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=1709" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="presentations" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/presentations/default.aspx" /><category term="stl.net" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/stl.net/default.aspx" /><category term="structuremap" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/structuremap/default.aspx" /></entry><entry><title>No Silverlight 4 with Visual Studio 2010 RC</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2010/02/17/No-Silverlight-4-with-Visual-Studio-2010-RC.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2010/02/17/No-Silverlight-4-with-Visual-Studio-2010-RC.aspx</id><published>2010-02-18T01:07:03Z</published><updated>2010-02-18T01:07:03Z</updated><content type="html">&lt;p&gt;I think I’m actually sort of relieved to find out that the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=457bab91-5eb2-4b36-b0f4-d6f34683c62a&amp;amp;displaylang=en"&gt;Visual Studio 2010 Release Candidate&lt;/a&gt; doesn’t support Silverlight 4.&amp;#160; I just finished up my Silverlight 4 development environment a few weeks back and wasn’t looking forward to blowing it away just yet.&lt;/p&gt;  &lt;p&gt;But just in case you were about to do the same thing, and didn’t notice the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=457bab91-5eb2-4b36-b0f4-d6f34683c62a&amp;amp;displaylang=en"&gt;fine print on the download page&lt;/a&gt;, you’ve now been warned.&amp;#160; No Silverlight 4 with Visual Studio 2010 RC.&amp;#160; &lt;/p&gt;  &lt;p&gt;I’m sure it’s hard enough to get all the tools playing together in release software, so it’s understandable that sometimes get left behind with all the betas floating out there currently.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email No+Silverlight+4+with+Visual+Studio+2010+RC" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2010/02/17/No-Silverlight-4-with-Visual-Studio-2010-RC.aspx&amp;subject=No+Silverlight+4+with+Visual+Studio+2010+RC"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/17/No-Silverlight-4-with-Visual-Studio-2010-RC.aspx&amp;title=No+Silverlight+4+with+Visual+Studio+2010+RC" title="Submit No+Silverlight+4+with+Visual+Studio+2010+RC to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/17/No-Silverlight-4-with-Visual-Studio-2010-RC.aspx&amp;phase=2" title="Submit No+Silverlight+4+with+Visual+Studio+2010+RC to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/17/No-Silverlight-4-with-Visual-Studio-2010-RC.aspx&amp;title=No+Silverlight+4+with+Visual+Studio+2010+RC" title="Submit No+Silverlight+4+with+Visual+Studio+2010+RC to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=1619" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="visual studio" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/visual+studio/default.aspx" /><category term="silverlight" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/silverlight/default.aspx" /><category term=".net4" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/.net4/default.aspx" /></entry><entry><title>Building a Silverlight Game: Part 9: Dropping Dragged Rectangles</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2010/02/10/Building-a-Silverlight-Game_3A00_-Part-9_3A00_-Dropping-Dragged-Rectangles.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2010/02/10/Building-a-Silverlight-Game_3A00_-Part-9_3A00_-Dropping-Dragged-Rectangles.aspx</id><published>2010-02-10T20:22:48Z</published><updated>2010-02-10T20:22:48Z</updated><content type="html">&lt;h3&gt;Introduction and Review&lt;/h3&gt;  &lt;p&gt;This is the eight post in a series on &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/08/19/Building-a-Silverlight-Game-_3A00_-Part-1-_3A00_-Introduction-_2600_-Tools.aspx"&gt;building a Silverlight game&lt;/a&gt;.&amp;#160; In &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2010/01/21/Building-a-Silverlight-Game-_3A00_-Part-8-_3A00_-Writing-Code-to-Drag-Rectangles.aspx"&gt;the last post&lt;/a&gt;, we coded up all the steps to drag rectangles around the canvas.&amp;#160; This left us with a very simple program where we could pick up and drag the top-most rectangle on a stack.&lt;/p&gt;  &lt;p&gt;&lt;img style="display:block;float:none;margin-left:auto;margin-right:auto;" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart8WritingCode_D7BF/image_thumb_3.png" /&gt;&lt;/p&gt;  &lt;p&gt;The obvious thing that are code from last week couldn’t do though, is drop the rectangle when you let go of the mouse.&amp;#160; We’ll write the code for dropping the dragged rectangle in this post.&lt;/p&gt;  &lt;h3&gt;Wiring up a mouse event&lt;/h3&gt;  &lt;p&gt;Like the other features that we’ve implemented so far, we first need to pick the mouse event to write into.&amp;#160; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;When checking if dragging was a valid thing to do, we attached to MouseEnter &lt;/li&gt;    &lt;li&gt;When setting up a rectangle to be dragged, we attached to MouseLeftButtonDown &lt;/li&gt;    &lt;li&gt;When dragging a rectangle, we attached to MouseMove &lt;/li&gt;    &lt;li&gt;And finally, for dropping a rectangle, we will attach to MouseLeftButtonUp &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In Blend, setting this up is just a matter of selecting the orange rectangle, bringing up the properties tab, switching to the event view, and double-clicking in the textbox next to MouseLeftButtonUp&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart9DroppingDra_9B23/image.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart9DroppingDra_9B23/image_thumb.png" width="255" height="180" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This will generate our method stub and the XAML below.&lt;/p&gt;  &lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;100&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Orange&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;            MouseEnter=&lt;span style="color:#006080;"&gt;&amp;quot;Rectangle_MouseEnter&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;            MouseLeftButtonDown=&lt;span style="color:#006080;"&gt;&amp;quot;Rectangle_MouseLeftButtonDown&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;            MouseMove=&lt;span style="color:#006080;"&gt;&amp;quot;Rectangle_MouseMove&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;            MouseLeftButtonUp=&lt;span style="color:#006080;"&gt;&amp;quot;Rectangle_MouseLeftButtonUp&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rectangle_MouseLeftButtonUp(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, System.Windows.Input.MouseButtonEventArgs e)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#008000;"&gt;// TODO: Add event handler implementation here.&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Just like our previous features, we’re going to defer anything related to dragging or dropping to our DragAndDrop class.&amp;#160; Let’s add the call to the event handler.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rectangle_MouseLeftButtonUp(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, MouseButtonEventArgs e)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     dragAndDrop.Drop(&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;         sender &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; Rectangle,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         e.GetPosition(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;));&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h4&gt;The Drop() Method&lt;/h4&gt;

&lt;p&gt;Here’s the new Drop() method for DragAndDrop.cs&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Drop(Rectangle rectangle, Point position)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     dragging = &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     Panel panel = main.GetDropPanel(position);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;     RectangleDropper.DropRectangle(&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;         draggingCanvas,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;         panel,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;         originalParent,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;         rectangle,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;         position);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;     rectangle.ReleaseMouseCapture();&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;     rectangle.Opacity = 1;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;On line 3, we set our dragging boolean to false.&amp;#160; This boolean is checked by our Drag() method, so setting it to false stops the rectangle from moving around with the mouse.&lt;/p&gt;

&lt;p&gt;On line 4, we get the panel to drop the rectangle into.&amp;#160; For now, this line won’t compile.&amp;#160; More on it later.&lt;/p&gt;

&lt;p&gt;On line 5, we drop the rectangle into the appropriate panel.&amp;#160; This line will also not compile at the moment since we don’t have a RectangleDropper class yet.&lt;/p&gt;

&lt;p&gt;Lines 11 and 12 reverse the UI stuff that we did when we started to drag.&amp;#160; We release the mouse capture and set the opacity of the rectangle back to 1 so that it’s not see through anymore.&lt;/p&gt;

&lt;p&gt;Now about those lines that are throwing compile errors – lines 5 and 6.&lt;/p&gt;

&lt;h3&gt;Getting the panel to drop the rectangle into&lt;/h3&gt;

&lt;p&gt;When the user released the mouse, the rectangle needs to drop neatly into the panel that they mouse is currently over.&amp;#160; The problem that we have is that the DragAndDrop helper doesn’t know about the panels and shouldn’t.&amp;#160; They are a concern of the main control. &lt;/p&gt;

&lt;p&gt;So let’s put a method on our main control that the DragAndDrop helper can call to find out about panels.&amp;#160; We’ll call it GetDropPanel() and it will look this:&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; StackPanel GetDropPanel(Point position)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (position.X &amp;gt; Canvas.GetLeft(RightBorder))&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; RightPanel;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (position.X &amp;gt; Canvas.GetLeft(MiddleBorder))&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; MiddlePanel;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; LeftPanel;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Remember that this method belongs to our main control, not the DragAndDrop helper.&amp;#160; It takes the position of the mouse, provided by the DragAndDrop helper, and gives the panel that lives at that location.&lt;/p&gt;

&lt;p&gt;To use this code from the DragAndDrop helper, we need to make sure that the DragAndDrop helper has a reference back to the main control.&amp;#160; We’ll add it as a constructor dependency for the DragAndDrop helper class.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; MainPage main;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; Canvas draggingCanvas;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; RectangleMover mover;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; dragging = &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; Panel originalParent;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; DragAndDrop(MainPage main, Canvas draggingCanvas)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.main = main;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.draggingCanvas = draggingCanvas;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;     mover = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; RectangleMover(&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;         draggingCanvas.Height,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;         draggingCanvas.Width);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now, when the main control creates an instance of the DragAndDrop class, it will have to pass itself in.&amp;#160; A more object-oriented approach would be to have the main control implement an interface and pass that in, but this is just a simple game, so we’re not going to bother.&lt;/p&gt;

&lt;p&gt;Here’s the code for the main control to instantiate an instance of DragAndDrop&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; DragAndDrop dragAndDrop;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; MainPage()&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;     InitializeComponent();&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;     dragAndDrop = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; DragAndDrop(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.LayoutRoot);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h4&gt;Dropping the rectangle&lt;/h4&gt;

&lt;p&gt;The last piece of the puzzle to drop the rectangle is the RectangleDropper class.&amp;#160; It looks like this.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; RectangleDropper&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; DropRectangle(&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;         Canvas canvas, &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         Panel panel, &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;         Panel oldParent,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;         Rectangle rectangle,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;         Point position)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (RectangleHasMoved(rectangle, panel))&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;         {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (RectangleIsBiggerThanRectangleOnTop(rectangle, panel))&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;             {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;                 panel = oldParent;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt;             }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum16"&gt;  16:&lt;/span&gt;             canvas.Children.Remove(rectangle);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum17"&gt;  17:&lt;/span&gt;             panel.Children.Insert(0, rectangle);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum18"&gt;  18:&lt;/span&gt;         }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum19"&gt;  19:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum21"&gt;  21:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; RectangleHasMoved(Rectangle rectangle, Panel panel)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum22"&gt;  22:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum23"&gt;  23:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; !panel.Children.Contains(rectangle);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum24"&gt;  24:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum25"&gt;  25:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum26"&gt;  26:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; RectangleIsBiggerThanRectangleOnTop(Rectangle rectangle, Panel panel)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum27"&gt;  27:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum28"&gt;  28:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (panel.Children.Count.Equals(0))&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum29"&gt;  29:&lt;/span&gt;         {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum30"&gt;  30:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum31"&gt;  31:&lt;/span&gt;         }    &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum32"&gt;  32:&lt;/span&gt;         Rectangle topRectangleInPanel = panel.Children[0] &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; Rectangle;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum33"&gt;  33:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; topRectangleInPanel.ActualWidth &amp;lt; rectangle.ActualWidth;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum34"&gt;  34:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum35"&gt;  35:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;It has one public method, DropRectangle(), that defers to a couple of private methods to make sure that the basic rules for dropping are followed.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingASilverlightGamePost8Code.zip"&gt;&lt;strong&gt;Download source code so far&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Building+a+Silverlight+Game%3a+Part+9%3a+Dropping+Dragged+Rectangles" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2010/02/10/Building-a-Silverlight-Game_3A00_-Part-9_3A00_-Dropping-Dragged-Rectangles.aspx&amp;subject=Building+a+Silverlight+Game%3a+Part+9%3a+Dropping+Dragged+Rectangles"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/10/Building-a-Silverlight-Game_3A00_-Part-9_3A00_-Dropping-Dragged-Rectangles.aspx&amp;title=Building+a+Silverlight+Game%3a+Part+9%3a+Dropping+Dragged+Rectangles" title="Submit Building+a+Silverlight+Game%3a+Part+9%3a+Dropping+Dragged+Rectangles to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/10/Building-a-Silverlight-Game_3A00_-Part-9_3A00_-Dropping-Dragged-Rectangles.aspx&amp;phase=2" title="Submit Building+a+Silverlight+Game%3a+Part+9%3a+Dropping+Dragged+Rectangles to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/10/Building-a-Silverlight-Game_3A00_-Part-9_3A00_-Dropping-Dragged-Rectangles.aspx&amp;title=Building+a+Silverlight+Game%3a+Part+9%3a+Dropping+Dragged+Rectangles" title="Submit Building+a+Silverlight+Game%3a+Part+9%3a+Dropping+Dragged+Rectangles to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=1505" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="visual studio" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/visual+studio/default.aspx" /><category term="silverlight" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/silverlight/default.aspx" /><category term="expression blend" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/expression+blend/default.aspx" /></entry><entry><title>Abtest = Tina</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2010/02/09/Abtest-_3D00_-Tina.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2010/02/09/Abtest-_3D00_-Tina.aspx</id><published>2010-02-10T02:03:33Z</published><updated>2010-02-10T02:03:33Z</updated><content type="html">&lt;p&gt;Check out this nice querystring from the fine folks at TurboTax.&amp;#160; I can only speculate as to who Tina is and what her abs are being tested on.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/AbtestTina_11A0A/image.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/AbtestTina_11A0A/image_thumb.png" width="333" height="119" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Abtest+%3d+Tina" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2010/02/09/Abtest-_3D00_-Tina.aspx&amp;subject=Abtest+%3d+Tina"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/09/Abtest-_3D00_-Tina.aspx&amp;title=Abtest+%3d+Tina" title="Submit Abtest+%3d+Tina to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/09/Abtest-_3D00_-Tina.aspx&amp;phase=2" title="Submit Abtest+%3d+Tina to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/09/Abtest-_3D00_-Tina.aspx&amp;title=Abtest+%3d+Tina" title="Submit Abtest+%3d+Tina to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=1497" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author></entry><entry><title>Presenting at .NET User Group – Feb 22</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2010/02/08/Presenting-at-.NET-User-Group-_1320_-Feb-22.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2010/02/08/Presenting-at-.NET-User-Group-_1320_-Feb-22.aspx</id><published>2010-02-08T18:18:17Z</published><updated>2010-02-08T18:18:17Z</updated><content type="html">&lt;p&gt;I’ll be presenting on Inversion of Control with StructureMap at the next meeting of the .NET user group.&amp;#160; It will be exactly as awesome as it sounds.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Simplify your life with Inversion of Control! One of the most challenging aspects of software development is dealing with code that depends on other code. The &lt;strong&gt;Dependency Inversion &lt;/strong&gt;principle tells us that we should depend on abstractions, not concretions but it doesn’t tell us &lt;strong&gt;how&lt;/strong&gt; to do that. That’s where &lt;strong&gt;Dependency Injection&lt;/strong&gt; comes in – we inject our dependencies into the mushy center of our classes with a big syringe. This can often be as messy as it sounds, but luckily &lt;strong&gt;Inversion of Control Containers&lt;/strong&gt; can help us by providing a single source for configuring dependencies. This presentation will show how to effectively manage dependencies with StructureMap, an open-source IOC container. StructureMap can make your life easier, your code more maintainable, and the world a better place.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;a href="http://www.stlnet.org/DesktopDefault.aspx"&gt;http://www.stlnet.org/DesktopDefault.aspx&lt;/a&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Presenting+at+.NET+User+Group+%e2%80%93+Feb+22" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2010/02/08/Presenting-at-.NET-User-Group-_1320_-Feb-22.aspx&amp;subject=Presenting+at+.NET+User+Group+%e2%80%93+Feb+22"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/08/Presenting-at-.NET-User-Group-_1320_-Feb-22.aspx&amp;title=Presenting+at+.NET+User+Group+%e2%80%93+Feb+22" title="Submit Presenting+at+.NET+User+Group+%e2%80%93+Feb+22 to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/08/Presenting-at-.NET-User-Group-_1320_-Feb-22.aspx&amp;phase=2" title="Submit Presenting+at+.NET+User+Group+%e2%80%93+Feb+22 to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/02/08/Presenting-at-.NET-User-Group-_1320_-Feb-22.aspx&amp;title=Presenting+at+.NET+User+Group+%e2%80%93+Feb+22" title="Submit Presenting+at+.NET+User+Group+%e2%80%93+Feb+22 to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=1490" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="presentations" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/presentations/default.aspx" /><category term="community" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/community/default.aspx" /><category term="stl.net" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/stl.net/default.aspx" /></entry><entry><title>Building a Silverlight Game : Part 8 : Writing Code to Drag Rectangles</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2010/01/21/Building-a-Silverlight-Game-_3A00_-Part-8-_3A00_-Writing-Code-to-Drag-Rectangles.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2010/01/21/Building-a-Silverlight-Game-_3A00_-Part-8-_3A00_-Writing-Code-to-Drag-Rectangles.aspx</id><published>2010-01-21T19:28:17Z</published><updated>2010-01-21T19:28:17Z</updated><content type="html">&lt;h3&gt;Introduction and Review&lt;/h3&gt;  &lt;p&gt;This is the eight post in a series on &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/08/19/Building-a-Silverlight-Game-_3A00_-Part-1-_3A00_-Introduction-_2600_-Tools.aspx"&gt;building a Silverlight game&lt;/a&gt;.&amp;#160; In &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/10/09/Building-a-Silverlight-Game-_3A00_-Part-7-_3A00_-Getting-Started-with-Dragging-Rectangles.aspx"&gt;the last post&lt;/a&gt;, we talked about all the steps that we need to take to drag a rectangle around.&amp;#160; In this post, we’ll write the code to satisfy all those steps and let us drag our rectangles around the canvas.&lt;/p&gt;  &lt;p&gt;For the sake of review, remember that in &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx"&gt;Part 6&lt;/a&gt; we wrote code to prepare a rectangle for dragging.&amp;#160; This included&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Setting a flag that tells us a rectangle is being dragged &lt;/li&gt;    &lt;li&gt;Adjusting the opacity of the rectangle to provide a nice visual effect &lt;/li&gt;    &lt;li&gt;Capturing the mouse so the rectangle will be sure to respond to mouse events &lt;/li&gt; &lt;/ol&gt;  &lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; StartDrag(Rectangle rectangle)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (rectangle.Cursor.Equals(Cursors.Hand))&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         dragging = &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;         rectangle.CaptureMouse();&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;         rectangle.Opacity = 0.6;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;That will set up a rectangle for dragging.&amp;#160; The code that will drag the rectangle around (Part 7) needs to do these things:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Check the flag to make sure it’s true &lt;/li&gt;

  &lt;li&gt;Remove the rectangle from the stack panel &lt;/li&gt;

  &lt;li&gt;Place the rectangle on the canvas so we can drag it around &lt;/li&gt;

  &lt;li&gt;Bring the rectangle forward &lt;/li&gt;

  &lt;li&gt;Move the rectangle to the current position of the mouse &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Wiring up the proper event&lt;/h3&gt;

&lt;p&gt;The first thing to do is to decide &lt;em&gt;when&lt;/em&gt; we want to do all these things.&amp;#160; In other words, what event of what object?&amp;#160; The answer (for now) is that we want to do these things when the &lt;em&gt;MouseMove&lt;/em&gt; event of the topmost rectangle fires off.&amp;#160; To get things started in blend, just select the top-most rectangle in the object explorer, switch your properties tab to the event view, and double-click inside the MouseMove event’s textbox.&amp;#160; This will auto-generate an event handler method and wire it up in the XAML.&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart8WritingCode_D7BF/image.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart8WritingCode_D7BF/image_thumb.png" width="281" height="438" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you’re not using Blend, the same event can be wired up manually in Visual Studio.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;StackPanel&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;LeftPanel&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Orientation&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Vertical&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;     &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;ZIndex&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Bottom&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Orange&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;                &lt;span style="color:#ff0000;"&gt;MouseEnter&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Rectangle_MouseEnter&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;                &lt;span style="color:#ff0000;"&gt;MouseLeftButtonDown&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Rectangle_MouseLeftButtonDown&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;                &lt;span style="color:#ff0000;"&gt;MouseMove&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Rectangle_MouseMove&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;110&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Blue&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;120&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Green&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;5&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;120&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Black&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Just like we’ve done with all of our other rectangle events so far, we are going to delegate the actual work to the DragAndDrop.cs class.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rectangle_MouseMove(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, System.Windows.Input.MouseEventArgs e)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     dragAndDrop.Drag(&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;         sender &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; Rectangle,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         e.GetPosition(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;));&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;The Drag() method &lt;/h3&gt;

&lt;p&gt;You can see that we’re calling a &lt;em&gt;Drag&lt;/em&gt; method on the instance of DragAndDrop.&amp;#160; This method wants to know the rectangle to drag and the current position of the mouse.&amp;#160; Now we just need to write this method.&lt;/p&gt;

&lt;p&gt;First things first, here’s the entire Drag() method.&amp;#160; &lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Drag(Rectangle rectangle, Point position)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (dragging)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         StackPanel panel = rectangle.Parent &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; StackPanel;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (panel != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;         {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;             originalParent = panel;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;             panel.Children.Remove(rectangle);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;             draggingCanvas.Children.Add(rectangle);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;             Canvas.SetZIndex(rectangle, 5);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;         }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;         mover.Move(rectangle, position);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Let’s step through this one line at a time.&amp;#160; &lt;/p&gt;

&lt;p&gt;On &lt;strong&gt;line 3&lt;/strong&gt;, we’re checking our dragging flag.&amp;#160; Since this method will be called whenever the rectangle’s MouseMove event fires, we want to make sure that we really should be dragging before we start moving things all over the screen.&lt;/p&gt;

&lt;p&gt;On &lt;strong&gt;line 5&lt;/strong&gt;, we put the rectangle’s parent in a local variable.&amp;#160; This is so we can put the rectangle back where it belongs in things go awry.&lt;/p&gt;

&lt;p&gt;On &lt;strong&gt;line 6&lt;/strong&gt;, we check to see if the rectangle’s parent is null.&amp;#160; If it is, then that means the cast to StackPanel failed (line 5).&amp;#160; And that means that the parent is not a stack panel.&amp;#160; And THAT means that rectangle is on the canvas.&amp;#160; And if the rectangle is on the canvas, then we skip lines 8 – 11, since those lines put the rectangle on the canvas.&amp;#160; Remember that this is being called over and over as the mouse moves across the screen.&lt;/p&gt;

&lt;p&gt;On &lt;strong&gt;line 8&lt;/strong&gt;, we keep track of the original parent.&amp;#160; On &lt;strong&gt;line 9&lt;/strong&gt;, we remove the rectangle from it’s parent stack panel.&amp;#160; On &lt;strong&gt;line 10&lt;/strong&gt;, we place the rectangle on the dragging canvas.&amp;#160; And on &lt;strong&gt;line 11&lt;/strong&gt;, we bring the rectangle to the front of the screen.&lt;/p&gt;

&lt;p&gt;Finally, one &lt;strong&gt;line 13&lt;/strong&gt;, we call out to another class that will actually move the rectangle.&amp;#160; We haven’t written the code for this class yet.&lt;/p&gt;

&lt;p&gt;If you paste the code for the Drag() method into your copy of DragAndDrop.cs, you’ll notice it doesn’t compile.&amp;#160; We just have to make a handful of changes to get things all wired up and working.&lt;/p&gt;

&lt;p&gt;The first problem is that we don’t have a field variable for the original parent.&amp;#160; The next problem is that we don’t have a reference to a dragging canvas.&lt;/p&gt;

&lt;h3&gt;DragAndDrop’s new constructor&lt;/h3&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Both of these problems are resolved by changing our field declarations and constructor definition.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; Canvas draggingCanvas;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; dragging = &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; Panel originalParent;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; DragAndDrop(Canvas draggingCanvas)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.draggingCanvas = draggingCanvas;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now we have fields for the dragging canvas and the original parent.&amp;#160; Notice also that we added the dragging canvas as a parameter for the constructor.&amp;#160; We’re telling anyone that wants to create an instance of a DragAndDrop helper that they better provide a canvas to use.&lt;/p&gt;

&lt;p&gt;If you remember, it’s MainPage.xaml.cs that is currently creating an instance of the DragAndDrop helper.&amp;#160; So we need to change the code there to pass in the dragging canvas.&amp;#160; In this case, the dragging canvas is the layout root for the main page.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; MainPage()&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     InitializeComponent();&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     dragAndDrop = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; DragAndDrop(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.LayoutRoot);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h4&gt;The RectangleMover class&lt;/h4&gt;

&lt;p&gt;At this point, the only thing that’s preventing our code from compiling is line 13 of the Drag() method above.&amp;#160; &lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; mover.Move(rectangle, position);&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;To get this working, we need a class that move a rectangle around the canvas … a mover.&amp;#160; This class will be very dumb.&amp;#160; While the DragAndDrop class has all the logic associated with dragging a rectangle around, the mover will just know how to move a rectangle within the bounds of a canvas.&lt;/p&gt;

&lt;p&gt;The code for this class looks like this:&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; RectangleMover&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; heightLimit;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; widthLimit;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; RectangleMover(&lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; heightLimit, &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; widthLimit)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.heightLimit = heightLimit;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.widthLimit = widthLimit;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Move(Rectangle rectangle, Point position)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; left = CalculateRectangleLeft(rectangle, position);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; top = CalculateRectangleTop(rectangle, position);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum16"&gt;  16:&lt;/span&gt;         Canvas.SetLeft(rectangle, left);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum17"&gt;  17:&lt;/span&gt;         Canvas.SetTop(rectangle, top);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum18"&gt;  18:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum19"&gt;  19:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum20"&gt;  20:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; CalculateRectangleTop(Rectangle rectangle, Point position)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum21"&gt;  21:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum22"&gt;  22:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; top = position.Y - (rectangle.ActualHeight / 2);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum23"&gt;  23:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; maxTop = &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.heightLimit - rectangle.ActualHeight;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum24"&gt;  24:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; minTop = 0;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum25"&gt;  25:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (top &amp;gt;= maxTop)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum26"&gt;  26:&lt;/span&gt;         {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum27"&gt;  27:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maxTop;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum28"&gt;  28:&lt;/span&gt;         }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum29"&gt;  29:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (top &amp;lt; minTop)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum30"&gt;  30:&lt;/span&gt;         {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum31"&gt;  31:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; minTop;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum32"&gt;  32:&lt;/span&gt;         }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum33"&gt;  33:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; top;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum34"&gt;  34:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum35"&gt;  35:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum36"&gt;  36:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; CalculateRectangleLeft(Rectangle rectangle, Point position)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum37"&gt;  37:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum38"&gt;  38:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; left = position.X - (rectangle.ActualWidth / 2);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum39"&gt;  39:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; maxLeft = &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.widthLimit - rectangle.ActualWidth;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum40"&gt;  40:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;double&lt;/span&gt; minLeft = 0;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum41"&gt;  41:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (left &amp;gt;= maxLeft)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum42"&gt;  42:&lt;/span&gt;         {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum43"&gt;  43:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; maxLeft;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum44"&gt;  44:&lt;/span&gt;         }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum45"&gt;  45:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (left &amp;lt; minLeft)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum46"&gt;  46:&lt;/span&gt;         {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum47"&gt;  47:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; minLeft;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum48"&gt;  48:&lt;/span&gt;         }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum49"&gt;  49:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; left;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum50"&gt;  50:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum51"&gt;  51:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This class can look a bit intimidating, but it doesn’t really do anything interesting.&amp;#160; It has one public method that takes a rectangle and a position.&amp;#160; It moves the rectangle to that position.&amp;#160; Feel free to explore the class on your own, but we’ll leave it at that for our purposes here.&lt;/p&gt;

&lt;p&gt;Now we just need to instantiate an instance of RectangleMover when we instantiate our DragAndDropClass, so DragAndDrop gets a new constructor a new instance field.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; Canvas draggingCanvas;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; RectangleMover mover;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; dragging = &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; Panel originalParent;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; DragAndDrop(Canvas draggingCanvas)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.draggingCanvas = draggingCanvas;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;     mover = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; RectangleMover(&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;         draggingCanvas.Height,&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;         draggingCanvas.Width);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Running the game&lt;/h3&gt;

&lt;p&gt;If we run the game now, we can now drag the top rectangle around the canvas.&amp;#160; But we can’t drop it yet.&amp;#160; That’s for next time!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart8WritingCode_D7BF/image_3.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart8WritingCode_D7BF/image_thumb_3.png" width="454" height="255" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingASilverlightGamePost8Code.zip"&gt;Download the source code so far&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Building+a+Silverlight+Game+%3a+Part+8+%3a+Writing+Code+to+Drag+Rectangles" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2010/01/21/Building-a-Silverlight-Game-_3A00_-Part-8-_3A00_-Writing-Code-to-Drag-Rectangles.aspx&amp;subject=Building+a+Silverlight+Game+%3a+Part+8+%3a+Writing+Code+to+Drag+Rectangles"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/01/21/Building-a-Silverlight-Game-_3A00_-Part-8-_3A00_-Writing-Code-to-Drag-Rectangles.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+8+%3a+Writing+Code+to+Drag+Rectangles" title="Submit Building+a+Silverlight+Game+%3a+Part+8+%3a+Writing+Code+to+Drag+Rectangles to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/01/21/Building-a-Silverlight-Game-_3A00_-Part-8-_3A00_-Writing-Code-to-Drag-Rectangles.aspx&amp;phase=2" title="Submit Building+a+Silverlight+Game+%3a+Part+8+%3a+Writing+Code+to+Drag+Rectangles to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/01/21/Building-a-Silverlight-Game-_3A00_-Part-8-_3A00_-Writing-Code-to-Drag-Rectangles.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+8+%3a+Writing+Code+to+Drag+Rectangles" title="Submit Building+a+Silverlight+Game+%3a+Part+8+%3a+Writing+Code+to+Drag+Rectangles to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=1378" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="silverlight" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/silverlight/default.aspx" /><category term="expression blend" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/expression+blend/default.aspx" /></entry><entry><title>Paint.NET: The friendliest update in town</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2010/01/11/Paint.NET_3A00_-The-friendliest-update-in-town.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2010/01/11/Paint.NET_3A00_-The-friendliest-update-in-town.aspx</id><published>2010-01-11T20:40:59Z</published><updated>2010-01-11T20:40:59Z</updated><content type="html">&lt;p&gt;As far as update processes go, Paint.NET has the best in town. Just check out this dialog that you see when launching the program and note how friendly it is.&amp;#160; It’s saying &amp;quot;Hi!&amp;#160; I’m sure you have some image editing to do.&amp;#160; When you’re done, I’d be happy to update myself.&amp;#160; Just let me know.”&amp;#160; Thanks, Paint.NET!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/Paint.NETThefriendliestupdateintown_CE6F/PaintNETInstall.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="PaintNETInstall" border="0" alt="PaintNETInstall" src="http://www.smips.com/smip/blogs/codebadger/uploads/Paint.NETThefriendliestupdateintown_CE6F/PaintNETInstall_thumb.png" width="352" height="231" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Let’s see how some other software on my machine stacks up.&amp;#160; Here’s Adobe.&amp;#160; It doesn’t even wait until I use the software, but just pops up at random times throughout the day.&amp;#160; Actually, this screenshot isn’t even from my machine since I get so annoyed at Adobe Updater I don’t allow it to run.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/Paint.NETThefriendliestupdateintown_CE6F/AdobeUpdater.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="AdobeUpdater" border="0" alt="AdobeUpdater" src="http://www.smips.com/smip/blogs/codebadger/uploads/Paint.NETThefriendliestupdateintown_CE6F/AdobeUpdater_thumb.jpg" width="547" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;FileZilla and Firefox are a little better, in that they only pop up when I’m using the software.&amp;#160; But not quite as friendly as Paint.NET since they expect me to either install the update before I use the software or not install the update.&amp;#160; This isn’t bad, but not near as slick as Paint.NET.&amp;#160; When I launch software, I want to USE it, not UPDATE it. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/Paint.NETThefriendliestupdateintown_CE6F/auomaticcheck.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="auomatic-check" border="0" alt="auomatic-check" src="http://www.smips.com/smip/blogs/codebadger/uploads/Paint.NETThefriendliestupdateintown_CE6F/auomaticcheck_thumb.png" width="290" height="246" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/Paint.NETThefriendliestupdateintown_CE6F/FireFoxUpdate.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="FireFoxUpdate" border="0" alt="FireFoxUpdate" src="http://www.smips.com/smip/blogs/codebadger/uploads/Paint.NETThefriendliestupdateintown_CE6F/FireFoxUpdate_thumb.png" width="406" height="366" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So my hat’s off to the guys at Paint.NET for letting me update my software while staying out of my way!&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Paint.NET%3a+The+friendliest+update+in+town" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2010/01/11/Paint.NET_3A00_-The-friendliest-update-in-town.aspx&amp;subject=Paint.NET%3a+The+friendliest+update+in+town"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/01/11/Paint.NET_3A00_-The-friendliest-update-in-town.aspx&amp;title=Paint.NET%3a+The+friendliest+update+in+town" title="Submit Paint.NET%3a+The+friendliest+update+in+town to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/01/11/Paint.NET_3A00_-The-friendliest-update-in-town.aspx&amp;phase=2" title="Submit Paint.NET%3a+The+friendliest+update+in+town to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2010/01/11/Paint.NET_3A00_-The-friendliest-update-in-town.aspx&amp;title=Paint.NET%3a+The+friendliest+update+in+town" title="Submit Paint.NET%3a+The+friendliest+update+in+town to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=1289" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author></entry><entry><title>Fixing Outlook Pet Peeves with Quick Steps</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2009/12/18/Fixing-Outlook-Pet-Peeves-with-Quick-Steps.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2009/12/18/Fixing-Outlook-Pet-Peeves-with-Quick-Steps.aspx</id><published>2009-12-18T20:15:35Z</published><updated>2009-12-18T20:15:35Z</updated><content type="html">&lt;p&gt;One of the new features in Outlook 2010 is Quick Steps.&amp;#160; Quick Steps let you chain multiple Outlook actions together into an easy-to-access action that shows up in the “Home” tab of the ribbon.&amp;#160; Kinda like macros, I suppose, but friendlier.&lt;/p&gt;  &lt;p&gt;Outlook 2010 comes with a few handy Quick Steps by default, including one to forward an email to your manager, send an email to your team, or send an email to a folder.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/FixingOutlookPetPeeveswithQuickSteps_C825/image.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/FixingOutlookPetPeeveswithQuickSteps_C825/image_thumb.png" width="400" height="90" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;It’s also super easy to create a new Quick Step.&amp;#160; I used one to solve one of my biggest pet-peeves about Outook: deleted items are not automatically marked as read.&amp;#160; By default, when you delete an email from your inbox without reading it, Outlook moves the message to your “Deleted Items” folder but is &lt;strong&gt;still marked as unread&lt;/strong&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/FixingOutlookPetPeeveswithQuickSteps_C825/image_3.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/FixingOutlookPetPeeveswithQuickSteps_C825/image_thumb_3.png" width="206" height="186" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This is crazy frustrating, because now I have a blue “1” in parentheses, meaning I have unread email.&amp;#160; Technically, this is true – I didn’t read it – but in practice, this drives me nuts, because the reason I deleted it is that I didn’t &lt;strong&gt;want&lt;/strong&gt; to read it. &lt;/p&gt;  &lt;p&gt;Quick Steps to the rescue …&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/FixingOutlookPetPeeveswithQuickSteps_C825/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/FixingOutlookPetPeeveswithQuickSteps_C825/image_thumb_4.png" width="514" height="411" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Here I’ve defined a Quick Step that will mark a message and read and then delete it.&amp;#160; Even better, I can add a keyboard shortcut.&amp;#160; Nice!&amp;#160; No more unread email in my trash can.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Fixing+Outlook+Pet+Peeves+with+Quick+Steps" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2009/12/18/Fixing-Outlook-Pet-Peeves-with-Quick-Steps.aspx&amp;subject=Fixing+Outlook+Pet+Peeves+with+Quick+Steps"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/12/18/Fixing-Outlook-Pet-Peeves-with-Quick-Steps.aspx&amp;title=Fixing+Outlook+Pet+Peeves+with+Quick+Steps" title="Submit Fixing+Outlook+Pet+Peeves+with+Quick+Steps to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/12/18/Fixing-Outlook-Pet-Peeves-with-Quick-Steps.aspx&amp;phase=2" title="Submit Fixing+Outlook+Pet+Peeves+with+Quick+Steps to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/12/18/Fixing-Outlook-Pet-Peeves-with-Quick-Steps.aspx&amp;title=Fixing+Outlook+Pet+Peeves+with+Quick+Steps" title="Submit Fixing+Outlook+Pet+Peeves+with+Quick+Steps to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=1161" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author></entry><entry><title>Building a Silverlight Game : Part 7 : Getting Started with Dragging Rectangles</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2009/10/09/Building-a-Silverlight-Game-_3A00_-Part-7-_3A00_-Getting-Started-with-Dragging-Rectangles.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2009/10/09/Building-a-Silverlight-Game-_3A00_-Part-7-_3A00_-Getting-Started-with-Dragging-Rectangles.aspx</id><published>2009-10-09T15:32:33Z</published><updated>2009-10-09T15:32:33Z</updated><content type="html">&lt;p&gt;This is the seventh post in a series on &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/08/19/Building-a-Silverlight-Game-_3A00_-Part-1-_3A00_-Introduction-_2600_-Tools.aspx"&gt;building a Silverlight game&lt;/a&gt;.&amp;#160; In &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx"&gt;the last post&lt;/a&gt;, we wrote code to set up a rectangle for dragging.&amp;#160; In this post, we’ll look at what it will take to drag the rectangle around the playing area.&lt;/p&gt;  &lt;h4&gt;Recap&lt;/h4&gt;  &lt;p&gt;So we don’t lose sight of the big picture, remember that our overall goal is to build a Towers of Hanoi clone that looks like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="display:block;float:none;margin-left:auto;margin-right:auto;" alt="CropperCapture[3]" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart1Introductio_C2E8/CropperCapture3_thumb.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;And so far, we’ve built a Towers of Hanoi clone that looks like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="display:block;float:none;margin-left:auto;margin-right:auto;" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart6Settingupar_DD97/image_thumb.png" /&gt;&lt;/p&gt;  &lt;p&gt;The current part of the game that we’re working on is the code to drag rectangles around the playing area since that’s pretty much the only thing there is to the game.&amp;#160; &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx"&gt;Last week&lt;/a&gt;, we wrote the code that sets up a rectangle for dragging.&amp;#160; Remember that this involved three things&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Setting a flag that tells us a rectangle is being dragged&lt;/li&gt;    &lt;li&gt;Adjusting the opacity of the rectangle to provide a nice visual effect&lt;/li&gt;    &lt;li&gt;Capturing the mouse so the rectangle will be sure to respond to mouse events&lt;/li&gt; &lt;/ol&gt;  &lt;h4&gt;Dragging&lt;/h4&gt;  &lt;p&gt;This week, we’ll think about the code that we need to write to drag the rectangle around the canvas. There are five things that need to happen to move the rectangle around&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1) &lt;/strong&gt;We have to &lt;strong&gt;check the flag&lt;/strong&gt; that was set previously.&amp;#160; If a dragging operation is not current, we certainly don’t want rectangles moving around the screen.&amp;#160; So we’re only going to drag things around the screen if the flag is set to true.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2) &lt;/strong&gt;We need to &lt;strong&gt;get the rectangle out of the stack panel&lt;/strong&gt; (remember that our rectangles are sitting in a stack panel).&amp;#160; Items in a stack panel have to be in a stack.&amp;#160; Think of the stack of papers on your desk.&amp;#160; You can’t drag them around while they’re in the stack; you have to get them out first.&amp;#160; &lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;StackPanel x:Name=&lt;span style="color:#006080;"&gt;&amp;quot;LeftPanel&amp;quot;&lt;/span&gt; Orientation=&lt;span style="color:#006080;"&gt;&amp;quot;Vertical&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;     Canvas.ZIndex=&lt;span style="color:#006080;"&gt;&amp;quot;1&amp;quot;&lt;/span&gt; VerticalAlignment=&lt;span style="color:#006080;"&gt;&amp;quot;Bottom&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;100&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Orange&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;                MouseEnter=&lt;span style="color:#006080;"&gt;&amp;quot;Rectangle_MouseEnter&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;                MouseLeftButtonDown=&lt;span style="color:#006080;"&gt;&amp;quot;Rectangle_MouseLeftButtonDown&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;     &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;110&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Blue&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;     &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;120&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Green&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;     &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;5&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;120&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Black&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt; &amp;lt;/StackPanel&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3) &lt;/strong&gt;We need to &lt;strong&gt;place the rectangle somewhere that it can be dragged&lt;/strong&gt;.&amp;#160; The root canvas is perfect for this.&amp;#160; Remember that our three stack panels are contained in a canvas.&amp;#160; A canvas container keeps track of its children by exact position, which is perfect for dragging.&amp;#160; Imagine that we’re taking a piece of paper from the stack on your desk and placing it on the desk to drag it around.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;Canvas x:Name=&lt;span style="color:#006080;"&gt;&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;800&amp;quot;&lt;/span&gt; Height=&lt;span style="color:#006080;"&gt;&amp;quot;430&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;     &amp;lt;Border Height=&lt;span style="color:#006080;"&gt;&amp;quot;380&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;257&amp;quot;&lt;/span&gt; Canvas.Left=&lt;span style="color:#006080;"&gt;&amp;quot;15&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;         &amp;lt;StackPanel x:Name=&lt;span style="color:#006080;"&gt;&amp;quot;LeftPanel&amp;quot;&lt;/span&gt; Orientation=&lt;span style="color:#006080;"&gt;&amp;quot;Vertical&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;             Canvas.ZIndex=&lt;span style="color:#006080;"&gt;&amp;quot;1&amp;quot;&lt;/span&gt; VerticalAlignment=&lt;span style="color:#006080;"&gt;&amp;quot;Bottom&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;             &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;100&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Orange&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;                        MouseEnter=&lt;span style="color:#006080;"&gt;&amp;quot;Rectangle_MouseEnter&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;                        MouseLeftButtonDown=&lt;span style="color:#006080;"&gt;&amp;quot;Rectangle_MouseLeftButtonDown&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;             &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;110&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Blue&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;             &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;120&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Green&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;             &amp;lt;Rectangle Height=&lt;span style="color:#006080;"&gt;&amp;quot;5&amp;quot;&lt;/span&gt; Width=&lt;span style="color:#006080;"&gt;&amp;quot;120&amp;quot;&lt;/span&gt; Fill=&lt;span style="color:#006080;"&gt;&amp;quot;Black&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;         &amp;lt;/StackPanel&amp;gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;     &amp;lt;/Border&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;4)&lt;/strong&gt; We need to &lt;strong&gt;bring the rectangle forward&lt;/strong&gt;, closer to the player.&amp;#160; We don’t want the rectangle to accidentally get dragged behind another graphic or another rectangle, so we’ll set the ZIndex to make sure that any rectangle that is currently being dragged is the front-most object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5)&lt;/strong&gt; And finally, the most important thing of all, we need to &lt;strong&gt;move the rectangle to the current position of the mouse&lt;/strong&gt; so that as the player moves the mouse the rectangle moves with it.&amp;#160; That’s the essence of dragging after all.&lt;/p&gt;

&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p&gt;So that’s it.&amp;#160; If we can write code to do those five things, we can drag a rectangle around the playing area.&amp;#160; Next post, we’ll write the code to do those things.&amp;#160; We didn’t write any code this week, so the &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx"&gt;code from last week&lt;/a&gt; will still be the most recent.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Building+a+Silverlight+Game+%3a+Part+7+%3a+Getting+Started+with+Dragging+Rectangles" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2009/10/09/Building-a-Silverlight-Game-_3A00_-Part-7-_3A00_-Getting-Started-with-Dragging-Rectangles.aspx&amp;subject=Building+a+Silverlight+Game+%3a+Part+7+%3a+Getting+Started+with+Dragging+Rectangles"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/10/09/Building-a-Silverlight-Game-_3A00_-Part-7-_3A00_-Getting-Started-with-Dragging-Rectangles.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+7+%3a+Getting+Started+with+Dragging+Rectangles" title="Submit Building+a+Silverlight+Game+%3a+Part+7+%3a+Getting+Started+with+Dragging+Rectangles to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/10/09/Building-a-Silverlight-Game-_3A00_-Part-7-_3A00_-Getting-Started-with-Dragging-Rectangles.aspx&amp;phase=2" title="Submit Building+a+Silverlight+Game+%3a+Part+7+%3a+Getting+Started+with+Dragging+Rectangles to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/10/09/Building-a-Silverlight-Game-_3A00_-Part-7-_3A00_-Getting-Started-with-Dragging-Rectangles.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+7+%3a+Getting+Started+with+Dragging+Rectangles" title="Submit Building+a+Silverlight+Game+%3a+Part+7+%3a+Getting+Started+with+Dragging+Rectangles to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=714" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="visual studio" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/visual+studio/default.aspx" /><category term="silverlight" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/silverlight/default.aspx" /><category term="expression blend" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/expression+blend/default.aspx" /></entry><entry><title>Speaking at Iowa Code Camp</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2009/10/08/Speaking-at-Iowa-Code-Camp.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2009/10/08/Speaking-at-Iowa-Code-Camp.aspx</id><published>2009-10-08T15:24:41Z</published><updated>2009-10-08T15:24:41Z</updated><content type="html">&lt;p&gt;I’ll be speaking at the &lt;a href="http://www.iowacodecamp.com/"&gt;Iowa Code Camp&lt;/a&gt; in Des Moines, IA on November 7th.&amp;#160; Should be great Iowa weather!&amp;#160; The topic will be Ruby on Rails for .NET/Java Developers.&lt;/p&gt;  &lt;p&gt;The Iowa Code Camp is a completely free, one-day event and &lt;a href="http://www.iowacodecamp.com/"&gt;registration is still open&lt;/a&gt;.&amp;#160; Should be a lot of fun.&lt;/p&gt;   &lt;div style="width:425px;text-align:left;" id="__ss_2166268"&gt;&lt;a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/parkbot/ruby-on-rails-for-net-developers" title="Ruby On Rails (RoR) For .Net Developers"&gt;Ruby On Rails (RoR) For .Net Developers&lt;/a&gt;&lt;div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"&gt;View more &lt;a style="text-decoration:underline;" href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a style="text-decoration:underline;" href="http://www.slideshare.net/parkbot"&gt;parkbot&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Speaking+at+Iowa+Code+Camp" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2009/10/08/Speaking-at-Iowa-Code-Camp.aspx&amp;subject=Speaking+at+Iowa+Code+Camp"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/10/08/Speaking-at-Iowa-Code-Camp.aspx&amp;title=Speaking+at+Iowa+Code+Camp" title="Submit Speaking+at+Iowa+Code+Camp to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/10/08/Speaking-at-Iowa-Code-Camp.aspx&amp;phase=2" title="Submit Speaking+at+Iowa+Code+Camp to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/10/08/Speaking-at-Iowa-Code-Camp.aspx&amp;title=Speaking+at+Iowa+Code+Camp" title="Submit Speaking+at+Iowa+Code+Camp to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=697" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author></entry><entry><title>Building a Silverlight Game : Part 6 : Setting up a rectangle for dragging</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx</id><published>2009-09-30T18:25:00Z</published><updated>2009-09-30T18:25:00Z</updated><content type="html">&lt;p&gt;This is the sixth post in a series on &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/08/19/Building-a-Silverlight-Game-_3A00_-Part-1-_3A00_-Introduction-_2600_-Tools.aspx"&gt;building a Silverlight game&lt;/a&gt;.&amp;nbsp; In &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/17/Building-a-Silverlight-Game-_3A00_-Part-5-_3A00_-Changing-the-cursor.aspx"&gt;the last post&lt;/a&gt;, we wrote code to change the cursor into a hand when the player mouses over the orange rectangle.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart6Settingupar_DD97/image.png"&gt;&lt;img alt="image" border="0" height="217" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart6Settingupar_DD97/image_thumb.png" style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0px;" title="image" width="502" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;h4&gt;Introduction&lt;/h4&gt;&lt;p&gt;In this post, we&amp;rsquo;ll write some code to set up a rectangle for dragging and dropping.&amp;nbsp; If we think about the idea of dragging a rectangle around the screen, there are a few things we need to take are of before a rectangle is ready to be dragged around.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;We need to set a flag that we&amp;rsquo;re dragging.&amp;nbsp; When we drag, we&amp;rsquo;re going to tie that to the rectangle MouseMove event and we don&amp;rsquo;t want to drag all the time, just when we&amp;rsquo;re supposed to.&amp;nbsp; So we&amp;rsquo;ll set a flag to tell us that dragging is currently active. That will prevent rectangles from being dragged around the screen every time the player mouses over them. &lt;/li&gt;&lt;li&gt;We need to adjust the opacity of the rectangle to provide a nice visual effect. This will distinguish the dragged rectangle from the rest of the rectangles. &lt;/li&gt;&lt;li&gt;We need to capture the mouse.&amp;nbsp; It is possible in Silverlight to move the cursor so fast that the cursor will come out of the item being dragged.&amp;nbsp; When we capture the mouse we tell Silverlight to keep responding to events as if the mouse was still inside the item being dragged. &lt;/li&gt;&lt;/ol&gt;&lt;h4&gt;Adding the MouseLeftButtonDown event handler&lt;/h4&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Our first task is to wire up the MouseLeftButtonDown event for the orange rectangle.&amp;nbsp; This is easiest in Blend.&amp;nbsp; Just select the orange rectangle, open the Properties tab, and then hit the event button in the upper right.&amp;nbsp; This will display all the events that we can wire up for the rectangle.&amp;nbsp; Double-click inside the MouseLeftButtonDown textbox to have Blend automatically create an event handler.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart6Settingupar_DD97/image_3.png"&gt;&lt;img alt="image" border="0" height="435" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart6Settingupar_DD97/image_thumb_3.png" style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0px;" title="image" width="303" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;If you would rather use Visual Studio, you can just manually add the event handler code to the rectangle&amp;rsquo;s XAML and then add the Rectangle_MouseLeftButtonDown method to the XAML&amp;rsquo;s code-behind.&lt;/p&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum1" style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Orange&amp;quot;&lt;/span&gt; &lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum2" style="color:#606060;"&gt;   2:&lt;/span&gt;            &lt;span style="color:#ff0000;"&gt;MouseEnter&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Rectangle_MouseEnter&amp;quot;&lt;/span&gt; &lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum3" style="color:#606060;"&gt;   3:&lt;/span&gt;            &lt;span style="color:#ff0000;"&gt;MouseMove&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Rectangle_MouseLeftButtonDown &amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum1" style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rectangle_MouseLeftButtonDown (&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, MouseEventArgs e)&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum2" style="color:#606060;"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum3" style="color:#606060;"&gt;   3:&lt;/span&gt;     &lt;span style="color:#008000;"&gt;// TODO: Add event handler implementation here.&lt;/span&gt;&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum4" style="color:#606060;"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Inside the Rectangle_MouseLeftButtonDown event handler, we&amp;rsquo;ll make a call to do the three things that are required to set up a rectangle for dragging and dropping: setting the flag, changing the opacity, and capturing the mouse.&amp;nbsp; We don&amp;rsquo;t want to put all of this code in our code-behind though, so let&amp;rsquo;s write a new class called &amp;ldquo;DragAndDrop&amp;rdquo; that can contain all of drag-and-drop logic.&amp;nbsp; &lt;/p&gt;&lt;p&gt;But first, let&amp;rsquo;s write the code that will call our new class.&amp;nbsp; As you can see below, we&amp;rsquo;re going to call an instance of our DragAndDrop class&amp;rsquo;s StartDrag method and send it the rectangle that we want to start dragging.&lt;/p&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum1" style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rectangle_MouseLeftButtonDown(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, &lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum2" style="color:#606060;"&gt;   2:&lt;/span&gt;      MouseButtonEventArgs e)&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum3" style="color:#606060;"&gt;   3:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum4" style="color:#606060;"&gt;   4:&lt;/span&gt;     dragAndDrop.StartDrag(sender &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; Rectangle);&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum5" style="color:#606060;"&gt;   5:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4&gt;The DragAndDrop class&lt;/h4&gt;&lt;p&gt;The DragAndDrop class is nice and simple.&amp;nbsp; It has a boolean that knows if something is being dragged or not and it has one method that can start the dragging process for a given rectangle.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div id="codeSnippetWrapper" style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;width:97.5%;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;cursor:text;border:silver 1px solid;padding:4px;"&gt;&lt;div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum1" style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; DragAndDrop&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum2" style="color:#606060;"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum3" style="color:#606060;"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; dragging = &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum4" style="color:#606060;"&gt;   4:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum5" style="color:#606060;"&gt;   5:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; StartDrag(Rectangle rectangle)&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum6" style="color:#606060;"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum7" style="color:#606060;"&gt;   7:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (rectangle.Cursor.Equals(Cursors.Hand))&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum8" style="color:#606060;"&gt;   8:&lt;/span&gt;         {&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum9" style="color:#606060;"&gt;   9:&lt;/span&gt;             dragging = &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum10" style="color:#606060;"&gt;  10:&lt;/span&gt;             rectangle.CaptureMouse();&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum11" style="color:#606060;"&gt;  11:&lt;/span&gt;             rectangle.Opacity = 0.6;&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum12" style="color:#606060;"&gt;  12:&lt;/span&gt;         }&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:white;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum13" style="color:#606060;"&gt;  13:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;margin:0em;width:100%;font-family:'Courier New', courier, monospace;direction:ltr;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0px;"&gt;&lt;span id="lnum14" style="color:#606060;"&gt;  14:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The StartDrag method first checks to see if the rectangle&amp;rsquo;s cursor is a hand.&amp;nbsp; If it is, then we know that this rectangle must be on top and so is eligible for dragging.&amp;nbsp; This will prevent players from dragging rectangles that are not on top.&lt;/p&gt;&lt;p&gt;If the rectangle is on top, we just do the three things required to start dragging&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Set the boolean to true &lt;/li&gt;&lt;li&gt;Capture the mouse so events on the rectangle will continue to fire even if the mouse leaves the rectangle&amp;rsquo;s area &lt;/li&gt;&lt;li&gt;Set the opacity of the rectangle to 0.6.&amp;nbsp; This means that the rectangle being dragged will be 40% see through. &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;In our next post, we&amp;rsquo;ll write some code to actually drag the rectangle around the canvas.&amp;nbsp; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingASilverlightGamePost6Code.zip"&gt;&lt;strong&gt;Download source code so far&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Building+a+Silverlight+Game+%3a+Part+6+%3a+Setting+up+a+rectangle+for+dragging" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx&amp;subject=Building+a+Silverlight+Game+%3a+Part+6+%3a+Setting+up+a+rectangle+for+dragging"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+6+%3a+Setting+up+a+rectangle+for+dragging" title="Submit Building+a+Silverlight+Game+%3a+Part+6+%3a+Setting+up+a+rectangle+for+dragging to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx&amp;phase=2" title="Submit Building+a+Silverlight+Game+%3a+Part+6+%3a+Setting+up+a+rectangle+for+dragging to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/30/Building-a-Silverlight-Game-_3A00_-Part-6-_3A00_-Setting-up-a-rectangle-for-dragging.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+6+%3a+Setting+up+a+rectangle+for+dragging" title="Submit Building+a+Silverlight+Game+%3a+Part+6+%3a+Setting+up+a+rectangle+for+dragging to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=610" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="silverlight" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/silverlight/default.aspx" /><category term="expression blend" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/expression+blend/default.aspx" /></entry><entry><title>Screencast: Silverlight 3 and ADO.NET Data Services</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/24/Screencast_3A00_-Silverlight-3-and-ADO.NET-Data-Services.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2009/09/24/Screencast_3A00_-Silverlight-3-and-ADO.NET-Data-Services.aspx</id><published>2009-09-24T20:11:54Z</published><updated>2009-09-24T20:11:54Z</updated><content type="html">&lt;p&gt;Here’s a short screencast that explores using ADO.NET Data Services (Astoria) to provide data for a Silverlight 3 navigation application.&amp;#160; The screencast is just a bit over thirty minutes and is about 1/3 slides and 2/3 demo.&lt;/p&gt;  &lt;p&gt;The screen cast covers&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A brief overview and history of Silverlight&lt;/li&gt;    &lt;li&gt;Overview of data access options in Silverlight&lt;/li&gt;    &lt;li&gt;Comparison / contrast between ADO.NET Data Services and RIA Services&lt;/li&gt;    &lt;li&gt;Demo showing how to&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;use Visual Studio to create an ADO.NET Data Service that exposes and ADO.NET Entity Data Model&lt;/li&gt;      &lt;li&gt;use Expression Blend to wire up a Silverlight Navigation Application to Expression Blend Sample Data&lt;/li&gt;      &lt;li&gt;use Visual Studio to wire up a Silverlight Navigation Application to communicate with an ADO.NET Data Service&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/Silverlight%203%20and%20ADO.NET%20Data%20Services.wmv" target="_blank"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/ScreencastSilverlight3an.NETDataServices_D5A1/image.png" width="504" height="293" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/Silverlight%203%20and%20ADO.NET%20Data%20Services.wmv" target="_blank"&gt;Download&lt;/a&gt; (WMV, 45MB)&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Screencast%3a+Silverlight+3+and+ADO.NET+Data+Services" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2009/09/24/Screencast_3A00_-Silverlight-3-and-ADO.NET-Data-Services.aspx&amp;subject=Screencast%3a+Silverlight+3+and+ADO.NET+Data+Services"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/24/Screencast_3A00_-Silverlight-3-and-ADO.NET-Data-Services.aspx&amp;title=Screencast%3a+Silverlight+3+and+ADO.NET+Data+Services" title="Submit Screencast%3a+Silverlight+3+and+ADO.NET+Data+Services to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/24/Screencast_3A00_-Silverlight-3-and-ADO.NET-Data-Services.aspx&amp;phase=2" title="Submit Screencast%3a+Silverlight+3+and+ADO.NET+Data+Services to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/24/Screencast_3A00_-Silverlight-3-and-ADO.NET-Data-Services.aspx&amp;title=Screencast%3a+Silverlight+3+and+ADO.NET+Data+Services" title="Submit Screencast%3a+Silverlight+3+and+ADO.NET+Data+Services to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=546" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="silverlight" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/silverlight/default.aspx" /><category term="expression blend" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/expression+blend/default.aspx" /><category term="ado.net data services" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/ado.net+data+services/default.aspx" /><category term="screencast" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/screencast/default.aspx" /></entry><entry><title>Using Converters Instead of Custom Client Properties with Silverlight and ADO.NET Data Services</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/23/Using-Converters-Instead-of-Custom-Client-Properties-with-Silverlight-and-ADO.NET-Data-Services.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2009/09/23/Using-Converters-Instead-of-Custom-Client-Properties-with-Silverlight-and-ADO.NET-Data-Services.aspx</id><published>2009-09-23T16:37:02Z</published><updated>2009-09-23T16:37:02Z</updated><content type="html">&lt;p&gt;One challenge with ADO.NET Data Services is that it has trouble understanding what’s going on if you add custom properties to your entities on the client side.&amp;#160; This post will explain using converters to overcome that challenge when using Silverlight.&amp;#160; Or WPF, I suppose.&lt;/p&gt;  &lt;h4&gt;Background&lt;/h4&gt;  &lt;p&gt;When you add a reference to an ADO.NET Data Service, Visual Studio generates a set of client classes that represent the entities on the server.&amp;#160; These classes are tantalizing marked as partial, which could lead you to believe that you are welcome to add additional client-only properties to these classes.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; [global::System.Data.Services.Common.DataServiceKeyAttribute(&lt;span style="color:#006080;"&gt;&amp;quot;Id&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;partial&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Employee&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;However, if you extend the partial class to add a property, ADO.NET Data Services will be grumpy when you try to save your object since it won’t know what to do with the extra property.&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Let’s say that we want to add an extra property to our Employee class called “HasCornerOffice” that returns “true” if the employee has “VP” in their title.&amp;#160; Something like this.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;partial&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Employee &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; HasCornerOffice &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.Title.StartsWith(&lt;span style="color:#006080;"&gt;&amp;quot;VP&amp;quot;&lt;/span&gt;);  }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;When you try to save an instance of an employee back to the database, you’ll get an error along the lines of &lt;strong&gt;“Error processing request stream. The property name ‘HasCornerOffice’ specified for type ‘Employee’ is not valid.”&amp;#160; &lt;/strong&gt;ADO.NET Data Services has no idea what the property is all about and is letting us know.&lt;/p&gt;

&lt;h4&gt;Some Solutions&lt;/h4&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;p&gt;There are a few ways around this.&amp;#160; &lt;/p&gt;

&lt;p&gt;You could use a brand-new client-only class that can be mapped to and from Employee.&amp;#160; Adding this layer of abstraction could make a lot of sense and add some insulation between your client and server that could come in handy later.&amp;#160; Not a bad way to go for the trade-off of writing and maintaining the mapping code to back and forth between the client and server objects.&lt;/p&gt;

&lt;p&gt;You could also customize the way that objects are serialized by digging into the bowels of the data context and intercepting the ATOM request before it is send to the server.&amp;#160; Not sure what this would do if you were using JSON, but &lt;a href="http://blogs.msdn.com/phaniraj/archive/2008/12/11/customizing-serialization-of-entities-in-the-ado-net-data-services-client-library.aspx" target="_blank"&gt;this blog post&lt;/a&gt; has the details for wiring it up with an ATOM request.&lt;/p&gt;

&lt;h4&gt;Using Convertors&lt;/h4&gt;

&lt;p&gt;An alternate quick and easy solution is to leave the client-side entities as-is and use a converter to transform our Employee data into the data that we want to display.&amp;#160; This has the advantage of being straightforward and low-impact, but is maybe not as flexible or extensible long-term as the two solutions above.&lt;/p&gt;

&lt;p&gt;Using the same Employee example as above, our Converter would look like this.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; CornerOfficeConverter : IValueConverter&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;  {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;      &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; Convert(&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;          &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;, &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;          Type targetType, &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;          &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; parameter, &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;          CultureInfo culture)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;      {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;          &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;.IsNullOrEmpty(&lt;span style="color:#0000ff;"&gt;value&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;))&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;          {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;          }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;          &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;.ToString().StartsWith(&lt;span style="color:#006080;"&gt;&amp;quot;VP&amp;quot;&lt;/span&gt;);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt;      }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum16"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;And we could bind to it like this.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;TextBlock &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;     Text=&lt;span style="color:#006080;"&gt;&amp;quot;{Binding Title, &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;            Converter={StaticResource TitleConverter}}&amp;quot;&lt;/span&gt; /&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p&gt;Hopefully, this shortcoming in ADO.NET Data Services will be resolved in the framework itself in the next version or so, but in the meantime, those are some ideas of how to work around the problem.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Using+Converters+Instead+of+Custom+Client+Properties+with+Silverlight+and+ADO.NET+Data+Services" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2009/09/23/Using-Converters-Instead-of-Custom-Client-Properties-with-Silverlight-and-ADO.NET-Data-Services.aspx&amp;subject=Using+Converters+Instead+of+Custom+Client+Properties+with+Silverlight+and+ADO.NET+Data+Services"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/23/Using-Converters-Instead-of-Custom-Client-Properties-with-Silverlight-and-ADO.NET-Data-Services.aspx&amp;title=Using+Converters+Instead+of+Custom+Client+Properties+with+Silverlight+and+ADO.NET+Data+Services" title="Submit Using+Converters+Instead+of+Custom+Client+Properties+with+Silverlight+and+ADO.NET+Data+Services to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/23/Using-Converters-Instead-of-Custom-Client-Properties-with-Silverlight-and-ADO.NET-Data-Services.aspx&amp;phase=2" title="Submit Using+Converters+Instead+of+Custom+Client+Properties+with+Silverlight+and+ADO.NET+Data+Services to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/23/Using-Converters-Instead-of-Custom-Client-Properties-with-Silverlight-and-ADO.NET-Data-Services.aspx&amp;title=Using+Converters+Instead+of+Custom+Client+Properties+with+Silverlight+and+ADO.NET+Data+Services" title="Submit Using+Converters+Instead+of+Custom+Client+Properties+with+Silverlight+and+ADO.NET+Data+Services to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=536" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="silverlight" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/silverlight/default.aspx" /><category term="ado.net data services" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/ado.net+data+services/default.aspx" /></entry><entry><title>Building a Silverlight Game : Part 5 : Changing the cursor</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/17/Building-a-Silverlight-Game-_3A00_-Part-5-_3A00_-Changing-the-cursor.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2009/09/17/Building-a-Silverlight-Game-_3A00_-Part-5-_3A00_-Changing-the-cursor.aspx</id><published>2009-09-17T16:59:44Z</published><updated>2009-09-17T16:59:44Z</updated><content type="html">&lt;p&gt;This is the fifth post in a series on &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/08/19/Building-a-Silverlight-Game-_3A00_-Part-1-_3A00_-Introduction-_2600_-Tools.aspx"&gt;building a Silverlight game&lt;/a&gt;.&amp;#160; In &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/10/Building-a-Silverlight-Game-_3A00_-Part-4.aspx"&gt;the last post&lt;/a&gt;, we finished our basic layout: three stack panels for the game rectangles, some rectangles to play with, and a bottom border for the rectangles to sit on.&lt;/p&gt;  &lt;p&gt;&lt;img style="display:block;float:none;margin-left:auto;margin-right:auto;" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_thumb_6.png" /&gt;&lt;/p&gt;  &lt;p&gt;With all of that set, we can start writing some code.&amp;#160; The first thing to do is let the user know which rectangle they are allowed to drag.&amp;#160; The rules of the game state that you can only drag the top rectangle around. In our case, this is the orange rectangle.&lt;/p&gt;  &lt;p&gt;The standard way to let someone know that they can interact with an object is to change the cursor from the default arrow to a hand, so that’s what we’ll do.&amp;#160; We need to set things up so that when the player mouses over the orange rectangle, the cursor changes into a hand.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart5Changingthe_A897/image.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart5Changingthe_A897/image_thumb.png" width="291" height="404" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Blend makes event handling an n easy task through the events pane.&amp;#160; Select the orange rectangle, and then look for the lightning bolt icon over on the Properties tab.&amp;#160; This gives us access to all of the events available for the orange rectangle.&lt;/p&gt;  &lt;p&gt;The one we want is the MouseEnter event.&amp;#160; Double-click inside of the textbox next to MouseEnter and Blend will create an event handler for us.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;partial&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; MainPage : UserControl&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; MainPage()&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;         InitializeComponent();&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rectangle_MouseEnter(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, MouseEventArgs e)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;         &lt;span style="color:#008000;"&gt;// TODO: Add event handler implementation here.&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Blend 3 will let us write C#, but the experience is a better in Visual Studio.&amp;#160; If you don’t have Blend, you can accomplish the same event handle wire-up task by adjusting the XAML for your orange rectangle to look like the snippet below and then manually adding the Rectangle_MouseEnter code to your code-behind.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;StackPanel&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;LeftPanel&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Orientation&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Vertical&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;     &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;ZIndex&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Bottom&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Orange&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;                &lt;span style="color:#ff0000;"&gt;MouseEnter&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Rectangle_MouseEnter&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;110&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Blue&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;120&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Green&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;5&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;120&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Black&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Inside of Rectangle_MouseEnter, we can write our code to change the cursor into a hand.&amp;#160; The easiest thing to do is this:&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rectangle_MouseEnter(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, MouseEventArgs e)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     Rectangle rectangle = sender &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; Rectangle;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;     rectangle.Cursor = Cursors.Hand;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;We cast the sender of the event to a rectangle (because it is a rectangle) and then set the Cursor to Cursors.Hand. This does the job, but isn’t very flexible.&amp;#160; We eventually want this code to apply to all of our rectangles, not just the orange one, so let’s add some checks to make sure that the rectangle is on top of its stack.&amp;#160; We only want to change the cursor to a hand if the rectangle being moused over is on top.&lt;/p&gt;

&lt;p&gt;So we adjust our Rectangle_MouseEnter to look like this:&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rectangle_MouseEnter(&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; sender, MouseEventArgs e)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;  {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;      Rectangle rectangle = sender &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; Rectangle;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;      Panel panel = rectangle.Parent &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; Panel;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;      rectangle.Cursor = (RectangleIsOnTop(rectangle, panel))&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;          ? Cursors.Hand&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;          : Cursors.Arrow;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;  }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;All we’re lacking now is the RectangleOnTop() method referenced by our new conditional logic.&amp;#160; Since the children (rectangles) of the stack panel are ordered by their index, with 0 being on top, such a method might look like this.&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; RectangleIsOnTop(Rectangle rectangle, Panel panel)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; panel.Children.IndexOf(rectangle).Equals(0);&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now when we mouse over the orange rectangle, our cursor will change into a hand to indicate that we can drag the rectangle around.&amp;#160; In the next post, we’ll write some code to start dragging the rectangle around.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Building+a+Silverlight+Game+%3a+Part+5+%3a+Changing+the+cursor" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2009/09/17/Building-a-Silverlight-Game-_3A00_-Part-5-_3A00_-Changing-the-cursor.aspx&amp;subject=Building+a+Silverlight+Game+%3a+Part+5+%3a+Changing+the+cursor"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/17/Building-a-Silverlight-Game-_3A00_-Part-5-_3A00_-Changing-the-cursor.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+5+%3a+Changing+the+cursor" title="Submit Building+a+Silverlight+Game+%3a+Part+5+%3a+Changing+the+cursor to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/17/Building-a-Silverlight-Game-_3A00_-Part-5-_3A00_-Changing-the-cursor.aspx&amp;phase=2" title="Submit Building+a+Silverlight+Game+%3a+Part+5+%3a+Changing+the+cursor to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/17/Building-a-Silverlight-Game-_3A00_-Part-5-_3A00_-Changing-the-cursor.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+5+%3a+Changing+the+cursor" title="Submit Building+a+Silverlight+Game+%3a+Part+5+%3a+Changing+the+cursor to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=447" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author><category term="visual studio" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/visual+studio/default.aspx" /><category term="silverlight" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/silverlight/default.aspx" /><category term="expression blend" scheme="http://www.smips.com/smip/blogs/codebadger/archive/tags/expression+blend/default.aspx" /></entry><entry><title>Building a Silverlight Game : Part 4 : Finishing the basic layout</title><link rel="alternate" type="text/html" href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/10/Building-a-Silverlight-Game-_3A00_-Part-4.aspx" /><id>http://www.smips.com/smip/blogs/codebadger/archive/2009/09/10/Building-a-Silverlight-Game-_3A00_-Part-4.aspx</id><published>2009-09-10T17:46:10Z</published><updated>2009-09-10T17:46:10Z</updated><content type="html">&lt;p&gt;This is the fourth post in a series on &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/08/19/Building-a-Silverlight-Game-_3A00_-Part-1-_3A00_-Introduction-_2600_-Tools.aspx"&gt;building a Silverlight game&lt;/a&gt;.&amp;#160; In &lt;a href="http://www.smips.com/smip/blogs/codebadger/archive/2009/09/04/Building-a-Silverlight-Game-_3A00_-Part-3-_3A00_-Adding-some-rectangles.aspx"&gt;the last post&lt;/a&gt;, we polished off our three stack panels and added some rectangles to the first stack panel.&lt;/p&gt;  &lt;p&gt;&lt;img style="display:block;float:none;margin-left:auto;margin-right:auto;" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart3Addingsomer_A12A/image_thumb.png" /&gt;&lt;/p&gt;  &lt;p&gt;The challenge we left off with is how to get the rectangles down to the bottom where they belong.&amp;#160; Stack panels like to put their items at the top and then add subsequent items underneath, just like in HTML.&lt;/p&gt;  &lt;p&gt;We can get around this by making our stack panel just tall enough to hold only the rectangles that are in it, and then forcing the entire stack panel down to the bottom.&amp;#160; This is accomplished by wrapping our stack panel in a border and taking away its height.&lt;/p&gt;  &lt;p&gt;A border is an interesting Silverlight control that can have only one child.&amp;#160; It is best used for making borders of course, but it can also make a handy container.&amp;#160; There are some nice benefits of having a container control that you know will only ever have one child.&amp;#160; &lt;/p&gt;  &lt;p&gt;To surround the panels with borders in Expression Blend, just right-click the panel and select “Group Into &amp;gt; Border”.&amp;#160; Blend is even kind enough to move our height from the stack panel to the border.&amp;#160; Repeat this for all of the panels. If you’re using Visual Studio, you can just skip ahead to the finished XAML below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_thumb.png" width="432" height="373" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;After surrounding the panels with borders, your object tree should look like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_3.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_thumb_3.png" width="275" height="179" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The next step is to get the panels to sit at the bottom of their panels.&amp;#160; This is done by selecting all three panels at once in the object explorer and changing their vertical alignment property to “Bottom”&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_4.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_thumb_4.png" width="271" height="119" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now all of the panels are sitting snugly at the bottom of their borders.&amp;#160; Remember that the empty space at the bottom is intentional.&amp;#160; We’ll fill that up shortly.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_5.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_thumb_5.png" width="504" height="277" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Your finished XAML should look something a lot like this.&amp;#160; We have three stack panels, each wrapped in a border.&amp;#160; The first stack panel has three playable rectangles and a rectangle platform.&lt;/p&gt;  &lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:200px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Canvas&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;800&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;430&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Border&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;380&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;257&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;Left&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;15&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum3"&gt;   3:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;StackPanel&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;LeftPanel&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Orientation&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Vertical&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum4"&gt;   4:&lt;/span&gt;             &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;ZIndex&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Bottom&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum5"&gt;   5:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Orange&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum6"&gt;   6:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;110&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Blue&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum7"&gt;   7:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;120&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Green&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum8"&gt;   8:&lt;/span&gt;             &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;5&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;120&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Black&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;Border&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Border&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;380&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;257&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;Left&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;272&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;StackPanel&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;MiddlePanel&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Orientation&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Vertical&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum13"&gt;  13:&lt;/span&gt;             &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;ZIndex&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Bottom&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;Border&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum15"&gt;  15:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Border&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;380&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;257&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;Left&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;529&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum16"&gt;  16:&lt;/span&gt;         &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;StackPanel&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;RightPanel&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Orientation&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Vertical&amp;quot;&lt;/span&gt;  &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum17"&gt;  17:&lt;/span&gt;             &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;ZIndex&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Bottom&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum18"&gt;  18:&lt;/span&gt;     &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;Border&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum19"&gt;  19:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;Canvas&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The last thing we need to do to finish our basic layout is to fill up the bottom area.&amp;#160; For now, we’ll just use a boring gray rectangle.&amp;#160; Later, we’ll use brushes to spice it up a bit.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;Rectangle&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;x:Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;BottomRectangle&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Height&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;800&amp;quot;&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#606060;" id="lnum2"&gt;   2:&lt;/span&gt;            &lt;span style="color:#ff0000;"&gt;Canvas&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;Top&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;380&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;Fill&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Gray&amp;quot;&lt;/span&gt;  &lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;After adding the bottom rectangle, our playing area looks like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_6.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://www.smips.com/smip/blogs/codebadger/uploads/BuildingaSilverlightGamePart4_B339/image_thumb_6.png" width="504" height="277" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And that’s it for basic layout.&amp;#160; In the next post, we’ll start writing some C# to enable dragging and dropping the rectangles.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a title="Email Building+a+Silverlight+Game+%3a+Part+4+%3a+Finishing+the+basic+layout" href = "mailto:?body=Thought you might like this: http://www.smips.com/smip/blogs/codebadger/archive/2009/09/10/Building-a-Silverlight-Game-_3A00_-Part-4.aspx&amp;subject=Building+a+Silverlight+Game+%3a+Part+4+%3a+Finishing+the+basic+layout"&gt;Email it!&lt;/a&gt; | &lt;a href = "http://del.icio.us/post?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/10/Building-a-Silverlight-Game-_3A00_-Part-4.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+4+%3a+Finishing+the+basic+layout" title="Submit Building+a+Silverlight+Game+%3a+Part+4+%3a+Finishing+the+basic+layout to del.icio.us" &gt;bookmark it!&lt;/a&gt; | &lt;a href = "http://www.digg.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/10/Building-a-Silverlight-Game-_3A00_-Part-4.aspx&amp;phase=2" title="Submit Building+a+Silverlight+Game+%3a+Part+4+%3a+Finishing+the+basic+layout to digg.com"&gt;digg it!&lt;/a&gt; | &lt;a href = "http://reddit.com/submit?url=http://www.smips.com/smip/blogs/codebadger/archive/2009/09/10/Building-a-Silverlight-Game-_3A00_-Part-4.aspx&amp;title=Building+a+Silverlight+Game+%3a+Part+4+%3a+Finishing+the+basic+layout" title="Submit Building+a+Silverlight+Game+%3a+Part+4+%3a+Finishing+the+basic+layout to reddit.com"&gt;reddit!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.smips.com/smip/aggbug.aspx?PostID=417" width="1" height="1"&gt;</content><author><name>brad</name><uri>http://www.smips.com/smip/members/brad.aspx</uri></author></entry></feed>