<?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>Atomic Blography</title>
	<atom:link href="http://karlhulme.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://karlhulme.wordpress.com</link>
	<description>By Karl Hulme</description>
	<lastBuildDate>Mon, 24 Oct 2011 15:50:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='karlhulme.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Atomic Blography</title>
		<link>http://karlhulme.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://karlhulme.wordpress.com/osd.xml" title="Atomic Blography" />
	<atom:link rel='hub' href='http://karlhulme.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Pasting Code into Blog Entries using Windows Live Writer</title>
		<link>http://karlhulme.wordpress.com/2007/04/01/pasting-code-into-blog-entries-using-windows-live-writer/</link>
		<comments>http://karlhulme.wordpress.com/2007/04/01/pasting-code-into-blog-entries-using-windows-live-writer/#comments</comments>
		<pubDate>Sun, 01 Apr 2007 09:54:07 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/04/01/pasting-code-into-blog-entries-using-windows-live-writer/</guid>
		<description><![CDATA[I&#8217;ve tried a couple of different ways of getting code from Visual Studio onto a blog post using Windows Live Writer.&#160; Unfortunately something has nearly always been&#160;lost on route.&#160; I&#8217;m trying out a new method which seems to be working ok on my local machine, but the only way to test it properly is to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=84&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve tried a couple of different ways of getting code from Visual Studio onto a blog post using Windows Live Writer.&nbsp; Unfortunately something has nearly always been&nbsp;lost on route.&nbsp; I&#8217;m trying out a new method which seems to be working ok on my local machine, but the only way to test it properly is to upload something -so here goes!</p>
<p>First download the <a title="http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/" href="http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/">CopySourceAsHTML</a> plugin for Visual Studio.&nbsp; It&#8217;s written by <a title="http://www.jtleigh.com/people/colin/" href="http://www.jtleigh.com/people/colin/">Colin Coller</a>, who I gather now works for <a title="http://www.avanade.com/" href="http://www.avanade.com/">Avanade</a>.&nbsp; This plugin&nbsp;adds a &#8216;Copy&nbsp;as HTML&#8217; command.&nbsp; Simply right-click on some selected text, hit the command, and it will convert the code to an HTML representation and place it&nbsp;on the clipboard.&nbsp; It uses the colors as defined in Visual Studio which is much more useful than anything else I&#8217;ve seen before.</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image0118.png"><img style="border-width:0;" height="240" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image027.png?w=237&#038;h=240" width="237" border="0"></a> </p>
<p>You can configure the css produced by the plugin at the file, line and block level.&nbsp;<strong>However for this to work properly you may need the CSS Upgrade from&nbsp;wordpress, otherwise it seems to strip out some of the styling on upload.</strong>&nbsp; This $15 for the year.&nbsp; Since WordPress has a maximum column width of 450px, I&#8217;ve specified this as a file level css rule.&nbsp; So my code should sit in a scrollable DIV element.&nbsp; I&#8217;ve limited the height too so that long scripts don&#8217;t disappear off the page.&nbsp; I&#8217;ve also set the padding on the lines to be zero, because otherwise it spaces out the lines of code massively, this is probably specific my current theme. The finished settings that work for me are below.</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image093.png"><img style="border-width:0;" height="137" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image083.png?w=240&#038;h=137" width="240" border="0"></a> <a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image0119.png"><img style="border-width:0;" height="137" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image0103.png?w=240&#038;h=137" width="240" border="0"></a> </p>
<p>Once the HTML is on the clipboard you can then flick to the HTML view in Windows Live Writer, paste, and then flick back to normal view.&nbsp; This requires 6 mouse clicks in WLW, but&nbsp;you can&nbsp;get it down to 1 if (like me) you want it to be really quick.&nbsp; To do this, create a trivial WLW Addin that inserts the clipboard contents directly into the HTML of the post.&nbsp; You can get a built version of the plugin from <a title="http://www.quarrie.net/kh/InsertHtmlPlugin.dll" href="http://www.quarrie.net/kh/InsertHtmlPlugin.dll">here</a>, but it&#8217;s just as quick to compile it yourself.&nbsp; The source code is below.</p>
<div style="font-size:10pt;background:#181818;overflow:scroll;width:450px;color:#e0e0e0;max-height:350px;font-family:consolas;white-space:nowrap;padding:5px;">
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Collections</span>.<span style="color:#fef1a9;">Generic</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Text</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Windows</span>.<span style="color:#fef1a9;">Forms</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">WindowsLive</span>.<span style="color:#fef1a9;">Writer</span>.<span style="color:#fef1a9;">Api</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">namespace</span> <span style="color:#fef1a9;">InsertHtmlPlugin</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; [<span style="color:#c7c7f1;">WriterPlugin</span>(<span style="color:#60ff60;">"58409179-ECA9-4BE4-8F4A-45F2D0DD79A6"</span>, <span style="color:#60ff60;">"Insert Clipboard Contents as HTML"</span>, </pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">HasEditableOptions</span> = <span style="color:#8080c0;">false</span>, <span style="color:#fef1a9;">ImagePath</span> = <span style="color:#60ff60;">"SmallHtml.png"</span>,</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">PublisherUrl</span> = <span style="color:#60ff60;">"http://karlhulme.wordpress.com"</span>,</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">Description</span> = <span style="color:#60ff60;">"Plugin for quickly insterting HTML from the clipboard."</span>)]</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; [<span style="color:#c7c7f1;">InsertableContentSource</span>(<span style="color:#60ff60;">"Insert Clipboard as HTML"</span>, <span style="color:#fef1a9;">SidebarText</span>=<span style="color:#60ff60;">"Clipboard as HTML"</span>)]</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; [<span style="color:#c7c7f1;">CLSCompliant</span>(<span style="color:#8080c0;">false</span>)]</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">class</span> <span style="color:#c7c7f1;">InsertHtmlPlugin</span> : <span style="color:#c7c7f1;">ContentSource</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">override</span> <span style="color:#c7c7f1;">DialogResult</span> <span style="color:#fef1a9;">CreateContent</span>(<span style="color:#c7c7f1;">IWin32Window</span> <span style="color:#fef1a9;">dialogOwner</span>, <span style="color:#8080c0;">ref</span> <span style="color:#8080c0;">string</span> <span style="color:#fef1a9;">newContent</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">newContent</span> = <span style="color:#c7c7f1;">Clipboard</span>.<span style="color:#fef1a9;">GetText</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#c7c7f1;">DialogResult</span>.<span style="color:#fef1a9;">OK</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">}</pre>
</div>
<p>The code should look reasonable on RSS feeds too.</p>
<p>Hopefully WordPress will get the missing pictures problem&nbsp;sorted very soon.&nbsp; The lack&nbsp;of pictures makes&nbsp;everything look very bland.&nbsp;</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/84/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/84/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=84&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/04/01/pasting-code-into-blog-entries-using-windows-live-writer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image027.png" medium="image" />

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image083.png" medium="image" />

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterpastingcodeintoblogentriesusingwindowsli-9942image0103.png" medium="image" />
	</item>
		<item>
		<title>AggregateCollection</title>
		<link>http://karlhulme.wordpress.com/2007/03/31/aggregatecollection/</link>
		<comments>http://karlhulme.wordpress.com/2007/03/31/aggregatecollection/#comments</comments>
		<pubDate>Sat, 31 Mar 2007 20:14:16 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/03/31/aggregatecollection/</guid>
		<description><![CDATA[My apparent obsession with collection classes continues, and hopefully reaches it&#8217;s conclusion, with the AggregateCollection class.&#160; Simply put, it allows you to access multiple collections from a single collection object.&#160; A basic usage would be something like&#8230; &#160; &#160; &#160; &#160; private void TestAggregate() &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=71&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My apparent obsession with collection classes continues, and hopefully reaches it&#8217;s conclusion, with the AggregateCollection class.&nbsp; Simply put, it allows you to access multiple collections from a single collection object.&nbsp; A basic usage would be something like&#8230;</p>
<p><div style="font-size:10pt;background:#181818;overflow:scroll;width:450px;color:#e0e0e0;max-height:350px;font-family:consolas;white-space:nowrap;padding:5px;">
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#8080c0;">void</span> <span style="color:#fef1a9;">TestAggregate</span>()</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">List</span>&lt;<span style="color:#c7c7f1;">Int32</span>&gt; <span style="color:#fef1a9;">listOne</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">List</span>&lt;<span style="color:#c7c7f1;">Int32</span>&gt;();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">List</span>&lt;<span style="color:#c7c7f1;">String</span>&gt; <span style="color:#fef1a9;">listTwo</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">List</span>&lt;<span style="color:#c7c7f1;">String</span>&gt;();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">for</span> (<span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">i</span> = 0; <span style="color:#fef1a9;">i</span> &lt; 10; <span style="color:#fef1a9;">i</span> += 2)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">listOne</span>.<span style="color:#fef1a9;">Add</span>(<span style="color:#fef1a9;">i</span> + 1);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">listTwo</span>.<span style="color:#fef1a9;">Add</span>(<span style="color:#fef1a9;">i</span>.<span style="color:#fef1a9;">ToString</span>());</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">AggregateCollection</span> <span style="color:#fef1a9;">agg</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">AggregateCollection</span>(<span style="color:#fef1a9;">listOne</span>, <span style="color:#fef1a9;">listTwo</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">foreach</span> (<span style="color:#c7c7f1;">Object</span> <span style="color:#fef1a9;">o</span> <span style="color:#8080c0;">in</span> <span style="color:#fef1a9;">agg</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">Console</span>.<span style="color:#fef1a9;">WriteLine</span>(<span style="color:#fef1a9;">o</span>.<span style="color:#fef1a9;">ToString</span>());</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
</div>
<p>And the output is as you might expect&#8230;<br /><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriteraggregatecollection-12a99image013.png"><img style="border-width:0;" height="240" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriteraggregatecollection-12a99image04.png?w=229&#038;h=240" width="229" border="0"></a> </p>
<p>The lists passed to the constructor need only support IEnumerable, but if they also support INotifyCollectionChanged then you&#8217;ll get a better WPF binding experience.&nbsp; I wrote this class for WPF in the first place, because I want to be able to pull information together from different lists into the UI and I don&#8217;t want&nbsp;to be monitoring for the change events myself.</p>
<p>The AggregateCollection class itself supports the IEnumerable interface of course, and it also implements IList (which thus brings ICollection into the fray).&nbsp; The fact that it implements IList, means that even if the constituent lists don&#8217;t support IList, you can still access all the objects in the aggregate collection via a single index (from 0 to &#8220;count of all the lists&#8221;).&nbsp; I think this is quite cool, but it serves a greater purpose&#8230;</p>
<p>When you bind to a collection class in WPF, a CollectionView (or derivative) is created as a wrapper around your collection, and WPF will bind to that instead.&nbsp; This allows items to be sorted, grouped, etc, without affecting the underlying data.&nbsp; <a href="http://www.beacosta.com/">Bea Costa</a> (data binding supremo) explains this very well (post November 22nd &#8217;06).&nbsp; The AggregateCollection class supports IList, so that at binding-time WPF will instantiate a ListCollectionView, instead of a CollectionView&nbsp;- which is necessary to support sorting.</p>
<p>The example app below demonstrates the AggregateCollection class in action in WPF, and shows how, with sorting, this can be helpful.&nbsp; The first and second columns show the contents of two seperate ObservableCollections.&nbsp; There&#8217;s also some buttons for adding and removing objects from those collections, and for moving those items around.&nbsp; The ListBox in the third column is bound to an AggregateCollection containing the first 2 lists.&nbsp; The ListBox in the fourth column is bound to a sorted CollectionViewSource which references the same AggregateCollection.&nbsp; As the items in the first two collections change the ListBoxes in columns 3 and 4 will update automatically.</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriteraggregatecollection-12a99image053.png"></a><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriteraggregatecollection-12a99image053.png"><img style="border-width:0;" height="250" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriteraggregatecollection-12a99image0-thumb12.png?w=410&#038;h=250" width="410" border="0"></a></p>
<p><a title="http://www.quarrie.net/kh/AggCollectionTest.exe" href="http://www.quarrie.net/kh/AggCollectionTest.exe">Example application exe</a>&nbsp; (save to your local machine first, then run)<br /><a title="http://www.quarrie.net/kh/AggCollectionTest.zip" href="http://www.quarrie.net/kh/AggCollectionTest.zip">Example application solution</a></p>
<p>The AggregateCollection class can&#8217;t be synchronised, because I only intended for it to be used in the UI layer, but I guess there would be a way to make this work.&nbsp; I also made it read-only because I couldn&#8217;t determine a satisfactory strategy for which constituent list a new item should be added to.&nbsp; Finally, you can&#8217;t add or remove constituent lists after it&#8217;s been created, but there&#8217;s no fundamental obstacle to implementing this.&nbsp; The code for the AggregateCollection class is below.</p>
<div style="font-size:10pt;background:#181818;overflow:scroll;width:450px;color:#e0e0e0;max-height:350px;font-family:consolas;white-space:nowrap;padding:5px;">
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Collections</span>.<span style="color:#fef1a9;">Generic</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Text</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Collections</span>.<span style="color:#fef1a9;">Specialized</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">ComponentModel</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Windows</span>.<span style="color:#fef1a9;">Threading</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Collections</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">using</span> <span style="color:#fef1a9;">System</span>.<span style="color:#fef1a9;">Collections</span>.<span style="color:#fef1a9;">ObjectModel</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080c0;">namespace</span> <span style="color:#fef1a9;">AggCollectionTest</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">{</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">class</span> <span style="color:#c7c7f1;">AggregateCollection</span> : <span style="color:#c7c7f1;">IEnumerable</span>, <span style="color:#c7c7f1;">IList</span>, <span style="color:#c7c7f1;">INotifyCollectionChanged</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#c7c7f1;">IEnumerable</span>[] <span style="color:#fef1a9;">lists</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#c7c7f1;">List</span>&lt;<span style="color:#c7c7f1;">Object</span>&gt; <span style="color:#fef1a9;">cache</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">List</span>&lt;<span style="color:#c7c7f1;">Object</span>&gt;();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#c7c7f1;">Boolean</span> <span style="color:#fef1a9;">cacheValid</span> = <span style="color:#8080c0;">false</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#c7c7f1;">Object</span> <span style="color:#fef1a9;">syncRoot</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">Object</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#fef1a9;">AggregateCollection</span>(<span style="color:#8080c0;">params</span> <span style="color:#c7c7f1;">IEnumerable</span>[] <span style="color:#fef1a9;">lists</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (<span style="color:#fef1a9;">lists</span> == <span style="color:#8080c0;">null</span>) <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">ArgumentNullException</span>(<span style="color:#60ff60;">"lists"</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">this</span>.<span style="color:#fef1a9;">lists</span> = <span style="color:#fef1a9;">lists</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">foreach</span> (<span style="color:#c7c7f1;">IEnumerable</span> <span style="color:#fef1a9;">list</span> <span style="color:#8080c0;">in</span> <span style="color:#fef1a9;">lists</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (<span style="color:#fef1a9;">list</span> <span style="color:#8080c0;">is</span> <span style="color:#c7c7f1;">INotifyCollectionChanged</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((<span style="color:#c7c7f1;">INotifyCollectionChanged</span>)<span style="color:#fef1a9;">list</span>).<span style="color:#fef1a9;">CollectionChanged</span> +=</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">delegate</span>(<span style="color:#c7c7f1;">Object</span> <span style="color:#fef1a9;">sender</span>, <span style="color:#c7c7f1;">NotifyCollectionChangedEventArgs</span> <span style="color:#fef1a9;">e</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">cacheValid</span> = <span style="color:#8080c0;">false</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">NotifyCollectionChangedEventArgs</span> <span style="color:#fef1a9;">eventArgs</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">switch</span> (<span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">Action</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">case</span> <span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Add</span>:</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">eventArgs</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotifyCollectionChangedEventArgs</span>(<span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Add</span>,</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">NewItems</span>, <span style="color:#fef1a9;">DetermineIndexInAggregateCollection</span>(<span style="color:#fef1a9;">sender</span> <span style="color:#8080c0;">as</span> <span style="color:#c7c7f1;">IEnumerable</span>, <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">NewStartingIndex</span>));</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">break</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">case</span> <span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Move</span>:</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">eventArgs</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotifyCollectionChangedEventArgs</span>(<span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Move</span>,</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">NewItems</span>, <span style="color:#fef1a9;">DetermineIndexInAggregateCollection</span>(<span style="color:#fef1a9;">sender</span> <span style="color:#8080c0;">as</span> <span style="color:#c7c7f1;">IEnumerable</span>, <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">NewStartingIndex</span>),</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">DetermineIndexInAggregateCollection</span>(<span style="color:#fef1a9;">sender</span> <span style="color:#8080c0;">as</span> <span style="color:#c7c7f1;">IEnumerable</span>, <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">OldStartingIndex</span>));</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">break</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">case</span> <span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Remove</span>:</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">eventArgs</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotifyCollectionChangedEventArgs</span>(<span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Remove</span>,</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">OldItems</span>, <span style="color:#fef1a9;">DetermineIndexInAggregateCollection</span>(<span style="color:#fef1a9;">sender</span> <span style="color:#8080c0;">as</span> <span style="color:#c7c7f1;">IEnumerable</span>, <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">OldStartingIndex</span>));</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">break</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">case</span> <span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Replace</span>:</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">eventArgs</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotifyCollectionChangedEventArgs</span>(<span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Replace</span>,</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">NewItems</span>, <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">OldItems</span>, <span style="color:#fef1a9;">DetermineIndexInAggregateCollection</span>(<span style="color:#fef1a9;">sender</span> <span style="color:#8080c0;">as</span> <span style="color:#c7c7f1;">IEnumerable</span>, <span style="color:#fef1a9;">e</span>.<span style="color:#fef1a9;">OldStartingIndex</span>));</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">break</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">default</span>:</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">case</span> <span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Reset</span>:</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">eventArgs</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotifyCollectionChangedEventArgs</span>(<span style="color:#c7c7f1;">NotifyCollectionChangedAction</span>.<span style="color:#fef1a9;">Reset</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">break</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">OnCollectionChanged</span>(<span style="color:#fef1a9;">eventArgs</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">DetermineIndexInAggregateCollection</span>(<span style="color:#c7c7f1;">IEnumerable</span> <span style="color:#fef1a9;">list</span>, <span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">index</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span>(<span style="color:#fef1a9;">list</span> == <span style="color:#8080c0;">null</span>) <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">ArgumentNullException</span>(<span style="color:#60ff60;">"list"</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (<span style="color:#fef1a9;">index</span> == -1) <span style="color:#8080c0;">return</span> -1;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">Int32</span> <span style="color:#fef1a9;">adjustedIndex</span> = -1;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">for</span> (<span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">i</span> = 0; <span style="color:#fef1a9;">i</span> &lt; <span style="color:#fef1a9;">lists</span>.<span style="color:#fef1a9;">Length</span>; <span style="color:#fef1a9;">i</span>++)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">IEnumerable</span> <span style="color:#fef1a9;">l</span> = <span style="color:#fef1a9;">lists</span>[<span style="color:#fef1a9;">i</span>];</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (<span style="color:#fef1a9;">l</span> == <span style="color:#fef1a9;">list</span>) { <span style="color:#8080c0;">break</span>; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">else</span> <span style="color:#fef1a9;">adjustedIndex</span>++;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">foreach</span> (<span style="color:#c7c7f1;">Object</span> <span style="color:#fef1a9;">o</span> <span style="color:#8080c0;">in</span> <span style="color:#fef1a9;">l</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">adjustedIndex</span>++;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#fef1a9;">list</span> == <span style="color:#fef1a9;">lists</span>[0] ? <span style="color:#fef1a9;">adjustedIndex</span> + <span style="color:#fef1a9;">index</span> + 1 :</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">adjustedIndex</span> + <span style="color:#fef1a9;">index</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080ff;">&nbsp; &nbsp; &nbsp; &nbsp; #region</span> IEnumerable Members</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#c7c7f1;">IEnumerator</span> <span style="color:#fef1a9;">GetEnumerator</span>()</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">Enumerator</span>(<span style="color:#fef1a9;">lists</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#8080c0;">class</span> <span style="color:#c7c7f1;">Enumerator</span> : <span style="color:#c7c7f1;">IEnumerator</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#c7c7f1;">Int32</span> <span style="color:#fef1a9;">listIndex</span> = -1;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">private</span> <span style="color:#c7c7f1;">IEnumerator</span>[] <span style="color:#fef1a9;">enumerators</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#fef1a9;">Enumerator</span>(<span style="color:#c7c7f1;">IEnumerable</span>[] <span style="color:#fef1a9;">lists</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">enumerators</span> = <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">IEnumerator</span>[<span style="color:#fef1a9;">lists</span>.<span style="color:#fef1a9;">Length</span>];</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">for</span> (<span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">i</span> = 0; <span style="color:#fef1a9;">i</span> &lt; <span style="color:#fef1a9;">lists</span>.<span style="color:#fef1a9;">Length</span>; <span style="color:#fef1a9;">i</span>++) </pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">enumerators</span>[<span style="color:#fef1a9;">i</span>] = <span style="color:#fef1a9;">lists</span>[<span style="color:#fef1a9;">i</span>].<span style="color:#fef1a9;">GetEnumerator</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">object</span> <span style="color:#fef1a9;">Current</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">get</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">try</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#fef1a9;">enumerators</span>[<span style="color:#fef1a9;">listIndex</span>].<span style="color:#fef1a9;">Current</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">catch</span> (<span style="color:#c7c7f1;">IndexOutOfRangeException</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">InvalidOperationException</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">bool</span> <span style="color:#fef1a9;">MoveNext</span>()</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (<span style="color:#fef1a9;">listIndex</span> &gt; -1 &amp;&amp; <span style="color:#fef1a9;">listIndex</span> &lt; <span style="color:#fef1a9;">enumerators</span>.<span style="color:#fef1a9;">Length</span> &amp;&amp; </pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">enumerators</span>[<span style="color:#fef1a9;">listIndex</span>].<span style="color:#fef1a9;">MoveNext</span>())</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#8080c0;">true</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">else</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">listIndex</span>++;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (<span style="color:#fef1a9;">listIndex</span> &lt; <span style="color:#fef1a9;">enumerators</span>.<span style="color:#fef1a9;">Length</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">try</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">enumerators</span>[<span style="color:#fef1a9;">listIndex</span>].<span style="color:#fef1a9;">Reset</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">catch</span> (<span style="color:#c7c7f1;">InvalidOperationException</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#8080c0;">false</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#fef1a9;">MoveNext</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">else</span> <span style="color:#8080c0;">return</span> <span style="color:#8080c0;">false</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">void</span> <span style="color:#fef1a9;">Reset</span>()</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">listIndex</span> = -1;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080ff;">&nbsp; &nbsp; &nbsp; &nbsp; #endregion</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080ff;">&nbsp; &nbsp; &nbsp; &nbsp; #region</span> INotifyCollectionChanged Members</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">protected</span> <span style="color:#8080c0;">virtual</span> <span style="color:#8080c0;">void</span> <span style="color:#fef1a9;">OnCollectionChanged</span>(<span style="color:#c7c7f1;">NotifyCollectionChangedEventArgs</span> <span style="color:#fef1a9;">e</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (<span style="color:#fef1a9;">e</span> == <span style="color:#8080c0;">null</span>) <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">ArgumentNullException</span>(<span style="color:#60ff60;">"e"</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (<span style="color:#fef1a9;">CollectionChanged</span> != <span style="color:#8080c0;">null</span>) </pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">CollectionChanged</span>(<span style="color:#8080c0;">this</span>, <span style="color:#fef1a9;">e</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">event</span> <span style="color:#c7c7f1;">NotifyCollectionChangedEventHandler</span> <span style="color:#fef1a9;">CollectionChanged</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080ff;">&nbsp; &nbsp; &nbsp; &nbsp; #endregion</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080ff;">&nbsp; &nbsp; &nbsp; &nbsp; #region</span> IList Members</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">Add</span>(<span style="color:#8080c0;">object</span> <span style="color:#fef1a9;">value</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotSupportedException</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">void</span> <span style="color:#fef1a9;">Clear</span>()</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotSupportedException</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">bool</span> <span style="color:#fef1a9;">Contains</span>(<span style="color:#8080c0;">object</span> <span style="color:#fef1a9;">value</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#fef1a9;">IndexOf</span>(<span style="color:#fef1a9;">value</span>) != -1;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">IndexOf</span>(<span style="color:#8080c0;">object</span> <span style="color:#fef1a9;">value</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">Int32</span> <span style="color:#fef1a9;">i</span> = -1;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">foreach</span> (<span style="color:#c7c7f1;">Object</span> <span style="color:#fef1a9;">o</span> <span style="color:#8080c0;">in</span> <span style="color:#8080c0;">this</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">i</span>++;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> ((<span style="color:#fef1a9;">value</span> == <span style="color:#8080c0;">null</span> &amp;&amp; <span style="color:#fef1a9;">o</span> == <span style="color:#8080c0;">null</span>) | (<span style="color:#fef1a9;">value</span> != <span style="color:#8080c0;">null</span> &amp;&amp; <span style="color:#fef1a9;">value</span>.<span style="color:#fef1a9;">Equals</span>(<span style="color:#fef1a9;">o</span>)))</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#fef1a9;">i</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> -1;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">void</span> <span style="color:#fef1a9;">Insert</span>(<span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">index</span>, <span style="color:#8080c0;">object</span> <span style="color:#fef1a9;">value</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotSupportedException</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">bool</span> <span style="color:#fef1a9;">IsFixedSize</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">get</span> { <span style="color:#8080c0;">return</span> <span style="color:#8080c0;">false</span>; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">bool</span> <span style="color:#fef1a9;">IsReadOnly</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">get</span> { <span style="color:#8080c0;">return</span> <span style="color:#8080c0;">true</span>; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">void</span> <span style="color:#fef1a9;">Remove</span>(<span style="color:#8080c0;">object</span> <span style="color:#fef1a9;">value</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotSupportedException</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">void</span> <span style="color:#fef1a9;">RemoveAt</span>(<span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">index</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotSupportedException</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">object</span> <span style="color:#8080c0;">this</span>[<span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">index</span>]</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">get</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">if</span> (!<span style="color:#fef1a9;">cacheValid</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">cache</span>.<span style="color:#fef1a9;">Clear</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">foreach</span> (<span style="color:#c7c7f1;">Object</span> <span style="color:#fef1a9;">o</span> <span style="color:#8080c0;">in</span> <span style="color:#8080c0;">this</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">cache</span>.<span style="color:#fef1a9;">Add</span>(<span style="color:#fef1a9;">o</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">cacheValid</span> = <span style="color:#8080c0;">true</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#fef1a9;">cache</span>[<span style="color:#fef1a9;">index</span>];</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">set</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">throw</span> <span style="color:#8080c0;">new</span> <span style="color:#c7c7f1;">NotSupportedException</span>();</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080ff;">&nbsp; &nbsp; &nbsp; &nbsp; #endregion</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080ff;">&nbsp; &nbsp; &nbsp; &nbsp; #region</span> ICollection Members</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">void</span> <span style="color:#fef1a9;">CopyTo</span>(<span style="color:#c7c7f1;">Array</span> <span style="color:#fef1a9;">array</span>, <span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">index</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">Int32</span> <span style="color:#fef1a9;">i</span> = -1;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">foreach</span> (<span style="color:#c7c7f1;">Object</span> <span style="color:#fef1a9;">o</span> <span style="color:#8080c0;">in</span> <span style="color:#8080c0;">this</span>)</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#fef1a9;">array</span>.<span style="color:#fef1a9;">SetValue</span>(<span style="color:#fef1a9;">o</span>, <span style="color:#fef1a9;">index</span> + ++<span style="color:#fef1a9;">i</span>);</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">int</span> <span style="color:#fef1a9;">Count</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">get</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#c7c7f1;">Int32</span> <span style="color:#fef1a9;">count</span> = 0;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">foreach</span> (<span style="color:#c7c7f1;">Object</span> <span style="color:#fef1a9;">o</span> <span style="color:#8080c0;">in</span> <span style="color:#8080c0;">this</span>) <span style="color:#fef1a9;">count</span>++;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">return</span> <span style="color:#fef1a9;">count</span>;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">bool</span> <span style="color:#fef1a9;">IsSynchronized</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">get</span> { <span style="color:#8080c0;">return</span> <span style="color:#8080c0;">false</span>; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">public</span> <span style="color:#8080c0;">object</span> <span style="color:#fef1a9;">SyncRoot</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; {</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#8080c0;">get</span> { <span style="color:#8080c0;">return</span> <span style="color:#fef1a9;">syncRoot</span>; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; &nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp;</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;"><span style="color:#8080ff;">&nbsp; &nbsp; &nbsp; &nbsp; #endregion</span></pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">&nbsp; &nbsp; }</pre>
<pre style="font-size:8pt;background:none transparent scroll repeat 0 0;margin:0;padding:0;">}</pre>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/71/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/71/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=71&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/03/31/aggregatecollection/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriteraggregatecollection-12a99image04.png" medium="image" />

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriteraggregatecollection-12a99image0-thumb12.png" medium="image" />
	</item>
		<item>
		<title>Using a ContentControl and DataTemplate to indicate new and/or modified data</title>
		<link>http://karlhulme.wordpress.com/2007/03/06/using-a-contentcontrol-and-datatemplate-to-indicate-new-andor-modified-data/</link>
		<comments>http://karlhulme.wordpress.com/2007/03/06/using-a-contentcontrol-and-datatemplate-to-indicate-new-andor-modified-data/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 23:31:49 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/03/06/using-a-contentcontrol-and-datatemplate-to-indicate-new-andor-modified-data/</guid>
		<description><![CDATA[I was familiar with using DataTemplate&#8217;s for multiple items, say for items in a ListBox, but what if you want to use a DataTemplate for a single item?&#160; Why would I want to do that?&#160; I can declare the UIElements I want, and bind the properties that I want.&#160; You don&#8217;t need a DataTemplate here!! [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=26&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was familiar with using DataTemplate&#8217;s for multiple items, say for items in a ListBox, but what if you want to use a DataTemplate for a single item?&nbsp; </p>
<blockquote><p><em>Why would I want to do that?&nbsp; I can declare the UIElements I want, and bind the properties that I want.&nbsp; You don&#8217;t need a DataTemplate here!!</em></p>
</blockquote>
<p>Well, not strictly true!&nbsp; If you want to be able to use properties of your&nbsp;business object&nbsp;within conditions that control the layout, then you&#8217;re going to need the services of DataTrigger&#8217;s. And although most UIElements have a Triggers property, DataTriggers are only supported on a DataTemplate.&nbsp; So this blog entry is an example of how to set that up&#8230;</p>
<p>&nbsp;</p>
<p>Think about Visual Studio tabs for a second.&nbsp; Whenever you change the content of a document, a small asterisk appears after the filename to indicate to you that it&#8217;s been changed, as illustrated below.</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image01.png"><img style="border-width:0;" height="49" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image0.png?w=240&#038;h=49" width="240" border="0"></a> </p>
<p>I wanted to do a similar thing in my application.&nbsp; I wanted to..</p>
<ul>
<li>Show an asterisk whenever the data has been changed since the last save, and
<li>Show if an item was&nbsp;new (that is has never been saved.</li>
</ul>
<p>For me, the second point is particularly important because my application deals with Customer entities, and until the customer is saved they don&#8217;t have the all-important customer number.</p>
<p>The first step is to add the required properties to the business object being bound to, and implement INotifyPropertyChanged so that we know when they&#8217;re changing.&nbsp; A heavily abridged/shell-like version of my Entity class is below.&nbsp; (Please note, the code below is only intended to highlight the need to define the properties and inplement INotifyPropertyChanged on the business object in use.)</p>
</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="font-size:7pt;overflow:scroll;width:430px;max-height:500px;font-family:'Courier New', monospace;">
<pre style="background-color:white;">
<div><span style="color:#0000ff;">using</span><span style="color:#000000;"> System;
</span><span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Collections.Generic;
</span><span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Text;
</span><span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Xml;
</span><span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Collections.ObjectModel;
</span><span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Collections.Specialized;
</span><span style="color:#0000ff;">using</span><span style="color:#000000;"> System.ComponentModel;

</span><span style="color:#0000ff;">namespace</span><span style="color:#000000;"> MyNamespace
{
    </span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span><span style="color:#008000;">
    </span><span style="color:#808080;">///</span><span style="color:#008000;"> Represents an entity loaded from the database.
    </span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span><span style="color:#808080;">
</span><span style="color:#000000;">    </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">class</span><span style="color:#000000;"> Entity: INotifyPropertyChanged
    {
        </span><span style="color:#0000ff;">#region</span><span style="color:#000000;"> properties</span><span style="color:#000000;">
        </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> Int32</span><span style="color:#000000;">?</span><span style="color:#000000;"> id;

        </span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span><span style="color:#008000;">
        </span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets the unique id of the entity.
        </span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span><span style="color:#808080;">
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> Int32</span><span style="color:#000000;">?</span><span style="color:#000000;"> Id
        {
            </span><span style="color:#0000ff;">get</span><span style="color:#000000;"> { </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> id; }
            </span><span style="color:#0000ff;">internal</span><span style="color:#000000;"> </span><span style="color:#0000ff;">set</span><span style="color:#000000;">
            {
                id </span><span style="color:#000000;">=</span><span style="color:#000000;"> value;
                OnPropertyChanged(</span><span style="color:#000000;">"</span><span style="color:#000000;">Id</span><span style="color:#000000;">"</span><span style="color:#000000;">);
                OnPropertyChanged(</span><span style="color:#000000;">"</span><span style="color:#000000;">IsNew</span><span style="color:#000000;">"</span><span style="color:#000000;">);
            }
        }

         </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> EntityDefinition definition;

        </span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span><span style="color:#008000;">
        </span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets the type of the entity.
        </span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span><span style="color:#808080;">
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> EntityDefinition Definition
        {
            </span><span style="color:#0000ff;">get</span><span style="color:#000000;"> { </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> definition; }
        }

        </span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span><span style="color:#008000;">
        </span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets a value that indicates if the entity has been modified
        </span><span style="color:#808080;">///</span><span style="color:#008000;"> since it was loaded.
        </span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span><span style="color:#808080;">
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> Boolean IsModified
        {
            </span><span style="color:#0000ff;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> changeHistory.Count </span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">;
            }
        }

        </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> EntityDataFieldChangeCollection changeHistory </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> EntityDataFieldChangeCollection();

        </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> EntityDataFieldChangeCollection ChangeHistory
        {
            </span><span style="color:#0000ff;">get</span><span style="color:#000000;"> { </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> changeHistory; }
        }
        </span><span style="color:#0000ff;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000ff;">#region</span><span style="color:#000000;"> INotifyPropertyChanged</span><span style="color:#000000;">
        </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">event</span><span style="color:#000000;"> PropertyChangedEventHandler PropertyChanged;

        </span><span style="color:#0000ff;">protected</span><span style="color:#000000;"> </span><span style="color:#0000ff;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> OnPropertyChanged(String propertyName)
        {
            </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (PropertyChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">null</span><span style="color:#000000;">)
            {
                PropertyChanged(</span><span style="color:#0000ff;">this</span><span style="color:#000000;">, </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> PropertyChangedEventArgs(propertyName));
            }
        }
        </span><span style="color:#0000ff;">#endregion</span><span style="color:#000000;">

     }
}
</span></div>
</pre>
</div>
</div>
<p>Then in XAML, define a <strong>ContentControl </strong>and set the Content of that control to be an instance of your business object.&nbsp; Clearly the ContentControl doesn&#8217;t know how to render said business object, so I&#8217;ve provided a DataTemplate.&nbsp; This DataTemplate uses a horizontal StackPanel to lay out a series of TextBlock elements.&nbsp; I then use the Triggers to turn the visibility on and off, dependent upon the IsNew and IsModified properties.&nbsp; </p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="font-size:7pt;overflow:scroll;width:430px;max-height:500px;font-family:'Courier New', monospace;">
<pre style="background-color:white;">
<div><span style="color:#000000;">    </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ContentControl </span><span style="color:#ff0000;">Grid.Row</span><span style="color:#0000ff;">="0"</span><span style="color:#ff0000;"> Content</span><span style="color:#0000ff;">="{Binding Source={StaticResource entity}}"</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ContentControl</span><span style="color:#ff0000;">.ContentTemplate</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">StackPanel </span><span style="color:#ff0000;">Orientation</span><span style="color:#0000ff;">="Horizontal"</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">="newBlock"</span><span style="color:#ff0000;"> Text</span><span style="color:#0000ff;">="New "</span><span style="color:#ff0000;"> Visibility</span><span style="color:#0000ff;">="Visible"</span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">="nameBlock"</span><span style="color:#ff0000;"> Text</span><span style="color:#0000ff;">="{Binding Path=Definition.Name}"</span><span style="color:#ff0000;"> Visibility</span><span style="color:#0000ff;">="Visible"</span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">="spacer"</span><span style="color:#ff0000;"> Text</span><span style="color:#0000ff;">=" "</span><span style="color:#ff0000;"> Visibility</span><span style="color:#0000ff;">="Collapsed"</span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">="idBlock"</span><span style="color:#ff0000;"> Text</span><span style="color:#0000ff;">="{Binding Path=Id}"</span><span style="color:#ff0000;"> Visibility</span><span style="color:#0000ff;">="Collapsed"</span><span style="color:#ff0000;"> </span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">="modifiedBlock"</span><span style="color:#ff0000;"> Text</span><span style="color:#0000ff;">="*"</span><span style="color:#ff0000;"> Visibility</span><span style="color:#0000ff;">="Collapsed"</span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">StackPanel</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">DataTemplate</span><span style="color:#ff0000;">.Triggers</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">DataTrigger </span><span style="color:#ff0000;">Binding</span><span style="color:#0000ff;">="{Binding Path=IsNew}"</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">="False"</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">DataTrigger</span><span style="color:#ff0000;">.Setters</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Setter </span><span style="color:#ff0000;">TargetName</span><span style="color:#0000ff;">="newBlock"</span><span style="color:#ff0000;"> Property</span><span style="color:#0000ff;">="UIElement.Visibility"</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">="Collapsed"</span><span style="color:#ff0000;"> </span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Setter </span><span style="color:#ff0000;">TargetName</span><span style="color:#0000ff;">="idBlock"</span><span style="color:#ff0000;"> Property</span><span style="color:#0000ff;">="UIElement.Visibility"</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">="Visible"</span><span style="color:#ff0000;"> </span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Setter </span><span style="color:#ff0000;">TargetName</span><span style="color:#0000ff;">="spacer"</span><span style="color:#ff0000;"> Property</span><span style="color:#0000ff;">="UIElement.Visibility"</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">="Visible"</span><span style="color:#ff0000;"> </span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">DataTrigger.Setters</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">DataTrigger</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">DataTrigger </span><span style="color:#ff0000;">Binding</span><span style="color:#0000ff;">="{Binding Path=IsModified}"</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">="True"</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">DataTrigger</span><span style="color:#ff0000;">.Setters</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Setter </span><span style="color:#ff0000;">TargetName</span><span style="color:#0000ff;">="modifiedBlock"</span><span style="color:#ff0000;"> Property</span><span style="color:#0000ff;">="UIElement.Visibility"</span><span style="color:#ff0000;"> Value</span><span style="color:#0000ff;">="Visible"</span><span style="color:#ff0000;"> </span><span style="color:#0000ff;">/&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">DataTrigger.Setters</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">DataTrigger</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">DataTemplate.Triggers</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">ContentControl.ContentTemplate</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
    </span><span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">ContentControl</span><span style="color:#0000ff;">&gt;</span></div>
</pre>
</div>
</div>
<p>So the tab headers throughout the life of one of my Customer entities would start out as follows&#8230;</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image031.png"><img style="border-width:0;" height="73" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image021.png?w=240&#038;h=73" width="240" border="0"></a> </p>
<p>Then, I would expect something to be changed&#8230;</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image051.png"><img style="border-width:0;" height="61" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image041.png?w=240&#038;h=61" width="240" border="0"></a> </p>
<p>Once the first set of changes can be made, it should be saved.&nbsp; This will result in an Id being returned from the database&#8230;</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image071.png"><img style="border-width:0;" height="66" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image061.png?w=240&#038;h=66" width="240" border="0"></a> </p>
<p>Obviously the data could be modified again at this point&#8230;</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image091.png"><img style="border-width:0;" height="60" src="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image081.png?w=240&#038;h=60" width="240" border="0"></a> </p>
<p>I originally implemented this feature using IValueConverters (and the like) but I believe the XAML solution is much nicer.&nbsp; </p>
<p>So if you need to display information related to a business object <strong>and </strong>you have some conditions associated with the display, then you could try using a data-templated content control.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=26&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/03/06/using-a-contentcontrol-and-datatemplate-to-indicate-new-andor-modified-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image0.png" medium="image" />

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image021.png" medium="image" />

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image041.png" medium="image" />

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image061.png" medium="image" />

		<media:content url="http://karlhulme.files.wordpress.com/2007/04/windowslivewriterusingacontentcontrolanddatatemplatetoind-14ad9image081.png" medium="image" />
	</item>
		<item>
		<title>SynchronizedObservableCollection and BindableCollection</title>
		<link>http://karlhulme.wordpress.com/2007/03/04/synchronizedobservablecollection-and-bindablecollection/</link>
		<comments>http://karlhulme.wordpress.com/2007/03/04/synchronizedobservablecollection-and-bindablecollection/#comments</comments>
		<pubDate>Sun, 04 Mar 2007 23:19:19 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/03/04/synchronizedobservablecollection-and-bindablecollection/</guid>
		<description><![CDATA[Yesterday I posted some code that marshals the events raised by an ObservableCollection onto the same thread as is running the UI layer.&#160; I called it a SynchronizedObservableCollection but said at the end of the post that I was unhappy with the name.&#160; Well, while continuing to work on my project I&#8217;ve found need for&#160;a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=15&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yesterday I posted some code that marshals the events raised by an ObservableCollection onto the same thread as is running the UI layer.&nbsp; I called it a SynchronizedObservableCollection but said at the end of the post that I was unhappy with the name.&nbsp; Well, while continuing to work on my project I&#8217;ve found need for&nbsp;a genuinely synchronized version of the ObservableCollection class. I also need a ReadOnly version &#8211; predominately as a base class so that I can add the methods I want for altering the collection, rather than the standard Add/Remove.&nbsp; On top of these two, I still need to be able to bind them both to controls in WPF and not worry about which thread is causing the collections to change.</p>
<p>Therefore, the classes I need are:</p>
<ul>
<li>SynchronizedObservableCollection</li>
<li>ReadOnlySynchronizedObservableCollection</li>
<li>BindableCollection</li>
</ul>
<p>The <strong>SynchronizedObservableCollection</strong> is a collection that will accept updates and changes from lot&#8217;s of different threads without complaining.&nbsp; It&#8217;s implemented the same way as the SynchronizedCollection class provided in the framework, e.g. you can provide your own syncRoot or one will be created.&nbsp; You can also provide an existing list if you wish, <em>but this is not a wrapper class</em>, so if you do pass a list&nbsp;to the constructor&nbsp;it will be copied and any changes made to one list will not be reflected in the other.</p>
<p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre style="background-color:White;">
<div><span style="color:#000000;">    [ComVisible(</span><span style="color:#0000FF;">false</span><span style="color:#000000;">)]
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> SynchronizedObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> : IList</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">, ICollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">, IEnumerable</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">,
        IList, ICollection, IEnumerable, INotifyPropertyChanged, INotifyCollectionChanged
    {
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> items;
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Object sync;

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> Constructors</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> SynchronizedObservableCollection(Object syncRoot, IEnumerable</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> list)
        {
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync </span><span style="color:#000000;">=</span><span style="color:#000000;"> (syncRoot </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#000000;">?</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> Object() : syncRoot;
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items </span><span style="color:#000000;">=</span><span style="color:#000000;"> (list </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#000000;">?</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">() :
                </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">(</span><span style="color:#0000FF;">new</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">(list));

            items.CollectionChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;">(Object sender, NotifyCollectionChangedEventArgs e)
            {
                OnCollectionChanged(e);
            };
            INotifyPropertyChanged propertyChangedInterface </span><span style="color:#000000;">=</span><span style="color:#000000;"> items </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyPropertyChanged;
            propertyChangedInterface.PropertyChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;">(Object sender, PropertyChangedEventArgs e)
            {
                OnPropertyChanged(e);
            };
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> SynchronizedObservableCollection(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> syncRoot) : </span><span style="color:#0000FF;">this</span><span style="color:#000000;">(syncRoot, </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) { }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> SynchronizedObservableCollection(): </span><span style="color:#0000FF;">this</span><span style="color:#000000;">(</span><span style="color:#0000FF;">null</span><span style="color:#000000;">, </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) { }
        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> Methods</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Add(T item)
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Count;
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.InsertItem(index, item);
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Clear()
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.ClearItems();
            }
        }

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> ClearItems()
        {
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Clear();
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> Contains(T item)
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Contains(item);
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> CopyTo(T[] array, </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index)
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.CopyTo(array, index);
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> IEnumerator</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> GetEnumerator()
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.GetEnumerator();
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> IndexOf(T item)
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.InternalIndexOf(item);
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Insert(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index, T item)
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> ((index </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">) </span><span style="color:#000000;">||</span><span style="color:#000000;"> (index </span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Count))
                {
                    </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ArgumentOutOfRangeException(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">index</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, index, </span><span style="color:#000000;">&quot;</span><span style="color:#000000;">Value must be in range.</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
                }
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.InsertItem(index, item);
            }
        }

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> InsertItem(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index, T item)
        {
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Insert(index, item);
        }

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> InternalIndexOf(T item)
        {
            </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> count </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Count;
            </span><span style="color:#0000FF;">for</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> i </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">; i </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> count; i</span><span style="color:#000000;">++</span><span style="color:#000000;">)
            {
                </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">object</span><span style="color:#000000;">.Equals(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items[i], item))
                {
                    </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> i;
                }
            }
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#000000;">-</span><span style="color:#000000;">1</span><span style="color:#000000;">;
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> Remove(T item)
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.InternalIndexOf(item);
                </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (index </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">)
                {
                    </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;
                }
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.RemoveItem(index);
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">;
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RemoveAt(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index)
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> ((index </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">) </span><span style="color:#000000;">||</span><span style="color:#000000;"> (index </span><span style="color:#000000;">&gt;=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Count))
                {
                    </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ArgumentOutOfRangeException(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">index</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, index,
                        </span><span style="color:#000000;">&quot;</span><span style="color:#000000;">Value must be in range.</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
                }
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.RemoveItem(index);
            }
        }

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RemoveItem(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index)
        {
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.RemoveAt(index);
        }

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> SetItem(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index, T item)
        {
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items[index] </span><span style="color:#000000;">=</span><span style="color:#000000;"> item;
        }

        </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> ICollection.CopyTo(Array array, </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index)
        {
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">for</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> i </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">; i </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> items.Count; i</span><span style="color:#000000;">++</span><span style="color:#000000;">)
                {
                    array.SetValue(items[i], index </span><span style="color:#000000;">+</span><span style="color:#000000;"> i);
                }
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.GetEnumerator();
        }

        </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> IList.Add(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            VerifyValueType(value);
            </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
            {
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.Add((T)value);
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.Count </span><span style="color:#000000;">-</span><span style="color:#000000;"> </span><span style="color:#000000;">1</span><span style="color:#000000;">);
            }
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IList.Contains(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            VerifyValueType(value);
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.Contains((T)value);
        }

        </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> IList.IndexOf(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            VerifyValueType(value);
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.IndexOf((T)value);
        }

        </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> IList.Insert(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index, </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            VerifyValueType(value);
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.Insert(index, (T)value);
        }

        </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> IList.Remove(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            VerifyValueType(value);
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.Remove((T)value);
        }

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> VerifyValueType(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (value </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(T).IsValueType)
                {
                    </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ArgumentException(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">Synchronized collection wrong type null.</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
                }
            }
            </span><span style="color:#0000FF;">else</span><span style="color:#000000;"> </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (</span><span style="color:#000000;">!</span><span style="color:#000000;">(value </span><span style="color:#0000FF;">is</span><span style="color:#000000;"> T))
            {
                </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ArgumentException(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">Synchronized collection wrong type.</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
            }
        }
        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> Properties</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> Count
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
                {
                    </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Count;
                }
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> T </span><span style="color:#0000FF;">this</span><span style="color:#000000;">[</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index]
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
                {
                    </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items[index];
                }
            }
            </span><span style="color:#0000FF;">set</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">lock</span><span style="color:#000000;"> (</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync)
                {
                    </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> ((index </span><span style="color:#000000;">&lt;</span><span style="color:#000000;"> </span><span style="color:#000000;">0</span><span style="color:#000000;">) </span><span style="color:#000000;">||</span><span style="color:#000000;"> (index </span><span style="color:#000000;">&gt;=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items.Count))
                    {
                        </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ArgumentOutOfRangeException(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">index</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, index,
                            </span><span style="color:#000000;">&quot;</span><span style="color:#000000;">Value must be in range.</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
                    }
                    </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.SetItem(index, value);
                }
            }
        }

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> Items
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.items;
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> SyncRoot
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync;
            }
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> ICollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">.IsReadOnly
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;
            }
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> ICollection.IsSynchronized
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">true</span><span style="color:#000000;">;
            }
        }

        </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> ICollection.SyncRoot
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.sync;
            }
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IList.IsFixedSize
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;
            }
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IList.IsReadOnly
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">false</span><span style="color:#000000;">;
            }
        }

        </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> IList.</span><span style="color:#0000FF;">this</span><span style="color:#000000;">[</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index]
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">this</span><span style="color:#000000;">[index];
            }
            </span><span style="color:#0000FF;">set</span><span style="color:#000000;">
            {
                VerifyValueType(value);
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">[index] </span><span style="color:#000000;">=</span><span style="color:#000000;"> (T)value;
            }
        }
        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> INotifyPropertyChanged Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> PropertyChangedEventHandler PropertyChanged;

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> OnPropertyChanged(PropertyChangedEventArgs e)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (PropertyChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) PropertyChanged(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">, e);
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> INotifyCollectionChanged Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> NotifyCollectionChangedEventHandler CollectionChanged;

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (CollectionChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) CollectionChanged(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">, e);
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">
    }</span></div>
</pre>
</div>
</div>
<p>The <strong>ReadOnlySynchronizedObservableCollection</strong> is a wrapper class that expects a SynchronizedObservableCollection as the only constructor parameter.&nbsp; Because it&#8217;s a wrapper class, you could maintain&nbsp;a SynchronizedObservableCollection in one layer of your app, and just expose a ReadOnlySynchronizedObservableCollection to&nbsp; the other layers.&nbsp; Similarly, as&nbsp;a read only class you wouldn&#8217;t expect change events, hence the INotifyPropertyChanged and INotifyCollectionChanged interfaces are implemented explicitly (again following the pattern of the ReadOnlyObservableCollection).&nbsp; Don&#8217;t forget you can always consume the events&nbsp;by casting&nbsp;the object to the interfaces of course, and for this reason, it doesn&#8217;t affect WPF binding.&nbsp;</p>
<p><div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre style="background-color:White;">
<div><span style="color:#000000;">    [ComVisible(</span><span style="color:#0000FF;">false</span><span style="color:#000000;">)]
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> ReadOnlySynchronizedObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> : ReadOnlyCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">,
        INotifyPropertyChanged, INotifyCollectionChanged
    {
        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> Constructor</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> ReadOnlySynchronizedObservableCollection(SynchronizedObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> list): </span><span style="color:#0000FF;">base</span><span style="color:#000000;">(list)
        {
            list.PropertyChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;">(Object sender, PropertyChangedEventArgs e)
            {
                OnPropertyChanged(e);
            };
            list.CollectionChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;">(Object sender, NotifyCollectionChangedEventArgs e)
            {
                OnCollectionChanged(e);
            };
        }
        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> Event Handling</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> NotifyCollectionChangedEventHandler collectionChanged;
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> PropertyChangedEventHandler propertyChanged;

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> NotifyCollectionChangedEventHandler CollectionChanged
        {
            add { collectionChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> value; }
            remove { collectionChanged </span><span style="color:#000000;">-=</span><span style="color:#000000;"> value; }
        }

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> PropertyChangedEventHandler PropertyChanged
        {
            add { propertyChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> value; }
            remove { propertyChanged </span><span style="color:#000000;">-=</span><span style="color:#000000;"> value; }
        }

        </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
        {
            add { collectionChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> value; }
            remove { collectionChanged </span><span style="color:#000000;">-=</span><span style="color:#000000;"> value; }
        }

        </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
        {
            add { propertyChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> value; }
            remove { propertyChanged </span><span style="color:#000000;">-=</span><span style="color:#000000;"> value; }
        }

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> OnPropertyChanged(PropertyChangedEventArgs e)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (propertyChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                propertyChanged(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">, e);
            }
        }

        </span><span style="color:#0000FF;">protected</span><span style="color:#000000;"> </span><span style="color:#0000FF;">virtual</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (collectionChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                collectionChanged(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">, e);
            }
        }
        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">
    }</span></div>
</pre>
</div>
</div>
<p>Finally, the <strong>BindableCollection</strong> is the class I started building yesterday. This class can be bound to a WPF ItemsControl (or similar) and then be updated on any thread.&nbsp; Among some minor coding changes, I&#8217;ve added support for the non-generic interfaces (e.g. IList as well as IList&lt;T&gt;) and&nbsp;I&#8217;ve allowed the Dispatcher to be passed in.&nbsp; This is necessary if the BindableCollection is not created on the UI thread.&nbsp; I&#8217;ve also dropped the word &#8216;Observable&#8217; from the class name on the grounds that the class must be Observable if it is to be Bindable, making that bit superflous.&nbsp; The BindableCollection is a&nbsp;wrapper class and will accept anything that implements IList&lt;T&gt;, INotifyCollectionChanged and INotifyPropertyChanged.&nbsp; However, most commonly it will be fed an ObservableCollection, ReadOnlyObservableCollection, SynchronizedObservableCollection, ReadOnlySynchronizedObservableCollection or a class derived from one of these.</p>
<p><div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre style="background-color:White;">
<div><span style="color:#000000;">    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> BindableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">: ICollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">, IList</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">, IEnumerable</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">,
        ICollection, IList, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
    {
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> IList</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> list;
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Dispatcher dispatcher;

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> Constructor</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> BindableCollection(IList</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> list) : </span><span style="color:#0000FF;">this</span><span style="color:#000000;">(list, </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) { }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> BindableCollection(IList</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> list, Dispatcher dispatcher)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (list </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">||</span><span style="color:#000000;">
                list </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyCollectionChanged </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">||</span><span style="color:#000000;">
                list </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyPropertyChanged </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ArgumentNullException(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">The list must support IList, INotifyCollectionChanged </span><span style="color:#000000;">&quot;</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;">
                    </span><span style="color:#000000;">&quot;</span><span style="color:#000000;">and INotifyPropertyChanged.</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
            }

            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.list </span><span style="color:#000000;">=</span><span style="color:#000000;"> list;
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.dispatcher </span><span style="color:#000000;">=</span><span style="color:#000000;"> (dispatcher </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#000000;">?</span><span style="color:#000000;"> Dispatcher.CurrentDispatcher : dispatcher;

            INotifyCollectionChanged collectionChanged </span><span style="color:#000000;">=</span><span style="color:#000000;"> list </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyCollectionChanged;
            collectionChanged.CollectionChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;">(Object sender, NotifyCollectionChangedEventArgs e)
            {
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.dispatcher.Invoke(DispatcherPriority.Normal,
                    </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> RaiseCollectionChangedEventHandler(RaiseCollectionChangedEvent), e);
            };

            INotifyPropertyChanged propertyChanged </span><span style="color:#000000;">=</span><span style="color:#000000;"> list </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyPropertyChanged;
            propertyChanged.PropertyChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;">(Object sender, PropertyChangedEventArgs e)
            {
                </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.dispatcher.Invoke(DispatcherPriority.Normal,
                    </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> RaisePropertyChangedEventHandler(RaisePropertyChangedEvent), e);
            };
        }
        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> INotifyCollectionChanged Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> NotifyCollectionChangedEventHandler CollectionChanged;

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RaiseCollectionChangedEvent(NotifyCollectionChangedEventArgs e)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (CollectionChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                CollectionChanged(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">, e);
            }
        }

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RaiseCollectionChangedEventHandler(NotifyCollectionChangedEventArgs e);

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> INotifyPropertyChanged Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> PropertyChangedEventHandler PropertyChanged;

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RaisePropertyChangedEvent(PropertyChangedEventArgs e)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (PropertyChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                PropertyChanged(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">, e);
            }
        }

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RaisePropertyChangedEventHandler(PropertyChangedEventArgs e);

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> ICollection&lt;T&gt; Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Add(T item)
        {
            list.Add(item);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Clear()
        {
            list.Clear();
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> Contains(T item)
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> list.Contains(item);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> CopyTo(T[] array, </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> arrayIndex)
        {
            list.CopyTo(array, arrayIndex);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> Count
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> list.Count; }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IsReadOnly
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> list.IsReadOnly; }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> Remove(T item)
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> list.Remove(item);
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> IList&lt;T&gt; Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> IndexOf(T item)
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> list.IndexOf(item);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Insert(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index, T item)
        {
            list.Insert(index, item);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RemoveAt(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index)
        {
            list.RemoveAt(index);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> T </span><span style="color:#0000FF;">this</span><span style="color:#000000;">[</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index]
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> list[index];
            }
            </span><span style="color:#0000FF;">set</span><span style="color:#000000;">
            {
                list[index] </span><span style="color:#000000;">=</span><span style="color:#000000;"> value;
            }
        }
        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> IEnumerable&lt;T&gt; Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> IEnumerator</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> GetEnumerator()
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> list.GetEnumerator();
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> ICollection Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> ICollection.CopyTo(Array array, </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index)
        {
            ((ICollection)list).CopyTo(array, index);
        }

        </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> ICollection.Count
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((ICollection)list).Count; }
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> ICollection.IsSynchronized
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((ICollection)list).IsSynchronized; }
        }

        </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> ICollection.SyncRoot
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((ICollection)list).SyncRoot; }
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> IList Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> IList.Add(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((IList)list).Add(value);
        }

        </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> IList.Clear()
        {
            ((IList)list).Clear();
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IList.Contains(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((IList)list).Contains(value);
        }

        </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> IList.IndexOf(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((IList)list).IndexOf(value);
        }

        </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> IList.Insert(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index, </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            ((IList)list).Insert(index, value);
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IList.IsFixedSize
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((IList)list).IsFixedSize; }
        }

        </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IList.IsReadOnly
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((IList)list).IsReadOnly; }
        }

        </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> IList.Remove(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value)
        {
            ((IList)list).Remove(value);
        }

        </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> IList.RemoveAt(</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index)
        {
            ((IList)list).RemoveAt(index);
        }

        </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> IList.</span><span style="color:#0000FF;">this</span><span style="color:#000000;">[</span><span style="color:#0000FF;">int</span><span style="color:#000000;"> index]
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;">
            {
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((IList)list)[index];
            }
            </span><span style="color:#0000FF;">set</span><span style="color:#000000;">
            {
                ((IList)list)[index] </span><span style="color:#000000;">=</span><span style="color:#000000;"> value;
            }
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> IEnumerable Members</span><span style="color:#000000;">

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((System.Collections.IEnumerable)list).GetEnumerator();
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

    }</span></div>
</pre>
</div>
</div>
<p>If anyone can make use of the above classes then you&#8217;re very welcome to use them, although you do so at your&nbsp;own risk!&nbsp; </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=15&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/03/04/synchronizedobservablecollection-and-bindablecollection/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>
	</item>
		<item>
		<title>ObservableCollection events and WPF Window/UI on Different Threads</title>
		<link>http://karlhulme.wordpress.com/2007/03/03/observablecollection-events-and-wpf-windowui-on-different-threads/</link>
		<comments>http://karlhulme.wordpress.com/2007/03/03/observablecollection-events-and-wpf-windowui-on-different-threads/#comments</comments>
		<pubDate>Sat, 03 Mar 2007 23:45:25 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/03/03/observablecollection-events-and-wpf-windowui-on-different-threads/</guid>
		<description><![CDATA[Warning: There’s an improved version of the class outlined in a subsequent blog post. When binding ObservableCollection&#8217;s using WPF you&#8217;ll probably encounter the following error, &#8216;This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.&#8217; This is simply telling you that the CollectionChanged event was not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=14&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><font color="#ff0000">Warning: There’s an improved version of the class outlined in a </font><a href="http://karlhulme.wordpress.com/2007/03/04/synchronizedobservablecollection-and-bindablecollection/"><font color="#ff0000">subsequent blog post</font></a><font color="#ff0000">.</font></strong></p>
<p>When binding ObservableCollection&#8217;s using WPF you&#8217;ll probably encounter the following error, &#8216;<em>This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.&#8217;</em></p>
<p>This is simply telling you that the CollectionChanged event was not raised on the thread that the Window was created on.&nbsp; It&#8217;s an easy problem to fix,&nbsp;we just need to wrap the collection so that any events raised on the source collection will be raised on the same thread as the UI.&nbsp; My complete implementation is below which can be copy/pasted and the namespace renamed.</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre style="background-color:White;">
<div><span style="color:#0000FF;">using</span><span style="color:#000000;"> System;
</span><span style="color:#0000FF;">using</span><span style="color:#000000;"> System.Collections.Generic;
</span><span style="color:#0000FF;">using</span><span style="color:#000000;"> System.Text;
</span><span style="color:#0000FF;">using</span><span style="color:#000000;"> System.Collections.Specialized;
</span><span style="color:#0000FF;">using</span><span style="color:#000000;"> System.ComponentModel;
</span><span style="color:#0000FF;">using</span><span style="color:#000000;"> System.Windows.Threading;

</span><span style="color:#0000FF;">namespace</span><span style="color:#000000;"> MyNamespace
{
    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> SynchronisedObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">: ICollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">,
        INotifyCollectionChanged, INotifyPropertyChanged
    {
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> ICollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> collection;
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> Dispatcher dispatcher;

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> SynchronisedObservableCollection(ICollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> collection)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (collection </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">||</span><span style="color:#000000;">
                collection </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyCollectionChanged </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">||</span><span style="color:#000000;">
                collection </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyPropertyChanged </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ArgumentException(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">Collection must support ICollection, INotifyCollectionChanged </span><span style="color:#000000;">&quot;</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;">
                    </span><span style="color:#000000;">&quot;</span><span style="color:#000000;"> and INotifyPropertyChanged interfaces.</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
            }

            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.collection </span><span style="color:#000000;">=</span><span style="color:#000000;"> collection;
            </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.dispatcher </span><span style="color:#000000;">=</span><span style="color:#000000;"> Dispatcher.CurrentDispatcher;

            INotifyCollectionChanged collectionChanged </span><span style="color:#000000;">=</span><span style="color:#000000;"> collection </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyCollectionChanged;
            collectionChanged.CollectionChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;">(Object sender, NotifyCollectionChangedEventArgs e)
            {
                dispatcher.Invoke(DispatcherPriority.Normal,
                    </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> RaiseCollectionChangedEventHandler(RaiseCollectionChangedEvent), e);
            };

            INotifyPropertyChanged propertyChanged </span><span style="color:#000000;">=</span><span style="color:#000000;"> collection </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> INotifyPropertyChanged;
            propertyChanged.PropertyChanged </span><span style="color:#000000;">+=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;">(Object sender, PropertyChangedEventArgs e)
            {
                dispatcher.Invoke(DispatcherPriority.Normal,
                    </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> RaisePropertyChangedEventHandler(RaisePropertyChangedEvent), e);
            };
        }

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> INotifyCollectionChanged Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> NotifyCollectionChangedEventHandler CollectionChanged;

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RaiseCollectionChangedEvent(NotifyCollectionChangedEventArgs e)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (CollectionChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                CollectionChanged(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">, e);
            }
        }

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RaiseCollectionChangedEventHandler(NotifyCollectionChangedEventArgs e);

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> INotifyPropertyChanged Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">event</span><span style="color:#000000;"> PropertyChangedEventHandler PropertyChanged;

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RaisePropertyChangedEvent(PropertyChangedEventArgs e)
        {
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (PropertyChanged </span><span style="color:#000000;">!=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">)
            {
                PropertyChanged(</span><span style="color:#0000FF;">this</span><span style="color:#000000;">, e);
            }
        }

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">delegate</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> RaisePropertyChangedEventHandler(PropertyChangedEventArgs e);

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> ICollection&lt;T&gt; Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Add(T item)
        {
            collection.Add(item);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> Clear()
        {
            collection.Clear();
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> Contains(T item)
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> collection.Contains(item);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> CopyTo(T[] array, </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> arrayIndex)
        {
            collection.CopyTo(array, arrayIndex);
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">int</span><span style="color:#000000;"> Count
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> collection.Count; }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> IsReadOnly
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> collection.IsReadOnly; }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">bool</span><span style="color:#000000;"> Remove(T item)
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> collection.Remove(item);
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> IEnumerable&lt;T&gt; Members</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> IEnumerator</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">T</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> GetEnumerator()
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> collection.GetEnumerator();
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">

        </span><span style="color:#0000FF;">#region</span><span style="color:#000000;"> IEnumerable Members</span><span style="color:#000000;">

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> ((System.Collections.IEnumerable)collection).GetEnumerator();
        }

        </span><span style="color:#0000FF;">#endregion</span><span style="color:#000000;">
    }
}
</span></div>
</pre>
</div>
</div>
<p>The wrapper above accepts any ICollection&lt;T&gt; that also supports INotifyCollectionChanges and INotifyPropertyChanged.&nbsp; Best candidates for this are the ObservableCollection&lt;T&gt; and ReadOnlyObservableCollection&lt;T&gt; classes.&nbsp; You use the wrapper inbetween your business layer (the original collection) and the UI classes that will consume it.&nbsp; For me, this means it sits in class that provides central access to all Model data (thinking MVC/MVP)</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre style="background-color:White;">
<div><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> AppModel
{
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> SynchronisedObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">String</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> GetSyncCollection()
        {
            ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">String</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> innerCollection </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">String</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> SynchronisedObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">String</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">(innerCollection);
        }
}</span></div>
</pre>
</div>
</div>
<p>You can now bind to the collection using an ObjectDataProvider that calls the GetSyncCollection method.&nbsp; Note that my implementation doesn&#8217;t require you to pass in the Dispatcher of the UI thread.&nbsp; That&#8217;s because I assume that the UI thread will be the one creating the wrapper.&nbsp; Since this class forms part of the UI layer and not the business layer, then it&#8217;s a fair assumption, but if it doesn&#8217;t work for you then you can always pass a Dispatcher into the constructor.</p>
</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre style="background-color:White;">
<div><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Window </span><span style="color:#FF0000;">x:Class</span><span style="color:#0000FF;">=&quot;MyApplication.Host&quot;</span><span style="color:#FF0000;">
    xmlns</span><span style="color:#0000FF;">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span><span style="color:#FF0000;">
    xmlns:x</span><span style="color:#0000FF;">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span><span style="color:#FF0000;">
    xmlns:model</span><span style="color:#0000FF;">=&quot;clr-namespace:MyNamespace.Model;assembly=MyAssembly.Model&quot;</span><span style="color:#FF0000;">
    Width</span><span style="color:#0000FF;">=&quot;800&quot;</span><span style="color:#FF0000;"> Height</span><span style="color:#0000FF;">=&quot;600&quot;</span><span style="color:#FF0000;">
   </span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
  </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Window</span><span style="color:#FF0000;">.Resources</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
    </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ObjectDataProvider </span><span style="color:#FF0000;">x:Key</span><span style="color:#0000FF;">=&quot;myList&quot;</span><span style="color:#FF0000;">
                        ObjectType</span><span style="color:#0000FF;">=&quot;model:AppModel&quot;</span><span style="color:#FF0000;"> MethodName</span><span style="color:#0000FF;">=&quot;GetSyncCollection&quot;</span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
  </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Window.Resources</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
    </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ListBox </span><span style="color:#FF0000;">ItemsSource</span><span style="color:#0000FF;">=&quot;{Binding Source={StaticResource myList}}&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
  </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Window</span><span style="color:#0000FF;">&gt;</span></div>
</pre>
</div>
</div>
<p>Incidently, I&#8217;m not particularly happy with SynchronisedObservableCollection as the class name.&nbsp; It implies that the collection is thread-safe, and although in one way it is, it many others it isn&#8217;t!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=14&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/03/03/observablecollection-events-and-wpf-windowui-on-different-threads/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>
	</item>
		<item>
		<title>Masking input to a WPF TextBox</title>
		<link>http://karlhulme.wordpress.com/2007/02/15/masking-input-to-a-wpf-textbox/</link>
		<comments>http://karlhulme.wordpress.com/2007/02/15/masking-input-to-a-wpf-textbox/#comments</comments>
		<pubDate>Thu, 15 Feb 2007 10:09:27 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/02/15/masking-input-to-a-wpf-textbox/</guid>
		<description><![CDATA[How do you go about masking the input to a textbox.  Say you wanted to allow numbers but not letters or any punctuation, how would you do it?  Well the simplest way is to trap the TextChanged event&#8230; private void TextChangedEventHandler(Object sender, EventArgs e) { TextBox textBox = sender as TextBox; Int32 selectionStart = textBox.SelectionStart; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=13&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>How do you go about masking the input to a textbox.  Say you wanted to allow numbers but not letters or any punctuation, how would you do it?  Well the simplest way is to trap the TextChanged event&#8230;</p>
<p style="display:inline;float:none;margin:0;padding:0;" class="wlWriterSmartContent">
<p style="font-size:7pt;overflow:scroll;width:430px;max-height:500px;font-family:'Courier New', monospace;">
<pre><span style="color:#000000;">        </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> TextChangedEventHandler(Object sender, EventArgs e)
        {
            TextBox textBox </span><span style="color:#000000;">=</span><span style="color:#000000;"> sender </span><span style="color:#0000ff;">as</span><span style="color:#000000;"> TextBox;
            Int32 selectionStart </span><span style="color:#000000;">=</span><span style="color:#000000;"> textBox.SelectionStart;
            Int32 selectionLength </span><span style="color:#000000;">=</span><span style="color:#000000;"> textBox.SelectionLength; 

            String newText </span><span style="color:#000000;">=</span><span style="color:#000000;"> String.Empty;
            </span><span style="color:#0000ff;">foreach</span><span style="color:#000000;"> (Char c </span><span style="color:#0000ff;">in</span><span style="color:#000000;"> textBox.Text.ToCharArray())
            {
                </span><span style="color:#0000ff;">if</span><span style="color:#000000;">(Char.IsDigit(c) </span><span style="color:#000000;">||</span><span style="color:#000000;"> Char.IsControl(c)) newText </span><span style="color:#000000;">+=</span><span style="color:#000000;"> c;
            } 

            textBox.Text </span><span style="color:#000000;">=</span><span style="color:#000000;"> newText; 

            textBox.SelectionStart </span><span style="color:#000000;">=</span><span style="color:#000000;"> selectionStart </span><span style="color:#000000;">&lt;=</span><span style="color:#000000;"> textBox.Text.Length </span><span style="color:#000000;">?</span><span style="color:#000000;">
                selectionStart : textBox.Text.Length;
        }</span></pre>
<p>This method is simple to understand (always a positive) but there are a few problems with this as I see it, namely..</p>
<ul>
<li>An additional TextChanged event is raised when input is rejected</li>
<li>You can&#8217;t tell what the change was, you can only inspect the end result</li>
<li>You have to re-implement the code that determines the correct caret position</li>
</ul>
<p>This is not a great way to solve the original problem, because we&#8217;re basically hacking at the input after it&#8217;s already been accepted.  Leaving us trying to fix the text and compensate for the changes in caret position.  It&#8217;s easier to reject invalid characters as they&#8217;re presented.  Let&#8217;s start by defining a very simple method for stripping out the input we don&#8217;t want..  </p>
<p style="display:inline;float:none;margin:0;padding:0;" class="wlWriterSmartContent">
<p style="font-size:7pt;overflow:scroll;width:430px;max-height:500px;font-family:'Courier New', monospace;">
<pre><span style="color:#000000;">        </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> Boolean IsTextAllowed(String text)
        {
            </span><span style="color:#0000ff;">foreach</span><span style="color:#000000;"> (Char c </span><span style="color:#0000ff;">in</span><span style="color:#000000;"> text.ToCharArray())
            {
                </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (Char.IsDigit(c) </span><span style="color:#000000;">||</span><span style="color:#000000;"> Char.IsControl(c)) </span><span style="color:#0000ff;">continue</span><span style="color:#000000;">;
                    </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">false</span><span style="color:#000000;">;
            }
            </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">true</span><span style="color:#000000;">;
        }</span></pre>
<p>This could be defined slightly more elegantly using a predicate..</p>
<p style="display:inline;float:none;margin:0;padding:0;" class="wlWriterSmartContent">
<p style="font-size:7pt;overflow:scroll;width:430px;max-height:500px;font-family:'Courier New', monospace;">
<pre><span style="color:#000000;">        </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> Boolean IsTextAllowed(String text)
        {
            </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> Array.TrueForAll</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">Char</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">(text.ToCharArray(),
                </span><span style="color:#0000ff;">delegate</span><span style="color:#000000;">(Char c) { </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> Char.IsDigit(c) </span><span style="color:#000000;">||</span><span style="color:#000000;"> Char.IsControl(c); });
        }</span></pre>
<p>We then need to identify the entry points to the control and for each one, identify how we will be notified about it&#8217;s use.  For typical a TextBox these entry points might be:</p>
<ul>
<li>Typing into the TextBox
<ul>
<li>Hook up to the PreviewTextInput event</li>
</ul>
</li>
<li>Copy/Pasting into the TextBox
<ul>
<li>Hook up to the DataObject.Pasting event</li>
</ul>
</li>
</ul>
<p>It&#8217;s easy to implement and hook up the handlers for these events..</p>
<p style="display:inline;float:none;margin:0;padding:0;" class="wlWriterSmartContent">
<p style="font-size:7pt;overflow:scroll;width:430px;max-height:500px;font-family:'Courier New', monospace;">
<pre><span style="color:#000000;">      </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBox </span><span style="color:#ff0000;">PreviewTextInput</span><span style="color:#0000ff;">="PreviewTextInputHandler"</span><span style="color:#ff0000;">
               DataObject.Pasting</span><span style="color:#0000ff;">="PastingHandler"</span><span style="color:#ff0000;"> </span><span style="color:#0000ff;">/&gt;</span></pre>
<p style="display:inline;float:none;margin:0;padding:0;" class="wlWriterSmartContent">
<p style="font-size:7pt;overflow:scroll;width:430px;max-height:500px;font-family:'Courier New', monospace;">
<pre><span style="color:#000000;">        </span><span style="color:#008000;">//</span><span style="color:#008000;"> Use the PreviewTextInputHandler to respond to key presses</span><span style="color:#008000;">
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> PreviewTextInputHandler(Object sender, TextCompositionEventArgs e)
        {
            e.Handled </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#000000;">!</span><span style="color:#000000;">IsTextAllowed(e.Text);
        } 

        </span><span style="color:#008000;">//</span><span style="color:#008000;"> Use the DataObject.Pasting Handler </span><span style="color:#008000;">
</span><span style="color:#000000;">        </span><span style="color:#0000ff;">private</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> PastingHandler(</span><span style="color:#0000ff;">object</span><span style="color:#000000;"> sender, DataObjectPastingEventArgs e)
        {
            </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (e.DataObject.GetDataPresent(</span><span style="color:#0000ff;">typeof</span><span style="color:#000000;">(String)))
            {
                String text </span><span style="color:#000000;">=</span><span style="color:#000000;"> (String)e.DataObject.GetData(</span><span style="color:#0000ff;">typeof</span><span style="color:#000000;">(String));
                </span><span style="color:#0000ff;">if</span><span style="color:#000000;"> (</span><span style="color:#000000;">!</span><span style="color:#000000;">IsTextAllowed(text)) e.CancelCommand();
            }
            </span><span style="color:#0000ff;">else</span><span style="color:#000000;"> e.CancelCommand();
        }</span></pre>
<p>In some cases, you may need to support other scenarios (such as allowing users to Drag-and-Drop text onto it) and these can be dealt with in a similar fashion &#8211; identify an appropriate event, check the input, and if it&#8217;s invalid then prevent any further processing.</p>
<p>I hope this information serves as a starting point for implementing a masked textbox.  That is, display an actual mask (using underlines) and rigidly control the input of the user.  One immediate change is that you&#8217;d look to subclass TextBox (or base class) and override the protected handlers (e.g. OnPreviewTextInput) rather than hook up directly to the events.  The underlines are also important because without them the user has little clue what is expected of them.  Infact, in a basic validation scenario I think it better to accept dodgy input and then provide UI cues as to why it isn&#8217;t acceptable.  I&#8217;m holding off doing this myself just in case it turns up in the standard library, perhaps when Orcas ships?  If it doesn&#8217;t, I&#8217;ll post animplementation because my project needs one. </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=13&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/02/15/masking-input-to-a-wpf-textbox/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>
	</item>
		<item>
		<title>XPath Variable/Dynamic Parameters in WPF Binding</title>
		<link>http://karlhulme.wordpress.com/2007/02/14/xpath-variabledynamic-parameters-in-wpf-binding/</link>
		<comments>http://karlhulme.wordpress.com/2007/02/14/xpath-variabledynamic-parameters-in-wpf-binding/#comments</comments>
		<pubDate>Wed, 14 Feb 2007 01:00:53 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/02/14/xpath-variabledynamic-parameters-in-wpf-binding/</guid>
		<description><![CDATA[The XML binding support in WPF is excellent and just about anything you&#8217;ve ever wanted to know about it&#8217;s binding support can be found on Beatriz Costa&#8217;s blog.&#160; However, as raised by Grae Foster in a recent WPF Forum posting the Binding support is not without limitations such as the lack of support for parameterising [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=12&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The XML binding support in WPF is excellent and just about anything you&#8217;ve ever wanted to know about it&#8217;s binding support can be found on <a href="http://www.beacosta.com/">Beatriz Costa&#8217;s</a> blog.&nbsp; However, as raised by Grae Foster in a recent <a href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&amp;SiteID=1">WPF Forum</a> <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1218041&amp;SiteID=1">posting</a> the Binding support is not without limitations such as the lack of support for parameterising an XPath expression.&nbsp; Let&#8217;s just confirm what it <strong>can</strong> do..</p>
<p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Binding </span><span style="color:#FF0000;">XPath</span><span style="color:#0000FF;">=&quot;root/reports/report[key='5']&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span></div>
</pre>
</div>
</div>
<p>If you want to parameterize your XPath expression with literal values, in this case &#8217;5&#8242;, then you can do it with little bother.&nbsp; This would be useful if you had a button which filtered your xml source based on specific well known values, say enum values, but it&#8217;s no good if the value comes from somewhere else in the app.&nbsp; Unfortunately this second scenario is very common.&nbsp; </p>
<p>Another, unsupported scenario that causes problems is if you want to allow the user to make a selection from one part of the xml, and use it to select a separate section from the xml.&nbsp; Sounds a bit specialist?&nbsp; It&#8217;s not, and better explained by example..</p>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#000000;">        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">root </span><span style="color:#FF0000;">xmlns</span><span style="color:#0000FF;">=&quot;&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">categories</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">category </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">=&quot;cat1&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">reports</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">report </span><span style="color:#FF0000;">key</span><span style="color:#0000FF;">=&quot;rep1&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">report </span><span style="color:#FF0000;">key</span><span style="color:#0000FF;">=&quot;rep2&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">reports</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">category</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">category </span><span style="color:#FF0000;">name</span><span style="color:#0000FF;">=&quot;cat2&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">reports</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">report </span><span style="color:#FF0000;">key</span><span style="color:#0000FF;">=&quot;rep1&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">reports</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">category</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">categories</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">reportdefinitions</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">reportdef </span><span style="color:#FF0000;">defkey</span><span style="color:#0000FF;">=&quot;rep1&quot;</span><span style="color:#FF0000;"> name</span><span style="color:#0000FF;">=&quot;Report1&quot;</span><span style="color:#FF0000;"> Description</span><span style="color:#0000FF;">=&quot;This first report has the following prop...&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">reportdef </span><span style="color:#FF0000;">defkey</span><span style="color:#0000FF;">=&quot;rep2&quot;</span><span style="color:#FF0000;"> name</span><span style="color:#0000FF;">=&quot;Report2&quot;</span><span style="color:#FF0000;"> Description</span><span style="color:#0000FF;">=&quot;For the second report I decided to...&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">reportdefinitions</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">root</span><span style="color:#0000FF;">&gt;</span></div>
</pre>
</div>
</div>
<p>In the xml above, the categories would be bound to a ComboBox so that the user can select one.&nbsp; Below this would be a ListBox, which would display the name of the reports in that category.&nbsp; The finished app is shown below.</p>
<p><a href="http://karlhulme.files.wordpress.com/2007/02/windowslivewriterxpathvariabledynamicparametersinwpfbindi-327image03.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="107" src="http://karlhulme.files.wordpress.com/2007/02/windowslivewriterxpathvariabledynamicparametersinwpfbindi-327image02.png?w=240&#038;h=107" width="240" border="0"></a> </p>
<ul>
<li><a href="http://www.quarrie.net/kh/wpfforum01.zip">VS Project</a></li>
<li><a href="http://www.quarrie.net/kh/wpfforum01.exe">EXE File</a></li>
</ul>
<p>The difficulty in getting this (apparently simple) master-detail app to work is that the &#8216;master&#8217; xml is in a <em>separate part</em> of the document to the &#8216;detail&#8217; xml.&nbsp; This post explains how you can resolve this issue.</p>
<p>First wrap the xml data island up in an XmlDataProvider, and key it as <em>xmlData</em>.&nbsp; Then bind the category elements to a ComboBox.&nbsp; Finally define a template so that the category name is displayed for the user.&nbsp; All straight forward..</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ComboBox </span><span style="color:#FF0000;">Name</span><span style="color:#0000FF;">=&quot;combo&quot;</span><span style="color:#FF0000;"> DataContext</span><span style="color:#0000FF;">=&quot;{StaticResource xmlData}&quot;</span><span style="color:#FF0000;">
                ItemsSource</span><span style="color:#0000FF;">=&quot;{Binding XPath=root/categories/category}&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ComboBox</span><span style="color:#FF0000;">.ItemTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#FF0000;">Text</span><span style="color:#0000FF;">=&quot;{Binding XPath=@name}&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">ComboBox.ItemTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">ComboBox</span><span style="color:#0000FF;">&gt;</span></div>
</pre>
</div>
</div>
<p>Now we need to bind the ListBox.&nbsp; We know that the contents of the ListBox has to depend on the user selection in the ComboBox, so represent this by binding the DataContext of the ListBox to the SelectedItem of the ComboBox.&nbsp; The ListBox.DataContext will now be a <em>category</em>&nbsp;element (or null).&nbsp; Then create bindings on the ListBox ItemTemplate which will pull out the name and description of the reports that correspond to the selected category.&nbsp; All sounds fine, but there&#8217;s&nbsp;no XPath statement defined.</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#000000;">     </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ListBox </span><span style="color:#FF0000;">DataContext</span><span style="color:#0000FF;">=&quot;{Binding ElementName=combo, Path=SelectedItem}&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ListBox</span><span style="color:#FF0000;">.ItemsSource</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Binding </span><span style="color:#FF0000;">XPath</span><span style="color:#0000FF;">=&quot;what goes here??&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">ListBox.ItemsSource</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ListBox</span><span style="color:#FF0000;">.ItemTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">StackPanel </span><span style="color:#FF0000;">Orientation</span><span style="color:#0000FF;">=&quot;Horizontal&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#FF0000;">Text</span><span style="color:#0000FF;">=&quot;{Binding XPath=@name}&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#FF0000;">Text</span><span style="color:#0000FF;">=&quot;: &quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#FF0000;">Text</span><span style="color:#0000FF;">=&quot;{Binding XPath=@Description}&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">StackPanel</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">ListBox.ItemTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">ListBox</span><span style="color:#0000FF;">&gt;</span></div>
</pre>
</div>
</div>
<p>From the perspective of the ListBox, our DataContext will be a <em>category</em> element but we need a set of <em>report</em> elements.&nbsp; Thankfully the Binding class has a Converter parameter, which can be used to convert the input values of a binding.&nbsp; Bingo &#8211; that&#8217;s exactly what we want to do.&nbsp; I&#8217;ve defined an XmlConverter class that can be used to perform that conversion, which would be used as follows..</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ListBox </span><span style="color:#FF0000;">DataContext</span><span style="color:#0000FF;">=&quot;{Binding ElementName=combo, Path=SelectedItem}&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ListBox</span><span style="color:#FF0000;">.ItemsSource</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Binding </span><span style="color:#FF0000;">XPath</span><span style="color:#0000FF;">=&quot;reports/report/@key&quot;</span><span style="color:#FF0000;"> Converter</span><span style="color:#0000FF;">=&quot;{StaticResource xmlConverter}&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Binding</span><span style="color:#FF0000;">.ConverterParameter</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">this:XmlConverterParameter </span><span style="color:#FF0000;">XPathTemplate</span><span style="color:#0000FF;">=&quot;/root/reportdefinitions/reportdef[{0}]&quot;</span><span style="color:#FF0000;">
                                          XPathCondition</span><span style="color:#0000FF;">=&quot;@defkey='{0}'&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Binding.ConverterParameter</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Binding</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">ListBox.ItemsSource</span><span style="color:#0000FF;">&gt;</span></div>
</pre>
</div>
</div>
<p>The XPath property of the ListBox Binding is used to select the specific @key&nbsp;values that uniquely identify the <em>report</em> elements that we want from the other part of the xml.&nbsp; So the input to the conversion is now a collection of XmlAttributes.&nbsp; Ok, but let&#8217;s imagine for a second that we had literal values, instead of XmlAttributes.&nbsp; What would the XPath look like?</p>
<p><font color="#ff0000">/root/reportdefinitions/reportdef[</font><font color="#0080ff">@defkey='</font><font color="#008000">rep1</font><font color="#0080ff">' or @defkey='</font><font color="#008000">rep2</font>'<font color="#ff0000">]</font></p>
<p>We don&#8217;t have literal values, so this needs to be broken down into 3 parts.&nbsp; An XPath template, an XPath condition and the XPath condition values.&nbsp; The XPath template (shown in red) is the bit that identifies what should be bound to the control, in our case we want the <em>reportdef</em> elements.&nbsp; The XPath condition (shown in blue) will be evaluated to determine which of the elements identified by the XPath template will be included, in this case the ones for the chosen category.&nbsp; In our case above the condition appears twice because there&#8217;s two condition values (shown in green) in the current category.&nbsp;&nbsp;The XPath template and XPath condition are declared in the xaml as shown above.</p>
<p>So that&#8217;s all there is to it, in terms of xaml.&nbsp;&nbsp;Just need to explain what the XmlConverter and XmlConverterParameter classes actually do.&nbsp; The XmlConverterParameter class is just a DependencyObject with 2 DependencyProperties declared.&nbsp; (Bear in mind this means that these values can also be data bound.)</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#000000;">    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> XmlConverterParameter: DependencyObject
    {
        </span><span style="color:#008000;">//</span><span style="color:#008000;"> An XPath statement that contains a {0} where the condition is to be inserted</span><span style="color:#008000;">
</span><span style="color:#000000;">        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String XPathTemplate
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> (String)</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.GetValue(XPathTemplateProperty); }
            </span><span style="color:#0000FF;">set</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.SetValue(XPathTemplateProperty, value); }
        }
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">readonly</span><span style="color:#000000;"> DependencyProperty XPathTemplateProperty </span><span style="color:#000000;">=</span><span style="color:#000000;"> DependencyProperty.Register(
          </span><span style="color:#000000;">&quot;</span><span style="color:#000000;">XPathTemplate</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, </span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(String), </span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(XmlConverterParameter), </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> PropertyMetadata(</span><span style="color:#0000FF;">null</span><span style="color:#000000;">));

        </span><span style="color:#008000;">//</span><span style="color:#008000;"> An XPath condition that contains a {0} where the value from the source XmlNode's will be placed</span><span style="color:#008000;">
</span><span style="color:#000000;">        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String XPathCondition
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> (String)</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.GetValue(XPathConditionProperty); }
            </span><span style="color:#0000FF;">set</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.SetValue(XPathConditionProperty, value); }
        }
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">readonly</span><span style="color:#000000;"> DependencyProperty XPathConditionProperty </span><span style="color:#000000;">=</span><span style="color:#000000;"> DependencyProperty.Register(
          </span><span style="color:#000000;">&quot;</span><span style="color:#000000;">XPathCondition</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, </span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(String), </span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(XmlConverterParameter), </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> PropertyMetadata(</span><span style="color:#0000FF;">null</span><span style="color:#000000;">));
    }</span></div>
</pre>
</div>
</div>
<p>And the XmlConverter?&nbsp; Well that&#8217;s pretty simple too, it just implements IValueConverter.Convert.&nbsp; This method checks the input, it then builds up the condition using the given XmlNode array (in our case the @key values) and then executes the XPath statement against the xml to find the resultant xml (in our case the <em>reportdef</em> elements).</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#000000;">    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> XmlConverter : IValueConverter
    {
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> Convert(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value, Type targetType, </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> parameter, System.Globalization.CultureInfo culture)
        {
            </span><span style="color:#008000;">//</span><span style="color:#008000;"> check that we've got all the inputs we need</span><span style="color:#008000;">
</span><span style="color:#000000;">            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (value </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> IEnumerable </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">;
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (parameter </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> XmlConverterParameter </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">;
            XmlConverterParameter cp </span><span style="color:#000000;">=</span><span style="color:#000000;"> parameter </span><span style="color:#0000FF;">as</span><span style="color:#000000;"> XmlConverterParameter;
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (cp.XPathTemplate </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;"> </span><span style="color:#000000;">||</span><span style="color:#000000;"> cp.XPathCondition </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">;

            </span><span style="color:#008000;">//</span><span style="color:#008000;"> build the condition part of the xpath statement using the given XmlNode[]</span><span style="color:#008000;">
</span><span style="color:#000000;">            XmlDocument doc </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">;
            List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">String</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> compoundCondition </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">String</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();
            </span><span style="color:#0000FF;">foreach</span><span style="color:#000000;"> (XmlNode node </span><span style="color:#0000FF;">in</span><span style="color:#000000;"> (IEnumerable)value)
            {
                </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (doc </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) doc </span><span style="color:#000000;">=</span><span style="color:#000000;"> node.OwnerDocument;
                compoundCondition.Add(String.Format(cp.XPathCondition, node.InnerText));
            }

            </span><span style="color:#008000;">//</span><span style="color:#008000;"> select the node set</span><span style="color:#008000;">
</span><span style="color:#000000;">            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> (doc </span><span style="color:#000000;">==</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">) { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> </span><span style="color:#0000FF;">null</span><span style="color:#000000;">; }
            </span><span style="color:#0000FF;">else</span><span style="color:#000000;">
            {
                String select </span><span style="color:#000000;">=</span><span style="color:#000000;"> String.Format(cp.XPathTemplate,
                    String.Join(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;"> or </span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, compoundCondition.ToArray()));
                </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> doc.SelectNodes(select);
            }
        }

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> ConvertBack(</span><span style="color:#0000FF;">object</span><span style="color:#000000;"> value, Type targetType, </span><span style="color:#0000FF;">object</span><span style="color:#000000;"> parameter, System.Globalization.CultureInfo culture)
        {
            </span><span style="color:#0000FF;">throw</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> Exception(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">The method or operation is not implemented.</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
        }
    }</span></div>
</pre>
</div>
</div>
<p>The XmlConverter class clearly won&#8217;t support every scenario.&nbsp; If you have another common scenario, you could create a different XmlConverterParameter object which allows the XPath query to be built up in a different way.&nbsp; But what if you want a complete solution?&nbsp; Well then you need to address the fundamental problem&#8230; you need a powerful expressive way of selecting one set of nodes given another set of nodes.&nbsp; Three methods spring to mind&#8230;</p>
<p>First you could use XSL.&nbsp; You could implement an XslConverter, to replace the XmlConverter class which accepts an XSL fragment to perform the select.&nbsp; However XSL uses XPath and so you&#8217;re likely to run into the same problems, specifically, finding a way to merge the source multiple input XmlNodes with the &#8216;select&#8217; statement.&nbsp; An XSL solution also presents problem of producing a new XmlDocument as the output, which would probably have to be related back to the original xml data.&nbsp; Second thoughts, this isn&#8217;t a solution at all.</p>
<p>Second, you could use <a href="http://www.w3.org/TR/xquery/">XQuery</a>.&nbsp; This is a much better tool for the job, although it&#8217;s been cooking for so long that the world has moved on.&nbsp; In addition, <a href="http://msdn.microsoft.com/XML/XQueryStatus/default.aspx">Microsoft dropped support for XQuery</a> along time ago (Microsoft.Xml.XQuery).&nbsp; You can still get <a href="http://aspnet.4guysfromrolla.com/code/XQueryStuff.zip">their implementation</a> of it from <a href="http://www.4guysfromrolla.com/">4guysfromrolla</a>, and it seems to work fairly well, but obviously this is a non-supported approach.&nbsp; Microsoft did include an implementation in Sql Server 2005, so you could (in theory) off-load the processing to it, but there&#8217;s far more drawbacks than benefits to this approach.&nbsp; XQuery support may re-appear but i believe the architect on this project, <a href="http://www.qbrundage.com/michaelb/">Michael Brundage</a>,&nbsp;is now working on the XBox &#8211; so I wouldn&#8217;t hold your breath.</p>
<p>Thirdly, you could use <a href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx">XLinq</a>, and you can get an <a href="http://www.xlinq.net/xlinq/overview/">overview here</a>.&nbsp; It provides all the expressiveness of XQuery, along with countless other advantages.&nbsp; This is the best solution, and will kill the parameterized XPath problem dead, by allowing you to perform a join on the xml.&nbsp; I suspect that&#8217;s why the XPath parameterization problem has been overlooked for now.&nbsp; It simple wasn&#8217;t worth producing a half way house solution.&nbsp; You can download the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea&amp;displaylang=en">May 2006 CTP</a> to create your own Binding Converter that uses XLinq to do the work.&nbsp; If you can wait though, the necessary functionality will probably appear natively, e.g. in the Binding class, or probably something much better that I never would have thought of.&nbsp; </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=12&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/02/14/xpath-variabledynamic-parameters-in-wpf-binding/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>

		<media:content url="http://karlhulme.files.wordpress.com/2007/02/windowslivewriterxpathvariabledynamicparametersinwpfbindi-327image02.png" medium="image" />
	</item>
		<item>
		<title>Tweaking the CodeFormatter plugin for Windows Live Writer</title>
		<link>http://karlhulme.wordpress.com/2007/02/13/tweaking-the-codeformatter-plugin-for-windows-live-writer/</link>
		<comments>http://karlhulme.wordpress.com/2007/02/13/tweaking-the-codeformatter-plugin-for-windows-live-writer/#comments</comments>
		<pubDate>Tue, 13 Feb 2007 00:16:59 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/02/13/tweaking-the-codeformatter-plugin-for-windows-live-writer/</guid>
		<description><![CDATA[I downloaded the binaries of the CodeFormatter plugin for Windows Live Writer (the blogging tool) from Steve Dunn&#8217;s blog.&#160; He&#8217;s provided the plugin in binary form so you can just extract the contents to your \Windows Live Writer\Plugins directory. One small problem with it though, is that the code it produces is enormous.&#160; I&#8217;m not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=9&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I downloaded the binaries of the <a href="http://stevedunns.blogspot.com/2006/08/code-formatter-plugin-for-windows-live.html">CodeFormatter plugin for Windows Live Writer</a> (the blogging tool) from <a href="http://stevedunns.blogspot.com/index.html">Steve Dunn&#8217;s blog</a>.&nbsp; He&#8217;s provided the plugin in <a href="http://homepage.ntlworld.com/steve_dunn/CodeFormatterPluginBinaries.zip">binary</a> form so you can just extract the contents to your \Windows Live Writer\Plugins directory.</p>
<p>One small problem with it though, is that the code it produces is enormous.&nbsp; I&#8217;m not talking about code bloat, i mean physically on the screen it&#8217;s huge.&nbsp; To make matters worse it doesn&#8217;t scroll, which means you can end up losing half of the code.&nbsp; Luckily the <a href="http://homepage.ntlworld.com/steve_dunn/CodeFormatterPluginSource.zip">source</a> is also available.&nbsp;</p>
<p>Using the source you can easily edit the HTML that&#8217;s produced.&nbsp; For some strange reason I can&#8217;t get it to pick up the font-family correct in the end result, but it looks ok in the editor so i think that&#8217;s something to do with the template i&#8217;m using on word press.</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#000000;">            sb.Append(</span><span style="color:#000000;">@&quot;</span><span style="color:#000000;">&lt;div style=&quot;&quot;width: 430px; max-height: 500px; overflow: scroll; font-family: 'Courier New', monospace; font-size: 7pt;&quot;&quot;&gt;&lt;pre style=&quot;&quot;</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">);
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> ( </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.BackgroundColor </span><span style="color:#000000;">!=</span><span style="color:#000000;"> Color.Empty )
                sb.AppendFormat( </span><span style="color:#000000;">@&quot;</span><span style="color:#000000;">background-color:{0};</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, ColorTranslator.ToHtml( </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.BackgroundColor) );
            </span><span style="color:#0000FF;">if</span><span style="color:#000000;"> ( </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.WordWrap )
                sb.Append( </span><span style="color:#000000;">@&quot;</span><span style="color:#000000;">white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;</span><span style="color:#000000;">&quot;</span><span style="color:#000000;"> );
            sb.AppendFormat( </span><span style="color:#000000;">@&quot;</span><span style="color:#000000;">&quot;&quot;&gt;{0}&lt;/pre&gt;&lt;/div&gt;</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, s );</span></div>
</pre>
</div>
</div>
<p>If you don&#8217;t have time to edit the files yourself then you can grab the <a href="http://www.quarrie.net/kh/CodeFormatter.zip">binaries that I rebuilt</a>.&nbsp; If anyone has a problem with me reposting here then let me know and i&#8217;ll take them down.</p>
<p>There&#8217;s more plugins on the <a href="http://www.codeplex.com/">codeplex</a> site <a href="http://www.codeplex.com/WLWPlugins/">here</a>, which includes a PasteAsHtml plugin by <a href="http://blogs.sqlxml.org/bryantlikes/">Bryant Likes</a>.&nbsp; It installed easy enough but I didn&#8217;t have much luck with it.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=9&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/02/13/tweaking-the-codeformatter-plugin-for-windows-live-writer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>
	</item>
		<item>
		<title>Easy Sci-fi Style Screen Readout</title>
		<link>http://karlhulme.wordpress.com/2007/02/12/easy-sci-fi-style-screen-readout/</link>
		<comments>http://karlhulme.wordpress.com/2007/02/12/easy-sci-fi-style-screen-readout/#comments</comments>
		<pubDate>Mon, 12 Feb 2007 21:35:32 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/02/12/easy-sci-fi-style-screen-readout/</guid>
		<description><![CDATA[I&#8217;m working on a sci-fi style screen readout control in WPF. Basically you can throw strings at it, and it will print them on the screen one character at a time. When you add the next, the first one slides down the page to make room for it. Nice I&#8217;ve got a lot more work [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=5&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a sci-fi style screen readout control in WPF. Basically you can throw strings at it, and it will print them on the screen one character at a time. When you add the next, the first one slides down the page to make room for it. Nice <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  I&#8217;ve got a lot more work to do on it, but I thought it best to share some of the code before it becomes a 20,000 line opus. Sadly the screen shot doesn&#8217;t do it justice – not least because I don&#8217;t want to bloat the xaml yet with gradient fill overload. </p>
<ul>
<li><a href="http://www.quarrie.net/kh/Ticker.zip">VS Project</a>
<li><a href="http://www.quarrie.net/kh/Ticker.exe">EXE File</a> </li>
</ul>
<p><img alt="" src="http://karlhulme.files.wordpress.com/2007/02/021207-2135-easyscifist11.png?w=460"> </p>
<p>First I need a class to represent the individual readouts. I&#8217;ll be binding to it so it&#8217;ll need to subclass DependencyObject and all the properties will need to be of a DependencyProperty type. </p>
</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#000000;">    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> LineItem: DependencyObject
    {
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> String Text
        {
            </span><span style="color:#0000FF;">get</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> (String)</span><span style="color:#0000FF;">this</span><span style="color:#000000;">.GetValue(TextProperty); }
            </span><span style="color:#0000FF;">set</span><span style="color:#000000;"> { </span><span style="color:#0000FF;">this</span><span style="color:#000000;">.SetValue(TextProperty, value); }
        }
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">readonly</span><span style="color:#000000;"> DependencyProperty TextProperty </span><span style="color:#000000;">=</span><span style="color:#000000;"> DependencyProperty.Register(
          </span><span style="color:#000000;">&quot;</span><span style="color:#000000;">Text</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">, </span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(String), </span><span style="color:#0000FF;">typeof</span><span style="color:#000000;">(LineItem), </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> PropertyMetadata(</span><span style="color:#0000FF;">null</span><span style="color:#000000;">));

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> LineItem(String text)
        {
            Text </span><span style="color:#000000;">=</span><span style="color:#000000;"> text;
        }
    }</span></div>
</pre>
</div>
</div>
<p>For most of my apps these days I centralise the data. It makes it much easier to introduce caching and performing optimisations later. I&#8217;m clearly over-selling here, all we need is a class that we can hook an ObjectDataProvider up to. </p>
<p><span style="font-size:10pt;font-family:courier new;"><span style="color:blue;"></span></span></p>
</p>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#000000;">    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> Model
    {
        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">LineItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> lineItems </span><span style="color:#000000;">=</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">LineItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();

        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">static</span><span style="color:#000000;"> ObservableCollection</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">LineItem</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> GetTickerItems()
        {
            </span><span style="color:#0000FF;">return</span><span style="color:#000000;"> lineItems;
        }
    }</span></div>
</pre>
</div>
</div>
<p>Next we need to add an event handler for a button we&#8217;re going to hook up later. This is placed into the partial class for the WPF window. </p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#000000;">    </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> </span><span style="color:#0000FF;">partial</span><span style="color:#000000;"> </span><span style="color:#0000FF;">class</span><span style="color:#000000;"> Window1 : System.Windows.Window
    {
        </span><span style="color:#0000FF;">public</span><span style="color:#000000;"> Window1()
        {
            InitializeComponent();
        }

        </span><span style="color:#0000FF;">private</span><span style="color:#000000;"> </span><span style="color:#0000FF;">void</span><span style="color:#000000;"> ButtonClick(Object sender, RoutedEventArgs e)
        {
            LineItem item </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000FF;">new</span><span style="color:#000000;"> LineItem(</span><span style="color:#000000;">&quot;</span><span style="color:#000000;">Item </span><span style="color:#000000;">&quot;</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;"> Model.GetTickerItems().Count.ToString());
            Model.GetTickerItems().Insert(</span><span style="color:#000000;">0</span><span style="color:#000000;">, item);
        }
    }</span></div>
</pre>
</div>
</div>
<p>The button click handler will create a new instance of our LineItem class and add it to the model. Since the model encompasses an ObservableCollection class, the WPF controls will be notified of the changes automatically. </p>
<p>Ok, that&#8217;s the easy bit. Now comes the other easy bit. The basic idea is that the when a new LineItem is added to the collection a new control will be created for it automatically in the StackPanel using the DataTemplate provided. I will use the FrameworkElement.Loaded event to provide the animation. This animation is achieved by sizing the control height from 0 to 15 pixels, and then sizing it from 0 to 100 pixels in width. This is done using key frames. To spice things up, I added a LinearGradientBrush which is used to fade the child controls out at the bottom of the StackPanel. </p>
<p><span style="font-size:10pt;font-family:courier new;"><span style="color:blue;"></span></span></p>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="width:430px;max-height:500px;overflow:scroll;font-family:'Courier New', monospace;font-size:7pt;">
<pre>
<div><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Window </span><span style="color:#FF0000;">x:Class</span><span style="color:#0000FF;">=&quot;Ticker.Window1&quot;</span><span style="color:#FF0000;">
    xmlns</span><span style="color:#0000FF;">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span><span style="color:#FF0000;">
    xmlns:x</span><span style="color:#0000FF;">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span><span style="color:#FF0000;">
    xmlns:this</span><span style="color:#0000FF;">=&quot;clr-namespace:Ticker&quot;</span><span style="color:#FF0000;">
    Title</span><span style="color:#0000FF;">=&quot;Ticker&quot;</span><span style="color:#FF0000;"> Height</span><span style="color:#0000FF;">=&quot;300&quot;</span><span style="color:#FF0000;"> Width</span><span style="color:#0000FF;">=&quot;300&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">

  </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Window</span><span style="color:#FF0000;">.Resources</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
    </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ObjectDataProvider </span><span style="color:#FF0000;">x:Key</span><span style="color:#0000FF;">=&quot;tickerLines&quot;</span><span style="color:#FF0000;"> ObjectType</span><span style="color:#0000FF;">=&quot;{x:Type this:Model}&quot;</span><span style="color:#FF0000;"> MethodName</span><span style="color:#0000FF;">=&quot;GetTickerItems&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">

    </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">LinearGradientBrush </span><span style="color:#FF0000;">x:Key</span><span style="color:#0000FF;">=&quot;VerticalGrayScale&quot;</span><span style="color:#FF0000;"> StartPoint</span><span style="color:#0000FF;">=&quot;0.5,0&quot;</span><span style="color:#FF0000;"> EndPoint</span><span style="color:#0000FF;">=&quot;0.5,1&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">GradientStop </span><span style="color:#FF0000;">Color</span><span style="color:#0000FF;">=&quot;Black&quot;</span><span style="color:#FF0000;"> Offset</span><span style="color:#0000FF;">=&quot;0.6&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">GradientStop </span><span style="color:#FF0000;">Color</span><span style="color:#0000FF;">=&quot;Transparent&quot;</span><span style="color:#FF0000;"> Offset</span><span style="color:#0000FF;">=&quot;1.0&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
    </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">LinearGradientBrush</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
  </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Window.Resources</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">

  </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Grid</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
    </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Grid</span><span style="color:#FF0000;">.RowDefinitions</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">RowDefinition </span><span style="color:#FF0000;">Height</span><span style="color:#0000FF;">=&quot;0.2*&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">RowDefinition </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
    </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Grid.RowDefinitions</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">

    </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Button </span><span style="color:#FF0000;">Grid.Row</span><span style="color:#0000FF;">=&quot;0&quot;</span><span style="color:#FF0000;"> Content</span><span style="color:#0000FF;">=&quot;Add New Message&quot;</span><span style="color:#FF0000;"> Click</span><span style="color:#0000FF;">=&quot;ButtonClick&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">

    </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ListBox </span><span style="color:#FF0000;">Grid.Row</span><span style="color:#0000FF;">=&quot;1&quot;</span><span style="color:#FF0000;"> ItemsSource</span><span style="color:#0000FF;">=&quot;{Binding Source={StaticResource tickerLines}}&quot;</span><span style="color:#FF0000;">
             ScrollViewer.HorizontalScrollBarVisibility</span><span style="color:#0000FF;">=&quot;Hidden&quot;</span><span style="color:#FF0000;">
             ScrollViewer.VerticalScrollBarVisibility</span><span style="color:#0000FF;">=&quot;Hidden&quot;</span><span style="color:#FF0000;">
             OpacityMask</span><span style="color:#0000FF;">=&quot;{StaticResource VerticalGrayScale}&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">ListBox</span><span style="color:#FF0000;">.ItemTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">TextBlock </span><span style="color:#FF0000;">Name</span><span style="color:#0000FF;">=&quot;block&quot;</span><span style="color:#FF0000;">  Text</span><span style="color:#0000FF;">=&quot;{Binding Path=Text}&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">TextBlock</span><span style="color:#FF0000;">.Triggers</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">EventTrigger </span><span style="color:#FF0000;">RoutedEvent</span><span style="color:#0000FF;">=&quot;TextBlock.Loaded&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">EventTrigger</span><span style="color:#FF0000;">.Actions</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                  </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">BeginStoryboard</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                    </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">Storyboard</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                      </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">DoubleAnimationUsingKeyFrames </span><span style="color:#FF0000;">Storyboard.TargetName</span><span style="color:#0000FF;">=&quot;block&quot;</span><span style="color:#FF0000;">
                                       Storyboard.TargetProperty</span><span style="color:#0000FF;">=&quot;(FrameworkElement.Height)&quot;</span><span style="color:#FF0000;">
                                       Duration</span><span style="color:#0000FF;">=&quot;0:0:0.5&quot;</span><span style="color:#FF0000;"> AutoReverse</span><span style="color:#0000FF;">=&quot;False&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">LinearDoubleKeyFrame </span><span style="color:#FF0000;">Value</span><span style="color:#0000FF;">=&quot;0&quot;</span><span style="color:#FF0000;"> KeyTime</span><span style="color:#0000FF;">=&quot;0:0:0&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
                        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">LinearDoubleKeyFrame </span><span style="color:#FF0000;">Value</span><span style="color:#0000FF;">=&quot;15&quot;</span><span style="color:#FF0000;"> KeyTime</span><span style="color:#0000FF;">=&quot;0:0:0.5&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
                      </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">DoubleAnimationUsingKeyFrames</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                      </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">DoubleAnimationUsingKeyFrames </span><span style="color:#FF0000;">Storyboard.TargetName</span><span style="color:#0000FF;">=&quot;block&quot;</span><span style="color:#FF0000;">
                                       Storyboard.TargetProperty</span><span style="color:#0000FF;">=&quot;(FrameworkElement.Width)&quot;</span><span style="color:#FF0000;">
                                       Duration</span><span style="color:#0000FF;">=&quot;0:0:1.5&quot;</span><span style="color:#FF0000;"> AutoReverse</span><span style="color:#0000FF;">=&quot;False&quot;</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">LinearDoubleKeyFrame </span><span style="color:#FF0000;">Value</span><span style="color:#0000FF;">=&quot;0&quot;</span><span style="color:#FF0000;"> KeyTime</span><span style="color:#0000FF;">=&quot;0:0:0&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
                        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">LinearDoubleKeyFrame </span><span style="color:#FF0000;">Value</span><span style="color:#0000FF;">=&quot;0&quot;</span><span style="color:#FF0000;"> KeyTime</span><span style="color:#0000FF;">=&quot;0:0:0.5&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
                        </span><span style="color:#0000FF;">&lt;</span><span style="color:#800000;">LinearDoubleKeyFrame </span><span style="color:#FF0000;">Value</span><span style="color:#0000FF;">=&quot;100&quot;</span><span style="color:#FF0000;"> KeyTime</span><span style="color:#0000FF;">=&quot;0:0:1.5&quot;</span><span style="color:#FF0000;"> </span><span style="color:#0000FF;">/&gt;</span><span style="color:#000000;">
                      </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">DoubleAnimationUsingKeyFrames</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                    </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Storyboard</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                  </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">BeginStoryboard</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
                </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">EventTrigger.Actions</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
              </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">EventTrigger</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
            </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">TextBlock.Triggers</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
          </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">TextBlock</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
        </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">DataTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
      </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">ListBox.ItemTemplate</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
    </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">ListBox</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">

  </span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Grid</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
</span><span style="color:#0000FF;">&lt;/</span><span style="color:#800000;">Window</span><span style="color:#0000FF;">&gt;</span><span style="color:#000000;">
</span></div>
</pre>
</div>
</div>
<p>I&#8217;ll endeavour to post some screen shots of the pretty version when it&#8217;s finished.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=5&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/02/12/easy-sci-fi-style-screen-readout/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>

		<media:content url="http://karlhulme.files.wordpress.com/2007/02/021207-2135-easyscifist11.png" medium="image" />
	</item>
		<item>
		<title>Hello, World!</title>
		<link>http://karlhulme.wordpress.com/2007/02/12/hello-world/</link>
		<comments>http://karlhulme.wordpress.com/2007/02/12/hello-world/#comments</comments>
		<pubDate>Mon, 12 Feb 2007 20:37:02 +0000</pubDate>
		<dc:creator>Karl Hulme</dc:creator>
				<category><![CDATA[Waffle]]></category>

		<guid isPermaLink="false">http://karlhulme.wordpress.com/2007/02/12/hello-world/</guid>
		<description><![CDATA[Apparently you can use Word to post to your blog. Which begs the question, how easy is this to do. Can a monkey do it? Can I do it? Can I do it while wearing a monkey suit? Clearly that would be difficult because monkeys have big chunky sausage fingers and the keys on my [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=3&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Apparently you can use Word to post to your blog. Which begs the question, how easy is this to do. Can a monkey do it? Can I do it? Can I do it while wearing a monkey suit? Clearly that would be difficult because monkeys have big chunky sausage fingers and the keys on my laptop here are quite small.</p>
<p>The answer to this question will of course be self evident.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlhulme.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlhulme.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlhulme.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlhulme.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlhulme.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlhulme.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/karlhulme.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/karlhulme.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/karlhulme.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/karlhulme.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlhulme.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlhulme.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlhulme.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlhulme.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlhulme.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlhulme.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlhulme.wordpress.com&amp;blog=774617&amp;post=3&amp;subd=karlhulme&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://karlhulme.wordpress.com/2007/02/12/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6eea865e38d62d1d98258cdab193ff8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Karl Hulme</media:title>
		</media:content>
	</item>
	</channel>
</rss>
