<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Nick Polyak's Software Blog</title>
	<atom:link href="http://nickssoftwareblog.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://nickssoftwareblog.com</link>
	<description>Programming theory, software development process, Silverlight, WPF</description>
	<lastBuildDate>Thu, 28 Jul 2011 01:02:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='nickssoftwareblog.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Nick Polyak's Software Blog</title>
		<link>http://nickssoftwareblog.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://nickssoftwareblog.com/osd.xml" title="Nick Polyak&#039;s Software Blog" />
	<atom:link rel='hub' href='http://nickssoftwareblog.com/?pushpress=hub'/>
		<item>
		<title>New articles on Silverlight and Prism</title>
		<link>http://nickssoftwareblog.com/2011/02/21/new-articles-on-silverlight-and-prism/</link>
		<comments>http://nickssoftwareblog.com/2011/02/21/new-articles-on-silverlight-and-prism/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 03:22:42 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nickssoftwareblog.com/?p=410</guid>
		<description><![CDATA[It has been a while and I kind of neglected the blog, but I did publish a bunch of new articles on code project: Prism for Silverlight/MEF in Easy Samples. Part 1 &#8211; Prism Modules Prism for Silverlight/MEF in Easy Samples. Part 2 &#8211; Prism Navigation Prism for Silverlight/MEF in Easy Samples. Part 3 &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=410&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It has been a while and I kind of neglected the blog, but I did publish a bunch of new articles on code project:</p>
<p><a href="http://www.codeproject.com/KB/silverlight/PrismTutorial_Part1.aspx" target="_blank">Prism for Silverlight/MEF in Easy Samples. Part 1 &#8211; Prism Modules</a></p>
<p><a href="http://www.codeproject.com/KB/silverlight/PrismTutorial_Part2.aspx" target="_blank">Prism for Silverlight/MEF in Easy Samples. Part 2 &#8211; Prism Navigation</a></p>
<p><a href="http://www.codeproject.com/KB/silverlight/PrismTutorial_Part3.aspx" target="_blank">Prism for Silverlight/MEF in Easy Samples. Part 3 &#8211; Communication between the Modules</a></p>
<p><a href="http://www.codeproject.com/KB/cs/PathAnimationsWithEasing.aspx" target="_blank">Silverlight Animations along Arbitrary Mathematical Paths via Easing</a></p>
<p><a href="http://www.codeproject.com/KB/cs/ParameterSubstitution.aspx" target="_blank">Parameter Substitution within Expression Trees<br />
</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/410/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=410&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2011/02/21/new-articles-on-silverlight-and-prism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight 2.0 In Examples: Part ? Drag and Drop Inside Out</title>
		<link>http://nickssoftwareblog.com/2008/10/07/silverlight-20-in-examples-part-drag-and-drop-inside-out/</link>
		<comments>http://nickssoftwareblog.com/2008/10/07/silverlight-20-in-examples-part-drag-and-drop-inside-out/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 02:08:26 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Drag and Drop]]></category>

		<guid isPermaLink="false">http://nickssoftwareblog.wordpress.com/?p=275</guid>
		<description><![CDATA[Introduction This is a continuation of a tutorial, see Silverlight 2.0 In Examples: Part 0. Introduction&#8221; and &#8220;Silverlight 2.0 In Examples: Part 1. Silverlight Elements: Panels and Controls. Since recently I&#8217;ve been working on Silverlight Drag and Drop, I decided to break the continuity of this tutorial and skip several parts, writing right away about how [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=275&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>This is a continuation of a tutorial, see <a href="http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-introduction/">Silverlight 2.0 In Examples: Part 0. Introduction&#8221;</a> and <a href="http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-overview-of-silverlight-controls/">&#8220;Silverlight 2.0 In Examples: Part 1. Silverlight Elements: Panels and Controls</a>.</p>
<p>Since recently I&#8217;ve been working on Silverlight Drag and Drop, I decided to break the continuity of this tutorial and skip several parts, writing right away about how to implement Drag and Drop in Silverlight. In addition to information from the previous sections of the tutorial, this part requires some knowledge of DataTemplates and binding (I will give brief explanations of both).</p>
<p>The article that started me on Silverlight 2.0 Drag and Drop can be accessed via the following link: <a href="http://leeontech.wordpress.com/2008/04/11/drag-and-drop-in-silverlight/">Drag and Drop in Silverlight</a>. At the bottom of the article you can find a link to download the source code.</p>
<p>Here, however, I go over Drag and Drop with more details and examples. A special feature of this article is a Drag and Drop custom control designed to absorb most of the Drag and Drop complexity. Based on this control, I created an example functionally similar to the one described in <a href="http://leeontech.wordpress.com/2008/04/11/drag-and-drop-in-silverlight/">Drag and Drop in Silverlight</a>.</p>
<p>Silverlight demos, including those corresponding to the samples presented here can be found at <a href="http://awebpros.com/index.html?AWebProsDemos.aspx">AWebPros Demos</a>.</p>
<h2>Simple Silverlight Drag and Drop Example</h2>
<p style="text-align:left;">Here is the screen capture of the first example:</p>
<p style="text-align:center;"><a href="http://nickssoftwareblog.files.wordpress.com/2008/10/simpledragdrop.jpg"><img class="size-full wp-image-302    aligncenter" title="simpledragdrop" src="http://nickssoftwareblog.files.wordpress.com/2008/10/simpledragdrop.jpg?w=430&#038;h=474" alt="" width="430" height="474" /></a></p>
<p>One can drag and drop the red circle anywhere within the Silverlight application area.<br />
The source code for this sample can be downloaded from <a href="http://nickssoftwareblog.files.wordpress.com/2008/10/simpledragdropzip2.doc">simpledragdropzip.doc</a>. As always, please remove .doc extension, rename the file to simpledragdrop.zip and then open it as a zip file.<br />
Below the code of the sample is explained in detail.<br />
Here are the contents of Page.xaml file:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">UserControl</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Class</span><span style="color:#0000ff;">=&#8221;SimpleDragDrop.Page&#8221; </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">xmlns</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>xmlns</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>Background</span><span style="color:#0000ff;">=&#8221;Yellow&#8221;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>Width</span><span style="color:#0000ff;">=&#8221;400&#8243;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>Height</span><span style="color:#0000ff;">=&#8221;300&#8243;&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">UserControl.Resources</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">DataTemplate</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Key</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;Circle&#8221;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>            </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Ellipse</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Width</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;20&#8243;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Height</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;20&#8243;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Fill</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;Red&#8221;&gt;&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Ellipse</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">DataTemplate</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">UserControl.Resources</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Name</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;LayoutRoot&#8221;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Background</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;White&#8221;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Popup</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Name</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;MyPopup&#8221;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">IsOpen</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;False&#8221;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>            </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ContentControl</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0 0 0 .5in;"><span style="font-size:10pt;color:#ff0000;font-family:&quot;"><span>   </span>ContentTemplate</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;{</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">StaticResource</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Circle</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">}&#8221;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0 0 0 .5in;"><span style="font-size:10pt;color:#ff0000;font-family:&quot;"><span>   </span>Opacity</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;0.5&#8243;/&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Popup</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ContentControl</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>ContentTemplate</span><span style="color:#0000ff;">=&#8221;{</span><span style="color:#a31515;">StaticResource</span><span style="color:#ff0000;"> Circle</span><span style="color:#0000ff;">}&#8221;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&#8221;MyControlToMove&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ContentControl</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">UserControl</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span><br />
The object that we are dragging and dropping is ContentControl at the very bottom of the XAML file. Its name is &#8220;MyControlToMove&#8221;.</p>
<p class="MsoNormal" style="margin:0;">ContentControl is a control that has two major properties: Content (which contains some data) and ContentTemplate (which specifies how to present this data).</p>
<p class="MsoNormal" style="margin:0;">In our case the presentation of MyControlToMove is not data dependent (Content property does not play any role). This presentation is determined only by the DataTemplate which is defined as a resource called &#8220;Circle&#8221; within UserControl.Resources section. In this example this ContentControl is always displayed as a red circle.<br />
Another control is used as a drag cursor to show where the circle is dragged. It is represented by a similar red circle with its opacity property set to 0.5, making it semitransparent. This control is of Popup type.</p>
<p>Now, let us deconstruct the C# code. While XAML contains mostly design and static information, C# carries information about actions. There are 3 main actions within the Drag and Drop process:</p>
<li>Drag beginning &#8211; occurs when the left mouse button is pressed on a draggable object.</li>
<li>Drag process &#8211; occurs when the mouse pointer is moved with the left mouse button still pressed.</li>
<li>Drop &#8211; occurs when the left mouse button is released.</li>
<p>Correspondingly, we have 3 event handlers for 3 events:</p>
<li>MouseLeftButtonDown &#8211; to handle start of the drag process</li>
<li>MouseMove &#8211; to handle visual moving of the dragged item</li>
<li>MouseLeftButtonUp &#8211; to handle drop operation</li>
<p>All of the events are registered with the top level panel &#8220;LayoutRoot&#8221;. This is possible because of the event &#8220;Bubbling&#8221;. Even if a child of &#8220;LayoutRoot&#8221; panel is clicked, the event eventually &#8220;bubbles&#8221; up to it, unless it is handled before.<br />
Here is how we set the event handlers within the application:</p>
<p class="MsoNormal" style="text-indent:-.5in;text-align:left;margin:0 0 0 .5in;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot.MouseLeftButtonDown += </span></p>
<p class="MsoNormal" style="text-indent:-.5in;text-align:left;margin:0 0 0 .5in;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">new</span> <span style="color:#2b91af;">MouseButtonEventHandler</span>(LayoutRoot_MouseLeftButtonDown);</span></p>
<p class="MsoNormal" style="text-indent:-.5in;text-align:left;margin:0 0 0 .5in;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot.MouseMove += </span></p>
<p class="MsoNormal" style="text-indent:-.5in;text-align:left;margin:0 0 0 .5in;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">new</span> <span style="color:#2b91af;">MouseEventHandler</span>(LayoutRoot_MouseMove);</span></p>
<p class="MsoNormal" style="text-indent:-.5in;text-align:left;margin:0 0 0 .5in;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot.MouseLeftButtonUp += </span></p>
<p class="MsoNormal" style="text-indent:-.5in;text-align:left;margin:0 0 0 .5in;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;"><span>    </span>new</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">MouseButtonEventHandler</span>(LayoutRoot_MouseLeftButtonUp);</span></p>
<p class="MsoNormal" style="text-indent:-.5in;text-align:left;margin:0 0 0 .5in;"> </p>
<p>Now let us describe these 3 operations in detail.</p>
<h3>Starting the Drag Operation</h3>
<p>Starting the drag operation is handled by the function LayoutRoot_MouseLeftButtonDown which in turn calls StartDragDrop.</p>
<p>Here is the code for LayoutRoot_MouseLeftButtonDown function:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">void</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot_MouseLeftButtonDown(<span style="color:#0000ff;">object</span> sender, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                                               </span><span style="color:#2b91af;">MouseButtonEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// obtain all UI elements at the </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;"><span>    </span>// current mouse pointer location</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">UIElement</span>&gt; elements = </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span>(<span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">UIElement</span>&gt;)<span style="color:#0000ff;">this</span>.HitTest(e.GetPosition(<span style="color:#0000ff;">null</span>));</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// get the first element of type Ellipse and </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;"><span>    </span>// start drag operation on it.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">foreach</span> (<span style="color:#2b91af;">UIElement</span> element <span style="color:#0000ff;">in</span> elements)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">if</span> (element <span style="color:#0000ff;">is</span> <span style="color:#2b91af;">Ellipse</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>StartDragDrop(element, e);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#0000ff;">break</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p>First HitTest gets all the elements &#8220;pierced&#8221; by the current mouse pointer. Then we iterate over each of of the elements, find the &#8220;Ellipse&#8221; (this is our circle we want to move) and start drag operation on it by calling StartDragDrop function.</p>
<p>Here is the StartDragDrop function code:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">private</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">void</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">StartDragDrop(<span style="color:#2b91af;">UIElement</span> element, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>              </span><span style="color:#2b91af;">MouseButtonEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// make the popup visible</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.IsOpen = <span style="color:#0000ff;">true</span>; </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// make the mouse events connected to </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// the popup</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.CaptureMouse(); </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// figure out the mouse coordinates at the onset </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// of Drag operation.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>_horisontalOffset = e.GetPosition(<span style="color:#0000ff;">null</span>).X;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>_verticalOffset = e.GetPosition(<span style="color:#0000ff;">null</span>).Y;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// set _captured flag to true</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// (this is to check later if drag drop </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">//<span>  </span>operation is in progress)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>_captured = <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// move the popup to the current mouse location.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.HorizontalOffset = _horisontalOffset;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.VerticalOffset = _verticalOffset;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p>The StartDragDrop functionality is explained in the comments within its code.</p>
<h3>Drag Operation During the Mouse Move</h3>
<p>Here is how we implemented Drag operation when mouse moves:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">void</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot_MouseMove(<span style="color:#0000ff;">object</span> sender, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                     </span><span style="color:#2b91af;">MouseEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// if no drag and drop started, </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// we do not need to do anything.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">if</span> (!_captured)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span> </span><span style="color:#008000;">// update the popup location to the </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// current mouse pointer location.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.HorizontalOffset = e.GetPosition(<span style="color:#0000ff;">null</span>).X;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.VerticalOffset = e.GetPosition(<span style="color:#0000ff;">null</span>).Y;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p>All we need to do is to move the Drag popup to the current location of the mouse pointer. </p>
<h3>Drop Operation</h3>
<p>Finally, here is the function in charge of Drop operation:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">void</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot_MouseLeftButtonUp(<span style="color:#0000ff;">object</span> sender, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                             </span><span style="color:#2b91af;">MouseButtonEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// if drag is not started we do not need</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// any drop functionality to execute</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">if</span> (!_captured)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// mouse capture is released</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.ReleaseMouseCapture();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// popup becomes invisible</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.IsOpen = <span style="color:#0000ff;">false</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// set captured flag to false</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// (no drag operation in progress)</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>_captured = <span style="color:#0000ff;">false</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// the rest of the code just moves</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// our content control to the new location</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// using TranslateTransform</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">GeneralTransform</span> gt = </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">this</span>.TransformToVisual(MyControlToMove);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">Point</span>startPoint = gt.Transform(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Point</span>(0, 0));</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">Point</span>p = e.GetPosition(<span style="color:#0000ff;">null</span>);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">TranslateTransform</span>tt = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">TranslateTransform</span>();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>tt.X = p.X &#8211; _horisontalOffset &#8211; startPoint.X;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>tt.Y = p.Y &#8211; _verticalOffset &#8211; startPoint.Y;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyControlToMove.RenderTransform = tt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p>As you can see, we stop the DragDrop operation by releasing the mouse capture, making the Drag popup invisible and setting _captured flag to false. Then we do the actual drop operation by moving the original dragged control to the new location using TranslateTransform.</p>
<h2>Drag and Drop with Forbidden Area</h2>
<p>Now, let us consider a more complicated example.<br />
In addition to the previously discussed functionality it has the following:</p>
<li>Area in which it is forbidden to drop.</li>
<li>A special template for the Drag popup to appear when the mouse pointer is in the area in which it is forbidden to drop.</li>
<li>The drag operation does not start right away, but only when the mouse is far enough from the origin.</li>
<p>Here is the screen capture for the example:</p>
<p style="text-align:center;"><a href="http://nickssoftwareblog.files.wordpress.com/2008/10/dragdropwithforbiddenarea.jpg"><img class="size-full wp-image-354  aligncenter" title="dragdropwithforbiddenarea" src="http://nickssoftwareblog.files.wordpress.com/2008/10/dragdropwithforbiddenarea.jpg?w=414&#038;h=432" alt="" width="414" height="432" /></a></p>
<p>The yellow circle signifies the area where the drop is allowed. Outside of it, the drop is forbidden.<br />
Here is the code for the example: <a href="http://nickssoftwareblog.files.wordpress.com/2008/10/dragdropwithforbiddenareazip1.doc">dragdropwithforbiddenareazip.doc</a>.<br />
As one can see from the code, the capture process now begins during MouseMove action and only when the distance between the original and current locations of the mouse is greater than _captureRadius:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">private</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">void </span>BeginCapture(<span style="color:#2b91af;">MouseEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// check if the mouse pointer position</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// within _captureRadius</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">double </span>diffX = </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>e.GetPosition(<span style="color:#0000ff;">null</span>).X &#8211; _horisontalOffset;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">double </span>diffY = </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>e.GetPosition(<span style="color:#0000ff;">null</span>).Y &#8211; _verticalOffset;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// if it is within _captureRadion, </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// do not start capture</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">if </span>((diffX * diffX + diffY * diffY) &lt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>_captureRaduis * _captureRaduis)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// make popup visible</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.IsOpen = <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// capture mouse</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyPopup.CaptureMouse();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// set _captured flag to true.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>_captured = <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p>There is also a function InAllowedArea that returns true if the mouse pointer is within an area in which we are allowed to drop and false otherwise:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// checks if drop is allowed</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// at the current location of the</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// mouse pointer.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">bool </span><span style="font-size:10pt;font-family:&quot;">InAllowedArea(<span style="color:#2b91af;">MouseEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">Point </span>p = e.GetPosition(<span style="color:#0000ff;">null</span>);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">UIElement</span>&gt; hitTestResult = </span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>AllowedArea.HitTest(p);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// see if mouse pointer hits AllowedArea</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// if yes, return true,</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// if no, return false.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">return</span>(hitTestResult.Count() != 0);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p>Then, during the Drag process, we check if we are within the area in which we are allowed to drop and set the ContentTemplate of the PopupControl correspondingly:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">if</span><span style="font-size:10pt;font-family:&quot;">(InAllowedArea(e))</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// if we are in an area</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// in which we are</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// allowed to drop</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// set the template accordingly</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// to our Circle</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>PopupControl.ContentTemplate = CircleTemplate;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">else</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// if we are in an area in which it</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#008000;">// is forbidden to drop, set</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>PopupControl.ContentTemplate = DropForbidden;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<h2>Generic Drag and Drop Control</h2>
<p>Based on the above examples and also taking into account that the Drag popup display can be data driven (as will be shown later) I came up with a generic Drag/Drop control implementation. While it is still rather complex to use, since drag and drop is a complex operation, it also absorbs a lot of complexity into itself, eliminating the need to implement and debug a large chunk of the Drag/Drop functionality over and over again.</p>
<p>Here is the code for generic Drag/Drop control together with a couple of samples showing how to use it: <a href="http://nickssoftwareblog.files.wordpress.com/2008/10/genericdragdropzip.doc">genericdragdropzip.doc</a>.</p>
<p>DragDrop control is defined within GenericDragDropLib project within DragDropControl.cs file. The generic.xaml file contains default control template for DragDropControl.<br />
DragDropControl contains a number of properties and events that allow customization of the Drag/Drop functionality. Here is the list of these properties and events with the explanations as to why they are needed.</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// mouse is captured and the popup </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// indicating the beginning of Drag</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// operation to the user becomes</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// visible on when the distance between</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// the mouse pointer and the original </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// point when the mouse button was pressed</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// during the Drag operation is </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// greater than CaptureRadius.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">double</span>CaptureRadius { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// the popup to show during Drag operation</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">Popup</span> DragDropPopup { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// The content control within the DragDropPopup</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// that can assume any shape defined by </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// its data template and date content. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">ContentControl</span> PopupContentControl { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// default data template for areas in </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// which drop is allowed</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">DataTemplate</span> DropAllowedTemplate { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// data template for areas in which</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// drop is forbidden</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">DataTemplate</span> DropForbiddenTemplate { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// element to be dragged</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">UIElement</span>DraggedElement { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// dragged business logic object</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// (specified by Content property of DraggedElement)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">object</span>DraggedObject { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// DragContainer property is used when DraggedElement is</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// one of the items within and ItemsControl e.g. a</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// ListBox this property contains the reference to this </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// container control of the dragged item</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">UIElement</span>DragContainer {<span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>;}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// does the drop operation</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">event</span> <span style="color:#2b91af;">DoDropDelegate</span>DoDrop = <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// used to filter in the element that can be</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// dragged</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">event</span> <span style="color:#2b91af;">IsDraggableDelegate</span>IsDraggable = <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// used to filter in the container of the element</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// that can be dragged</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">event</span> <span style="color:#2b91af;">IsContainerDelegate</span> IsDragContainer = <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// returns true if, during the drag operation,</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// the mouse pointer is inside the area </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// it which drops are allowed, false otherwise.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">event</span> <span style="color:#2b91af;">IsInAllowedAreaDelegate</span>IsInAllowedArea = <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// returns data template for the case when the drops are</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// allowed during the drag operation</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">event</span> <span style="color:#2b91af;">GetDataTemplateDelegate</span> GetDataTemplate = <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">//used to set the DraggedObject from the </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// DraggedElement. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// Most of the times, this is just DraggedElement.Content</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">event</span> <span style="color:#2b91af;">GetBusinessLogicObjectDelegate</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>GetBusinessLogicObject = <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// used to record the origin of the drag operation</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">Point</span> StartDragPoint { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</span></p>
<p>DragDropControl also contains three functions that need to be triggered by the Button Down, Mouse Move and Button Up events of the application that uses DragDropControl. These functions are</p>
<li>StartDragDrop</li>
<li>OnMove</li>
<li>OnButtonUp</li>
<p>Below we describe two examples using DragDropControl.</p>
<h3>Drag Drop with Forbidden Area Implemented Using DragDropControl</h3>
<p>The solution for this test is called GenericDragDropTest.sln and it is located under GenericDragDropTest within genericdragdrop.zip file. It produces exactly the same result as our Drag/Drop with forbidden area example above, but it uses DragDropControl. Below we show how DragDropControl is used.<br />
Here is the code showing how we connect the events of DragDropControl:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.DoDrop += </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">new</span> GenericDragDropLib.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">DoDropDelegate</span>(MyDragDropControl_DoDrop);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// we only drag ellipses!</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.IsDraggable +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#2b91af;">UIElement</span> element)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">if</span> (element <span style="color:#0000ff;">is</span> <span style="color:#2b91af;">Ellipse</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// data template for the drag popup is</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// provided by CircleTemplate resource</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.GetDataTemplate +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#2b91af;">UIElement</span> element)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span> (<span style="color:#2b91af;">DataTemplate</span>) <span style="color:#0000ff;">this</span>.Resources[<span style="color:#a31515;">"CircleTemplate"</span>];</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// we are in an area in which are</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// are allowed to drop if the </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// mouse pointer is</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// inside AllowedArea circle.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.IsInAllowedArea += </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#2b91af;">Point</span> p)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">UIElement</span>&gt; hitTestResult = </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>AllowedArea.HitTest(p);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span>(hitTestResult.Count() != 0);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p>And here is the code that connects the mouse button events to the DragDropControl functions:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// connect the mouse button events to</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// the corresponding functions </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// of our DragDropControl.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot.MouseLeftButtonDown +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">MouseButtonEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>MyDragDropControl.StartDragDrop(<span style="color:#0000ff;">this</span>, e);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot.MouseMove +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">MouseEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>MyDragDropControl.OnMove(e);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">LayoutRoot.MouseLeftButtonUp +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">MouseButtonEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span> </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>MyDragDropControl.OnButtonUp(e);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<h3>Drag and Drop between Two ListBox Elements</h3>
<p>Here we show an implementation of Drag/Drop analogous to that of <a href="http://leeontech.wordpress.com/2008/04/11/drag-and-drop-in-silverlight/">Drag and Drop in Silverlight</a>. The ListBoxItem objects are dragged and dropped between two ListBoxes.</p>
<p>The code for this sample can be found under ListBoxDragDropTest directory of genericdragdrop.zip file.<br />
Here is the screen capture for this sample:</p>
<p style="text-align:center;"><a href="http://nickssoftwareblog.files.wordpress.com/2008/10/listboxdragdrop.jpg"><img class="aligncenter size-full wp-image-381" title="listboxdragdrop" src="http://nickssoftwareblog.files.wordpress.com/2008/10/listboxdragdrop.jpg?w=435&#038;h=501" alt="" width="435" height="501" /></a></p>
<p>This sample also provides an example of having data driven visual presentation of the dragged item (the first and last names of the students provide the data that can change depending on the dragged item).<br />
Here is the code showing setting the event handlers for DragDropControl events:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.DoDrop +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">new</span> GenericDragDropLib.<span style="color:#2b91af;">DoDropDelegate</span>(DoDrop);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// we only Drag and Drop ListBoxItem objects!</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.IsDraggable +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#2b91af;">UIElement</span> element)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">if</span> (element <span style="color:#0000ff;">is</span> <span style="color:#2b91af;">ListBoxItem</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// our drag container is ListBox</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.IsDragContainer +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#2b91af;">UIElement</span> element)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">if</span> (element <span style="color:#0000ff;">is</span> <span style="color:#2b91af;">ListBox</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// we use the same DataTemplate</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// to display the drag popup as</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// we use to display the items in the list</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.GetDataTemplate +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#2b91af;">UIElement</span> element)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">ListBoxItem</span>lbi = MyDragDropControl.DraggedElement <span style="color:#0000ff;">as</span> <span style="color:#2b91af;">ListBoxItem</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">if</span>(lbi == <span style="color:#0000ff;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span> (<span style="color:#2b91af;">DataTemplate</span>)lbi.ContentTemplate;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// we are in allowed area if and only if we are </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// inside a ListBox</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.IsInAllowedArea +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#2b91af;">Point</span> p)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">ListBox</span>lb = GetListBox(p);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">if</span> (lb == <span style="color:#0000ff;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#008000;font-family:&quot;">// returns Content property of the ListBoxItem</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">MyDragDropControl.GetBusinessLogicObject +=</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">delegate</span>(<span style="color:#2b91af;">UIElement</span> element)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">ContentControl</span> cc = element <span style="color:#0000ff;">as</span> <span style="color:#2b91af;">ContentControl</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">if</span> (cc == <span style="color:#0000ff;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#0000ff;">return</span> cc.Content;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>};</span></p>
<p>One can see that the DoDrop function (called during the drop operation) checks if the target ListBox is not the same as the original ListBox from where the item was dragged and if true, removes the item from the original collection and adds it to the collection of the target ListBox.</p>
<h2>Conclusion</h2>
<p style="text-align:left;">This article describes the implementation of drag and drop functionality in Silverlight. It starts with a simple example and progresses to more complex ones. It features custom DragDropControl which is used to absorb a lot of complexity of Drag/Drop implementation.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/275/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=275&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2008/10/07/silverlight-20-in-examples-part-drag-and-drop-inside-out/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/10/simpledragdrop.jpg" medium="image">
			<media:title type="html">simpledragdrop</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/10/dragdropwithforbiddenarea.jpg" medium="image">
			<media:title type="html">dragdropwithforbiddenarea</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/10/listboxdragdrop.jpg" medium="image">
			<media:title type="html">listboxdragdrop</media:title>
		</media:content>
	</item>
		<item>
		<title>Happy Rosh HaShanah</title>
		<link>http://nickssoftwareblog.com/2008/09/29/happy-rosh-hashana/</link>
		<comments>http://nickssoftwareblog.com/2008/09/29/happy-rosh-hashana/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 20:44:31 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://nickssoftwareblog.wordpress.com/?p=273</guid>
		<description><![CDATA[There will be no blog entries for a couple of days due to the Jewish holiday.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=273&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There will be no blog entries for a couple of days due to the Jewish holiday.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/273/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/273/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=273&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2008/09/29/happy-rosh-hashana/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Spy</title>
		<link>http://nickssoftwareblog.com/2008/09/29/silverlight-spy/</link>
		<comments>http://nickssoftwareblog.com/2008/09/29/silverlight-spy/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 20:37:42 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Tools]]></category>

		<guid isPermaLink="false">http://nickssoftwareblog.com/?p=266</guid>
		<description><![CDATA[By googling for &#8220;Silverlight Snoop&#8221; (Snoop is a tool for investigating WPF GUI) I came (via jimmangaly.blogspot.com across an interesting tool: Silverlight Spy. Make sure you have all prerequisites before installing it. Not only it allows you to disassemble and show the composition of your own Silverlight application, but it also allows you to do it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=266&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>By googling for &#8220;Silverlight Snoop&#8221; (Snoop is a tool for investigating WPF GUI) I came (via <a href="http://jimmangaly.blogspot.com/2008/03/silverlight-spy-snoop-for-silverlight.html">jimmangaly.blogspot.com</a> across an interesting tool: <a href="http://silverlightspy.com/silverlightspy/download-silverlight-spy/">Silverlight Spy</a>.</p>
<p>Make sure you have all prerequisites before installing it.</p>
<p style="text-align:left;">Not only it allows you to disassemble and show the composition of your own Silverlight application, but it also allows you to do it to any Silverlight application accessible on the Internet. All you need to do is to type in the url of the page containing that Silverlight application: e.g. I did it for my AWebPros banner typing in &#8220;http://awebpros.com/AWebProsMain.aspx&#8221; URL. Then I go to the panel on the right and expand &#8220;Silverlight 2 Beta 2 Application (Xaml1)&#8221;. Here is the resulting layout:</p>
<div id="attachment_267" class="wp-caption aligncenter" style="width: 460px"><a href="http://nickssoftwareblog.files.wordpress.com/2008/09/silverlightspy.jpg"><img class="size-large wp-image-267" title="silverlightspy" src="http://nickssoftwareblog.files.wordpress.com/2008/09/silverlightspy.jpg?w=450&#038;h=391" alt="Silverlight Spy" width="450" height="391" /></a><p class="wp-caption-text">Silverlight Spy</p></div>
<p>As you can see, the TextBlock at the top is selected by selecting &#8220;textBlock&#8221; in the right hand panel!. When I try to select other text blocks, however, they are not shown in the right place &#8211; possibly because of the animation. Still it is a very impressive tool.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/266/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=266&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2008/09/29/silverlight-spy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/silverlightspy.jpg?w=450" medium="image">
			<media:title type="html">silverlightspy</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight 2.0 In Examples: Part 1. Silverlight Elements: Panels and Controls</title>
		<link>http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-overview-of-silverlight-controls/</link>
		<comments>http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-overview-of-silverlight-controls/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 15:07:53 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Controls]]></category>
		<category><![CDATA[Silverlight Panels]]></category>

		<guid isPermaLink="false">http://nickssoftwareblog.wordpress.com/?p=139</guid>
		<description><![CDATA[Introduction This is part 1 of the tutorial, but there is also Part 0. You can access it through the following link: Part 0. Part 0 of the tutorial was at an introductory level. Here we will switch to the more advanced concepts. In particular, we will assume that the readers are familiar with C# [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=139&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>This is part 1 of the tutorial, but there is also Part 0. You can access it through the following link: <a href="http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-introduction">Part 0</a>.<br />
Part 0 of the tutorial was at an introductory level. Here we will switch to the more advanced concepts. In particular, we will assume that the readers are familiar with C# and most of the OO concepts it uses, e.g. inheritance. We will also assume that the readers have some basic knowledge of Visual Studio 2008.</p>
<p>This installment will include multiple simple examples showing how to use Silverlight elements: panels and controls, while, at the same time displaying the ways Silverlight works.</p>
<h2>Overview of Panels and Controls</h2>
<p>Silverlight 2.0 comes with many built-in objects ready to be used for building a business logic application. Such objects are sub-divided into Panels and Controls.<br />
Panels are GUI objects that contain other GUI objects (their children object). Practically, any visual object can be placed within a panel: other panels, controls, etc. A panel&#8217;s main purpose is to position its child objects.<br />
Controls usually serve to trigger some business logic behavior of an application or to provide (and change) some business logic values.</p>
<p>For a comprehensive demo with Silverlight 2.0 Beta 2 controls check the following <a href="http://silverlight.net/samples/2b2/SilverlightControls/run/default.html">site</a>.</p>
<p>Both Panels and Controls derive from FrameworkElement class.<br />
The figure below desplays a class Hierarchy for Panels and Controls.<a href="http://nickssoftwareblog.files.wordpress.com/2008/09/silverlightobjectsinheritancediagram.jpg"></a><br />
<img class="size-full wp-image-151 aligncenter" title="Silverlight Element Inheritance Diagram" src="http://nickssoftwareblog.files.wordpress.com/2008/09/silverlightobjectsinheritancediagram.jpg?w=417&#038;h=325" alt="" width="417" height="325" /><br />
ContentControls have a property &#8220;Content&#8221; that can be used to contain other controls (not quite true yet for Silverlight 2.0 Beta). ItemsControls are used to display collections of objects. Example of ItemControl is ListBox.</p>
<h2>Controls</h2>
<p>In this section, we are going to consider individual Control examples.</p>
<h3>Button</h3>
<p>Button is a ContentControl whose primary goal is to trigger some business logic when it is clicked. After the click, the usual button comes back to the original state and becomes ready for the next click.</p>
<p>Here is the source code for a simple project emphasizing the way buttons work: <a href="http://nickssoftwareblog.files.wordpress.com/2008/09/buttonsamplezip.doc">buttonsamplezip.doc</a>. As always, remove the doc extension and rename it to ButtonSample.zip.</p>
<p>Here is the screen for the project:</p>
<div id="attachment_165" class="wp-caption aligncenter" style="width: 423px"><a href="http://nickssoftwareblog.files.wordpress.com/2008/09/buttonproject.jpg"><img class="size-full wp-image-165" title="buttonproject" src="http://nickssoftwareblog.files.wordpress.com/2008/09/buttonproject.jpg?w=413&#038;h=395" alt="Button Sample" width="413" height="395" /></a><p class="wp-caption-text">Button Sample</p></div>
<p>Every time you click this button, the number of clicks increases.</p>
<p>Now, let us discuss the code. As was mentioned in <a href="http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-introduction">Part 0 of this tutorial</a>, most of the time we do not need modify App.xaml and App.xaml.cs files. So let us take a look at the Page.xaml and Page.xaml.cs files within the solution.<br />
Here are the contents of Page.xaml file:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">UserControl</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Class</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;ButtonSample.Page&#8221;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>xmlns</span><span style="color:#0000ff;">=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>xmlns</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>Width</span><span style="color:#0000ff;">=&#8221;400&#8243;</span><span style="color:#ff0000;"> Height</span><span style="color:#0000ff;">=&#8221;300&#8243;&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Name</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;LayoutRoot&#8221;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Background</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;White&#8221;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Button</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&#8221;MyButton&#8221;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Width</span><span style="color:#0000ff;">=&#8221;150&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Height</span><span style="color:#0000ff;">=&#8221;25&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Content</span><span style="color:#0000ff;">=&#8221;Clicked 0 Times&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">UserControl</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p>One can see a simple button within a Grid. The button has a name (x:Name=&#8221;MyButton&#8221;). Name is used for accessing this control or element from the C# code (we&#8217;ll talk more about it below). It also has its Width, Height and Content properties set. You can play with the button by changing or removing the properties and watching the way the button changes.</p>
<p>Now, let us take a look at the C# code within the Page.xaml.cs file. Here are its contents: </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Page</span> : <span style="color:#2b91af;">UserControl</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">int</span>numClicks = 0;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">public</span> Page()</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>InitializeComponent();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>MyButton.Click += <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">RoutedEventHandler</span>(MyButton_Click);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#0000ff;">void</span>MyButton_Click(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">RoutedEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>numClicks++;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>MyButton.Content = <span style="color:#a31515;">&#8220;Clicked &#8220;</span>+ numClicks + <span style="color:#a31515;">&#8221; times.&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;">Take a look at Page() constructor. One can notice that within that constructor we refer to MyButton as if it was a member of the class. Well, in fact, it is a member of the class; we&#8217;ve made it so, by naming it &#8220;MyButton&#8221; within XAML code. Now, all we have to do is to specify the desired behavior when the button is clicked. This is achieved by adding a handler to the &#8220;Click&#8221; event:</p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:x-small;">MyButton.Click += <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">RoutedEventHandler</span>(MyButton_Click);</span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;">and by creating the body of the handler as MyButton_Click function:</p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;"><span>    </span><span style="color:#0000ff;">void</span>MyButton_Click(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">RoutedEventArgs</span> e)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;"><span>        </span>numClicks++;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;"><span>        </span>MyButton.Content = <span style="color:#a31515;">“Clicked “</span>+ numClicks + <span style="color:#a31515;">” times.”</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<h3>DatePicker</h3>
<p>DatePicker is a control that allows to choose a date. The chosen date is specified by the SelectedDate property of the DatePicker. Here is the source code for DatePicker sample: <a href="http://nickssoftwareblog.files.wordpress.com/2008/09/datepickersamplezip.doc">datepickersamplezip.doc</a>.<br />
The sample allows the user to choose the date using the DatePicker. Then, whenever the button at the bottom is clicked, the content of the button is changed to the picked date:</p>
<div id="attachment_179" class="wp-caption alignnone" style="width: 423px"><a href="http://nickssoftwareblog.files.wordpress.com/2008/09/datepickersample.jpg"><img class="size-full wp-image-179" title="datepickersample" src="http://nickssoftwareblog.files.wordpress.com/2008/09/datepickersample.jpg?w=413&#038;h=456" alt="Date Picker Sample" width="413" height="456" /></a><p class="wp-caption-text">Date Picker Sample</p></div>
<p>Note, that in order to make DatePickerSample compile, we had to add System.Windows.Controls.Extended assembly to the project&#8217;s references. This is also reflected within the Page.xaml file by the following line:</p>
<p><span style="font-size:x-small;color:#ff0000;"><span style="font-size:x-small;color:#ff0000;">xmlns</span></span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">:</span></span><span style="font-size:x-small;color:#ff0000;"><span style="font-size:x-small;color:#ff0000;">extended</span></span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">=&#8221;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Extended&#8221;</span></span></p>
<p>This line makes &#8220;extended&#8221; to be the XAML namespace for the functionality located within System.Windows.Controls namespace of System.Windows.Controls.Extended assembly.<br />
Later within the XAML code, we can find DatePicker control by adding &#8220;extended:&#8221; prefix to it:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">extended</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">DatePicker</span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:10pt;color:#ff0000;font-family:&quot;">x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Name</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;MyDatePicker&#8221;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:#ff0000;">HorizontalAlignment</span><span style="color:#0000ff;">=&#8221;Center&#8221;</span></span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:10pt;color:#ff0000;font-family:&quot;">VerticalAlignment</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;Center&#8221;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">extended</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">DatePicker</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p>Finally, if we look at the C# code, we notice that the Content property of the Button is set to SelectedDate property of the DatePicker:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#2b91af;font-family:&quot;">DateTime</span><span style="font-size:10pt;font-family:&quot;">? selectedDate = MyDatePicker.SelectedDate;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">if</span><span style="font-size:10pt;font-family:&quot;">(selectedDate != <span style="color:#0000ff;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>MyButton.Content = ((<span style="color:#2b91af;">DateTime</span>)selectedDate).ToString();</span></p>
<h3>ListBox Control</h3>
<p>ListBox is an ItemsControl. Its purpose is to display multiple items as a list. It can have one of the items selected. Here is a very simple example: <a href="http://nickssoftwareblog.files.wordpress.com/2008/09/listboxsamplezip.doc">listboxsamplezip.doc</a> (more complicated examples with binding will be presented in subsequent parts of this tutorial).</p>
<div id="attachment_185" class="wp-caption aligncenter" style="width: 423px"><a href="http://nickssoftwareblog.files.wordpress.com/2008/09/listboxsample.jpg"><img class="size-full wp-image-185" title="listboxsample" src="http://nickssoftwareblog.files.wordpress.com/2008/09/listboxsample.jpg?w=413&#038;h=456" alt="ListBox Sample" width="413" height="456" /></a><p class="wp-caption-text">ListBox Sample</p></div>
<p>Here is the interesting part of the Page.xaml file:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ListBox</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Width</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;100&#8243;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Height</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;100&#8243;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ListBoxItem</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Content</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;Item1&#8243;/&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ListBoxItem</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Content</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;Item2&#8243;/&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ListBoxItem</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Content</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;Item3&#8243;/&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ListBox</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p>You can see ListBox containing multiple ListBoxItems. The selected item is referenced by the SelectedItem property of the ListBox.</p>
<h3>Other Controls</h3>
<p>As one can see from <a href="http://silverlight.net/samples/2b2/SilverlightControls/run/default.html">Demo Controls</a> there are many other important controls. Since currently I do not have time to provide examples for them all, I am going to briefly describe some of them in this section.</p>
<p>Border &#8211; purely visual control without any specific behaviors. It provides the visual presentation for the border of its content.</p>
<p>CheckBox &#8211; a control with two states: &#8220;Clicked&#8221; and &#8220;Not Clicked&#8221;. Its boolean property IsClicked reflects its state.</p>
<p>GridSplitter &#8211; allows resizing the rows or the columns within the GridPanel.</p>
<p>RadioButton &#8211; allows to create groups of mutually exclusive check buttons: if one is in the pressed state, the others are not.</p>
<p>Slider &#8211; slider control. Its Value property specifies how far the slider moved.</p>
<p>TextBlock &#8211; just a way to present the text that cannot be edited by the user. The text string is stored in its Text property.</p>
<p>TextBox &#8211; represents editable text. The text string is reflected by its Text property.</p>
<p>DataGrid &#8211; deserve a special section all to itself. Allows presenting data in table format.</p>
<p>TabControl &#8211; allows presenting multiple screens as tabs within the same window.</p>
<p>ToolTip &#8211; associates a popup message with any control. This message is displayed whenever the mouse is on top of the control.</p>
<h2>Panels</h2>
<p>As was mentioned before, panels are containers of Silverlight visual objects that have a say over where and how the objects are positioned.</p>
<h3>Canvas</h3>
<p>Canvas is a panel that positions its child objects by the coordinates (how much to the right the object is from the left end of the panel and how much down it is from the top).<br />
The sample code can be downloaded from here: <a href="http://nickssoftwareblog.files.wordpress.com/2008/09/canvassamplezip.doc">canvassamplezip.doc</a>.<br />
The figure below, shows a button positioned on top of a Canvas, 200 generic pixels down and 100 to the right.</p>
<div id="attachment_261" class="wp-caption alignnone" style="width: 423px"><a href="http://nickssoftwareblog.files.wordpress.com/2008/09/canvassample.jpg"><img class="size-full wp-image-261" title="canvassample" src="http://nickssoftwareblog.files.wordpress.com/2008/09/canvassample.jpg?w=413&#038;h=456" alt="Canvas Sample" width="413" height="456" /></a><p class="wp-caption-text">Canvas Sample</p></div>
<p>The corresponding XAML code is the following:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Canvas</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Name</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;LayoutRoot&#8221;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Background</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;White&#8221;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Button</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Canvas.Left</span><span style="color:#0000ff;">=&#8221;100&#8243;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Canvas.Top</span><span style="color:#0000ff;">=&#8221;200&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Content</span><span style="color:#0000ff;">=&#8221;Hello World&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Canvas</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p>As you can see, the property Canvas.Left sets the position of the button horizontally and Canvas.Top &#8211; vertically.</p>
<h3>StackPanel</h3>
<p>StackPanel allows to put visual objects one after another vertically or horizontally. One can only space out the objects one from another by using their Margin property. Margin consists of 4 numbers specifying in the same order the distance from the left, from the top and the extra space before next element from the right and from the bottom.<br />
Here is the source code for StackPanel example: <a href="http://nickssoftwareblog.files.wordpress.com/2008/09/stackpanelsamplezip.doc">stackpanelsamplezip.doc</a>.<br />
The following figure shows the screen for the sample:</p>
<div id="attachment_203" class="wp-caption aligncenter" style="width: 432px"><a href="http://nickssoftwareblog.files.wordpress.com/2008/09/stackpanelsample.jpg"><img class="size-full wp-image-203" title="stackpanelsample" src="http://nickssoftwareblog.files.wordpress.com/2008/09/stackpanelsample.jpg?w=422&#038;h=397" alt="Stack Panel Sample" width="422" height="397" /></a><p class="wp-caption-text">Stack Panel Sample</p></div>
<p>The sample includes 2 StackPanels: Vertical and Horizontal. Horizontal StackPanel is placed inside the Vertical one.<br />
Here is the corresponding XAML:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">StackPanel</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&#8221;LayoutRoot&#8221;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>Background</span><span style="color:#0000ff;">=&#8221;White&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Button</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Width</span><span style="color:#0000ff;">=&#8221;200&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Height</span><span style="color:#0000ff;">=&#8221;25&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Margin</span><span style="color:#0000ff;">=&#8221;0,10,0,0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Content</span><span style="color:#0000ff;">=&#8221;Vertical Button 1&#8243;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Button</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Width</span><span style="color:#0000ff;">=&#8221;200&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Height</span><span style="color:#0000ff;">=&#8221;25&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Margin</span><span style="color:#0000ff;">=&#8221;0,10,0,0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Content</span><span style="color:#0000ff;">=&#8221;Vertical Button 2&#8243;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">StackPanel</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Margin</span><span style="color:#0000ff;">=&#8221;0,10,0,0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Orientation</span><span style="color:#0000ff;">=&#8221;Horizontal&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Button</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Width</span><span style="color:#0000ff;">=&#8221;150&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Height</span><span style="color:#0000ff;">=&#8221;25&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Margin</span><span style="color:#0000ff;">=&#8221;10,0,0,0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Content</span><span style="color:#0000ff;">=&#8221;Horizontal Button 1&#8243;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Button</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Width</span><span style="color:#0000ff;">=&#8221;150&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Height</span><span style="color:#0000ff;">=&#8221;25&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Margin</span><span style="color:#0000ff;">=&#8221;10,0,0,0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>           </span><span style="color:#ff0000;"><span> </span>Content</span><span style="color:#0000ff;">=&#8221;Horizontal Button 2&#8243;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">StackPanel</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">StackPanel</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p>One can see that the top level StackPanel has Vertical (default) orientation and contains two buttons and another StackPanel as children. With the help of Margin property the buttons and the child StackPanel are spaced vertically 10 generic pixels apart. The child StackPanel has Horizontal orientation (controlled by the property &#8220;Orientation&#8221;) and contains 2 buttons spaced horizontally by 10 generic pixels.</p>
<h3>Grid</h3>
<p>Grid allows to split the area it occupies into rows and columns. There can be different number of rows and columns; the rows can have different height and the columns can have different width.<br />
Here is a code sample for the Grid: <a href="http://nickssoftwareblog.files.wordpress.com/2008/09/gridsamplezip.doc">gridsamplezip.doc</a>.<br />
When run, this sample produces the following window:</p>
<div id="attachment_210" class="wp-caption aligncenter" style="width: 387px"><a href="http://nickssoftwareblog.files.wordpress.com/2008/09/gridsample.jpg"><img class="size-full wp-image-210" title="gridsample" src="http://nickssoftwareblog.files.wordpress.com/2008/09/gridsample.jpg?w=377&#038;h=376" alt="Grid Sample" width="377" height="376" /></a><p class="wp-caption-text">Grid Sample</p></div>
<p>Let us take a look at the XAML:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Name</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;LayoutRoot&#8221;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Background</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;White&#8221;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid.ColumnDefinitions</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ColumnDefinition</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Width</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;80&#8243;/&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ColumnDefinition</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Width</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;80&#8243;/&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid.ColumnDefinitions</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid.RowDefinitions</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">RowDefinition</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Height</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;55&#8243;/&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">RowDefinition</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Height</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;55&#8243;/&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid.RowDefinitions</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">TextBlock</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Grid.Row</span><span style="color:#0000ff;">=&#8221;0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Grid.Column</span><span style="color:#0000ff;">=&#8221;0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Text</span><span style="color:#0000ff;">=&#8221;Cell (0, 0)&#8221;/&gt;</span><span style="color:#a31515;"><span>        </span></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">TextBlock</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Grid.Row</span><span style="color:#0000ff;">=&#8221;0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Grid.Column</span><span style="color:#0000ff;">=&#8221;1&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>HorizontalAlignment</span><span style="color:#0000ff;">=&#8221;Right&#8221;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Text</span><span style="color:#0000ff;">=&#8221;Cell (1, 0)&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">TextBlock</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Grid.Row</span><span style="color:#0000ff;">=&#8221;1&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Grid.Column</span><span style="color:#0000ff;">=&#8221;0&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Text</span><span style="color:#0000ff;">=&#8221;Cell (0, 1)&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">TextBlock</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Grid.Row</span><span style="color:#0000ff;">=&#8221;1&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Grid.Column</span><span style="color:#0000ff;">=&#8221;1&#8243;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>VerticalAlignment</span><span style="color:#0000ff;">=&#8221;Bottom&#8221;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span style="color:#ff0000;"><span> </span>Text</span><span style="color:#0000ff;">=&#8221;Cell (1, 1)&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p>The rows and columns are defined by RowDefinition and ColumnDefinition tags correspondingly. The item can be placed to a certain cell by defining Grid.Row and Grid.Column properties. Within each cell, the item position is controlled by HorizontalAlignment and VerticalAlignment properties. In addition, one can use Margin property to position an element within each cell.</p>
<h2>Conclusion</h2>
<p>In this part of the tutorial, we presented several Silverlight controls and panels, which are the building blocks of business logic applications. Later we are going to use them to create some cooler stuff.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=139&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-overview-of-silverlight-controls/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/silverlightobjectsinheritancediagram.jpg" medium="image">
			<media:title type="html">Silverlight Element Inheritance Diagram</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/buttonproject.jpg" medium="image">
			<media:title type="html">buttonproject</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/datepickersample.jpg" medium="image">
			<media:title type="html">datepickersample</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/listboxsample.jpg" medium="image">
			<media:title type="html">listboxsample</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/canvassample.jpg" medium="image">
			<media:title type="html">canvassample</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/stackpanelsample.jpg" medium="image">
			<media:title type="html">stackpanelsample</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/gridsample.jpg" medium="image">
			<media:title type="html">gridsample</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight 2.0 In Examples: Part 0. Introduction</title>
		<link>http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-introduction/</link>
		<comments>http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-introduction/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 00:23:10 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://nickssoftwareblog.wordpress.com/?p=55</guid>
		<description><![CDATA[Introducing Introduction Although, this tutorial is called &#8220;Silverlight 2.0 In Examples&#8221;, this introduction will not have many examples. The main purpose of this article is to describe what Silverlight is, where it can be used, its advantages and shortcomings. What is Silverlight Silverlight is a framework for developing browser based applications. In this sense it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=55&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Introducing Introduction</h2>
<p>Although, this tutorial is called &#8220;Silverlight 2.0 In Examples&#8221;, this introduction will not have many examples. The main purpose of this article is to describe what Silverlight is, where it can be used, its advantages and shortcomings.</p>
<h2>What is Silverlight</h2>
<p>Silverlight is a framework for developing browser based applications. In this sense it is similar to Html and JavaScript. Just like Html and JavaScript, the Silverlight application is downloaded by the client&#8217;s machine from the web server after which it runs within the client&#8217;s browser.</p>
<p>There is a difference, however, between Silverlight and Html. In order for Silverlight to work in your browser you need to install the Silverlight framework from Microsoft. Silverlight framework is a small package (around 5Mb) which can be downloaded and installed pretty fast. In that sense Silverlight is closer to Adobe Flash which requires Flash framework installed, or, for that matter, to Java applets, which require Java Virtual Machine.</p>
<p>Silverlight can run on different platforms within different browsers. It runs on Windows within IE and Firefox. It also runs on Mac under Safari and Firefox. This should cover most of the possible clients. For the full list of platforms, take a look at <a href="http://en.wikipedia.org/wiki/Silverlight">the Silverlight article on Wiki</a>. Microsoft also promises to expand the list of platforms and browsers.</p>
<p>Silverlight 1.0 is an old version that will not be discussed here. It only allows programming in JScript language.</p>
<p>Instead I will be concentrating on Silverlight 2.0 (still in Beta &#8211; <a href="http://blogs.zdnet.com/Stewart/?p=934">according to some unconfirmed internet rumors it will be released at the PDC conference at the end of October</a>). In spite of still being in beta, it was used by the major networks for the coverage of 2008 Olympics and Democratic convention.</p>
<p>Silverlight 2.0 allows creating applications in many different programming languages. Here, however, I&#8217;ll be concentrating on creating Silverlight 2.0 applications in C#.</p>
<p>C# or other programming languages can be used to program the business logic of the Silverlight application. The presentation and static content are usually created in <a href="http://msdn.microsoft.com/en-us/library/ms752059.aspx">XAML</a> (though it is possible to create the whole application in C#).</p>
<p>XAML is an XML based language which (very successfully from my point of view) uses XML hierarchical structure to reflect the containment hierarchy of objects (primarily GUI objects). It will be discussed in more detail later.</p>
<p>Silverlight applications are usually embedded into HTML or ASP pages. They can be initialized by the user clicking on a certain HTML hyperlink or a button.</p>
<h2>Why I Love Silverlight</h2>
<ol>
<li>Using Silverlight, one can achieve clean separation between business objects and the way they are displayed. That means that the underlying business logic of an application does not have to be polluted with the visual presentation details. Instead XAML files contain DataTemplates that know how to present the data provided by the business logic. These DataTemplates are mapped to the underlying business objects with the help of a technique called binding.</li>
<li>Silverlight controls can be developed lookless (without the visual representation). E.g. a button can be simplified to a control that only has &#8220;Click&#8221; event. The way the actual button looks and behaves when clicked can be provided by the Control Templates and Styles. This again helps to separate the underlying logic from the visual representation. It also allows having multiple ways in which the same controls are shown without changing the underlying logic.</li>
<li>Silverlight has a powerful set of geometric tools that allow creation of various 2-D drawings. It also has a powerful set of geometric transforms which are easy to user and which can be applied to any Silverlight visual objects.</li>
<li>Silverlight has a rich set of built-in controls, even though, at this point some important controls are missing. WrapPanel, ComboBox, TreeView, ContextMenu are just several examples of missing controls. However, there are some publicly available open source implementations of those controls.</li>
<li>
Silverlight includes powerful animation functionality.
</li>
<li>On a personal note, I came to Silverlight from the <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation">the WPF (Windows Presentation Foundation)</a>. Silverlight, from the developer&#8217;s point of view is almost a subset of WPF. So, WPF developers should not have any problem mastering Silverlight.</li>
</ol>
<p>Because of the clean separation between the business logic and the presentation, I think Silverlight will take a much more prominent role in business application development than Adobe Flash.</p>
<h2>Silverlight Resources</h2>
<p>The best on-line silverlight resource is located at <a href="silverlight.net">siverlight.net</a>. From there you can get to <a href="http://silverlight.net/blogs/jesseliberty/">Jesse Liberty blog</a>. Jesse is a renowned author whose latest passion became Silverlight. There are other valuable places on the internet including <a href="http://codeproject.com">codeproject.com</a>.</p>
<h2>Finally an Example: &#8220;Hello World&#8221; Application in Silverlight</h2>
<p>In order to build Silverlight applications you need to have the following packages installed: <a href="http://msdn.microsoft.com/en-us/vs2008/products/cc268305.aspx">VS 2008</a> and <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=50A9EC01-267B-4521-B7D7-C0DBA8866434&amp;displaylang=en">Silverlight Tools Beta 2 for Visual Studio 2008</a>.</p>
<p>To create a Silverlight application, open VS 2008, go to File menu and choose New-&gt;Project. On the left side panel choose Visual C#-&gt;Silverlight to be the Project Type. Choose &#8220;Silverlight Application&#8221; on the right hand side. Also choose the path where you want your solution to reside and choose the name of the solution (and the project) to be &#8220;HelloWorld&#8221;. At the next screen choose &#8220;Dynamically generate an HTML test page to host Silverlight within this project&#8221; for simplicity.</p>
<p>In your VS solution window you will see that Visual Studio generated 4 files containing C# and XAML code: App.xaml, App.xaml.cs, Page.xaml, Page.xaml.cs. You do not have to pay much attention to the App.xaml and App.xaml.cs files. They are only used to initialize the Silverlight application. Most times you won&#8217;t have to touch them. The really interesting files are Page.xaml and Page.xaml.cs.</p>
<p>Here is the content of Page.xaml file: </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">UserControl</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Class</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;HelloWorld.Page&#8221;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>xmlns</span><span style="color:#0000ff;">=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>xmlns</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:#ff0000;"><span> </span>Width</span><span style="color:#0000ff;">=&#8221;400&#8243;</span><span style="color:#ff0000;"> Height</span><span style="color:#0000ff;">=&#8221;300&#8243;&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> x</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">:</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;">Name</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;LayoutRoot&#8221;</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Background</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;White&#8221;&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Grid</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">UserControl</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&gt;</span></p>
<p>Let us investigate its contents line by line.<br />
UserControl is the superclass from which our Page control is derived.<br />
HelloWorld.Page is the namespace and the class name of our control.<br />
Two lines that start with xmlns should be present in almost every XAML file. They declare the default and &#8220;x:&#8221; namespaces, making available much of Silverlight functionality to be used within the file.<br />
Width and Height properties specify Width and Height of our Page control.<br />
Finally Grid is a panel. Panels are controls in charge of positioning other controls.<br />
To Display &#8220;Hello World&#8221; within the Silverlight application all we need to do is to add the following line to the Grid:</p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">TextBlock</span><span style="font-size:10pt;color:#ff0000;font-family:&quot;"> Text</span><span style="font-size:10pt;color:#0000ff;font-family:&quot;">=&#8221;Hello World&#8221;/&gt;</span></p>
<p>Eventually we never touched Page.xaml.cs file. That is because we did not want our application to have any behavior: all we wanted was to display a static &#8220;Hello World&#8221; message.<br />
The code for this example can be found at <a href="http://nickssoftwareblog.files.wordpress.com/2008/09/helloworldzip.doc">helloworldzip.doc</a>. This is a simple .zip file. Remove &#8220;.doc&#8221; extension and change the name of the file to HelloWorld.zip.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=55&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2008/09/23/silverlight-20-in-examples-part-1-introduction/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Tutorial Project</title>
		<link>http://nickssoftwareblog.com/2008/09/21/silverlight-tutorial-project/</link>
		<comments>http://nickssoftwareblog.com/2008/09/21/silverlight-tutorial-project/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 19:08:13 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://nickssoftwareblog.wordpress.com/?p=45</guid>
		<description><![CDATA[I would like to start a Silverlight tutorial in several installments, and, perhaps, crosspost it at several other web sites. I would appreciate if people specify what they want to know about Silverlight in the comments.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=45&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I would like to start a Silverlight tutorial in several installments, and, perhaps, crosspost it at several other web sites. I would appreciate if people specify what they want to know about Silverlight in the comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=45&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2008/09/21/silverlight-tutorial-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>
	</item>
		<item>
		<title>Client Driven Design and Development of an Enterprise Software System</title>
		<link>http://nickssoftwareblog.com/2008/09/21/client-driven-design-and-development-of-an-enterprise-software-system/</link>
		<comments>http://nickssoftwareblog.com/2008/09/21/client-driven-design-and-development-of-an-enterprise-software-system/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 16:17:32 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Software Development Process]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[Back End]]></category>
		<category><![CDATA[Enterprise System]]></category>
		<category><![CDATA[Front End]]></category>
		<category><![CDATA[Middle Tier]]></category>
		<category><![CDATA[Software development]]></category>

		<guid isPermaLink="false">http://nickssoftwareblog.wordpress.com/?p=6</guid>
		<description><![CDATA[Enterprise System Definition By enterprise software system I mean a system that involves a database that can be accessed by multiple users at the same time. As shown at the figure below, such system usually consists of three parts: Front End (whether it is a stand alone or a browser based application). Front End is part [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=6&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Enterprise System Definition</h2>
<p>By enterprise software system I mean a system that involves a database that can be accessed by multiple users at the same time.<br />
As shown at the figure below, such system usually consists of three parts:</p>
<ol>
<li>Front End (whether it is a stand alone or a browser based application). Front End is part of the system that the users are aware of: some Graphical interface through which the users can view and/or modify the data.</li>
<li>Middle Tier for connecting the Front End application and the Back End. In addition to connecting the database and the Front End, the Middle Tier can also play role in other aspects of the application such as security, load balancing, failover, error handling, etc.</li>
<li>Back End for storing, updating and reading the data in the database or in multiple databases. </li>
</ol>
<div class="mceTemp" style="text-align:center;">
<dl class="wp-caption alignnone">
<dt class="wp-caption-dt"><a href="http://nickssoftwareblog.files.wordpress.com/2008/09/enterprisesystem.jpg"><br />
<img class="size-medium wp-image-7" title="enterprisesystem" src="http://nickssoftwareblog.files.wordpress.com/2008/09/enterprisesystem.jpg?w=300&#038;h=210" alt="Enterprise System" width="300" height="210" /></a> </dt>
<dd class="wp-caption-dd">Enterprise System</dd>
</dl>
</div>
<p>In order to create an enterprise application one needs to develop all the above layers (tiers).<br />
Front End is usually built using languages that have packages for developing GUI (Graphical User Interface), e.g. C#, Visual Basic, or Java for stand alone application; Html, JavaScript, Flash, Silverlight for browser based applications.<br />
The Back End database tier is usually written in a superset of SQL language: Transact SQL for Microsoft SQL Server and PL/SQL for oracle.<br />
The Middle Tier, whose main purpose is to connect the database and the Front End application, is usually built in one of the common programming languages: C#, Java, C++ or Visual Basic.</p>
<p>To speed up the development, the Middle Tier and the Back End are often developed together. This was made possible by the code generators (which generate code for calling the database stored procedures from the Middle Tier language) or by frameworks like hibernate (which generate both the database code and its middle tier accessors).</p>
<h2>Client Driven Design and Development</h2>
<p>When a brand new enterprise product is about to be built, the team or company in charge of its development, faces obvious questions: which tier to start building it from, which tier should be given more importance at the beginning.</p>
<p>In my experience, many times the companies have all three tiers built at the same time by different people. Sometimes, the database and middle tier pieces are given priority since they are the core of the system, and the Front End development is considered to be an icing on the cake.<br />
The point I am trying to make here is that the above approaches are wrong, and actually the Front End development should be given priority while the middle tier and the Back End development should be determined by the Front End needs.<br />
The reasons for such an approach are the following:</p>
<ol>
<li>Front End is closest to the customers, so the Front End developers understand the customer or Product Management requirements the best. While developing the Front End, they can write requests for the Back End and the Middle Tier functionality that they need; those requests being fulfilled by the Back End and the Middle Tier developers.</li>
<li>In the same way that the end users or product managers are the customers of the Front End developers, the Front End developers are the customers of the Back End and the Middle Tier developers.</li>
<li>When Middle Tier and Back End developers work in a vacuum they are risking spending a lot of time developing functionality unnecessary for the Front End development and skipping what is really important.</li>
</ol>
<p>This is not to say that no database and Middle Tier work can be done in parallel or even preceding the Front End design and development. Everything that does not have a direct impact on the Front End, everything that the end user does not know about, like security framework, failover, load balancing, error handling, etc, can be developed without existing Front End design. Preferably it should be developed in a way that would have minimal effect on the Front End functionality.</p>
<h2>Vertical Development</h2>
<p>In the case where the team posesses the right set of skills, I would advocate something I call Vertical Development. This is an ultimate case of the Client Driven Development. Under Vertical Development, the same person creates the Front End, the Back End (up to creating and modifying the database tables) and the Middle Tier functionality for a specific chunk of the Front End application. The great plus of such approach, is that the developer is given more power to change and prototype: the developer does not have to request changes from somebody else for every minor change in the Front End application. Also, the unit testing is simplified: the Back End and Middle Tier changes can be tested via the Front End application.<br />
There are two manageable shortcomings to such approach:</p>
<ol>
<li>There are more opportunities for the developers to &#8220;step on each other&#8221; if they work across all three tiers. This should be mitigated by more care on the developer&#8217;s side and by the developers&#8217; goals being defined in such way as to minimize the collisions.</li>
<li>Datables and stored procedures might be developed in completely different styles which would lead to confusion later. This should be taken care of by the setting the rigorous standards for code development and by the architects carefully reviewing the code and asking the developers to re-factor it if necessary.</li>
</ol>
<p>There are two questions with respect to Vertical Development aproach that can arise</p>
<ol>
<li>
If developers A, B and C work at the same time on different screens or different sets of screens of the same application using Vertical Development approach, how easy is it going to be to put their stuff together? The answer is that usually it is much easier to integrate the code developed vertically, than horizontally. The reason for that is that different screens of the same application have much less dependency on each other than the Front End of the same screen on the Back End and the Middle Tier. Still even under Vertical Development, the team needs to have good procedures in place for integrating their work.
</li>
<li>
The second question is about the code reuse. Would not code reuse be weaker under Vertical Development; can it be that multiple developers will be working on similar functionality? In my experience this is not the case. Both in case of Vertical and Horizontal development methods, the code reuse requires good procedures, good communications between the developers, a lot of effort by the architect and the willingness to spend time re-factoring the code.
</li>
</ol>
<p>There is another advantadge to Vertical Development method. Since the developers are less depended on each other, it is much easier figure out who is actually responsible for success or failure.</p>
<p>
Please tell me what you think in the comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=6&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2008/09/21/client-driven-design-and-development-of-an-enterprise-software-system/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>

		<media:content url="http://nickssoftwareblog.files.wordpress.com/2008/09/enterprisesystem.jpg?w=300" medium="image">
			<media:title type="html">enterprisesystem</media:title>
		</media:content>
	</item>
		<item>
		<title>Why I started this blog</title>
		<link>http://nickssoftwareblog.com/2008/09/19/hello-world/</link>
		<comments>http://nickssoftwareblog.com/2008/09/19/hello-world/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 21:56:00 +0000</pubDate>
		<dc:creator>npolyak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I have a lot of thoughts, sketches and projects that I would like to share with the world.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=1&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have a lot of thoughts, sketches and projects that I would like to share with the world. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nickssoftwareblog.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nickssoftwareblog.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nickssoftwareblog.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nickssoftwareblog.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nickssoftwareblog.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nickssoftwareblog.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nickssoftwareblog.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nickssoftwareblog.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nickssoftwareblog.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nickssoftwareblog.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nickssoftwareblog.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nickssoftwareblog.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nickssoftwareblog.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nickssoftwareblog.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nickssoftwareblog.com&amp;blog=4912334&amp;post=1&amp;subd=nickssoftwareblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nickssoftwareblog.com/2008/09/19/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ff20b993fdf8c23e289222482bb9cbd8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">npolyak</media:title>
		</media:content>
	</item>
	</channel>
</rss>
