<?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>Accelerated Development</title>
	<atom:link href="http://mwohltman.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mwohltman.wordpress.com</link>
	<description>Blog by Michael Wohltman</description>
	<lastBuildDate>Tue, 24 Mar 2009 18:09:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mwohltman.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Accelerated Development</title>
		<link>http://mwohltman.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mwohltman.wordpress.com/osd.xml" title="Accelerated Development" />
	<atom:link rel='hub' href='http://mwohltman.wordpress.com/?pushpress=hub'/>
		<item>
		<title>A Custom Silverlight List &#8211; Part V, Implementing A Sorted List View</title>
		<link>http://mwohltman.wordpress.com/2009/03/13/a-custom-silverlight-list-part-v-implementing-a-sorted-list-view/</link>
		<comments>http://mwohltman.wordpress.com/2009/03/13/a-custom-silverlight-list-part-v-implementing-a-sorted-list-view/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 19:58:08 +0000</pubDate>
		<dc:creator>mwohltman</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ListBox]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[Sorted View]]></category>
		<category><![CDATA[SortedList]]></category>
		<category><![CDATA[Top]]></category>

		<guid isPermaLink="false">http://mwohltman.wordpress.com/?p=61</guid>
		<description><![CDATA[Overview: So while I was trying to validate my List design I started thinking about other things I could do with a List.  Obviously I could add selection but that just seemed boring.  I happened to be watching some NASCAR at the time and an idea popped in my head.  If I were writing an [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=61&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Overview:</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">So while I was trying to validate my List design I started thinking about other things I could do with a List.<span>  </span>Obviously I could add selection but that just seemed boring.<span>  </span>I happened to be watching some NASCAR at the time and an idea popped in my head.<span>  </span>If I were writing an application with real time race information, I would really need to sort some data.<span>  </span>Further, since this data would be highly dynamic it wouldn’t be viable to rely on the data source to sort this data either.<span>  </span>Additionally, we may want to display two different views of the same data.<span>  </span>For race information, one view might sort by current race position while another view might sort by current speed or time of the driver’s last lap.<span>  </span>So I had my answer.<span>  </span>How could I develop a Sorted List View on top of my current List infrastructure?<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;font-family:Calibri;"> </span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Simplifying our Use Case</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">With some thought on what would be involved to accomplish this goal, I immediately started trying to simplify my problem.<span>  </span>First, how would I do my sorting?<span>  </span>I think a tree would be most appropriate but I don’t need to be efficient on my first pass.<span>  </span>I am not going to implement a binary tree, but I will make sure it will be straightforward replace my linear sort/search with a logarithmic algorithm at a later time.<span>  </span>Secondly, will I support an observable list?<span>  </span><span> </span>This is actually a pretty interesting question.<span>  </span>At first thought, it sounds like an important feature but note that I am not talking about listening for value changes I am talking about list changes.<span>  </span>I will obviously want to watch for data changes in the list, but do I need to watch for list changes?<span>  </span>After more thought I concluded that 1) it wasn’t needed for my use case (new drivers won’t enter the race) and 2) I’m not even sure it’s viable for the general scenario and 3) I already implemented binding to an observed list so the excitement was gone </span><span style="font-family:Wingdings;"><span>J</span></span><span style="font-family:Calibri;">.<span>  </span>Ok, Again, I will not implement binding to an observed list, but I will make sure I know where to place this logic when I add it later.<span>  </span>Finally, will I queue updates or handle them synchronously?<span>  </span>Same decision – I will defer until later.</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><strong>Design</strong>:</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">So I looked at the components I needed to develop and might develop in the future and came up with the following design.</span></p>
<p><span style="font-size:small;font-family:Calibri;"></p>
<div id="attachment_66" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-66" title="sortedlist_cd1" src="http://mwohltman.files.wordpress.com/2009/03/sortedlist_cd1.jpg" alt="Sorted List Class Diagram" width="450" height="476" /><p class="wp-caption-text">Sorted List Class Diagram</p></div>
<p></span></p>
<p> </p>
<p><span style="font-size:small;font-family:Calibri;"></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><em>SortedList</em></p>
<p class="MsoNormal" style="margin:0 0 10pt;">The SortedList class will inherit from my existing ListBase class.<span>  </span>The ListBase class provides ItemType initialization without doing any binding.<span>  </span>The SortedList defines the following properties.<span>  </span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span>1)<span style="font:7pt &quot;">      </span></span></span>ItemsSource – bound list of items</p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span>2)<span style="font:7pt &quot;">      </span></span></span>SortProperty – Property to sort by</p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span>3)<span style="font:7pt &quot;">      </span></span></span>SortOrder – Asc or Desc?</p>
<p class="MsoListParagraphCxSpLast" style="text-indent:-.25in;margin:0 0 10pt .5in;"><span><span>4)<span style="font:7pt &quot;">      </span></span></span>Top – How many items to display</p>
<p class="MsoNormal" style="margin:0 0 10pt;">The SortedList class will implement Top functionality as well as maintaining the displayed list items.<span>  </span>In the future it will also implement binding to an observable collection.<span>  </span>It will not do any sorting itself.<span>  </span>This class will rely on a SortedListManager to maintain sorted items.<span>  </span>I put Add and Remove methods on the SortedListManager.<span>  </span>Currently, I just call Add, but when I implement an observed binding, I will have to utilize remove as well.<span>  </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><em>SortedListManager</em></p>
<p class="MsoNormal" style="margin:0 0 10pt;">The SortedListManager class maintains the sorted order of items in the source list.<span>  </span>In the future, this class will also implement queuing before doing the re-sort.<span>  </span>It will also be updated to a logarithmic algorithm.<span>  </span>The SortedListManager will communicate updates to the sorted order of items via a ListUpdated event that the SortedList will listen to and handle.<span>  </span>To monitor the individual list items, the SortedListManager will attach listeners to the individual objects INotifyPropertyChanged interfaces.</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><em>DataObjectWatcher</em></p>
<p class="MsoNormal" style="margin:0 0 10pt;">The DataObjectWatcher listens for updates to the individual data objects.<span>  </span>It does this by binding to the objects INotifyPropertyChanged interface.<span>  </span>When I first wrote this class it just had a SourceIndex property which was the index of the watched object in the source array.<span>  </span>This way when I received the PropertyChanged event, I would know exactly which item changed.<span>  </span>As I got further with development this object changed completely so I would like to spend some time discussing the important properties in detail.</p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="text-decoration:underline;">KnownValue</span> : I added the KnownValue attribute on this class to keep a local copy of the data objects sorted property value.<span>  </span>This property isn’t so useful now but when I implement event queuing this will be an extremely important attribute.<span>  </span>When we have multiple pending updates to re-sort, it will be an error to always sort against other data objects current values because those values may themselves be a pending update.<span>  </span>Sorting against current values could lead to incorrectly ordering the items.</p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="text-decoration:underline;">DataObject: <span> </span></span><span>  </span>I’ll be perfectly honest; I wasn’t thrilled about having this property here!<span>  </span>While developing the SortedList I realized that it was going to be important to have the SortedList class “own” the original list.<span>  </span>By this, I mean that the SortedList was going to monitor the source list for changes and then call appropriate Add/Remove methods on the SortedListManager.<span>  </span>This way I simplified the SortedListManager class.<span>  </span>It also occurred to me that this not only simplified the SortedListManager but it also added to the overall functionality by allowing for use cases which don’t actually include a source list!<span>  </span>Now, at that time I could have asserted for non source list scenario’s that the SortedList class would create its own internal List but that would create unnecessary complexity in the SortedList class.<span>  </span>I decided that having the DataObject Property here, not a ‘SourceIndex’ property into the original list, was the best solution.</p>
<p class="MsoNormal" style="margin:0 0 10pt;">Implementation (top down)</p>
<p class="MsoNormal" style="margin:0 0 10pt;"><em>SortedList</em></p>
<p class="MsoNormal" style="margin:0 0 10pt;">Start with the skeleton including dependency properties:</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">enum</span> <span style="color:#2b91af;">SortOrder</span> { Asc, Desc };</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">SortedList</span>&lt;ItemType, DataObjectType&gt; : <span style="color:#2b91af;">ListBase</span>&lt;ItemType, DataObjectType&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">where</span> ItemType : <span style="color:#2b91af;">FrameworkElement</span>, <span style="color:blue;">new</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">where</span> DataObjectType : <span style="color:#2b91af;">INotifyPropertyChanged</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Members</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:#2b91af;">SortedListManager</span>&lt;DataObjectType&gt; _manager;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Dependency Properties</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> SortPropertyProperty;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> SortOrderProperty;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> ItemsSourceProperty;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> TopProperty;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:#2b91af;">SortOrder</span> SortOrder</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> (<span style="color:#2b91af;">SortOrder</span>)GetValue(SortOrderProperty); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">set</span> { SetValue(SortOrderProperty, <span style="color:blue;">value</span>); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">string</span> SortProperty</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> (<span style="color:blue;">string</span>)GetValue(SortPropertyProperty); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">set</span> { SetValue(SortPropertyProperty, <span style="color:blue;">value</span>); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">int</span> Top</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> (<span style="color:blue;">int</span>)GetValue(TopProperty); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">set</span> { SetValue(TopProperty, <span style="color:blue;">value</span>); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:#2b91af;">IList</span>&lt;DataObjectType&gt; ItemsSource</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> (<span style="color:#2b91af;">IList</span>&lt;DataObjectType&gt;)GetValue(ItemsSourceProperty); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">set</span> { SetValue(ItemsSourceProperty, <span style="color:blue;">value</span>); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Constructor</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> SortedList()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">static</span> SortedList()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>SortPropertyProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#a31515;">&#8220;SortProperty&#8221;</span>, <span style="color:blue;">typeof</span>(<span style="color:blue;">string</span>), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SortedList</span>&lt;ItemType, DataObjectType&gt;), <span style="color:blue;">null</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>ItemsSourceProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#a31515;">&#8220;ItemsSource&#8221;</span>, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">IList</span>&lt;DataObjectType&gt;), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SortedList</span>&lt;ItemType, DataObjectType&gt;), <span style="color:blue;">null</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>SortOrderProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#a31515;">&#8220;SortOrderProperty&#8221;</span>, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SortOrder</span>), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SortedList</span>&lt;ItemType, DataObjectType&gt;), <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>TopProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#a31515;">&#8220;TopProperty&#8221;</span>, <span style="color:blue;">typeof</span>(<span style="color:blue;">int</span>), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SortedList</span>&lt;ItemType, DataObjectType&gt;), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">new</span> <span style="color:#2b91af;">PropertyMetadata</span>(-1));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">Then Include Some Initialization Logic:</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">override</span> <span style="color:blue;">void</span> OnApplyTemplate()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">base</span>.OnApplyTemplate();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>Initialize();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">private</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">void</span> Initialize()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>_manager = <span style="color:blue;">new</span> <span style="color:#2b91af;">SortedListManager</span>&lt;DataObjectType&gt;(SortProperty, SortOrder);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>_manager.ListUpdated += <span style="color:blue;">new</span> <span style="color:#2b91af;">ListEventHandler</span>&lt;DataObjectType&gt;(_manager_ListUpdated);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">if</span> (<span style="color:blue;">null</span> != <span style="color:blue;">base</span>.Panel)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">base</span>.Clear();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">for</span> ( <span style="color:blue;">int</span> i = 0; i &lt; ItemsSource.Count; ++ i )</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>_manager.AddItem(ItemsSource[i]);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span><span style="font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span>And finally logic to handle list changed events:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:blue;">void</span> _manager_ListUpdated(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">ListEventArgs</span>&lt;DataObjectType&gt; args)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">switch</span> (args.EventType)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">case</span> <span style="color:#2b91af;">ListEventType</span>.Insert:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>HandleInsert(args);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">break</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">case</span> <span style="color:#2b91af;">ListEventType</span>.Move :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>HandleMove(args);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">break</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">void</span> HandleInsert(<span style="color:#2b91af;">ListEventArgs</span>&lt;DataObjectType&gt; args)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span> (Top &lt; 0) <span style="color:green;">// top not used</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">base</span>.InsertItem(args.NewIndex, args.DataObject);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">else</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (args.NewIndex &lt; Top) <span style="color:green;">// insert into top</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">base</span>.InsertItem(args.NewIndex, args.DataObject);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">if</span> (Count &gt; Top)<span>      </span><span style="color:green;">// remove old top</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>RemoveAt(Top);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">void</span> HandleMove(<span style="color:#2b91af;">ListEventArgs</span>&lt;DataObjectType&gt; args)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span> (Top &lt; 0)<span>  </span><span style="color:green;">// Top not used</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">base</span>.Move(args.OldIndex, args.NewIndex);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">else</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (args.NewIndex &lt; Top)<span>  </span><span style="color:green;">// Moved into top</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">if</span> (args.OldIndex &lt; Top)<span>   </span><span style="color:green;">// From within top</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">base</span>.Move(args.OldIndex, args.NewIndex);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">else</span><span>  </span><span style="color:green;">// From outside top</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>InsertItem(args.NewIndex, _manager[args.NewIndex]);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">if</span> (Count &gt; Top)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>              </span>RemoveAt(Top);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">else</span> <span style="color:blue;">if</span> (args.OldIndex &lt; Top) <span style="color:green;">// Moved out of top</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">base</span>.RemoveAt(args.OldIndex);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">if</span> (_manager.Count &gt;= Top)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>InsertItem(Top &#8211; 1, _manager[Top - 1]);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span>Sorted List Manager</span></em><span>: ( a linear implementation)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">SortedListManager</span>&lt;DataObjectType&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">where</span> DataObjectType : <span style="color:#2b91af;">INotifyPropertyChanged</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">delegate</span> <span style="color:blue;">bool</span> <span style="color:#2b91af;">LessThanDelegate</span>(<span style="color:#2b91af;">IComparable</span> a, <span style="color:#2b91af;">IComparable</span> b);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> members</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:#2b91af;">PropertyInfo</span> _propertyInfo;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:#2b91af;">LessThanDelegate</span> _comparer;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">DataObjectWatcher</span>&lt;DataObjectType&gt;&gt; _list;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Events</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">event</span> <span style="color:#2b91af;">ListEventHandler</span>&lt;DataObjectType&gt; ListUpdated;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Properties</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">int</span> Count</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> _list.Count; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> DataObjectType <span style="color:blue;">this</span>[<span style="color:blue;">int</span> index]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> _list[index].DataObject; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Constructor</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> SortedListManager( <span style="color:blue;">string</span> sortProperty, <span style="color:#2b91af;">SortOrder</span> order)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>_propertyInfo = <span style="color:blue;">typeof</span>(DataObjectType).GetProperty(sortProperty);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>_list = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">DataObjectWatcher</span>&lt;DataObjectType&gt;&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span> (<span style="color:#2b91af;">SortOrder</span>.Asc.Equals ( order ))</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>_comparer = <span style="color:blue;">delegate</span>(<span style="color:#2b91af;">IComparable</span> a, <span style="color:#2b91af;">IComparable</span> b) </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>{ </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> (a.CompareTo(b) &lt;= 0); </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>};</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">else</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>_comparer = <span style="color:blue;">delegate</span>(<span style="color:#2b91af;">IComparable</span> a, <span style="color:#2b91af;">IComparable</span> b) </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{ </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">return</span> (a.CompareTo(b) &gt;= 0); </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>};</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> List Updates</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> AddItem(<span style="color:green;">/*int index,*/</span> DataObjectType dataObject)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:#2b91af;">DataObjectWatcher</span>&lt;DataObjectType&gt; watcher = </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">new</span> <span style="color:#2b91af;">DataObjectWatcher</span>&lt;DataObjectType&gt;( _propertyInfo.Name,dataObject);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>watcher.KnownValue = (<span style="color:#2b91af;">IComparable</span>)_propertyInfo.GetValue(dataObject,<span style="color:blue;">null</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>watcher.DataObjectUpdated += </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">new</span> <span style="color:#2b91af;">DataObjectChangeHandler</span>(watcher_DataObjectUpdated);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>DataObjectWatcherInserted(watcher);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> RemoveItem(<span style="color:blue;">int</span> sourceIndex)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Data Object Updates</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">void</span> watcher_DataObjectUpdated(<span style="color:blue;">object</span> sender)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>DataObjectWatcherUpdated (( <span style="color:#2b91af;">DataObjectWatcher</span>&lt;DataObjectType&gt;) sender);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">void</span> DataObjectWatcherInserted(<span style="color:#2b91af;">DataObjectWatcher</span>&lt;DataObjectType&gt; watcher)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">lock</span> (<span style="color:blue;">this</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">int</span> index = FindIndex ( watcher.KnownValue);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>_list.Insert(index, watcher);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>ListUpdated(<span style="color:blue;">this</span>, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">new</span> <span style="color:#2b91af;">ListEventArgs</span>&lt;DataObjectType&gt;(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">ListEventType</span>.Insert, watcher.DataObject, -1, index));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">int</span> FindIndex(<span style="color:#2b91af;">IComparable</span> knownValue)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">int</span> index = 0;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">for</span> (index = 0; index &lt; _list.Count; ++index)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (_comparer(knownValue, _list[index].KnownValue))</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">break</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">return</span> index;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">void</span> DataObjectWatcherUpdated(<span style="color:#2b91af;">DataObjectWatcher</span>&lt;DataObjectType&gt; watcher)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">lock</span> (<span style="color:blue;">this</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>watcher.KnownValue = </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>(<span style="color:#2b91af;">IComparable</span>)_propertyInfo.GetValue( watcher.DataObject,<span style="color:blue;">null</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">int</span> sourceIndex = _list.IndexOf(watcher);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>_list.RemoveAt(sourceIndex);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">int</span> destinationIndex = FindIndex(watcher.KnownValue);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>_list.Insert(destinationIndex, watcher);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>ListUpdated(<span style="color:blue;">this</span>, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">new</span> <span style="color:#2b91af;">ListEventArgs</span>&lt;DataObjectType&gt;(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">ListEventType</span>.Move, watcher.DataObject, sourceIndex, destinationIndex));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span>DataObjectWatcher</span></em></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">delegate</span> <span style="color:blue;">void</span> <span style="color:#2b91af;">DataObjectChangeHandler</span> (<span style="color:blue;">object</span> sender );</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">DataObjectWatcher</span>&lt;DataObjectType&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">where</span> DataObjectType : <span style="color:#2b91af;">INotifyPropertyChanged</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Members</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">string</span> _monitoredProperty;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Properties</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:#2b91af;">IComparable</span> KnownValue { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> DataObjectType DataObject { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Events</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">event</span> <span style="color:#2b91af;">DataObjectChangeHandler</span> DataObjectUpdated;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Constructors</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> DataObjectWatcher( <span style="color:blue;">string</span> monitoredProperty, DataObjectType dataObject)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>DataObject = dataObject;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>_monitoredProperty = monitoredProperty;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>dataObject.PropertyChanged += </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">new</span> <span style="color:#2b91af;">PropertyChangedEventHandler</span>(dataObject_PropertyChanged);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">void</span> dataObject_PropertyChanged(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">PropertyChangedEventArgs</span> e)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span> (e.PropertyName == _monitoredProperty)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (<span style="color:blue;">null</span> != DataObjectUpdated)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>DataObjectUpdated(<span style="color:blue;">this</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span><span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span>And some miscellaneous classes</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">enum</span> <span style="color:#2b91af;">ListEventType</span> { Insert, Remove, Move };</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ListEventArgs</span>&lt;DataObjectType&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span>  </span><span style="color:blue;">public</span> ListEventArgs()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> ListEventArgs(<span style="color:#2b91af;">ListEventType</span> eventType,</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>DataObjectType dataObject, <span style="color:blue;">int</span> oldIndex, <span style="color:blue;">int</span> newIndex)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>EventType = eventType;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>DataObject = dataObject;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>OldIndex = oldIndex;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>NewIndex = newIndex;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:#2b91af;">ListEventType</span> EventType { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">int</span> OldIndex { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">int</span> NewIndex { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> DataObjectType DataObject{ <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">delegate</span> <span style="color:blue;">void</span> <span style="color:#2b91af;">ListEventHandler</span>&lt;DataObjectType&gt;(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">object</span> sender, <span style="color:#2b91af;">ListEventArgs</span>&lt;DataObjectType&gt; args);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span> </span></p>
<p><font face="Calibri" size="3"></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p></font></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mwohltman.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mwohltman.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mwohltman.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mwohltman.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mwohltman.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mwohltman.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mwohltman.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mwohltman.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mwohltman.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mwohltman.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mwohltman.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mwohltman.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mwohltman.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mwohltman.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=61&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mwohltman.wordpress.com/2009/03/13/a-custom-silverlight-list-part-v-implementing-a-sorted-list-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0cfde768c5471a49f953c0bf8a340f3?s=96&#38;d=identicon" medium="image">
			<media:title type="html">mwohltman</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/03/sortedlist_cd1.jpg" medium="image">
			<media:title type="html">sortedlist_cd1</media:title>
		</media:content>
	</item>
		<item>
		<title>A Custom Silverlight List &#8211; Part IV, Evaluation</title>
		<link>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-iv-evaluation/</link>
		<comments>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-iv-evaluation/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 16:40:51 +0000</pubDate>
		<dc:creator>mwohltman</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[ListBox]]></category>

		<guid isPermaLink="false">http://mwohltman.wordpress.com/?p=56</guid>
		<description><![CDATA[So when I got to this point with my List I took a step back and asked myself a couple questions.  1)      Did I reach my goal 2)      What doesn’t my List support 3)      Will my list be easy to use 4)      Do I even like it 5)      Will my list be easy to expand/update [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=56&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">So when I got to this point with my List I took a step back and asked myself a couple questions.<span>  </span></span></span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">1)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">Did I reach my goal</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">2)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">What doesn’t my List support</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">3)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">Will my list be easy to use</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">4)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">Do I even like it</span></p>
<p class="MsoListParagraphCxSpLast" style="text-indent:-.25in;margin:0 0 10pt .5in;"><span><span><span style="font-size:small;font-family:Calibri;">5)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">Will my list be easy to expand/update with other complex needs</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Did I reach my goal?</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">YES! <span> </span>The VisualListBase class provides an indexer property for access to our item controls.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">What doesn’t my list support?</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">At this point, the List still does not support selection.<span>  </span>I spoke about this feature in my first post and have a strategy to implement it.<span>  </span>I should note, I haven’t implemented selection but I may go back and make it a topic for a future post.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">My list also does not inherently support scrolling or a default Panel type.<span>  </span>This is probably the major disadvantage to using my list.<span>  </span>With the ListBox, you don’t have to provide a template for the List.<span>   </span>If you don’t provide a custom ItemsPanel the ListBox will inject a vertical StackPanel with a Scrollbar.<span>  </span>I thought about doing this because let’s face it; it will save time each time I use my list.<span>  </span>In the end, however, I decided I didn’t like polluting my List class with extra code when defining a template is a very ‘Silverlight-ish’ thing to do.<span>  </span>What I may be able to do though is provide a default template at my base class’s level.<span>  </span>It wasn’t obvious to me how to do this because my type utilizes generics but I suspect the “DefaultStyleKey” property is designed for just this thing.<span>  </span>I will have to revisit!</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Will my list be easy to use?</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">As stated above, it will be as easy to use as the ListBox with the disadvantage of (1) having to define our list type and (2) having to define our default template.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">I suppose there is one other disadvantage as well.<span>  </span>Because I couldn’t use a template (DataTemplate, FrameworkTemplate) for my ItemControl an explicit type is needed.<span>  </span>Now your ItemControl can certainly be a template control (I have already used both UserControl’s and custom control’s), but I can’t use ad hoc DataTemplates.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Do I like it?</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Yes.<span>  </span>I like it.<span>  </span>Clearly, for fast ad hoc usage the ListBox is still a better choice.<span>  </span>Once I implement selection capabilities my feature set should be the same.<span>  </span>Of course, having a list framework ready to extend with custom logic like selection capabilities when they arrive is certainly useful.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Can it be extended?</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Stay tuned for my next post …</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mwohltman.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mwohltman.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mwohltman.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mwohltman.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mwohltman.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mwohltman.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mwohltman.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mwohltman.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mwohltman.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mwohltman.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mwohltman.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mwohltman.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mwohltman.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mwohltman.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=56&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-iv-evaluation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0cfde768c5471a49f953c0bf8a340f3?s=96&#38;d=identicon" medium="image">
			<media:title type="html">mwohltman</media:title>
		</media:content>
	</item>
		<item>
		<title>A Custom Silverlight List &#8211; Part III, Using the List</title>
		<link>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-iii-using-the-list/</link>
		<comments>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-iii-using-the-list/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 16:08:04 +0000</pubDate>
		<dc:creator>mwohltman</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[ListBox]]></category>

		<guid isPermaLink="false">http://mwohltman.wordpress.com/?p=51</guid>
		<description><![CDATA[Developing Our Item Control (Visual Control) The first thing we want to develop is our Item Control (Visual Control) and our Data Object.  For my test bed, I made these extremely simple.  I did use a custom control with 3 VisualState’s.  After all, the inability to manipulate a control’s VisualState within a ListBox was the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=51&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><strong>Developing Our Item Contro</strong>l (Visual Control)</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The first thing we want to develop is our Item Control (Visual Control) and our Data Object.<span>  </span>For my test bed, I made these extremely simple. <span> </span>I did use a custom control with 3 VisualState’s. <span> </span>After all, the inability to manipulate a control’s VisualState within a ListBox was the main reason for developing my List.<span>  </span>So my simple custom control for our Item type was:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>[<span style="color:#2b91af;">TemplateVisualState</span>(GroupName = <span style="color:#a31515;">"Status"</span>, Name = <span style="color:#a31515;">"Drafting"</span>)]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>[<span style="color:#2b91af;">TemplateVisualState</span>(GroupName = <span style="color:#a31515;">"Status"</span>, Name = <span style="color:#a31515;">"Drafted"</span>)]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>[<span style="color:#2b91af;">TemplateVisualState</span>(GroupName = <span style="color:#a31515;">"Status"</span>, Name = <span style="color:#a31515;">"Normal"</span>)]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">MyCustomControl</span> : <span style="color:#2b91af;">ContentControl</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> MyCustomControl()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>DefaultStyleKey = <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">MyCustomControl</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span> </span>I also created a default template and put into the resource dictionary.<span>  </span>I not going to show the theme, but remember it has three visual states.</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Our Data Object</span></span></strong></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">CustomData</span> : <span style="color:#2b91af;">INotifyPropertyChanged</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">string</span> _valueString;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">event</span> <span style="color:#2b91af;">PropertyChangedEventHandler</span> PropertyChanged;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> CustomData(<span style="color:blue;">string</span> controlText)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>ValueString = controlText;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">string</span> ValueString</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> _valueString; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">set</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (_valueString != <span style="color:blue;">value</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>_valueString = <span style="color:blue;">value</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>OnPropertyChanged(<span style="color:#a31515;">&#8220;ValueString&#8221;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">void</span> OnPropertyChanged(<span style="color:blue;">string</span> propertyName)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span> (<span style="color:blue;">null</span> != PropertyChanged)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> <span style="color:#2b91af;">PropertyChangedEventArgs</span>(propertyName));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Defining our List</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">The next thing we have to do is define our List.<span>  </span>Because of my use of generics, I have to define my list type in code before it can be used in XAML.<span>  </span>It’s also important to remember, that besides defining the type which will usually be extremely straightforward, you will need to also define a default control template.<span>  </span>Also, the control template for our list has to include a Panel with name “Container” which is defined as a template part of our base class (VisualListBase).<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">List Definition:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">class</span> <span style="color:#2b91af;">MyCustomControlList</span> : <span style="color:#2b91af;">BindableList</span>&lt;<span style="color:#2b91af;">MyCustomControl</span>, <span style="color:#2b91af;">CustomData</span>&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">int</span> _selectedIndex;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> MyCustomControlList()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>DefaultStyleKey = <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">MyCustomControlList</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>_selectedIndex = 0;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> Next()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span> (_selectedIndex &lt; Count)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>_selectedIndex++;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">VisualStateManager</span>.GoToState(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">this</span>[_selectedIndex - 1], <span style="color:#a31515;">&#8220;Drafting&#8221;</span>, <span style="color:blue;">false</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (_selectedIndex &gt; 1)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:#2b91af;">VisualStateManager</span>.GoToState(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">this</span>[_selectedIndex - 2], <span style="color:#a31515;">&#8220;Drafted&#8221;</span>, <span style="color:blue;">false</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">You obviously won’t usually need the ‘Next’ method, but this demonstrates my lone goal for developing my list.<span>  </span>I have access to the individual Controls within the list, not just the data objects.<span>  </span>Next, I’ll show you the default template I added for the MyCustomControlList type.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>  </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Style</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:red;"><span> </span>TargetType</span><span style="color:blue;">=&#8221;l:MyCustomControlList&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Setter</span><span style="font-size:10pt;color:red;font-family:&quot;"> Property</span><span style="font-size:10pt;color:blue;font-family:&quot;">=&#8221;Template&#8221;&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>      </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Setter.Value</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ControlTemplate</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>          </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">StackPanel</span><span style="font-size:10pt;color:red;font-family:&quot;"> x</span><span style="font-size:10pt;color:blue;font-family:&quot;">:</span><span style="font-size:10pt;color:red;font-family:&quot;">Name</span><span style="font-size:10pt;color:blue;font-family:&quot;">=&#8221;Container&#8221;</span><span style="font-size:10pt;color:red;font-family:&quot;"> Orientation</span><span style="font-size:10pt;color:blue;font-family:&quot;">=&#8221;Vertical&#8221;</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>             </span><span style="color:red;"><span> </span>Background</span><span style="color:blue;">=&#8221;{</span><span style="color:#a31515;">TemplateBinding</span><span style="color:red;"> Background</span><span style="color:blue;">}&#8221;</span> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>             </span><span style="color:red;"><span> </span>Height</span><span style="color:blue;">=&#8221;{</span><span style="color:#a31515;">TemplateBinding</span><span style="color:red;"> Height</span><span style="color:blue;">}&#8221;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>             </span><span style="color:red;"><span> </span>Width</span><span style="color:blue;">=&#8221;{</span><span style="color:#a31515;">TemplateBinding</span><span style="color:red;"> Width</span><span style="color:blue;">}&#8221;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>             </span><span style="color:red;"><span> </span>Margin</span><span style="color:blue;">=&#8221;{</span><span style="color:#a31515;">TemplateBinding</span><span style="color:red;"> Margin</span><span style="color:blue;">}&#8221;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                        </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                   </span><span>    </span><span style="color:blue;"><span> </span>/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ControlTemplate</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>      </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Setter.Value</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Setter</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;color:#a31515;line-height:115%;font-family:&quot;"><span>  </span></span><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;line-height:115%;font-family:&quot;">Style</span><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">So the magic is done and we are free to add our list into XAML with the following definition:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">l</span><span style="font-size:10pt;color:blue;font-family:&quot;">:</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">MyCustomControlList</span><span style="font-size:10pt;color:red;font-family:&quot;"> x</span><span style="font-size:10pt;color:blue;font-family:&quot;">:</span><span style="font-size:10pt;color:red;font-family:&quot;">Name</span><span style="font-size:10pt;color:blue;font-family:&quot;">=&#8221;MyControlList&#8221;</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span><span style="color:red;">ItemsSource</span><span style="color:blue;">=&#8221;{</span><span style="color:#a31515;">Binding</span><span style="color:red;"> Items</span><span style="color:blue;">,</span><span style="color:red;"> Source</span><span style="color:blue;">={</span><span style="color:#a31515;">StaticResource</span><span style="color:red;"> State</span><span style="color:blue;">}}&#8221; /&gt;</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mwohltman.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mwohltman.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mwohltman.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mwohltman.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mwohltman.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mwohltman.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mwohltman.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mwohltman.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mwohltman.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mwohltman.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mwohltman.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mwohltman.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mwohltman.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mwohltman.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=51&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-iii-using-the-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0cfde768c5471a49f953c0bf8a340f3?s=96&#38;d=identicon" medium="image">
			<media:title type="html">mwohltman</media:title>
		</media:content>
	</item>
		<item>
		<title>A Custom Silverlight List &#8211; Part II, Design &amp; Implementation</title>
		<link>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-ii-design-implementation/</link>
		<comments>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-ii-design-implementation/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 00:52:55 +0000</pubDate>
		<dc:creator>mwohltman</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mwohltman.wordpress.com/?p=44</guid>
		<description><![CDATA[Design Designing a list doesn’t require tremendous thought but there were some things worth considering.  Primarily, what abstractions could be made?  For your basic list supporting databinding, I see three main pieces of functionality. 1)      Adding and the visual components 2)      Initializing List Items from Data Objects 3)      Binding to our ItemsSource property and maintaining [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=44&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><strong>Design</strong></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Designing a list doesn’t require tremendous thought but there were some things worth considering.<span>  </span>Primarily, what abstractions could be made?<span>  </span>For your basic list supporting databinding, I see three main pieces of functionality.</span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">1)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">Adding and the visual components</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">2)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">Initializing List Items from Data Objects</span></p>
<p class="MsoListParagraphCxSpLast" style="text-indent:-.25in;margin:0 0 10pt .5in;"><span><span><span style="font-size:small;font-family:Calibri;">3)</span><span style="font:7pt &quot;">      </span></span></span><span style="font-size:small;font-family:Calibri;">Binding to our ItemsSource property and maintaining our list based on modifications to our source list</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Looking at this list, I decided to build a class hierarchy abstracting each “level” of functionality.<span>  </span>I came up with the following:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<div></div>
<p><span style="font-size:small;font-family:Calibri;"></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p> </p>
<p></span></p>
<div id="attachment_45" class="wp-caption aligncenter" style="width: 306px"><img class="size-full wp-image-45" title="bindablelist_cd" src="http://mwohltman.files.wordpress.com/2009/03/bindablelist_cd.jpg" alt="Bindable List Class Diagram" width="296" height="583" /><p class="wp-caption-text">Bindable List Class Diagram</p></div>
<p> </p>
<p> </p>
<p class="MsoNormal" style="margin:0 0 10pt;">Here I used Generic classes with the Types: ItemType &amp; DataObjectType.<span>  </span>DataObjectType is the type of object in the ItemsSource collection.<span>  </span>ItemType is the visual control added to the list.<span>  </span>Everything else seems pretty straightforward.<span>  </span>The VisualListBase abstracts adding and removing items from the List.<span>  </span>ListBase abstracts initializing the ItemType instance for each Data Object and BindableList listens for updates to the ItemsSource property.<span>  </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong>Implementation</strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;">Most of the implementation is pretty boring.<span>  </span>In fact, after the design was in place the code mostly wrote itself.<span>  </span>There were, however, some key details</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><em>VisualListBase</em>:</p>
<p class="MsoNormal" style="margin:0 0 10pt;">The VisualListBase class is the collection of visual controls that get displayed.<span>  </span>To make the most flexible list and provide the same template capabilities of the ListBox I realized I needed to use a ContentControl with a TemplatePart to identify the Panel that would hold the items.<span>  </span>The class then started as :</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>[<span style="color:#2b91af;">TemplatePart</span>(Name = <span style="color:#a31515;">"Container"</span>, Type = <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Panel</span>))]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">VisualListBase</span>&lt;ItemType&gt; : <span style="color:#2b91af;">ContentControl</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">where</span> ItemType : <span style="color:#2b91af;">FrameworkElement</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span><span style="color:blue;">protected</span> <span style="color:#2b91af;">Panel</span> Panel { <span style="color:blue;">get</span>; <span style="color:blue;">private</span> <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">protected</span> <span style="color:blue;">void</span> InitializeVisualList()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>Panel = GetTemplateChild(<span style="color:#a31515;">&#8220;Container&#8221;</span>) <span style="color:blue;">as</span> <span style="color:#2b91af;">Panel</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> OnApplyTemplate()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">base</span>.OnApplyTemplate();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>InitializeVisualList();</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;">From here I filled in the list modification routines:</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> Add(ItemType item)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>Panel.Children.Add(item);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> RemoveAt(<span style="color:blue;">int</span> index)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>Panel.Children.RemoveAt(index);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> Insert(<span style="color:blue;">int</span> index, ItemType item)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>Panel.Children.Insert(index, item);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> Move(<span style="color:blue;">int</span> sourceIndex, <span style="color:blue;">int</span> destinationIndex)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>ItemType item = (ItemType)Panel.Children[sourceIndex];</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>Panel.Children.RemoveAt(sourceIndex);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>Panel.Children.Insert(destinationIndex, item);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> Clear()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>Panel.Children.Clear();</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">And finally some helpful list properties.</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">int</span> Count</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> {<span style="color:blue;">return</span> Panel.Children.Count; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> ItemType <span style="color:blue;">this</span>[<span style="color:blue;">int</span> index]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> (ItemType)Panel.Children[index];}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;">See what I mean?<span>  </span>Code wrote itself …</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><em>ListBase</em></p>
<p class="MsoNormal" style="margin:0 0 10pt;">The ListBase class extends the VisualListBase class and provided routines to initialize a ItemType (the visual control). To that end, it provides a DependencyProperty ItemStyle.<span>  </span>The ItemStyle property allows for styling and templeting of the ItemType.<span>  </span>The class started as :</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ListBase</span>&lt;ItemType, DataObjectType&gt; : <span style="color:#2b91af;">VisualListBase</span>&lt;ItemType&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">where</span> ItemType : <span style="color:#2b91af;">FrameworkElement</span>, <span style="color:blue;">new</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> ItemStyleProperty;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:#2b91af;">Style</span> ItemStyle</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> (<span style="color:#2b91af;">Style</span>)GetValue(ItemStyleProperty); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">set</span> { SetValue(ItemStyleProperty, <span style="color:blue;">value</span>); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> ListBase()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">static</span> ListBase()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>ItemStyleProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(<span style="color:#a31515;">&#8220;ItemStyle&#8221;</span>, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Style</span>), <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">ListBase</span>&lt;ItemType, DataObjectType&gt;), <span style="color:blue;">null</span>);</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">And I then add the ItemType initialization code:</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> Item Initialization</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">protected</span> <span style="color:blue;">virtual</span> ItemType InitializeNewItem(DataObjectType dataObject)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>ItemType item = <span style="color:blue;">new</span> ItemType();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>item.Style = ItemStyle;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>item.DataContext = dataObject;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">return</span> item;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>#region</span><span style="font-size:10pt;font-family:&quot;"> List Modifications</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">protected</span> <span style="color:blue;">virtual</span> <span style="color:blue;">void</span> InsertItem(<span style="color:blue;">int</span> index, DataObjectType dataObject)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>ItemType item = InitializeNewItem(dataObject);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">base</span>.Insert(index, item);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">protected</span> <span style="color:blue;">virtual</span> <span style="color:blue;">void</span> AddItem(DataObjectType dataObject)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>ItemType item = InitializeNewItem(dataObject);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">base</span>.Add(item);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;"><span>    </span>#endregion</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">Again, pretty straightforward.</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><em>BindableList</em></p>
<p class="MsoNormal" style="margin:0 0 10pt;">The BindableList extends ListBase and adds logic to monitor its ItemsSource DependencyProperty.<span>  </span>The class started as :</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">class</span> <span style="color:#2b91af;">BindableList</span>&lt;ItemType, DataObjectType&gt; </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>: <span style="color:#2b91af;">ListBase</span>&lt;ItemType, DataObjectType&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">where</span> ItemType : <span style="color:#2b91af;">FrameworkElement</span>, <span style="color:blue;">new</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> ItemsSourceProperty;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> BindableList() {}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">static</span> BindableList()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>ItemsSourceProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(<span style="color:#a31515;">&#8220;ItemsSource&#8221;</span>, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">typeof</span>(<span style="color:#2b91af;">IEnumerable</span>&lt;DataObjectType&gt;), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">typeof</span>(<span style="color:#2b91af;">BindableList</span>&lt;ItemType, DataObjectType&gt;), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">new</span> <span style="color:#2b91af;">PropertyMetadata</span>(<span style="color:blue;">null</span>, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">new</span> <span style="color:#2b91af;">PropertyChangedCallback</span>(ItemsSourceChanged)));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;DataObjectType&gt; ItemsSource</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> (<span style="color:#2b91af;">IEnumerable</span>&lt;DataObjectType&gt;)GetValue(ItemsSourceProperty); }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">set</span> { SetValue(ItemsSourceProperty, <span style="color:blue;">value</span>); }</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">I then added code to handle changes in the ItemSource property:</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> ItemsSourceChanged(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:#2b91af;">DependencyObject</span> dependencyObject, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:#2b91af;">DependencyPropertyChangedEventArgs</span> args)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span> </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:#2b91af;">BindableList</span>&lt;ItemType, DataObjectType&gt; list = </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>(<span style="color:#2b91af;">BindableList</span>&lt;ItemType, DataObjectType&gt;)dependencyObject;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span> (args.NewValue <span style="color:blue;">is</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;DataObjectType&gt;)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">ObservableCollection</span>&lt;DataObjectType&gt; oc = </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>(<span style="color:#2b91af;">ObservableCollection</span>&lt;DataObjectType&gt;)args.NewValue;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>oc.CollectionChanged += <span style="color:blue;">new</span> <span style="color:#2b91af;">NotifyCollectionChangedEventHandler</span>(</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>list.oc_CollectionChanged);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>list.Initialize();</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> oc_CollectionChanged(<span style="color:blue;">object</span> sender, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:#2b91af;">NotifyCollectionChangedEventArgs</span> e)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">switch</span> ( e.Action )</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">case</span> <span style="color:#2b91af;">NotifyCollectionChangedAction</span>.Add :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 0; i &lt; e.NewItems.Count; ++i)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>InsertItem(e.NewStartingIndex + i, (DataObjectType)e.NewItems[i]);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">break</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">case</span> <span style="color:#2b91af;">NotifyCollectionChangedAction</span>.Remove :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 0; i &lt; e.OldItems.Count; ++i)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>RemoveAt(e.OldStartingIndex + i);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">break</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">case</span> <span style="color:#2b91af;">NotifyCollectionChangedAction</span>.Replace :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>RemoveAt(e.NewStartingIndex);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>InsertItem(e.NewStartingIndex, (DataObjectType)e.NewItems[0]);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">break</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">case</span> <span style="color:#2b91af;">NotifyCollectionChangedAction</span>.Reset:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>Clear();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span style="color:blue;">break</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;">And finally some initialization code:</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> OnApplyTemplate()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">base</span>.OnApplyTemplate();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>Initialize();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:blue;">void</span> Initialize()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span> ((<span style="color:blue;">null</span> != <span style="color:blue;">base</span>.Panel) &amp; (<span style="color:blue;">null</span> != ItemsSource) )</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">base</span>.Clear();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">foreach</span> (DataObjectType dataObject <span style="color:blue;">in</span> ItemsSource)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span>AddItem(dataObject);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mwohltman.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mwohltman.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mwohltman.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mwohltman.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mwohltman.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mwohltman.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mwohltman.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mwohltman.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mwohltman.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mwohltman.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mwohltman.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mwohltman.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mwohltman.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mwohltman.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=44&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mwohltman.wordpress.com/2009/03/12/a-custom-silverlight-list-part-ii-design-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0cfde768c5471a49f953c0bf8a340f3?s=96&#38;d=identicon" medium="image">
			<media:title type="html">mwohltman</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/03/bindablelist_cd.jpg" medium="image">
			<media:title type="html">bindablelist_cd</media:title>
		</media:content>
	</item>
		<item>
		<title>A Custom Silverlight List &#8211; Part I: Overview, Goal &amp; Concpetual Components</title>
		<link>http://mwohltman.wordpress.com/2009/03/11/a-custom-silverlight-list-part-i-overview-goal-concpetual-components/</link>
		<comments>http://mwohltman.wordpress.com/2009/03/11/a-custom-silverlight-list-part-i-overview-goal-concpetual-components/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 18:33:23 +0000</pubDate>
		<dc:creator>mwohltman</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Silverlight ListBox List]]></category>

		<guid isPermaLink="false">http://mwohltman.wordpress.com/?p=38</guid>
		<description><![CDATA[ Overview I was recently working on a daft tool for my Fantasy Baseball League.  I found myself using a lot of lists to display the teams, free agents and selected players.  The first list I was looking at was a list of team names I wanted to stretch from left to right at the top [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=38&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span><span style="font-size:small;font-family:Calibri;"><strong>Overview</strong></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">I was recently working on a daft tool for my Fantasy Baseball League.<span>  </span>I found myself using a lot of lists to display the teams, free agents and selected players.<span>  </span>The first list I was looking at was a list of team names I wanted to stretch from left to right at the top of the page.<span>  </span>I wanted to use this list not just to display the teams in our league, but to also identify which team was currently selecting and what direction the draft was going.<span>  </span>Most fantasy drafts “snake” meaning that the last team to pick in the first round picks first in the second round.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">Now, being a newly equipped Silverlight programmer, I quickly wrote a control to display a team name and gave this control three states: ‘Drafting’, ‘Drafted’, ‘Normal’.<span>  </span>‘Drafting’ would be for the team currently picking, ‘Drafted’ would be for teams that have selected during the current round and ‘Normal’ would be for teams left to pick.<span>  </span>I then added a ListBox, and created the appropriate DataTemplate.<span>  </span>What I later found out, however, was that I couldn’t obtain a reference to my team control (The control with three visual states) from outside the ListBox.<span>  </span>I needed this reference to pass into the VisualStateManager.GoToState function.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">So at this point, I said ‘shucks’ and just manually added my controls to a StackPanel instead of using the ListBox and DataBinding.<span>  </span>I moved on to another List on my page which was a list of the Teams in our league.<span>  </span>For each team I wanted to display all the players on their roster.<span>  </span>This would be an active list, as their rosters obviously grow during the draft.<span>  </span>Again, I was confronted with the same issue.<span>  </span>I added an “AddPlayer” function to this ‘TeamRoster’ control but could not readily get at the control from outside the List.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now I needed to give this some thought!<span>  </span>What I determined was that I decided to use the ListBox because it was the most appropriate databinding control.<span>  </span>I also realized I was not using the ListBox for its intended purpose.<span>  </span>In neither case was I displaying controls for the purpose of selecting an item from the list.<span>  </span>With this enlightenment, I decided it would pay great future dividends to me to design the List that I do want.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><strong>Goal</strong></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">When I set out to develop my list class my goal was really quite simple.<span>  </span>Do everything as close to the ListBox as possible while providing indexed access to the visual controls within the list.<span>  </span>I’m using visual control to distinguish between the UIElement placed within the List and the Data Item from the usual ItemsSource databinding property.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><strong>Conceptual Components:</strong></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;">I started looking at the Conceptual components that make up a list.<span>  </span>This work was pretty easy because after all, I had the ListBox to look at.<span>  </span></span><span style="font-family:Wingdings;"><span>J</span></span><span style="font-family:Calibri;"><span>  </span>I quickly identified the following components.</span></span></p>
<div></div>
<p><span style="font-size:small;font-family:Calibri;"></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">1)</span><span style="font:7pt 'Times New Roman';">      </span></span></span><span style="font-size:small;font-family:Calibri;">List Class – the list class (i.e. ListBox)</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">2)</span><span style="font:7pt 'Times New Roman';">      </span></span></span><span style="font-size:small;font-family:Calibri;">List Panel – the panel within where the individual items were added</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">3)</span><span style="font:7pt 'Times New Roman';">      </span></span></span><span style="font-size:small;font-family:Calibri;">Item Container<span>  </span>- a Container to wrap the visual controls</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span><span style="font-size:small;font-family:Calibri;">4)</span><span style="font:7pt 'Times New Roman';">      </span></span></span><span style="font-size:small;font-family:Calibri;">Item Control – The Visual Control (UIElement) produced for each Data Item</span></p>
<div></div>
<p><span style="font-size:small;font-family:Calibri;"></p>
<p class="MsoListParagraphCxSpLast" style="text-indent:-.25in;margin:0 0 10pt .5in;"><span><span><span style="font-size:small;font-family:Calibri;">5)</span><span style="font:7pt 'Times New Roman';">      </span></span></span><span style="font-size:small;font-family:Calibri;">Data Object – The DataContext for the visual control.</span></p>
<p> </p>
<p></span></span></p>
<p class="MsoListParagraphCxSpLast" style="text-indent:-.25in;margin:0 0 10pt .5in;"> </p>
<div></div>
<p><span style="font-size:small;font-family:Calibri;"></p>
<div id="attachment_39" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-39" title="conceptualcomponents" src="http://mwohltman.files.wordpress.com/2009/03/conceptualcomponents.jpg" alt="Conceptual Components" width="450" height="236" /><p class="wp-caption-text">Conceptual Components</p></div>
<div></div>
<p></span><span style="font-size:small;font-family:Calibri;"></p>
<p class="MsoNormal" style="margin:0 0 10pt;">At this point, the component I was immediately finding both the most interesting and the most irrelevant was the Item Container.<span>  </span>It’s in the Item Container where the ListBox places selection logic.<span>  </span>In the ListBox, we are free to override the appearance for each of the visual states but we cannot add logic or define our own states.<span>  </span>I started thinking about what logic could go in the Container and I came up with very few possibilities.<span>  </span>Logic that applies to the container would be logic that is data/visual control independent.<span>  </span>The best possibilities I came up with, besides selection logic, were visual states for 1) when an Item was inserted/removed from the list and 2) when an item was moved within the list.<span>  </span>Ultimately, I realized that this container was very dynamic.<span>  </span>Selection logic would be highly useful but needs for custom logic would be few and far between.<span>  </span>Because I didn’t need the selection logic right away, I decided I would figure out how it would be implemented and move on.<span>  </span>These were my thoughts:</p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-.25in;margin:0 0 0 .5in;"><span><span>1)<span style="font:7pt &quot;">      </span></span></span>It would be easy to inject the Container around the ListItem.<span>  </span>Since I manually instantiate and insert the ListItem’s, all I needed to do was make this Initialization logic overridable.<span>  </span></p>
<p class="MsoListParagraphCxSpLast" style="text-indent:-.25in;margin:0 0 10pt .5in;"><span><span>2)<span style="font:7pt &quot;">      </span></span></span>There would be multiple communication options for calls between the item Container and the List.<span>  </span>The Item Container could provide events the list could subscribe to or the container could even be initialized with a reference to the parent list.<span>  </span>Further, the List would obviously have access to the individual item containers.</p>
<p class="MsoNormal" style="margin:0 0 10pt;">Great!<span>  </span>Simple yet even the complex is possible!<span>  </span>I’m moving on …</p>
<div></div>
<p><span style="font-size:small;font-family:Calibri;"></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mwohltman.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mwohltman.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mwohltman.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mwohltman.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mwohltman.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mwohltman.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mwohltman.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mwohltman.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mwohltman.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mwohltman.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mwohltman.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mwohltman.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mwohltman.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mwohltman.wordpress.com/38/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=38&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mwohltman.wordpress.com/2009/03/11/a-custom-silverlight-list-part-i-overview-goal-concpetual-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0cfde768c5471a49f953c0bf8a340f3?s=96&#38;d=identicon" medium="image">
			<media:title type="html">mwohltman</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/03/conceptualcomponents.jpg" medium="image">
			<media:title type="html">conceptualcomponents</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Started With Silverlight</title>
		<link>http://mwohltman.wordpress.com/2009/02/27/getting-started-with-silverlight/</link>
		<comments>http://mwohltman.wordpress.com/2009/02/27/getting-started-with-silverlight/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 18:43:04 +0000</pubDate>
		<dc:creator>mwohltman</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mwohltman.wordpress.com/?p=4</guid>
		<description><![CDATA[Overview I am very excited to finally be taking the time to learn Silverlight 2.0, Microsoft’s new Web based Rich Interactive Application (RIA) technology.  Anybody who as seen a Silverlight or Windows Presentation Framework (WPF) sample knows the kind of intuitive and powerful user interfaces that are possible with these technologies.  I decided to concentrate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=4&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="color:#1f497d;"><span style="font-size:small;"><span style="font-family:Calibri;">Overview</span></span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">I am very excited to finally be taking the time to learn Silverlight 2.0, Microsoft’s new Web based Rich Interactive Application (RIA) technology.<span>  </span>Anybody who as seen a Silverlight or Windows Presentation Framework (WPF) sample knows the kind of intuitive and powerful user interfaces that are possible with these technologies.<span>  </span>I decided to concentrate on Silverlight vs. WPF partly because I felt like the investment on a web technology would better balance my skills but also because I read in Rocky Lhotka’s blog his opinions that Silverlight would win out over WPF.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">While I don’t always find UI development to be the most interesting work, I think this investment is almost imperative for my career.<span>  </span>With my first exposure to XAML presentation applications I saw a widening of the gap between presentation tier and general .NET development.<span>  </span>I always felt extremely comfortable as a web developer based on my .Net skills, solid understanding of the asp.net pipeline and understanding of CSS &amp; JavaScript.<span>  </span>With my first look at XAML based applications and Microsoft Expression Blend, however, I quickly understood that a new set of skills would be needed to keep my flexibility of working between the web and server tiers.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">While I was entering Silverlight as a beginner, my goals were not pedestrian.<span>   </span>I needed to get into the framework and really understand the concepts.<span>  </span>As a consultant, I can’t allow for my first few weeks on a project to be spent passively getting up speed when important design decisions are being made.<span>  </span>I also need to make sure I stock my tool belt with the design pattern, code templates, and reusable components needed to really accelerate development.<span>  </span>To get started, I decided I’d first target something simple.<span>  </span>My first idea was to develop a simple online version of Microsoft OneNote.<span>  </span>I’m open to publishing the full source, but below are a few topics I felt noteworthy during development.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="color:#1f497d;">Getting started developing the OnlineNote’s Application</span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;">It was pretty straightforward to get a working application.<span>  </span>My Page class was very simple.<span>  </span>On Startup it retrieved all existing notes from my WCF Service and initialized a NoteControl for each note instance.<span>  </span>It then waited for mouse clicks, to create new (empty) Note instances.<span>  </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">My NoteControl was also very basic.<span>  </span>It has a Border, TextBox and two Buttons for saving and deleting.<span>  </span>The DataContext for each NoteControl was a wrapper I created around my WCF DataContract object.<span>  </span>I created a wrapper for my DataContract object as I needed to add a Margin property.<span>  </span>Note’s can be dragged around so I needed to bind not only the Note’s text but also its Margin (position).<span>  </span>My DataContract object had two position attributes: PositionX &amp; PositionY.<span>   </span>I needed to convert these attributes into one “Margin” property of Type Thickness for Silverlight.<span>  </span>My Binding Wrapper therefore added the following property.</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#2b91af;">Thickness</span> Margin</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">get</span> { <span style="color:blue;">return</span> _margin; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">set</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>_margin = <span style="color:blue;">value</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>_note.PositionX = (<span style="color:blue;">int</span>)<span style="color:blue;">value</span>.Left;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>_note.PositionY = (<span style="color:blue;">int</span>)<span style="color:blue;">value</span>.Top;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>OnPropertyChanged(<span style="color:#a31515;">&#8220;Margin&#8221;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">The Binding Wrapper aggregated my DataContract instance.<span>  </span>It provided access to the required attributes, but it did not expose PositionX or PositionY.<span>  </span>It instead exposed the attribute above.<span>  </span>Also note that on my DataContract’s PropertyChanged event handler, I had to swallow property changes on PositionX and PositionY.<span>  </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="color:#1f497d;">Deciding a Note’s Visual States</span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;">By far the most interesting part of this application was deciding and implementing my Note’s visual characteristics.<span>  </span>With Silverlight’s VisualStateManager, one defines VisualStateGroup’s for a control.<span>  </span>Each VisualStateGroup has individual VisualState’s. <span> </span>My NoteControl had two VisualStateGroups, ‘HighlightedStates’ and ‘EditStates’.<span>  </span>My highlighted states are ‘Highlighted’ and ‘UnHighlighted’, while my edit states are ‘Dirty’, ‘Clean’ and ‘Saving’.<span>  </span>It was important to consider that each control is always in one VisualState for each VisualStateGroup.<span>  </span>Therefore, the NoteControl will always be in one of its highlighted states and one of its edit states.<span>  </span><span> </span>Let’s take a look at my NoteControl:</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<div id="attachment_18" class="wp-caption aligncenter" style="width: 419px"><img class="size-full wp-image-18" title="normalstate1" src="http://mwohltman.files.wordpress.com/2009/02/normalstate1.jpg" alt="Clean &amp; UnHighlighted" width="409" height="163" /><p class="wp-caption-text">Clean &amp; UnHighlighted</p></div>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<div id="attachment_24" class="wp-caption aligncenter" style="width: 426px"><img class="size-full wp-image-24" title="highlightedstate1" src="http://mwohltman.files.wordpress.com/2009/02/highlightedstate1.jpg" alt="Clean &amp; Highlighted" width="416" height="168" /><p class="wp-caption-text">Clean &amp; Highlighted</p></div>
<p> </p>
<div id="attachment_25" class="wp-caption aligncenter" style="width: 430px"><img class="size-full wp-image-25" title="dirtystate1" src="http://mwohltman.files.wordpress.com/2009/02/dirtystate1.jpg" alt="Dirty &amp; UnHighlighted" width="420" height="154" /><p class="wp-caption-text">Dirty &amp; UnHighlighted</p></div>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="color:#1f497d;"> </span></strong></p>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<div><strong></strong></div>
<p><strong><span style="color:#1f497d;"></p>
<div id="attachment_26" class="wp-caption aligncenter" style="width: 428px"><img class="size-full wp-image-26" title="highlighteddirty1" src="http://mwohltman.files.wordpress.com/2009/02/highlighteddirty1.jpg" alt="Dirty &amp; Highlighted" width="418" height="146" /><p class="wp-caption-text">Dirty &amp; Highlighted</p></div>
<p> </p>
<p> </p>
<p></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong></strong></p>
<div id="attachment_27" class="wp-caption aligncenter" style="width: 453px"><img class="size-full wp-image-27" title="savingstate1" src="http://mwohltman.files.wordpress.com/2009/02/savingstate1.jpg" alt="Saving &amp; UnHighlighted" width="443" height="159" /><p class="wp-caption-text">Saving &amp; UnHighlighted</p></div>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;">When I began wiring up these states, I quickly realized while these were the visual states, there were a more primitive set of control states.<span>  </span>For example, I decided my Note would be highlighted when either the mouse was hovering over the note or the note was being edited (the textbox had focus).<span>  </span>I consider the Note to have two primitive states (Hover &amp; Focus) that work together to control the single ‘Highlighted’ visual state.<span>  </span>You will notice similar primitives for my ‘EditStates’ VisualStateGroup.<span>  </span>My NoteControl has the primitive states Dirty (true or false) and Saving (true or false) but three Visual States in the ‘EditStates’ VisualStateGroup.<span>  </span>I quickly realized that in a collaborative environment, designers are probably going to be constantly tinkering with not only the VisualStates but also the triggers (the underlying primitive control states) for each of these states.<span>  </span>For instance, it would not have been unrealistic to divide my ‘EditStates’ VisualStateGroup into two VisualStateGroups; the second containing only the Saving state and a Normal state.<span>  </span>Under a single ‘EditStates’ group, I currently change the VisualState to ‘Saving” when the user clicks the save button.<span>  </span>Under a two group approach, I would have to update the control to Transition into both the “Clean” and “Saving” VisualState.<span>  </span>This would require a code change. <span> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">Confronted with this problem, I decided the most important thing was to keep my NoteControl’s logic as simple as possible.<span>  </span>Personally, I just love code that writes itself.<span>  </span>To that end, I decided I’d develop the control to only manipulate what I consider to be its primitive states and ignore the control’s VisualState’s.<span>  </span>I created a NoteStates object to hold this primitive state values and added it to my Control’s resources.<span>  </span>From there, the NoteControl’s logic became elementary.</p>
<p class="MsoNormal" style="margin:0 0 10pt;">Next I faced my largest obstacle.<span>  </span>I needed to develop a mechanism to bind the VisualState’s to my control’s primitive states.<span>  </span>I also wanted to do this completely in XAML.<span>  </span>The first thing I discovered was that if I wanted to hook into Silverlight’s Binding infrastructure, I need to do it declaratively in XAML.<span>  </span>Therefore, if I wanted sexy XAML syntax such as</p>
<p class="MsoNormal" style="margin:0 0 10pt;">&lt;VisualStateSetter State=”Highlighted” Expression=”Dirty || Hover” /&gt;</p>
<p class="MsoNormal" style="margin:0 0 10pt;">I would have to implement the binding myself.<span>  </span>I don’t see this as an insurmountable challenge, but I also wanted to leverage what I could.<span>   </span>As a result, I had to move expression operands into individual nodes and build an Expression note to reevaluate the expression on property changes.<span>  Below is a sample XAML for my VisualState Expression Monitor:</span></p>
<p class="MsoNormal" style="text-align:center;"><img class="aligncenter size-full wp-image-30" title="expressionxaml" src="http://mwohltman.files.wordpress.com/2009/02/expressionxaml.jpg" alt="expressionxaml" width="715" height="150" /></p>
<p class="MsoNormal" style="margin:0 0 10pt;">The syntax is still a little bit awkward but it functioned for this application.<span>  </span>I’m sure I’ll be updating the VisualStateExpression &amp; VisualStateExpressionOperand components as requirements grow.<span>  </span>I would like to point out one issue I encountered.<span>  </span>Custom Controls can inherit from DependencyObject directly, FrameworkElement or ContentControl.<span>   </span>Non visual components should probably all inherit from DependencyObject.<span>  </span>An example of such a control is the VisualStateManager.<span>  </span>The first problem this presented is that they wouldn’t be eligible for placement under general layout controls.<span>  </span>They would have to be placed under either the Control’s resources section or in a custom TemplatePart.<span>  </span>My greater issue, however, was controls don’t have a Parent property unless they are a FrameworkElement and placed in general layout.<span>  </span>I needed the Parent property to obtain the Control instance to pass into the VisualStateManager.GoToState() method.<span>  </span>It was also convenient as FrameworkElement’s have a handy Loaded event.<span>  </span>The Loaded event was used to iterate through operands and register for property changes.<span>  </span>If my expression component inherited from DependencyObject directly, its ContentProperty would have be an ObservableCollection instead of just a regular List.<span>  </span>The ObservableCollection would provide a hook to subscribe to operands PropertyChanged event at the time they were added to the expression’s content.</p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="color:#1f497d;"> </span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="color:#1f497d;">Cleaning up some TextBox behavior</span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;">There were two things I noticed about the TextBox containing my Note’s text that I didn’t like.<span>  </span>First, I wanted to remove the hover styling that placed a thin border around the text.<span>  </span>Secondly, I wanted to do something to prevent my text boxes from accepting tabs.<span>  </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">When I thought about changing the textbox’s hover state, I considered two approaches.<span>  </span>My first thought after reading up on Silverlight’s custom templates was to create a new ControlTemplate for my TextBox.<span>  </span>I have to say, I’m a big fan of the custom template feature.<span>  </span>Unfortunately, in this circumstance, I saw one major drawback.<span>  </span>By defining my template, I’d be permanently setting my Textbox’s style.<span>  </span>Any future change to the default TextBox look and feel would not automatically be present in my application.<span>  </span>This seems like a pretty aggressive action considering all I want to do is remove a single VisualState.<span>  </span>Now, in the case of my OnlineNote’s application, it wouldn’t actually be a big concern.<span>  </span>For a more robust application, however, it would be an issue worth more consideration.<span>  </span>So not totally thrilled with the prospect, I looked at what could be done pragmatically.<span>  </span>First I looked to see if I could manipulate the VisualStateManager.<span>   </span>I thought I may be able to disable a VisualState pragmatically.<span>  </span>I didn’t get very far so I switched to looking at the TextBox class itself.<span>  </span>Sure enough, there were OnMouseEnter and OnMouseLeave methods I could override with an empty implementation thus swallowing the events.<span>  </span>Perfect!<span>  </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;">So my next issue with the TextBox was its tabbing behavior.<span>  </span>Silverlight’s TextBox has a IsTabStop attribute.<span>  </span>I just set this flag to False and figured I was on my way.<span>  </span>Unfortunately setting IsTabStop=”False” also disables the TextBox.<span>  </span>I did a quick search and found this post: <a href="http://silverlight.net/forums/t/33523.aspx">http://silverlight.net/forums/t/33523.aspx</a> stating this is the TextBox’s intended behavior.<span>  </span>Further, the behavior is different in WPF.<span>  </span>I didn’t spend any more time investigating why but I assume it’s some web standard for INPUT controls.<span>  </span>I honestly don’t know if this is even a viable answer, but it’s a good enough justification for me not to be to put off by the rather unfortunate functionality.<span>  </span>Fortunately, this same thread offers a solution of pragmatically manipulating the IsTabStop property on the MoustLeftDown/LostFocus events.<span>  </span>This solution works but I found that I also needed to override the Focus method as my note control is pragmatically assigned focus when the note is created.</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;">So, with this, My new TextBox class was now:</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">class</span> <span style="color:#2b91af;">NoteTextBox</span> : <span style="color:#2b91af;">TextBox</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> NoteTextBox()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">base</span>.MouseLeftButtonDown += <span style="color:blue;">new</span> <span style="color:#2b91af;">MouseButtonEventHandler</span>( NonTabStopTextBox_MouseLeftButtonDown);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">base</span>.LostFocus += <span style="color:blue;">new</span> <span style="color:#2b91af;">RoutedEventHandler</span>(NonTabStopTextBox_LostFocus);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> OnMouseEnter(<span style="color:#2b91af;">MouseEventArgs</span> args)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> OnMouseLeave(<span style="color:#2b91af;">MouseEventArgs</span> e)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">void</span> NonTabStopTextBox_LostFocus(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">RoutedEventArgs</span> e)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>IsTabStop = <span style="color:blue;">false</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">void</span> NonTabStopTextBox_MouseLeftButtonDown(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">MouseButtonEventArgs</span> e)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>IsTabStop = <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>Focus();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">new</span> <span style="color:blue;">public</span> <span style="color:blue;">bool</span> Focus()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>IsTabStop = <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">return</span> <span style="color:blue;">base</span>.Focus();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span> </span><strong><span style="color:#1f497d;">WCF Integration</span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;">After creating a quick basic Windows Communication Foundation (WCF) service to persist and retrieve my Notes and started looking at how to integrate the service into my Silverlight application.<span>  </span>This was extremely straightforward with the Add Service Reference command in Visual Studio. The Add Service Reference utility will generate a “Client” that will manage the WCF client channel plumbing.<span>  </span>What I found interesting was the structure of this class.<span>  </span>For each Method in the service, the Client class has an Asynchronous method to begin the method call and a callback event that the caller can subscribe to in order to receive the Service Request’s return value.<span>  </span>It shouldn’t be surprising that a Web based UI leveraged service would want asynchronous behavior.<span>  </span>What is surprising is the event infrastructure for passing return values.<span>  </span>The problem I have with this structure is that it will bring unexpected results if the Service Client object is shared between multiple components. <span> </span>For my OnlineNote’s application I was going to handle persistence at the Note level.<span>  </span>At any given time, any number of notes could be dirty (non-saved) or be in the process of saving.<span>  </span>I decided it shouldn’t be an unrealistic need to have multiple callers of the same Client component so I quickly worked up my own little “Wrapper Pattern”.</p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;">My Wrapper class shortened to support one method (for size):</p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">class</span> <span style="color:#2b91af;">NoteServerWrapper</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">private</span> ServiceReference1.<span style="color:#2b91af;">NoteServerClient</span> _client;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">delegate</span> <span style="color:blue;">void</span> <span style="color:#2b91af;">GetNotesCompleted</span>( ServiceReference1.<span style="color:#2b91af;">GetNotesCompletedEventArgs</span> args);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> NoteServerWrapper()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>_client = <span style="color:blue;">new</span> SilverlightExamples.ServiceReference1.<span style="color:#2b91af;">NoteServerClient</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span></span><span style="font-size:10pt;font-family:&quot;"><span>  </span>_client.GetNotesCompleted += <span style="color:blue;">new</span> <span style="color:#2b91af;">EventHandler</span>&lt;ServiceReference1.<span style="color:#2b91af;">GetNotesCompletedEventArgs</span>&gt;(_client_GetNotesCompleted);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span> </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span><span style="font-size:10pt;font-family:&quot;"><span> </span><span style="color:blue;">private</span> <span style="color:blue;">void</span><span>  </span>_client_GetNotesCompleted(<span style="color:blue;">object</span> sender,ServiceReference1.<span style="color:#2b91af;">GetNotesCompletedEventArgs</span> e)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>((<span style="color:#2b91af;">GetNotesCompleted</span>)e.UserState)(e);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> GetNotes(<span style="color:#2b91af;">GetNotesCompleted</span> handler)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>_client.GetNotesAsync(handler);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span><span style="font-size:10pt;line-height:115%;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mwohltman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mwohltman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mwohltman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mwohltman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mwohltman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mwohltman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mwohltman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mwohltman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mwohltman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mwohltman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mwohltman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mwohltman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mwohltman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mwohltman.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mwohltman.wordpress.com&amp;blog=6563446&amp;post=4&amp;subd=mwohltman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mwohltman.wordpress.com/2009/02/27/getting-started-with-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e0cfde768c5471a49f953c0bf8a340f3?s=96&#38;d=identicon" medium="image">
			<media:title type="html">mwohltman</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/02/normalstate1.jpg" medium="image">
			<media:title type="html">normalstate1</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/02/highlightedstate1.jpg" medium="image">
			<media:title type="html">highlightedstate1</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/02/dirtystate1.jpg" medium="image">
			<media:title type="html">dirtystate1</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/02/highlighteddirty1.jpg" medium="image">
			<media:title type="html">highlighteddirty1</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/02/savingstate1.jpg" medium="image">
			<media:title type="html">savingstate1</media:title>
		</media:content>

		<media:content url="http://mwohltman.files.wordpress.com/2009/02/expressionxaml.jpg" medium="image">
			<media:title type="html">expressionxaml</media:title>
		</media:content>
	</item>
	</channel>
</rss>
