<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CEQDQH46cCp7ImA9WxBUFkQ.&quot;"><id>tag:blogger.com,1999:blog-9534263</id><updated>2010-03-04T08:46:11.018Z</updated><title>compilewith.net</title><subtitle type="html">software by design</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://compilewith.net/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://compilewith.net/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>146</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Compilewithnet" /><feedburner:info uri="compilewithnet" /><entry gd:etag="W/&quot;DUICR30yfyp7ImA9WxBXFko.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-6285778246468946065</id><published>2010-01-21T17:10:00.001Z</published><updated>2010-01-28T11:19:26.397Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-28T11:19:26.397Z</app:edited><title>GL.NET WPF Talk</title><content type="html">&lt;p&gt;For those of you who attended &lt;a href="http://www.gl-net.org.uk/Events/january10.aspx"&gt;my WPF talk&lt;/a&gt; last night at the &lt;a href="http://www.gl-net.org.uk/"&gt;GL.NET User Group&lt;/a&gt; meeting, thank you for coming and listening; here are the book references I promised:&lt;/p&gt;  &lt;blockquote&gt;   &lt;table border="0" cellspacing="0" cellpadding="2" width="553"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="22"&gt;&lt;strong&gt;&lt;font color="#ff8000"&gt;&lt;em&gt;1.&lt;/em&gt;&lt;/font&gt;&lt;/strong&gt; &lt;/td&gt;          &lt;td valign="top" width="529"&gt;&lt;a href="http://www.amazon.co.uk/Essential-Presentation-Foundation-Microsoft-Development/dp/0321374479/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1264091650&amp;amp;sr=8-1"&gt;&lt;strong&gt;Essential WPF by Chris Anderson&lt;/strong&gt;&lt;/a&gt;             &lt;br /&gt;            &lt;br /&gt;Chris was one of the Architects on WPF and therefore provides a lot of insight into &lt;em&gt;why&lt;/em&gt; things were done the way they were. This book gives you the essence of what WPF is all about.             &lt;br /&gt;            &lt;br /&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="22"&gt;&lt;strong&gt;&lt;font color="#ff8000"&gt;&lt;em&gt;2.&lt;/em&gt;&lt;/font&gt;&lt;/strong&gt; &lt;/td&gt;          &lt;td valign="top" width="529"&gt;&lt;strong&gt;&lt;a href="http://www.amazon.co.uk/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1264091928&amp;amp;sr=1-1"&gt;WPF Unleashed by Adam Nathan&lt;/a&gt;               &lt;br /&gt;&lt;/strong&gt;            &lt;br /&gt;Adam is an excellent writer and this all colour book is a real &amp;quot;how to&amp;quot; book; a book on how to get things done by using WPF.             &lt;br /&gt;            &lt;br /&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="22"&gt;&lt;strong&gt;&lt;font color="#ff8000"&gt;&lt;em&gt;3.&lt;/em&gt;&lt;/font&gt;&lt;/strong&gt; &lt;/td&gt;          &lt;td valign="top" width="529"&gt;&lt;strong&gt;&lt;a href="http://www.amazon.co.uk/Programming-WPF-Building-Presentation-Foundation/dp/0596510373/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1264092137&amp;amp;sr=1-1"&gt;Programming WPF by Chris Sells and Ian Griffiths&lt;/a&gt;&lt;/strong&gt;             &lt;br /&gt;            &lt;br /&gt;This is the deep dive on WPF, the nuts and bolts, the nitty gritty of how things work. This is a great book that I constantly find myself going back to.&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/blockquote&gt;  &lt;p&gt;If you have any questions or comments please feel free to drop me a line here, just add a comment to this post or send me a mail by using the contact link above. See you all next month at the next meeting; think deeply and enjoy.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;a href="http://www.box.net/shared/o6ebai3quk" target="_blank"&gt;Download the presentation.&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-6285778246468946065?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=qjfKHVKz9Wo:SuNke26wFMY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=qjfKHVKz9Wo:SuNke26wFMY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/qjfKHVKz9Wo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/6285778246468946065/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=6285778246468946065" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6285778246468946065?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6285778246468946065?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/qjfKHVKz9Wo/glnet-wpf-talk.html" title="GL.NET WPF Talk" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://compilewith.net/2010/01/glnet-wpf-talk.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08BRHY5eyp7ImA9WxBSFEs.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-1970259983916265631</id><published>2009-12-22T08:08:00.001Z</published><updated>2009-12-22T08:17:35.823Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-22T08:17:35.823Z</app:edited><title>MIX10 10K Smart Coding Challenge</title><content type="html">&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_acf4FzpScrE/SzB-mf35cBI/AAAAAAAAAL8/o8NDelczY80/s1600-h/logo6.gif"&gt;&lt;img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="logo" border="0" alt="logo" align="right" src="http://lh3.ggpht.com/_acf4FzpScrE/SzB-mxcDmNI/AAAAAAAAAMA/nE_ByYgBOJY/logo_thumb4.gif?imgmax=800" width="201" height="154" /&gt;&lt;/a&gt; The Microsoft MIX conference is starting to ramp up again with &lt;a href="http://www.visitmix.com/"&gt;&lt;strong&gt;MIX10&lt;/strong&gt;&lt;/a&gt;, and with it the &lt;a href="http://mix10k.visitmix.com/"&gt;MIX10K Smart Coding Challenge&lt;/a&gt;. So it’s time to crank out another application with 10K or less of source code, and get me another one of those lovely MIX t-shirts!&lt;/p&gt;  &lt;p&gt;This year I’m doing something a little more conventional than &lt;a href="http://compilewith.net/2009/01/mix09-10k-smart-coding-challenge.html"&gt;my entry last year&lt;/a&gt;: a game (albeit a simple one), a game I like to call &lt;a href="http://www.bing.com/"&gt;&lt;strong&gt;Bing&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; Pairs&lt;/strong&gt;. The idea is to simply find the pairs of Bing background images as fast as you can [&lt;strong&gt;&lt;a href="http://mix10k.visitmix.com/entry/details/128"&gt;click here to vote for my efforts&lt;/a&gt;&lt;/strong&gt;].&lt;/p&gt;  &lt;p&gt;Here’s a short video of the game in action:&lt;/p&gt; &lt;object width="400" height="300"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=8309061&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=8309061&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"&gt;&lt;/embed&gt;&lt;/object&gt;  &lt;p&gt;All that, and all for less than 10K of source code! &lt;/p&gt;  &lt;p&gt;I would be &lt;em&gt;very&lt;/em&gt; grateful if you could take a moment out of your day to go and &lt;strong&gt;&lt;a href="http://mix10k.visitmix.com/entry/details/128"&gt;vote for my entry&lt;/a&gt;&lt;/strong&gt;, thank you.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-1970259983916265631?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=34VGb7OxEQs:f65z8TpAXfU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=34VGb7OxEQs:f65z8TpAXfU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/34VGb7OxEQs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/1970259983916265631/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=1970259983916265631" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/1970259983916265631?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/1970259983916265631?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/34VGb7OxEQs/mix10-10k-smart-coding-challenge.html" title="MIX10 10K Smart Coding Challenge" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/12/mix10-10k-smart-coding-challenge.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUQNQX45eSp7ImA9WxNaFUo.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-4772840425648196184</id><published>2009-11-28T17:24:00.001Z</published><updated>2009-11-30T09:29:50.021Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-30T09:29:50.021Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>WPF Data Bound RadioButtonList</title><content type="html">&lt;p&gt;During the process of writing a WPF application recently, I had the need for a data bound list of items where the options had to be mutually exclusive, so I figured something like a list of &lt;strong&gt;RadioButton&lt;/strong&gt;s would be in order.&lt;/p&gt;  &lt;p&gt;However, when I started looking around I could not find a &lt;strong&gt;RadioButtonList&lt;/strong&gt; or anything that fitted the bill out-of-the-box. Therefore, I thought I’d put something together myself; I also needed to have the list render horizontally rather than vertically. This is what I came up with:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;&amp;lt;!-- Item Style for the ListBoxItem to add a RadioButton --&amp;gt;        &lt;br /&gt;&lt;/font&gt;&amp;lt;Style x:Key=&amp;quot;RadioButtonItemStyle&amp;quot; TargetType=&amp;quot;{x:Type ListBoxItem}&amp;quot;&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Margin&amp;quot; Value=&amp;quot;0,0,5,0&amp;quot; /&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter Property=&amp;quot;Template&amp;quot;&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Setter.Value&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ControlTemplate TargetType=&amp;quot;{x:Type ListBoxItem}&amp;quot;&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Border BorderThickness=&amp;quot;0&amp;quot; Background=&amp;quot;Transparent&amp;quot;&amp;gt;       &lt;br /&gt;&lt;font color="#008000"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;!-- Note: IsChecked is bound to IsSelected--&amp;gt;        &lt;br /&gt;&lt;/font&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RadioButton       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Focusable=&amp;quot;False&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IsHitTestVisible=&amp;quot;False&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; IsChecked=&amp;quot;{TemplateBinding IsSelected}&amp;quot;&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ContentPresenter /&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/RadioButton&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Border&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/ControlTemplate&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter.Value&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Setter&amp;gt;       &lt;br /&gt;&amp;lt;/Style&amp;gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;&amp;lt;!-- Turns the ListBox in to a Horizontal ListBox --&amp;gt;        &lt;br /&gt;&lt;/font&gt;&amp;lt;ItemsPanelTemplate x:Key=&amp;quot;HorizontalItemsPanel&amp;quot;&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;VirtualizingStackPanel       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Orientation=&amp;quot;Horizontal&amp;quot; /&amp;gt;       &lt;br /&gt;&amp;lt;/ItemsPanelTemplate&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;I defined a &lt;strong&gt;Style&lt;/strong&gt; and the &lt;strong&gt;ItemsPanelTemplate&lt;/strong&gt; in the &lt;strong&gt;Resources&lt;/strong&gt; property of my &lt;strong&gt;Window&lt;/strong&gt; that contains all the necessary XAML for the effects I need; note that you could just as easily define this XAML inline on the &lt;strong&gt;ListBox&lt;/strong&gt; as opposed to using the &lt;strong&gt;Resources&lt;/strong&gt; property. I then applied these two new elements to an instance of &lt;strong&gt;ListBox&lt;/strong&gt; using the following mark-up:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;lt;ListBox      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; BorderThickness=&amp;quot;0&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ItemsSource=&amp;quot;{Binding MyDataList}&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SelectedValue=&amp;quot;{Binding MyDataListSelectedValue}&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ItemContainerStyle=&amp;quot;{StaticResource &lt;font color="#ff8000"&gt;RadioButtonItemStyle&lt;/font&gt;}&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ItemsPanel=&amp;quot;{StaticResource &lt;font color="#ff8000"&gt;HorizontalItemsPanel&lt;/font&gt;}&amp;quot; /&amp;gt; &lt;/font&gt;&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;I’ve &lt;font color="#ff8000"&gt;highlighted&lt;/font&gt; where I’ve used the two resources. &lt;/p&gt;  &lt;p&gt;For this example the data list is trivial and is provided by a &lt;em&gt;ViewModel&lt;/em&gt; class attached to the &lt;strong&gt;DataContext&lt;/strong&gt; of the &lt;strong&gt;Window&lt;/strong&gt;; I’m only showing the code here as a example of how you can add sample data to an application, as well as proving that the above XAML all works as expected using a bound list of data:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;public class MainWindowViewModel      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public IEnumerable&amp;lt;string&amp;gt; MyDataList       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; yield return &amp;quot;Stan&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; yield return &amp;quot;Cartman&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; yield return &amp;quot;Kenny&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; yield return &amp;quot;Karl&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public string MyDataListSelectedValue      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return &amp;quot;Cartman&amp;quot;; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set { &lt;font color="#008000"&gt;/* TODO: save the value */&lt;/font&gt; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;&amp;lt;!-- XAML --&amp;gt;&lt;/font&gt;       &lt;br /&gt;&amp;lt;Window.DataContext&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;vm:MainWindowViewModel /&amp;gt;       &lt;br /&gt;&amp;lt;/Window.DataContext&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Here’s what it all looks like in the Visual Studio designer:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_acf4FzpScrE/SxFczlVfdkI/AAAAAAAAALw/I52Tek3g84Y/s1600-h/image%5B3%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_acf4FzpScrE/SxFc0f6tZ2I/AAAAAAAAAL0/OOeiyqnTcs4/image_thumb%5B1%5D.png?imgmax=800" width="516" height="343" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And there we have it, job done. Hope this helps someone, happy XAML hacking.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-4772840425648196184?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=u0CXLODhgPc:a98YkTXwMzU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=u0CXLODhgPc:a98YkTXwMzU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/u0CXLODhgPc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/4772840425648196184/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=4772840425648196184" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/4772840425648196184?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/4772840425648196184?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/u0CXLODhgPc/wpf-data-bound-radiobuttonlist.html" title="WPF Data Bound RadioButtonList" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://compilewith.net/2009/11/wpf-data-bound-radiobuttonlist.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0EHRXw8eCp7ImA9WxNUE04.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-8488942669966948780</id><published>2009-11-04T10:47:00.001Z</published><updated>2009-11-04T10:47:14.270Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-04T10:47:14.270Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="Architecture" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net" /><title>WPF: MV-VM Sample Application with Navigation</title><content type="html">&lt;p&gt;I have recently been reminded of how difficult it can be to get started when you are trying to build an application and have been given a completely clean sheet of paper to start from – in terms of the application architecture and design – the options are limitless, which can at times be a little daunting.&lt;/p&gt;  &lt;p&gt;Recently, to help a colleague combat the &lt;strong&gt;clean sheet of paper syndrome&lt;/strong&gt;, we had a conversation about some of the patterns and ideas that he might want to consider with the particular application he is writing with WPF. The result of the meeting, after 90 minutes of discussion, was a whiteboard full of pattern names, blocks and arrows, which all appeared to be clearly understood by all involved at the time and we left feeling that it was a job well done. However, it occurred to me on the drive home that when faced with a blank code editor the next morning, would all those squiggles and arrows still make sense?&lt;/p&gt;  &lt;p&gt;That lead me to thinking that a &lt;strong&gt;simple&lt;/strong&gt; application that outlines not just the theory of some of the standard patterns that I use for building applications today, but also shows concrete implementations, real strategies, real code and compromises, not just code snippets of isolated issues, but a complete, albeit simple, application. &lt;/p&gt;  &lt;p&gt;The following sample application, and accompanying screencast, are the results of that thinking. When I handed off both of these to my colleague it also occurred to me that others might benefit from the sample and would also serve as a reminder for me in the future, hence this post. &lt;/p&gt;  &lt;p&gt;The application itself is somewhat trivial, but the patterns and architecture discussed are not. The sample covers:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;ModelView-ViewModel&lt;/strong&gt; (Application architecture) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Repository&lt;/strong&gt; and &lt;strong&gt;Service Patterns&lt;/strong&gt; (data modelling and retrieval) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Command Pattern&lt;/strong&gt; (for communication between the Views and the ViewModels) &lt;strong&gt;&lt;sup&gt;[1]&lt;/sup&gt;&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Various different types of View&lt;/strong&gt;, including Page and Window &lt;strong&gt;&lt;sup&gt;[2]&lt;/sup&gt;&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Text to FlowDocument&lt;/strong&gt; value converter &lt;/li&gt;    &lt;li&gt;Poor man’s &lt;strong&gt;Dependency Injection&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt; &lt;object width="400" height="300"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=7390612&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=7390612&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"&gt;&lt;/embed&gt;&lt;/object&gt;  &lt;p&gt;&lt;a href="http://www.box.net/shared/ud331u4nlm" target="_blank"&gt;&lt;strong&gt;Click here to download the sample code.&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I sincerely hope that you get some value out of this post, and as usual if you have any comments, questions, flames, enhancements I would love to hear from you. In the meantime, think deeply and enjoy.&lt;/p&gt;  &lt;hr /&gt;  &lt;p style="margin-top: 0px; font-size: smaller"&gt;&lt;sup&gt;&lt;strong&gt;[1]&lt;/strong&gt;&lt;/sup&gt;&lt;em&gt; Including a hybrid DelegateCommand class inspired by standard MV-VM commanding, sometimes referred to as a RelayCommand, and Prism’s DelegateCommand implementation&lt;/em&gt;&lt;/p&gt;  &lt;p style="margin-top: 0px; font-size: smaller"&gt;&lt;sup&gt;&lt;strong&gt;[2]&lt;/strong&gt;&lt;/sup&gt;&lt;em&gt; &lt;strong&gt;Page&lt;/strong&gt; based Views and navigation are specific to the application discussed in the 90 minute meeting, where what you would usually see in a traditional MV-VM discussion would be &lt;strong&gt;UserControl&lt;/strong&gt; instances as the Views. I think the use of Pages in the sample makes it a more interesting sample that shows more varied View types than you would normally see.&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-8488942669966948780?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=WiX8WwRwZjE:8ChqoKdQyUI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=WiX8WwRwZjE:8ChqoKdQyUI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/WiX8WwRwZjE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/8488942669966948780/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=8488942669966948780" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/8488942669966948780?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/8488942669966948780?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/WiX8WwRwZjE/wpf-mv-vm-sample-application-with.html" title="WPF: MV-VM Sample Application with Navigation" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/11/wpf-mv-vm-sample-application-with.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08DQ3w-fyp7ImA9WxNUEUo.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-397923301411002145</id><published>2009-10-08T17:35:00.001+01:00</published><updated>2009-11-02T16:37:52.257Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-02T16:37:52.257Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="News" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net" /><title>MSDN Flash</title><content type="html">&lt;p&gt;&lt;strong&gt;Update: 2009-11-02 &lt;/strong&gt;&lt;a href="http://channel9.msdn.com/posts/Eric+Nelson/MSDN-Flash-Podcast-010--Paul-Jackson-on-Memory-Mapped-Files-in-NET-4-Oslo-and-more/" target="_blank"&gt;The podcast is now available on Channel9 too&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_acf4FzpScrE/Ss4UtJ05VEI/AAAAAAAAALQ/mO0lG2RaZfg/s1600-h/aa570311.thumb2%28en-gb%2CMSDN.10%29%5B1%5D%5B3%5D.jpg"&gt;&lt;img style="border-right-width: 0px; margin: 0px 0px 0px 25px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="aa570311.thumb2(en-gb,MSDN.10)[1]" border="0" alt="aa570311.thumb2(en-gb,MSDN.10)[1]" align="right" src="http://lh6.ggpht.com/_acf4FzpScrE/Ss4Ut5GYx-I/AAAAAAAAALU/vJNM4OJkDE8/aa570311.thumb2%28en-gb%2CMSDN.10%29%5B1%5D_thumb%5B1%5D.jpg?imgmax=800" width="153" height="157" /&gt;&lt;/a&gt; At a recent &lt;a href="http://www.gl-net.org.uk/" target="_blank"&gt;GL.NET user group&lt;/a&gt; meeting I met &lt;a href="http://geekswithblogs.net/iupdateable/"&gt;Eric Nelson&lt;/a&gt; (&lt;a href="http://twitter.com/ericnel" target="_blank"&gt;@ericnel&lt;/a&gt;), and he asked me to write an article for the &lt;a href="http://www.microsoft.com/uk/msdn/flash/" target="_blank"&gt;&lt;strong&gt;MSDN Flash newsletter&lt;/strong&gt;&lt;/a&gt; (&lt;a href="http://twitter.com/ukmsdn" target="_blank"&gt;@ukmsdn&lt;/a&gt;), so I did. I expanded on my previous post regarding &lt;a href="http://compilewith.net/2009/06/net4-and-memory-mapped-files.html" target="_blank"&gt;Memory Mapped Files in .NET 4&lt;/a&gt;, and that article has been published today.&lt;/p&gt;  &lt;p&gt;You should be able to read &lt;a href="http://www.microsoft.com/uk/msdn/flash/" target="_blank"&gt;the entire newsletter on-line&lt;/a&gt;, however, at the time of writing this post the &lt;a href="http://www.microsoft.com/uk/msdn/flash/latest.htm" target="_blank"&gt;current newsletter&lt;/a&gt; link was showing last month’s newsletter, but I’m sure that will change very soon. However, I’ve put a copy of the article at the end of this post, if you’re interested in reading it.&lt;/p&gt;  &lt;p&gt;I also did &lt;strong&gt;&lt;a href="http://geekswithblogs.net/iupdateable/archive/2009/10/08/msdn-flash-podcast-show-010-ndash-paul-jackson-on-memory.aspx" target="_blank"&gt;the podcast which accompanies the newsletter&lt;/a&gt;&lt;/strong&gt; with &lt;a href="http://geekswithblogs.net/iupdateable/"&gt;Eric&lt;/a&gt;, and it was an absolute blast. I’ve not done anything like that before so it was quite a departure from my normal working day. You can find all the podcasts &lt;a href="http://bit.ly/msdnpodcast" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;As usual if you have any comments, questions, flames, enhancements I would love to hear from you. In the meantime, think deeply and enjoy.&lt;/p&gt;  &lt;hr /&gt;  &lt;h4&gt;Memory Mapped Files with .NET 4&lt;/h4&gt;  &lt;p&gt;.NET 4 is on its way and there are many new features being blogged about, such as Parallel Computing and Dynamic Languages but the new feature that caught my eye was Memory Mapped Files. The idea of mapping memory to a physical file on disk has been around for a very long time on the Windows platform but this capability has not been available natively in managed code before and instead needed to be accessed via P/Invoke. &lt;/p&gt;  &lt;p&gt;You might be wondering why you would wish to map memory on to a file, and why after numerous versions of the .NET Framework we need this feature now. To answer the first question it is worth pointing out that a memory mapped file is one of &lt;i&gt;the most&lt;/i&gt; efficient ways for multiple processes on a single machine to talk to each other. What is more, most Windows IPC based communication mechanisms, such as COM, DDE, Sockets, Pipes and even Windows Messages themselves all sit on top of Memory Mapped Files. Another reason for using Memory Mapped Files is for processing extremely large files, as they enable random and concurrent access to a file without the need for seeking.&lt;/p&gt;  &lt;p&gt;The large file processing is lovely and all that but I want to talk about inter-process communication on a single machine for a moment. There are many available options. You could go old school by using classic .NET Remoting for cross AppDomain communication by using transparent proxies, MarshalByRef and ContextBoundObject classes. You could code this using WCF and Named-Pipes; as well as all the available cross-machine techniques such as streams and sockets, or Web services by using one the various flavours of WCF Bindings or not forgetting plain old ASMX.&lt;/p&gt;  &lt;p&gt;Given this wealth of options, when should you use Memory Mapped Files (MMF) over, say, WCF? For me, the answer is simple: it depends. As always with new technologies your millage may vary, but I think as a general rule, for IPC on a single machine MMF is the way to go; if only for the relatively simple programming model (see my blog post for a &lt;a href="http://compilewith.net/2009/06/net4-and-memory-mapped-files.html"&gt;simple code example&lt;/a&gt;) and performance characteristics. Sometimes, when you need to send 4 bytes, you should just send 4 bytes; not a Soap envelope, encoded with a myriad of WS-* standards and human readable mark-up running into hundreds and hundreds of bytes – just to send your 4 byte message.&lt;/p&gt;  &lt;p&gt;Memory mapped files will be my first choice for the scenarios that were previously reserved for &lt;i&gt;WCF and Named Pipes&lt;/i&gt;, well, they will be as soon as .NET 4 ships. However, if you even suspect that at some point you might need your communication to spread across machines, then you are better off starting with WCF and named-pipes, because supporting cross machine communication in the future should simply be about making changes to configuration not recoding the communication layer.&lt;/p&gt;  &lt;p&gt;That brings us back to the second question of: why now, why in .NET 4 and not some previous release. For that, we can only guess; but I am glad they finally did! You can find out more in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.memorymappedfiles(VS.100).aspx"&gt;preliminary MSDN documentation&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Paul Jackson&lt;/strong&gt;     &lt;br /&gt;Blog: &lt;a href="http://compilewith.net"&gt;http://compilewith.net&lt;/a&gt;     &lt;br /&gt;LinkedIn: &lt;a href="http://www.linkedin.com/in/paulja"&gt;http://www.linkedin.com/in/paulja&lt;/a&gt;&lt;/p&gt;  &lt;hr /&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-397923301411002145?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=mT753zbKqcY:FQz1gd6KAq4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=mT753zbKqcY:FQz1gd6KAq4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/mT753zbKqcY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/397923301411002145/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=397923301411002145" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/397923301411002145?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/397923301411002145?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/mT753zbKqcY/msdn-flash.html" title="MSDN Flash" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/10/msdn-flash.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUQDSXgycCp7ImA9WxJbGEU.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-3524013993017424665</id><published>2009-07-29T18:09:00.001+01:00</published><updated>2009-07-29T18:09:38.698+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-29T18:09:38.698+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Comment" /><category scheme="http://www.blogger.com/atom/ns#" term="Oslo" /><title>A word on Microsoft Oslo and installing MX files</title><content type="html">&lt;p&gt;Each time I sit down to do something with &lt;a href="http://msdn.com/oslo"&gt;Oslo&lt;/a&gt; I look forward to it. However, I keep tripping over the same issue: &lt;em&gt;I never seem to be able to get the switch combination right the first time&lt;/em&gt;, and often not after the tenth time either! I always seem to burn 30-40 minutes each and every time I try and get my first &lt;strong&gt;.MX&lt;/strong&gt; file into the target datastore.&lt;/p&gt;  &lt;p&gt;This time loss is partly my fault, as for some reason I’ve neglected to write down the command line that &lt;em&gt;works&lt;/em&gt; before moving on. Each and every time I’ve done this; it seems that after I’ve got it working, I look at it and say to myself: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;“&lt;em&gt;Oh, come-on. That’s obvious. I’ll figure it out &lt;strong&gt;easily&lt;/strong&gt; next time&lt;/em&gt;”      &lt;br /&gt;&lt;font size="1"&gt;Quote by: A Pillock&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Well, let me present this post as evidence that this is positively &lt;strong&gt;the last time that it will EVER happen to me again&lt;/strong&gt;. I’ve been duped too many times, I have now learned my lesson… promise. &lt;/p&gt;  &lt;p&gt;I’m just not using the tooling often enough for it to stick, and it’s subtly broken enough to keep tripping me up, so here, for ever more (thanks to &lt;a href="http://google.com"&gt;Google&lt;/a&gt;… oh, and &lt;a href="http://bing.com"&gt;Bing&lt;/a&gt; I guess – the jury is still out on that one though) is what you need to do to get a compiled “M” file into a SQL Express database using Integrated security where SQL Express is &lt;em&gt;not&lt;/em&gt; the default instance, but &lt;em&gt;is&lt;/em&gt; the default SQL Express install (if that makes any sense!?):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font color="#808080" size="2" face="Consolas"&gt;MX install &amp;lt;filename&amp;gt;.mx -s .\SQLEXPRESS -d &amp;lt;database name&amp;gt; -c –f&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Don’t be fooled. I know this looks deceptively simple, but believe me, this is hard won information! Note the spaces between the switch and its value, for example &lt;font face="Consolas"&gt;&lt;font size="2"&gt;&lt;strong&gt;–&lt;em&gt;s &lt;/em&gt;&lt;/strong&gt;&lt;font size="3" face="Calibri"&gt;and&lt;/font&gt; &lt;strong&gt;\SQLEXPRESS&lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;; that’s the thing that &lt;strong&gt;screws with your mind&lt;/strong&gt;. The docs clearly state that a colon “:” between the name value pair should be used, however, I have found this not to be the case! &lt;/p&gt;  &lt;p&gt;I’ve have had it confirmed by &lt;a href="http://twitter.com/csells"&gt;@csells&lt;/a&gt; via &lt;a href="http://twitter.com/pj_"&gt;Twitter&lt;/a&gt; &lt;a href="http://twitter.com/csells/status/2910254838"&gt;that this is indeed a bug&lt;/a&gt;, and I should be able to use a space, colon or even an equals! But I’m telling you now, dear reader, this won’t be catching &lt;strong&gt;&lt;em&gt;ME&lt;/em&gt;&lt;/strong&gt; out again!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-3524013993017424665?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=upbHoQFqw8U:NawUoHQuND0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=upbHoQFqw8U:NawUoHQuND0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/upbHoQFqw8U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/3524013993017424665/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=3524013993017424665" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/3524013993017424665?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/3524013993017424665?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/upbHoQFqw8U/word-on-microsoft-oslo-and-installing.html" title="A word on Microsoft Oslo and installing MX files" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/07/word-on-microsoft-oslo-and-installing.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMGQ3s5fSp7ImA9WxJWEko.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-6136407503006143341</id><published>2009-06-11T09:29:00.001+01:00</published><updated>2009-06-17T23:07:02.525+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-17T23:07:02.525+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Architecture" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net" /><title>.NET4 and Memory Mapped Files</title><content type="html">&lt;p&gt;I think I am really going to like .NET 4:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_acf4FzpScrE/SjDAe1mEvOI/AAAAAAAAAKY/a-ErP2zrbNU/s1600-h/MemoryMappedFiles_Net4%5B10%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="MemoryMappedFiles_Net4" border="0" alt="MemoryMappedFiles_Net4" src="http://lh4.ggpht.com/_acf4FzpScrE/SjDAfW1WTpI/AAAAAAAAAKc/8nMoCnvryPY/MemoryMappedFiles_Net4_thumb%5B6%5D.png?imgmax=800" width="679" height="583" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I certainly welcome this new addition to .NET, and for inter-process communication on a single machine, it’s fabulous. Move over &lt;em&gt;WCF and Named Pipes&lt;/em&gt; memory mapped files coming through. Memory mapped files will be my first choice for the scenarios that were previously reserved for &lt;em&gt;WCF and Named Pipes&lt;/em&gt;, well, as soon as .NET 4 ships.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://en.wikiquote.org/wiki/Stan_Lee"&gt;With great power comes great responsibility&lt;/a&gt;, the memory mapped file approach seriously ups the ante when it comes to understanding and using multithreading in your code; incidentally I highly recommend &lt;a href="http://www.bluebytesoftware.com/"&gt;Joe Duffy&lt;/a&gt;’s &lt;a href="http://www.bluebytesoftware.com/books/winconc/winconc_book_resources.html"&gt;Concurrent Programming on Windows&lt;/a&gt;, it is on my &lt;strong&gt;must read&lt;/strong&gt; list for any developer working in Windows today.&lt;/p&gt;  &lt;p&gt;If this is a topic that you enjoy, you can find more information &lt;a href="http://blogs.msdn.com/salvapatuel/archive/2009/06/08/working-with-memory-mapped-files-in-net-4.aspx"&gt;about this feature in .NET 4 on Salvador Patuel’s blog&lt;/a&gt;. As usual if you have any comments, questions, flames, enhancements I would love to hear from you. In the meantime, think deeply and enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-6136407503006143341?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=JfXOIgmPBcA:aggJ06Pz1Vg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=JfXOIgmPBcA:aggJ06Pz1Vg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/JfXOIgmPBcA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/6136407503006143341/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=6136407503006143341" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6136407503006143341?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6136407503006143341?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/JfXOIgmPBcA/net4-and-memory-mapped-files.html" title=".NET4 and Memory Mapped Files" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total><feedburner:origLink>http://compilewith.net/2009/06/net4-and-memory-mapped-files.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcMSHwzeyp7ImA9WxJWEko.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-326989438801445863</id><published>2009-05-29T17:36:00.001+01:00</published><updated>2009-06-17T23:18:09.283+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-17T23:18:09.283+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>XBAPs and Bitmap Effects</title><content type="html">&lt;p&gt;It has be a while since I last put together an XBAP (&lt;b&gt;X&lt;/b&gt;AML &lt;b&gt;B&lt;/b&gt;rowser &lt;b&gt;Ap&lt;/b&gt;plication), so the myriad of security hurdles that one has to overcome has long since vanished from my short term memory; to the point where I am having to re-learning things. Bugger, I hate that! With that in mind, the purpose of this post is to document something I have rediscovered about XBAP’s and bitmap effects, in an attempt to help me remember and not have to keep relearning the same stuff.&lt;/p&gt;  &lt;p&gt;So first off, bitmap effects are cool; they add a certain pizzazz to your UI, and if used subtly they really can make a big difference in the visual appeal of your UI:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_acf4FzpScrE/SiAO641QxvI/AAAAAAAAAJM/toboYVXTkiY/s1600-h/image%5B12%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_acf4FzpScrE/SiAO7tQZI-I/AAAAAAAAAJQ/XA60VBkhXKY/image_thumb%5B8%5D.png?imgmax=800" width="794" height="190" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;However, you cannot use the &lt;b&gt;BitmapEffect&lt;/b&gt; property on the &lt;b&gt;UIElement&lt;/b&gt; class in an XBAP – note that &lt;b&gt;UIElement&lt;/b&gt; is very high in the object hierarchy for WPF, so just about all visual elements contain this property by way of &lt;strong&gt;UIElement&lt;/strong&gt; and then &lt;strong&gt;FrameworkElement&lt;/strong&gt;; here is how you would use a &lt;strong&gt;BitmapEffect&lt;/strong&gt; in XAML:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;lt;Image Source=&amp;quot;Images\Cube.png&amp;quot;&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image.BitmapEffect&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;BevelBitmapEffect/&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Image.BitmapEffect&amp;gt;       &lt;br /&gt;&amp;lt;/Image&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Attempting to run this XAML from within an XBAP, with the default configuration of Partial Trust, you see the following error message:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_acf4FzpScrE/SiAO8C6YAZI/AAAAAAAAAJU/OxTLP5wJ2O8/s1600-h/image%5B17%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_acf4FzpScrE/SiAO8pGiaWI/AAAAAAAAAJY/OV-So9Z6tps/image_thumb%5B11%5D.png?imgmax=800" width="456" height="299" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Interestingly, this is not a &lt;strong&gt;SecurityException&lt;/strong&gt;, but simply a &lt;strong&gt;XamlParseException&lt;/strong&gt;. However, if you are running in debug mode and happen to check the Output window, you see the following:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_acf4FzpScrE/SiAO_LsAH1I/AAAAAAAAAJc/CN8TIb2RkMw/s1600-h/image%5B21%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_acf4FzpScrE/SiAO_vywHDI/AAAAAAAAAJg/k0wt7djDQXA/image_thumb%5B13%5D.png?imgmax=800" width="746" height="459" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Note that the second to last line &lt;em&gt;is&lt;/em&gt; a &lt;strong&gt;SecurityException&lt;/strong&gt;, so the reason that the XAML cannot be parsed is due to a security failure. If you remove the &lt;strong&gt;BitmapEffect&lt;/strong&gt; from the XAML, and only the &lt;strong&gt;BitmapEffect&lt;/strong&gt;, all works as you would expect. From my experience this is the typical developer experience when falling over a partial trust issue, note that the &lt;strong&gt;SecurityException&lt;/strong&gt; contains no additional information, let the needle in a haystack search begin; but more on that later.&lt;/p&gt;  &lt;p&gt;It is also worth noting that WPF has matured, and is now able to leverage the GPU in your graphics card (or an approximation in software) by way of the &lt;strong&gt;Effect&lt;/strong&gt; class. I am sure that there are some really awesome explanations as to how that works and what that is all really about, but that is not what this post is all about (if you know of a good explanation then please let leave a comment at the end of the post). From the point of view of a developer who has little interest in creating their own effects, to make use of this great feature simply use the new shiny &lt;b&gt;Effect&lt;/b&gt; property, also found on the &lt;b&gt;UIElement&lt;/b&gt; class, introduced in WPF 3.5 SP1.&lt;/p&gt;  &lt;p&gt;However, WPF also does not allow an &lt;b&gt;Effect&lt;/b&gt; class instance in Partial Trust – and therefore you still cannot use one in an XBAP without changing the permission requests. It is worth pointing out that not all the previous bitmap effects have been implemented as &lt;strong&gt;Effect&lt;/strong&gt;‘s; at the time of writing there are only three:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;BlurEffect &lt;/li&gt;    &lt;li&gt;DropShadowEffect &lt;/li&gt;    &lt;li&gt;ShaderEffect (used for creating custom effects) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Meaning that we cannot make use of the GPU today for the following type of effects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Bevel &lt;/li&gt;    &lt;li&gt;Emboss &lt;/li&gt;    &lt;li&gt;OuterGlow &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Personally, I do not think that this is any great loss, as the only effect that I miss is the &lt;b&gt;OuterGlowBitmapEffect&lt;/b&gt;; it may well serve as a good catalyst to prompt me to learn a little more about creating my own effects.&lt;/p&gt;  &lt;p&gt;To add an Effect to your application you use the following XAML:&lt;/p&gt;  &lt;p&gt;&lt;font face="Consolas"&gt;&amp;lt;Image Source=&amp;quot;Images\Cube.png&amp;quot; &amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Image.Effect&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;BlurEffect/&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Image.Effect&amp;gt;       &lt;br /&gt;&amp;lt;/Image&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Attempting to run this XAML from within an XBAP, with the default configuration of Partial Trust, you see the following error message:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_acf4FzpScrE/SiAPBDDE91I/AAAAAAAAAJk/krcxVPVx3bs/s1600-h/image%5B26%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_acf4FzpScrE/SiAPB7_HAXI/AAAAAAAAAJo/D9SQINi_2zc/image_thumb%5B16%5D.png?imgmax=800" width="757" height="440" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This time, while it is a &lt;strong&gt;XamlParseException&lt;/strong&gt;, as before, but Microsoft have massively improved the exception handling with these effects as they actually tell me WHY it has failed: &lt;em&gt;Request for the permission of type ‘System.Security.Permissions.UIPermission’ failed&lt;/em&gt;. Awesome, this means I can “tweak” my security settings to get the application to run when using an &lt;strong&gt;Effect&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_acf4FzpScrE/SiAPC1u7mvI/AAAAAAAAAJs/acjYR-sb0Po/s1600-h/image%5B32%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_acf4FzpScrE/SiAPDW3VPpI/AAAAAAAAAJw/zMo_5Pbz4PA/image_thumb%5B20%5D.png?imgmax=800" width="587" height="516" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now this is the only permission I have to change, I do not have to make my whole application run in Full Trust to use the effects. I can take this a step further in for my application by configuring the properties of the specific permission, to prevent access to the Clipboard, if the application does not need it:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_acf4FzpScrE/SiAPDx4MMoI/AAAAAAAAAJ0/DETy6h27rTU/s1600-h/image%5B36%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_acf4FzpScrE/SiAPEZNUIoI/AAAAAAAAAJ4/DbNW8gHSfT0/image_thumb%5B22%5D.png?imgmax=800" width="410" height="427" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So thanks to the better error reporting when using the &lt;strong&gt;Effect&lt;/strong&gt;’s classes in a partial trust environment, I can now successfully isolate just the permission I need, and make a calculated decision as to whether this is something the application really needs. Note however, tweaking this permission does not work when using the &lt;strong&gt;BitmapEffect&lt;/strong&gt; classes, I still have not found that needle in the haystack yet.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://code.compilewith.net/xbaps/bitmapeffects/paulj.bitmapeffects.xbap"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_acf4FzpScrE/SiAPE2HWvBI/AAAAAAAAAJ8/zxBx9On7BLU/image%5B43%5D.png?imgmax=800" width="321" height="198" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So while I cannot show you the application running in the wild due to the “extra” permission required (click the image above to see the security error), the screenshot above does show the application running in my environment, where I’m happy to allow the application the permission it requires, which is perfect for an intranet or extranet environment. Alternatively, I could sign the application with an SSL certificate and you could trust that.&lt;/p&gt;  &lt;p&gt;Finally, I want to talk quickly about the analyzer tool in Visual Studio 2008. The purpose of the tool is to work out if your application can run in partial trust; it is good at telling me if I need to run in full trust or not, which is very helpful, but it is really poor at telling me WHY! Making it really, really, really hard to fix these violations of partial trust, especially in these cases where I cannot easily remember all the details of what you can and cannot do, or if you are a newbie. As we have seen they have improved the exception handling for an &lt;strong&gt;Effect&lt;/strong&gt;, however, I sincerely hope for more improvements with WPF 4.0 in this area. &lt;strong&gt;&lt;font color="#ff0000"&gt;If anyone knows of any other tooling or a better way to keep on top of this issue, I would love to hear from you&lt;/font&gt;&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;I hope this has been useful, as it was only a small “nice to have” feature that I added to one of my applications and it threw for me quite a while to isolate the problem and get the XBAP working at all, never mind the effects; but it was useful to also explore both &lt;strong&gt;BitmapEffect&lt;/strong&gt; and &lt;strong&gt;Effect&lt;/strong&gt; and work out the differences. &lt;/p&gt;  &lt;p&gt;As usual if you have any comments, questions, flames, enhancements I would love to hear from you. In the meantime, think deeply and enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-326989438801445863?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=gB611revjh0:AhU3GweTvtY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=gB611revjh0:AhU3GweTvtY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/gB611revjh0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/326989438801445863/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=326989438801445863" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/326989438801445863?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/326989438801445863?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/gB611revjh0/xbaps-and-bitmap-effects.html" title="XBAPs and Bitmap Effects" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total><feedburner:origLink>http://compilewith.net/2009/05/xbaps-and-bitmap-effects.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUINRHc8eSp7ImA9WxJWEko.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-5421263857215193753</id><published>2009-05-28T11:36:00.001+01:00</published><updated>2009-06-17T23:26:35.971+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-17T23:26:35.971+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>Invalidate Often, Update Once</title><content type="html">&lt;p&gt;I’ve recently been watching a bunch of the longer sessions from &lt;a href="http://videos.visitmix.com/MIX09/All" target="_blank"&gt;MIX09&lt;/a&gt;, mainly &lt;a href="http://videos.visitmix.com/MIX09/06W" target="_blank"&gt;Hiking Mount Avalon&lt;/a&gt; and &lt;a href="http://nerdplusart.com/" target="_blank"&gt;Robbie Ingebretsen&lt;/a&gt;’s session(s) &lt;a title="Design Fundamentals for Developers" href="http://videos.visitmix.com/MIX09/02W"&gt;Design Fundamentals for Developers&lt;/a&gt;; both of which are about 3 hours long but well worth the time spent watching. &lt;/p&gt;  &lt;p&gt;During these sessions I’ve taken copious notes (by using &lt;a href="http://evernote.com" target="_blank"&gt;Evernote&lt;/a&gt;) and for a few of the more complex and/or unexplored topics I want to write a post, as well as put together some code, on my own to make sure I’ve understood the concept, and to generally share the wealth: this is first post in what I suspect will be a series.&lt;/p&gt;  &lt;p&gt;This post is about updating UI elements on the UI thread. A lot. Time consuming updates. On the UI thread. A lot of updates.&lt;/p&gt;  &lt;p&gt;The example application I’ve written to discuss this technique is described by the following class diagram:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_acf4FzpScrE/Sh5pLQHWztI/AAAAAAAAAI8/upLCtC3iw6U/s1600-h/ObjectModel_UpdateOnce17.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ObjectModel_UpdateOnce1" border="0" alt="ObjectModel_UpdateOnce1" src="http://lh3.ggpht.com/_acf4FzpScrE/Sh5pLlY2QTI/AAAAAAAAAJA/1f3wmRSHqFs/ObjectModel_UpdateOnce1_thumb3.png?imgmax=800" width="570" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And this screenshot:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_acf4FzpScrE/Sh5pMJfpfeI/AAAAAAAAAJE/Wki-3EAPvvI/s1600-h/UI_UpdateOnce13.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="UI_UpdateOnce1" border="0" alt="UI_UpdateOnce1" src="http://lh3.ggpht.com/_acf4FzpScrE/Sh5pMjiKYbI/AAAAAAAAAJI/83vrFN590v8/UI_UpdateOnce1_thumb1.png?imgmax=800" width="240" height="240" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The application consists of a &lt;strong&gt;ListBox&lt;/strong&gt; where the &lt;strong&gt;ItemsSource&lt;/strong&gt; property is set to an &lt;strong&gt;ObservableCollection&amp;lt;int&amp;gt;&lt;/strong&gt;, and then when the &lt;strong&gt;Add Items&lt;/strong&gt; button is clicked a method called &lt;strong&gt;OnAddItems&lt;/strong&gt; appends &lt;em&gt;ten thousand&lt;/em&gt; random integer values to the collection. There is also a listener wired to the &lt;strong&gt;CollectionChanged&lt;/strong&gt; event on the &lt;strong&gt;ObservableCollection&amp;lt;int&amp;gt;&lt;/strong&gt;, which simply invokes a method called &lt;strong&gt;UpdateTotal&lt;/strong&gt; that adds up all the integers currently in the collection, and then presents the calculated value in the UI as the &lt;strong&gt;Total&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;What this application is attempting to simulate is a situation where a large number of items need to be added to the UI in quick succession, but where there is also some additional action required after an item has been added, a calculated value in the example application. Here’s the code for &lt;strong&gt;OnAddItems&lt;/strong&gt;, &lt;strong&gt;OnCollectionChanged&lt;/strong&gt; and &lt;strong&gt;UpdateTotal&lt;/strong&gt; which outlines how these methods interact:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;private void OnAddItems(object sender, RoutedEventArgs e)      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Random rnd = new Random((int)DateTime.Now.Ticks);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; for (int i = 0; i &amp;lt; 10000; i++)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.list.Add(rnd.Next(0, 100));       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; UpdateTotal();       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;private void UpdateTotal()      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int total = 0;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; foreach (var item in this.list)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; total += item; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; this.Total.Text = total.ToString();      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The problem with the code is simply that it’s too noisy on the UI thread. The &lt;strong&gt;OnCollectionChanged&lt;/strong&gt; method is called &lt;em&gt;ten thousand&lt;/em&gt; times, and the list is totalled &lt;em&gt;ten thousand&lt;/em&gt; times as each integer and the UI is also updated &lt;em&gt;tens of thousands&lt;/em&gt; of times. Obviously this example is a little contrived but I’m sure you can think of some real world scenarios or maybe you’ve seen code like this in the wild.&lt;/p&gt;  &lt;p&gt;To give you some idea of how the performance degrades on my machine here’s the debug output for this sample application, which displays the total time it takes, in milliseconds, along with how many items are currently in the list; remember that ten thousand items are appended each time &lt;strong&gt;Add Items&lt;/strong&gt; is clicked:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;Time taken (milliseconds): 787.375,&amp;#160;&amp;#160; # List Items: 10000      &lt;br /&gt;Time taken (milliseconds): 2084.1261, # List Items: 20000       &lt;br /&gt;Time taken (milliseconds): 3344.678,&amp;#160; # List Items: 30000       &lt;br /&gt;Time taken (milliseconds): 4715.5841, # List Items: 40000       &lt;br /&gt;Time taken (milliseconds): 5948.9176, # List Items: 50000       &lt;br /&gt;Time taken (milliseconds): 7232.911,&amp;#160; # List Items: 60000&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Assuming that we all agree that while this is a contrived example it is still a real world problem that needs a solution; and that solution is the WPF &lt;strong&gt;Dispatcher&lt;/strong&gt; and a single &lt;strong&gt;boolean&lt;/strong&gt; flag. Take a look at the following video that I put together to demonstrate how badly the current code impacts the UI thread, and how massive the improvement is by using the &lt;strong&gt;Dispatcher&lt;/strong&gt; and an invalidate approach, as opposed to update approach:&lt;/p&gt; &lt;object width="400" height="300"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4880949&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=4880949&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"&gt;&lt;/embed&gt;&lt;/object&gt;  &lt;p&gt;Here are the the changes to &lt;strong&gt;OnCollectionChanged&lt;/strong&gt; and &lt;strong&gt;UpdateTotal&lt;/strong&gt; methods, and the new &lt;strong&gt;InvalidateTotal&lt;/strong&gt; method that makes this approach work:&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;font face="Consolas"&gt;private bool isTotalValid; &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;…&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&lt;font color="#808080"&gt;private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)        &lt;br /&gt;{         &lt;br /&gt;&lt;/font&gt;&amp;#160;&amp;#160;&amp;#160; InvalidateTotal();       &lt;br /&gt;&lt;font color="#808080"&gt;}&lt;/font&gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;private void InvalidateTotal()      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (this.isTotalValid)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.isTotalValid = false;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; UpdateTotal();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;} &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#808080" size="2" face="Consolas"&gt;private void UpdateTotal()      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int total = 0;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; foreach (var item in this.list)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; total += item; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&lt;font color="#808080"&gt;&amp;#160;&amp;#160;&amp;#160; this.Total.Text = total.ToString();&lt;/font&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; this.isTotalValid = true;       &lt;br /&gt;&lt;font color="#808080"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;With the code above, a new flag has been introduced: &lt;strong&gt;isTotalValid&lt;/strong&gt;, which indicates whether the &lt;strong&gt;UpdateTotal&lt;/strong&gt; method should be called. The &lt;strong&gt;OnCollectionChanged&lt;/strong&gt; method no longer invokes &lt;strong&gt;UpdateTotal&lt;/strong&gt; directly, instead it calls a new method called &lt;strong&gt;InvalidateTotal&lt;/strong&gt;. The new method checks the &lt;strong&gt;isTotalValid&lt;/strong&gt; flag, and if the total is valid promptly marks the total as invalid and queues a asynchronous call to &lt;strong&gt;UpdateTotal&lt;/strong&gt; by using the &lt;strong&gt;Dispatcher&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;By doing this the call to &lt;strong&gt;UpdateTotal&lt;/strong&gt; has been placed on the &lt;strong&gt;Dispatcher&lt;/strong&gt;’s message queue behind the currently executing call, effectively delaying the call to the &lt;strong&gt;UpdateTotal&lt;/strong&gt; method until &lt;em&gt;after&lt;/em&gt; the current thread becomes idle or the scheduler decides to let someone else have a turn, meaning that in most cases the &lt;strong&gt;UpdateTotal&lt;/strong&gt; method is called only once, but &lt;strong&gt;InvalidateTotal&lt;/strong&gt; is called thousands of times. Finally, the &lt;strong&gt;UpdateTotal&lt;/strong&gt; method marks the total as valid once more, and the cycle begins again.&lt;/p&gt;  &lt;p&gt;The key takeaway here, is invalidate rather than update; this is an approach adopted all over WPF, and one that I will certainly be adopting in my WPF code. I also want to offer a &lt;em&gt;big thank&lt;/em&gt; you to Robby Ingebretsen, Jaime Rodriguez, Mike Hillberg, Lee Brenner, Laurent Bugnion and particularly for his help with this post Jonathan Russ, who explained this concept in the &lt;a href="http://videos.visitmix.com/MIX09/06W" target="_blank"&gt;Hiking Mount Avalon&lt;/a&gt; session.&lt;/p&gt;  &lt;p&gt;You can &lt;strong&gt;download&lt;/strong&gt; the sample application from here: &lt;a href="http://www.box.net/shared/a3e4na27af" target="_blank"&gt;&lt;strong&gt;PaulJ.InvalidateOftenUpdateOnce.zip&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As usual if you have any comments, questions, flames, enhancements I would love to hear from you. In the meantime think deeply and enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-5421263857215193753?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=kfIxJfaMcys:s_rdhig8SJs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=kfIxJfaMcys:s_rdhig8SJs:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/kfIxJfaMcys" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/5421263857215193753/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=5421263857215193753" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/5421263857215193753?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/5421263857215193753?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/kfIxJfaMcys/invalidate-often-update-once.html" title="Invalidate Often, Update Once" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://compilewith.net/2009/05/invalidate-often-update-once.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYCQXo9fip7ImA9WxJQE08.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-5151567785077838425</id><published>2009-05-09T12:36:00.001+01:00</published><updated>2009-05-26T09:22:40.466+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-05-26T09:22:40.466+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Architecture" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net" /><title>ICloneable, a perspective on the current guidelines</title><content type="html">&lt;p&gt;To be talking about an interface this old might seem strange, but I’m primarily working with legacy code (code without tests) at the moment, and I’ve seen some &lt;em&gt;uses&lt;/em&gt; of this interface that took me aback, as for me, the thinking shown below has been with me so long it’s almost a subconscious thought; but I felt the need to say it out loud as it might help someone.&lt;/p&gt;  &lt;p&gt;First off, &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.icloneable.aspx" target="_blank"&gt;ICloneable&lt;/a&gt;&lt;/strong&gt; is considered a &lt;em&gt;Bad Thing&lt;sup&gt;&lt;font size="1"&gt;TM&lt;/font&gt;&lt;/sup&gt;&lt;/em&gt;; the reason for this is poor naming in relation to whether the clone is a deep or shallow copy, &lt;a href="http://blogs.msdn.com/brada/archive/2003/04/09/49935.aspx" target="_blank"&gt;see here for more information about this&lt;/a&gt;, but here’s a snippet from &lt;a href="http://blogs.msdn.com/brada" target="_blank"&gt;BradA’s blog&lt;/a&gt; about the use of &lt;strong&gt;ICloneable&lt;/strong&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2003/04/09/49935.aspx" target="_blank"&gt;Because the interface contract does not specify the type of clone performed, different classes have different implementations. A consumer cannot rely on &lt;strong&gt;ICloneable&lt;/strong&gt; to let them know whether an object is deep-cloned or not.&lt;/a&gt;&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Having said that, cloning is useful. Given that we’re not going to be able to change the name of the interface method inside the framework, here are my guidelines for working with cloning and the &lt;strong&gt;ICloneable&lt;/strong&gt; interface:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Do use the &lt;strong&gt;ICloneable&lt;/strong&gt; interface .. but decide upfront in your project whether &lt;strong&gt;Clone&lt;/strong&gt; means a deep or shallow copy .. to be perfectly honest a shallow copy is rarely useful, therefore I nearly always stipulate that &lt;strong&gt;Clone&lt;/strong&gt; means deep; and then, be consistent throughout the code-base. &lt;/li&gt;    &lt;li&gt;If &lt;strong&gt;Clone&lt;/strong&gt; means shallow in your project, then use the Brad’s guideline and create a new interface, say &lt;strong&gt;ICloneable&amp;lt;T&amp;gt;&lt;/strong&gt;, with two methods: &lt;strong&gt;Clone&lt;/strong&gt; and &lt;strong&gt;DeepClone&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;If following step 1, implement the &lt;strong&gt;Clone&lt;/strong&gt; method to be type safe and then also provide a public typed version of the call; for example: &lt;/li&gt; &lt;/ol&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;&lt;font color="#808080"&gt;public class EffectInfo : &lt;font color="#000000"&gt;&lt;strong&gt;ICloneable&lt;/strong&gt;&lt;/font&gt;           &lt;br /&gt;{&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&amp;#160;&amp;#160;&amp;#160; #region ICloneable Members &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#808080"&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;&amp;#160;&amp;#160;&amp;#160; // Typed version of the call            &lt;br /&gt;&lt;/font&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#000000"&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; EffectInfo &lt;strong&gt;Clone()&lt;/strong&gt;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {             &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;return&lt;/font&gt; (EffectInfo)&lt;font color="#0000ff"&gt;this&lt;/font&gt;.MemberwiseClone();&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#808080"&gt;&lt;font face="Consolas"&gt;&lt;font color="#008000"&gt;&amp;#160;&amp;#160;&amp;#160; // Interface implementation            &lt;br /&gt;&lt;/font&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#000000"&gt;&lt;font face="Consolas"&gt;&lt;font color="#0000ff"&gt;object&lt;/font&gt; &lt;strong&gt;ICloneable.Clone()&lt;/strong&gt;             &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {             &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;return this&lt;/font&gt;.Clone();             &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#808080" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; #endregion        &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;em&gt;&amp;lt;digression&amp;gt; The &lt;strong&gt;ICloneable&lt;/strong&gt; interface shipped with v.1.0 of the Framework, generics did not yet exist; therefore to implement a type safe version of an interface you have to do interface implementation and then provide public typed versions of the members, as shown above. &amp;lt;/digression&amp;gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Obviously, if you have the concept of &lt;strong&gt;ICloneable&amp;lt;T&amp;gt;&lt;/strong&gt; in your project, with deep and shallow copies, you do not need to take this approach to get type safe versions of the call.&lt;/p&gt;  &lt;p&gt;As usual if you have any comments, questions, flames, enhancements I would love to hear from you. In the meantime think deeply and enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-5151567785077838425?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=sImnF1Z06WU:XgykyxtutGk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=sImnF1Z06WU:XgykyxtutGk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/sImnF1Z06WU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/5151567785077838425/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=5151567785077838425" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/5151567785077838425?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/5151567785077838425?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/sImnF1Z06WU/icloneable-perspective-on-current.html" title="ICloneable, a perspective on the current guidelines" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://compilewith.net/2009/05/icloneable-perspective-on-current.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkYBQXY5fip7ImA9WxJTFUg.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-3751021686944677304</id><published>2009-04-24T08:29:00.001+01:00</published><updated>2009-04-24T08:29:10.826+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-04-24T08:29:10.826+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="Comment" /><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><category scheme="http://www.blogger.com/atom/ns#" term="Design" /><title>Just say no to the pop-up</title><content type="html">&lt;p&gt;I don’t usually write a blog post to simply &lt;a href="http://blogs.msdn.com/surface/archive/2009/04/24/how-pop-is-the-new-flicker.aspx" target="_blank"&gt;link to some other blog post&lt;/a&gt; (that’s what &lt;a href="http://delicious.com/compilewith.net" target="_blank"&gt;delicious&lt;/a&gt; and &lt;a href="http://twitter.com/pj_" target="_blank"&gt;Twitter&lt;/a&gt; are for), but I think that this is such an important concept for UI design today, and in the future, that I feel the need to underscore it with a blog post:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;font color="#ff8000"&gt;yes, … &amp;quot;pop&amp;quot; is a bad thing.&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Above is a (mangled) quote from the “&lt;a href="http://blogs.msdn.com/surface/archive/2009/04/24/how-pop-is-the-new-flicker.aspx" target="_blank"&gt;&lt;strong&gt;How pop is the new flicker&lt;/strong&gt;&lt;/a&gt;” blog post by the &lt;a href="http://www.microsoft.com/surface/" target="_blank"&gt;Microsoft Surface&lt;/a&gt; team, which highlights a very simple but important aspect for new UI, also illustrated in the following short movie from the same post .. which is: &lt;strong&gt;remove the pop-up&lt;/strong&gt; window/dialog/menu.&lt;/p&gt;  &lt;p&gt;&lt;embed src="http://images.video.msn.com/flash/soapbox1_1.swf" width="432" height="364" id="ofb7g797" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" pluginspage="http://macromedia.com/go/getflashplayer" flashvars="c=v&amp;v=ba9515fe-4e6c-4299-9cf4-a3a31b9a2503&amp;ifs=true&amp;fr=shared&amp;mkt=en-US"&gt;&lt;/embed&gt;&lt;noembed&gt;&lt;a href="http://video.msn.com/?mkt=en-US&amp;amp;playlist=videoByUuids:uuids:ba9515fe-4e6c-4299-9cf4-a3a31b9a2503&amp;amp;showPlaylist=true&amp;amp;from=msnvideo" target="_new" title="Photos grid-stack transition"&gt;Video: Photos grid-stack transition&lt;/a&gt;&lt;/noembed&gt;&lt;/p&gt;  &lt;p&gt;The call to action: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;Read the &lt;/strong&gt;&lt;a href="http://blogs.msdn.com/surface/archive/2009/04/24/how-pop-is-the-new-flicker.aspx" target="_blank"&gt;&lt;strong&gt;post&lt;/strong&gt;&lt;/a&gt;, and then &lt;strong&gt;eliminate the pop-up from your code&lt;/strong&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you do this I believe you’ll dramatically improve the user experience and polish of your application. Obviously you have to put this advice in context with your application as it might not always be appropriate, but as a general rule, if you can replace a pop-up with a transition (made easier by tools such as &lt;a href="msdn.microsoft.com/wpf" target="_blank"&gt;WPF&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/silverlight" target="_blank"&gt;Silverlight&lt;/a&gt;) you will be in a better place, and your users will thank you.&lt;/p&gt;  &lt;p&gt;As usual if you have any comments, questions, flames, enhancements I would love to hear from you. In the meantime think deeply and enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-3751021686944677304?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=Uh9mkUBhNuI:Qv4QamHZx8I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=Uh9mkUBhNuI:Qv4QamHZx8I:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/Uh9mkUBhNuI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/3751021686944677304/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=3751021686944677304" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/3751021686944677304?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/3751021686944677304?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/Uh9mkUBhNuI/just-say-no-to-pop-up.html" title="Just say no to the pop-up" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/04/just-say-no-to-pop-up.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcMQ3s4fCp7ImA9WxVbFks.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-3848112048501104003</id><published>2009-04-02T09:14:00.001+01:00</published><updated>2009-04-02T09:14:42.534+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-04-02T09:14:42.534+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="News" /><category scheme="http://www.blogger.com/atom/ns#" term="Prism" /><title>Have you taken the Prism survey?</title><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/blaine" target="_blank"&gt;Blaine Wastell&lt;/a&gt; has published a survey on his blog about &lt;a href="http://www.codeplex.com/compositewpf" target="_blank"&gt;Prism&lt;/a&gt;, in his words:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;We use this information to understand where we need to improve the guidance for the next release of Prism. If you have ideas for what is needed in the next version of Prism....&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you have used &lt;a href="http://www.codeplex.com/CompositeWPF/" target="_blank"&gt;&lt;strong&gt;Composite WPF (a.k.a. Prism)&lt;/strong&gt;&lt;/a&gt; in any way and want to help shape the next release, &lt;a href="http://blogs.msdn.com/blaine/archive/2009/04/01/have-you-taken-the-prism-survey.aspx" target="_blank"&gt;&lt;strong&gt;please go ahead and take the survey&lt;/strong&gt;&lt;/a&gt; .. it’s about 20 questions and will only take you about 10 minutes.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-3848112048501104003?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=YUXuHpARV6M:uWtGJt2ch4E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=YUXuHpARV6M:uWtGJt2ch4E:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/YUXuHpARV6M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/3848112048501104003/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=3848112048501104003" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/3848112048501104003?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/3848112048501104003?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/YUXuHpARV6M/have-you-taken-prism-survey.html" title="Have you taken the Prism survey?" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/04/have-you-taken-prism-survey.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMHQn47fyp7ImA9WxVbFU4.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-4762481350406907419</id><published>2009-03-30T11:02:00.001+01:00</published><updated>2009-03-31T22:53:53.007+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-31T22:53:53.007+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>WPF unit testing trouble with Pack URIs</title><content type="html">&lt;p&gt;I have been busily coding WPF and Silverlight 2 for the last couple of months, and I will be for at least a few more weeks to come; however, during this development frenzy I ran into an issue with unit testing some new code. I also found an interesting solution to the problem, which required more than a simple query by way of &lt;a href="http://google.com" target="_blank"&gt;Google&lt;/a&gt;, so I thought I’d share the problem and the solution here, just help the boys and girls at Google out a little. &lt;/p&gt;  &lt;p&gt;The code under test relies on certain embedded resources. Said resources are to be consumed by a WPF bootstrapped assembly; therefore each resource is embedded in the assembly by using the build type of &lt;strong&gt;Resource&lt;/strong&gt;, as opposed to &lt;strong&gt;Embedded Resource&lt;/strong&gt;, which in turn means each resource has to be referenced by using a &lt;a title="Pack URI Link to MSDN" href="http://msdn.microsoft.com/en-us/library/aa970069.aspx" target="_blank"&gt;Pack URI&lt;/a&gt;. Therein lies the rub: &lt;em&gt;whenever the unit test attempted to call the code that pulled out any of resources I would get the following&amp;#160; &lt;strong&gt;UriFormatException&lt;/strong&gt;&lt;/em&gt;:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;System.UriFormatException was unhandled      &lt;br /&gt;&amp;#160; Message=&amp;quot;&lt;font color="#ff8000"&gt;Invalid URI: A port was expected because of there is a colon (':') present but the port could not be parsed.&lt;/font&gt;&amp;quot;       &lt;br /&gt;&amp;#160; Source=&amp;quot;System&amp;quot;       &lt;br /&gt;&amp;#160; StackTrace:       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; at System.Uri..ctor(String uriString, UriKind uriKind)&lt;/font&gt; … &amp;lt;snip/&amp;gt; &lt;/p&gt;  &lt;p&gt;Bugger! You can easily reproduce this error by running the following code snippet in anything other than a WPF application:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;var packUri = new Uri(      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;quot;&lt;font color="#808080"&gt;pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml&lt;/font&gt;&amp;quot;,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; UriKind.Absolute);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;As the test harness is not bootstrapped by a WPF application it knows absolutely nothing about Pack URIs; and in my case the &lt;strong&gt;System.Uri&lt;/strong&gt; parsing code ended up trying to parse the Pack URI as if it were a Web URI, which is clearly not what I wanted and creates a situation where all roads lead to Exception City.&lt;/p&gt;  &lt;p&gt;However, all is not lost, here is the simple solution I used for my tests:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;if (!UriParser.IsKnownScheme(&amp;quot;pack&amp;quot;))      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; UriParser.Register(new GenericUriParser       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; (GenericUriParserOptions.GenericAuthority), &amp;quot;pack&amp;quot;, -1);       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;If you run this code before you try to parse any Pack URIs all will be well. It is worth mentioning that you need to only call this code once per process. This code registers &lt;strong&gt;pack&lt;/strong&gt; as a valid scheme (in the form of &lt;em&gt;pack://&lt;/em&gt;) and then puts all URI parsing into a generic mode, only parsing against registered schemes (which pack is now one), and that is it .. the job, as they say, is a good ‘un.&lt;/p&gt;  &lt;p&gt;I’ve written a small test application that tests the URI parsing across threads to prove that the &lt;strong&gt;Register&lt;/strong&gt; call is truly process wide, which &lt;strong&gt;you can download from here&lt;/strong&gt;: &lt;a title="Code Download" href="http://www.box.net/shared/dnpzcyetje" target="_blank"&gt;PaulJ.PackUriParsing.zip&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;img src="http://farm4.static.flickr.com/3544/3397622261_7162b6796e_o.png" width="600" height="139" /&gt; &lt;/p&gt;  &lt;p&gt;Above is a screenshot of the app .. the first call shows the parse failing, before the call to &lt;strong&gt;Register&lt;/strong&gt;, then the second two calls show the exact same Pack URI being parsed successfully on two different threads (the main UI thread, and a newly created thread for the test).&lt;/p&gt;  &lt;p&gt;I hope this helps to make for a better Google experience for someone; as usual if you have any comments, questions, flames, enhancements I would love to hear from you. In the meantime think deeply and enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-4762481350406907419?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=TxILdTTEhrg:WL9w70VddE8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=TxILdTTEhrg:WL9w70VddE8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/TxILdTTEhrg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/4762481350406907419/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=4762481350406907419" title="16 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/4762481350406907419?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/4762481350406907419?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/TxILdTTEhrg/wpf-unit-testing-trouble-with-pack-uris.html" title="WPF unit testing trouble with Pack URIs" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">16</thr:total><feedburner:origLink>http://compilewith.net/2009/03/wpf-unit-testing-trouble-with-pack-uris.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D04NQXs4cSp7ImA9WxVVGEg.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-6816804264376196061</id><published>2009-03-12T09:31:00.001Z</published><updated>2009-03-12T11:06:30.539Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-12T11:06:30.539Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>Taskbar Compass: how to use NotifyIcon in WPF</title><content type="html">&lt;p&gt;&lt;img border="0" alt="TaskbarCompass_design" align="right" src="http://static.flickr.com/3298/3341804446_de1267d3a7_t.jpg" /&gt;There are a number of options available ranging from a &lt;a href="http://www.codeplex.com/" target="_blank"&gt;CodePlex&lt;/a&gt; rewrite of the whole &lt;strong&gt;NotifyIcon&lt;/strong&gt; control using the native WIN32 APIs to simply reusing the Windows Forms version of the control. I did not want to take a dependency on code that I did not have to, so in this case so I went with the Windows Forms version. It has all I need, and the implementation is really simple to boot.&lt;/p&gt;  &lt;p&gt;This is the process I followed in my WPF app:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create an Icon (I use &lt;a href="http://www.getpaint.net/download.html" target="_blank"&gt;Paint.NET&lt;/a&gt; with &lt;a href="http://www.evanolds.com/pdnicocur.html" target="_blank"&gt;this plug-in&lt;/a&gt; to create icons) &lt;/li&gt;    &lt;li&gt;Add the new icon to your project as a resource Windows Forms style .. &lt;strong&gt;not as a Resource build type&lt;/strong&gt; but as &lt;strong&gt;EmbeddedResource&lt;/strong&gt; (I tend to put icons in a folder with the name &lt;em&gt;Resources&lt;/em&gt; and then use then use the &lt;strong&gt;Resources&lt;/strong&gt; tab in the projects &lt;strong&gt;Properties&lt;/strong&gt;). &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;App&lt;/strong&gt; class, override the &lt;strong&gt;OnStartup&lt;/strong&gt; method, and then create your &lt;strong&gt;NotifyIcon&lt;/strong&gt; instance: &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2" face="Consolas"&gt;private System.Windows.Forms.NotifyIcon notify;        &lt;br /&gt;...         &lt;br /&gt;        &lt;br /&gt;this.notify = new System.Windows.Forms.NotifyIcon();         &lt;br /&gt;this.notify.Text = &amp;quot;Taskbar Compass&amp;quot;;         &lt;br /&gt;this.notify.Icon = PaulJ.TaskbarCompass.Properties.Resources.Compass;         &lt;br /&gt;this.notify.Visible = true;         &lt;br /&gt;this.notify.ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[]         &lt;br /&gt;{         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; new System.Windows.Forms.MenuItem(&amp;quot;Show compass&amp;quot;, (s, e) =&amp;gt; this.MainWindow.Show()),         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; new System.Windows.Forms.MenuItem(&amp;quot;Hide compass&amp;quot;, (s, e) =&amp;gt; this.MainWindow.Hide()),         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; new System.Windows.Forms.MenuItem(&amp;quot;-&amp;quot;),         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; new System.Windows.Forms.MenuItem(&amp;quot;Close&amp;quot;, (s, e) =&amp;gt; this.Shutdown())         &lt;br /&gt;});&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;In the &lt;strong&gt;App&lt;/strong&gt; class, over the &lt;strong&gt;OnExit&lt;/strong&gt; method, and then dispose the &lt;strong&gt;NotifyIcon&lt;/strong&gt;; otherwise the icon will hang around after the application is closed: &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2" face="Consolas"&gt;if (this.notify != null)        &lt;br /&gt;{         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; this.notify.Dispose();         &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;And there you have it. I have updated the Taskbar Compass sample application (initially created &lt;a href="http://compilewith.net/2009/03/taskbar-compass-how-to-use.html" target="_blank"&gt;in this post&lt;/a&gt;) to now include with a &lt;strong&gt;NotifyIcon&lt;/strong&gt;, which you can &lt;strong&gt;download&lt;/strong&gt; from here: &lt;strong&gt;&lt;a href="http://www.box.net/shared/nvvl0f1fnu" target="_blank"&gt;TaskbarCompass.zip&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;As usual if you have a comments, questions, flames, enhancements I would love to hear from you; in the meantime think deeply and enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-6816804264376196061?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=08THS04zVzE:tr-2xMOKSHM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=08THS04zVzE:tr-2xMOKSHM:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/08THS04zVzE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/6816804264376196061/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=6816804264376196061" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6816804264376196061?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6816804264376196061?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/08THS04zVzE/taskbar-compass-how-to-use-notifyicon.html" title="Taskbar Compass: how to use NotifyIcon in WPF" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://compilewith.net/2009/03/taskbar-compass-how-to-use-notifyicon.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQMQnY9fCp7ImA9WxVVFkw.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-1312513390021781840</id><published>2009-03-09T16:33:00.001Z</published><updated>2009-03-09T16:33:03.864Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-09T16:33:03.864Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>The Taskbar Compass: how to use the SHAppBarMessage Windows API</title><content type="html">&lt;p&gt;Over the last couple of weeks I’ve been writing production code in both Silverlight 2 and WPF; during that development I have had a need to provide a custom notify icon in WPF, to which I chose to the WinForms version as opposed to the myriad of versions available on &lt;a href="http://www.codeplex.com/" target="_blank"&gt;Codeplex&lt;/a&gt;, but that’s a whole different post. &lt;/p&gt;  &lt;p&gt;One issue that I came across was that I wanted my custom popup window to be positioned based on the location of the Windows Taskbar. There did not appear to be a WPF API to help there, so I resorted to the Win32 API and the &lt;strong&gt;SHAppBarMessage&lt;/strong&gt; call:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2" face="Consolas"&gt;[DllImport(&amp;quot;shell32&amp;quot;, CallingConvention = CallingConvention.StdCall)]        &lt;br /&gt;private static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData);&lt;/font&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The &lt;strong&gt;APPBARDATA&lt;/strong&gt; class is a simple &lt;em&gt;struct&lt;/em&gt; that provides, amongst a few other things, the location of the Taskbar on the screen (left, top, right or bottom). By way of an example I’ve written a fun little application that I call the &lt;strong&gt;Taskbar Compass&lt;/strong&gt; that points to the current position of the Taskbar. &lt;/p&gt;  &lt;p&gt;The idea is that the red arrow points to where the Taskbar currently is. The application also listens for changes in user preferences and updates the compass if the Taskbar is moved. You can drag the window around as you would expect and a right mouse close will close it down. Take a look at a little movie I did to show the app in action:&lt;/p&gt; &lt;embed src="http://images.video.msn.com/flash/soapbox1_1.swf" width="432" height="364" id="nc3uiqrd" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" pluginspage="http://macromedia.com/go/getflashplayer" flashvars="c=v&amp;v=9be37e4c-6644-4961-a5f9-771e76cefe35&amp;ifs=true&amp;fr=msnvideo&amp;mkt=en-GB"&gt;&lt;/embed&gt;&lt;noembed&gt;&lt;br/&gt;&lt;a href="http://video.msn.com/video.aspx?vid=9be37e4c-6644-4961-a5f9-771e76cefe35" target="_new" title="Taskbar Compass"&gt;Video: Taskbar Compass&lt;/a&gt;&lt;/noembed&gt;   &lt;p&gt;You can &lt;strong&gt;download&lt;/strong&gt; the sample application from here: &lt;strong&gt;&lt;a href="http://www.box.net/shared/nvvl0f1fnu" target="_blank"&gt;TaskbarCompass.zip&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;As usual if you have a comments, questions, flames, enhancements I would love to hear from you; in the meantime think deeply and enjoy.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-1312513390021781840?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=vj3nIpdSxbo:T56O_NnWbPk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=vj3nIpdSxbo:T56O_NnWbPk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/vj3nIpdSxbo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/1312513390021781840/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=1312513390021781840" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/1312513390021781840?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/1312513390021781840?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/vj3nIpdSxbo/taskbar-compass-how-to-use.html" title="The Taskbar Compass: how to use the SHAppBarMessage Windows API" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/03/taskbar-compass-how-to-use.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUAQHk-fSp7ImA9WxVVFUQ.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-6013793726702438876</id><published>2009-03-08T21:37:00.007Z</published><updated>2009-03-09T10:24:01.755Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-09T10:24:01.755Z</app:edited><title>Synchronisation shock… you do not need Lock</title><content type="html">&lt;p&gt;When you write code that must work in a concurrent environment you may have to synchronise access a resource. It is very common to use a semaphore for this need; .NET is no different, and provides the &lt;strong&gt;Monitor&lt;/strong&gt; class specifically for this purpose. You use the &lt;strong&gt;Monitor&lt;/strong&gt; class like so:&lt;/p&gt;&lt;pre&gt;&lt;font size="2" face="Consolas"&gt;private static object SyncObject = new object();&lt;br /&gt;...&lt;br /&gt;Monitor.Enter(SyncObject);&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;    // thread sensitive code&lt;br /&gt;}&lt;br /&gt;finally&lt;br /&gt;{&lt;br /&gt;    Monitor.Exit(SyncObject);&lt;br /&gt;}&lt;/font&gt;&lt;/pre&gt;&lt;p&gt;This code enters in to a critical section of code by using the &lt;strong&gt;Monitor.Enter()&lt;/strong&gt; method, passing in a static sync object on which all threads can block; creating a mechanism to synchronise access to a thread sensitive resource. Then, after the code has completed its work with the resource, in the finally block, it exits the critical section with a call to &lt;strong&gt;Monitor.Exit()&lt;/strong&gt; handing in the same sync lock object. &lt;/p&gt;&lt;p&gt;This was considered a common scenario by the C# designer, so common in fact a special keyword for exists to facilitate this pattern of &lt;strong&gt;Monitor&lt;/strong&gt; usage; the keyword is called &lt;em&gt;lock&lt;/em&gt;, and the following code that uses the &lt;em&gt;lock&lt;/em&gt; keyword is semantically the same as the code shown above:&lt;/p&gt;&lt;pre&gt;&lt;font size="2" face="Consolas"&gt;private static object SyncObject = new object();&lt;br /&gt;...&lt;br /&gt;lock(SyncObject)&lt;br /&gt;{&lt;br /&gt;    // thread sensitive code&lt;br /&gt;}&lt;/font&gt;&lt;/pre&gt;&lt;p&gt;It is worth mentioning that the &lt;em&gt;lock&lt;/em&gt; keyword does not actually do anything special; it simply emits the same code shown in the first code snippet in this post, by wrapping the use of the &lt;strong&gt;Monitor&lt;/strong&gt; class in a &lt;em&gt;try/finally&lt;/em&gt; guaranteeing that you exit the &lt;strong&gt;Monitor&lt;/strong&gt; on exception.&lt;/p&gt;&lt;p&gt;While I would find it difficult to argue that this code is not simpler and cleaner than direct &lt;strong&gt;Monitor&lt;/strong&gt; usage, I do assert &lt;strong&gt;that this is actually very rare scenario, and almost certainly not common enough to warrant a keyword all of its own&lt;/strong&gt;! This may sound a little controversial but let me explain.&lt;/p&gt;&lt;p&gt;Consider for a moment that the vast majority of code that needs to be synchronised needs to also be atomic; therefore, if an exception is thrown during the execution of the code within the critical section you would not want your application to hobble on using potentially corrupt or broken data by blindly exiting the critical section. This would almost certainly put your application is an unstable state, creating intermittent and really tough to find and debug errors. &lt;/p&gt;&lt;p&gt;Now consider the scenario where you &lt;strong&gt;do not leave the critical section on error&lt;/strong&gt; and simply report the exception &lt;strong&gt;and let the application hang the thread&lt;/strong&gt;. Now you are in a situation that’s much easier to debug, as you’ll most likely be very near the call site where the error occurred, and your application is then not &lt;em&gt;allowed&lt;/em&gt; to continue in an inconsistent state, which is a very good thing in my book.&lt;/p&gt;&lt;p&gt;Here’s a little sample code, showing what I think to be a more common scenario than that promoted by the use of the &lt;em&gt;lock&lt;/em&gt; keyword:&lt;/p&gt;&lt;pre&gt;&lt;font size="2" face="Consolas"&gt;private static object SyncObject = new object();&lt;br /&gt;...&lt;br /&gt;Monitor.Enter(SyncObject);&lt;br /&gt;// thread sensitive code&lt;br /&gt;Monitor.Exit(SyncObject);&lt;/font&gt;&lt;/pre&gt;&lt;p&gt;Note this time there is no&lt;em&gt; try/finally&lt;/em&gt;, so the code will stop on any unhandled exception (good thing). Obviously you can still wrap code of this nature in a &lt;em&gt;try/catch&lt;/em&gt;, but then the normal rules of engagement come into play with regards to exception handling; it may even be appropriate to exit the critical section in the exception handler, and in that exception case you should probably use the &lt;em&gt;lock&lt;/em&gt; keyword. However, &lt;strong&gt;I think that situation is rare; about as rare as actually handling a known exception&lt;/strong&gt;, which of course you should only do when you can actually do something about it.&lt;/p&gt;&lt;p&gt;As usual if you have a comments, questions, flames, enhancements I would love to hear from you; but in the meantime happy multithreading, the future is concurrent and massively multithreaded, so think deeply and enjoy.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-6013793726702438876?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=-STHawKIoLk:Pzja10bNtCM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=-STHawKIoLk:Pzja10bNtCM:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/-STHawKIoLk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/6013793726702438876/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=6013793726702438876" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6013793726702438876?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6013793726702438876?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/-STHawKIoLk/synchronisation-shock-you-do-not-need.html" title="Synchronisation shock… you do not need Lock" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://compilewith.net/2009/03/synchronisation-shock-you-do-not-need.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcHQng9cCp7ImA9WxVWFkk.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-6545336609456891066</id><published>2009-02-26T09:20:00.001Z</published><updated>2009-02-26T09:20:33.668Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-26T09:20:33.668Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="News" /><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><title>GL.NET Group Meeting … the code</title><content type="html">&lt;p&gt;The first &lt;a href="http://www.gl-net.org.uk/"&gt;Gloucestershire .NET User Group&lt;/a&gt; meeting was a great success; a big thank you to all that came along, I hope you enjoyed the talks.&lt;/p&gt;  &lt;p&gt;As promised here’s the image from my talk on &lt;strong&gt;Sockets in Silverlight 2&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a title="Silverlight.Sockets.Large" href="http://www.flickr.com/photos/10896098@N07/3311321896/"&gt;&lt;img border="0" alt="Silverlight.Sockets.Large" src="http://static.flickr.com/3432/3311321896_4cd0a7e734.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The code is available for download here: &lt;a title="Code Download" href="http://www.box.net/shared/5gy1cgboy7" target="_blank"&gt;&lt;strong&gt;SilverlightSockets.zip&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.gl-net.org.uk/Events/GLnet_March.aspx" target="_blank"&gt;The next meeting is scheduled for the &lt;strong&gt;25th March&lt;/strong&gt;, same place and time&lt;/a&gt;. If you have any questions or comments about the talk, Silverlight, WPF or you just have something to say then, as always, I’d love to hear from you.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-6545336609456891066?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=mC0lPV37NHc:W5xcy_YhbBQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=mC0lPV37NHc:W5xcy_YhbBQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/mC0lPV37NHc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/6545336609456891066/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=6545336609456891066" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6545336609456891066?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6545336609456891066?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/mC0lPV37NHc/glnet-group-meeting-code.html" title="GL.NET Group Meeting … the code" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/02/glnet-group-meeting-code.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQAQ3w5cSp7ImA9WxVRE0o.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-2727616677985605049</id><published>2009-01-19T14:45:00.001Z</published><updated>2009-01-19T14:45:42.229Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-01-19T14:45:42.229Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="News" /><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net" /><title>GL.NET Group Meeting</title><content type="html">&lt;p&gt;&lt;img style="margin: 0px 0px 0px 20px; display: inline" align="right" src="http://i.msdn.microsoft.com/aa905717.gl_net(en-gb,MSDN.10).gif" /&gt; The first &lt;a href="http://www.gl-net.org.uk/"&gt;Gloucestershire .NET User Group&lt;/a&gt; meeting &lt;a href="http://www.gl-net.org.uk/Events/GLnet_February.aspx"&gt;date and agenda&lt;/a&gt; has been set (&lt;em&gt;well done &lt;/em&gt;&lt;a href="http://devlicio.us/blogs/ziemowit_skowronski/"&gt;&lt;em&gt;Jimmy&lt;/em&gt;&lt;/a&gt;). There will be two presentations: &lt;strong&gt;What’s new in C# 4.0&lt;/strong&gt; by &lt;a href="http://www.guysmithferrier.com/"&gt;Guy Smith-Ferrier&lt;/a&gt;, and the second by me on &lt;strong&gt;Sockets in Silverlight 2&lt;/strong&gt;. The idea for my presentation is to code up a simple &lt;a href="http://silverlight.net/default.aspx"&gt;Silverlight 2&lt;/a&gt; socket based application in front of your very eyes, Quick Start Guide style. &lt;/p&gt;  &lt;p&gt;It should be a fun evening; would be great to see &lt;strong&gt;you&lt;/strong&gt; there.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-2727616677985605049?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=bu6uob1zv0I:9LmSi8N0cHA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=bu6uob1zv0I:9LmSi8N0cHA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/bu6uob1zv0I" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/2727616677985605049/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=2727616677985605049" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/2727616677985605049?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/2727616677985605049?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/bu6uob1zv0I/glnet-group-meeting.html" title="GL.NET Group Meeting" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/01/glnet-group-meeting.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0ADRHY8fip7ImA9WxBSFEs.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-6377260331205996841</id><published>2009-01-09T08:57:00.001Z</published><updated>2009-12-22T08:16:15.876Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-22T08:16:15.876Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><title>MIX09 10K Smart Coding Challenge</title><content type="html">&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; &lt;em&gt;Sadly all good things must come to an end; the &lt;/em&gt;&lt;a href="http://visitmix.com/" target="_blank"&gt;&lt;em&gt;MIX09 event&lt;/em&gt;&lt;/a&gt;&lt;em&gt; is now over; I do not know how long they’ll keep the 10K completion pages alive for so I have uploaded my entry to the &lt;/em&gt;&lt;a href="http://silverlight.live.com/" target="_blank"&gt;&lt;em&gt;Silverlight Streaming Service&lt;/em&gt;&lt;/a&gt;&lt;em&gt; (which is awesome BTW) and provides a simple page to host my entry&lt;/em&gt;: &lt;a title="http://code.compilewith.net/pj.fviz.html" href="http://code.compilewith.net/pj.fviz.html"&gt;&lt;strong&gt;&lt;font color="#ff8000"&gt;http://code.compilewith.net/pj.fviz.html&lt;/font&gt;&lt;/strong&gt;&lt;/a&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;–PJ&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://2009.visitmix.com/MIXtify/TenKDisplay.aspx?SubmissionID=0062"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="logo" border="0" alt="logo" align="right" src="http://lh5.ggpht.com/_acf4FzpScrE/SzCATiTC1iI/AAAAAAAAAM0/xJPjFOLCFXo/logo%5B3%5D.gif?imgmax=800" width="201" height="154" /&gt; My entry for the 10K coding challenge&lt;/a&gt; has been accepted, &lt;strong&gt;let the voting begin&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;The basic premise for my idea is to visualize RSS or ATOM feeds. I don’t know about you but I have loads of feeds in my &lt;a href="http://reader.google.com"&gt;RSS reader&lt;/a&gt; and I come in to contact with countless others during my day; sometimes I just want a quick &lt;em&gt;fingerprint&lt;/em&gt; of what the feed looks like, a snapshot of what they talk about, how often they post over what time frame etc. etc.&lt;/p&gt;  &lt;p&gt;To that end the &lt;strong&gt;Visualizer&lt;/strong&gt; was born:&lt;/p&gt;  &lt;p&gt;&lt;a title="PJ.FViz.Screenshot" href="http://www.flickr.com/photos/10896098@N07/3177196625/"&gt;&lt;img border="0" alt="PJ.FViz.Screenshot" src="http://static.flickr.com/3501/3177196625_8903701c21.jpg" width="300" height="158" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Above is a screenshot of the application, showing three feeds: &lt;a href="http://compilewith.net/"&gt;this blog&lt;/a&gt;, &lt;a href="http://cloudstore.blogspot.com/"&gt;Derek’s Cloudstore&lt;/a&gt; and the feed for &lt;a href="http://www.hanselman.com/"&gt;Scott Hanselman’s site&lt;/a&gt;. The following is the help for the application that describes each element within the UI:&lt;/p&gt;  &lt;p&gt;&lt;a title="PJ.FViz.Help" href="http://www.flickr.com/photos/10896098@N07/3179549054/"&gt;&lt;img border="0" alt="PJ.FViz.Help" src="http://static.flickr.com/3126/3179549054_3ae58904e8.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Also, I’d like to point out the crux of the challenge: &lt;em&gt;this has to all be achieved in &lt;strong&gt;10K&lt;/strong&gt; or less of source code.&lt;/em&gt; Source code includes all &lt;em&gt;.cs&lt;/em&gt; and &lt;em&gt;.xaml&lt;/em&gt; files as well as any resources and/or images used; a challenge indeed.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;I would really appreciate it if you would take the time and &lt;a href="http://2009.visitmix.com/MIXtify/TenKDisplay.aspx?SubmissionID=0062"&gt;pop on over to my entry&lt;/a&gt; and vote…&lt;/strong&gt; I’m not asking for 5 stars or anything (although that would be nice :o), I’m just after your vote. As always if you have any other comments or suggestions please let me know.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-6377260331205996841?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=qfgdYwOu6wo:MotEKJkB0fY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=qfgdYwOu6wo:MotEKJkB0fY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/qfgdYwOu6wo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/6377260331205996841/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=6377260331205996841" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6377260331205996841?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6377260331205996841?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/qfgdYwOu6wo/mix09-10k-smart-coding-challenge.html" title="MIX09 10K Smart Coding Challenge" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/01/mix09-10k-smart-coding-challenge.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0cBQHYycSp7ImA9WxVSEk4.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-2208372474590605110</id><published>2009-01-02T15:29:00.001Z</published><updated>2009-01-06T09:44:11.899Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-01-06T09:44:11.899Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>ScrollViewer customization – Part 2</title><content type="html">&lt;p&gt;Carrying on from &lt;a href="http://compilewith.net/2009/01/scrollviewer-customization.html"&gt;my previous post&lt;/a&gt;, I&amp;#8217;ve added a little more functionality to the &lt;strong&gt;CyclicScrollViewer&lt;/strong&gt; control. I have added code to handle &lt;em&gt;horizontal scrolling&lt;/em&gt; and included an &lt;em&gt;attached property&lt;/em&gt; for turning off the cyclic behaviour, making the control behave similar to a standard &lt;strong&gt;ScrollViewer&lt;/strong&gt; . I have also created a sample application to show all these new features:&lt;/p&gt;  &lt;p&gt;&lt;img style="margin: 0px 25px 20px 0px" border="0" alt="CyclicListBox" align="left" src="http://static.flickr.com/3063/3159223177_1581a2e3ff.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;For the top two &lt;strong&gt;ListBoxes&lt;/strong&gt; cyclic scrolling is enabled; so, if you click and hold the &lt;strong&gt;ScrollBar&lt;/strong&gt; buttons the list goes around and around as you would expect. However, for the bottom &lt;strong&gt;ListBox&lt;/strong&gt; the &lt;strong&gt;CyclicScrollViewer&lt;/strong&gt; is in use, but the&amp;#160; &lt;strong&gt;CanContentCycle&lt;/strong&gt; attached property has been set to &lt;em&gt;False&lt;/em&gt; (the default is &lt;em&gt;True&lt;/em&gt;).&lt;/p&gt;  &lt;p&gt;Here&amp;#8217;s the code for the attached dependency property:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;public static readonly DependencyProperty CanContentCycleProperty =      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; DependencyProperty.&lt;strong&gt;RegisterAttached&lt;/strong&gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;CanContentCycle&amp;quot;,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(bool),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeof(CyclicScrollViewer),       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new FrameworkPropertyMetadata(true) { &lt;strong&gt;Inherits = true&lt;/strong&gt; });&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The reason I wanted to show this code is that there is a gotcha when working with attached properties in this way: by that I mean when you apply them to parent containers as opposed to child objects (you apply a &lt;strong&gt;DockPanel&lt;/strong&gt;&amp;#8217;s attach properties to the elements it contains, as opposed to the containing element). In our case, we&amp;#8217;re contained rather that containing. Anyway, ensure you replace the property metadata, by using a &lt;strong&gt;FrameworkPropertyMetadata&lt;/strong&gt; instance, and set the &lt;strong&gt;Inherits&lt;/strong&gt; to &lt;em&gt;true&lt;/em&gt;; otherwise all you&amp;#8217;ll see at runtime is the default value, no matter what you&amp;#8217;d applied it in the code. Here&amp;#8217;s how to use the property:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;lt;ListBox ...      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;strong&gt;l:CyclicScrollViewer.CanContentCycle=&amp;quot;False&amp;quot;&lt;/strong&gt; /&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;What you may notice if you &lt;a href="http://www.box.net/shared/sndurzjkrd"&gt;&lt;strong&gt;download&lt;/strong&gt; the sample application&lt;/a&gt; is that we&amp;#8217;re still missing one key feature&amp;#8230; &lt;strong&gt;&lt;em&gt;keyboard support&lt;/em&gt;&lt;/strong&gt;. Currently items only cycle if you use your mouse on the &lt;strong&gt;ScrollBar&lt;/strong&gt; buttons, so that&amp;#8217;s the next feature.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Here's an &lt;a href="http://code.compilewith.net/xbaps/scrollviewer/PaulJ.Web.CyclicScrollViewer.xbap"&gt;XBAP version&lt;/a&gt; of the sample application for your viewing pleasure.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-2208372474590605110?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=JkV0bVv-60g:ldleWA3lfzs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=JkV0bVv-60g:ldleWA3lfzs:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/JkV0bVv-60g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/2208372474590605110/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=2208372474590605110" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/2208372474590605110?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/2208372474590605110?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/JkV0bVv-60g/scrollviewer-customization-part-2.html" title="ScrollViewer customization – Part 2" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/01/scrollviewer-customization-part-2.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EARH0_fSp7ImA9WxVTGEU.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-5974476706005612805</id><published>2009-01-02T09:47:00.001Z</published><updated>2009-01-02T09:47:25.345Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-01-02T09:47:25.345Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>ScrollViewer customization</title><content type="html">&lt;p&gt;Another &lt;a href="http://stackoverflow.com/"&gt;StackOverflow&lt;/a&gt; &lt;a href="http://stackoverflow.com/questions/389341/wpf-listbox-can-you-make-it-cycle-ie-not-hit-hard-stops-at-top-and-bottom"&gt;question&lt;/a&gt;; this time about making a &lt;strong&gt;ListBox&lt;/strong&gt; cycle its contents when scrolling. The question:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;WPF ListBox: Can you make it cycle? i.e. not hit hard stops at top and bottom&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Seems like a pretty simple request: make a circular list, i.e. when you roll off the end of the list start from the beginning again (or end depending on which direction you scrolled in). After a quick examination of the control template for a &lt;strong&gt;ListBox&lt;/strong&gt; I figured that a good solution might be to try and work with the &lt;strong&gt;ScrollViewer&lt;/strong&gt; control, and see if I could get that to cycle... then I could simply replace the &lt;strong&gt;ScrollViewer&lt;/strong&gt; instance in the control template for the &lt;strong&gt;ListBox&lt;/strong&gt;, job done!&lt;/p&gt;  &lt;p&gt;So that's what I did:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;public class CyclicScrollViewer : ScrollViewer     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public CyclicScrollViewer()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.CommandBindings.Add(new CommandBinding(ScrollBar.LineUpCommand, LineCommandExecuted));      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.CommandBindings.Add(new CommandBinding(ScrollBar.LineDownCommand, LineCommandExecuted));      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; private void LineCommandExecuted(object sender, ExecutedRoutedEventArgs e)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (e.Command == ScrollBar.LineUpCommand)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (this.VerticalOffset == 0)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.ScrollToEnd();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; else      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.LineUp();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (e.Command == ScrollBar.LineDownCommand)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (this.VerticalOffset == this.ScrollableHeight)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.ScrollToTop();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; else      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.LineDown();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160; }      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This code simply installs event handlers for the &lt;strong&gt;LineUpCommand&lt;/strong&gt; and &lt;strong&gt;LineDownCommand&lt;/strong&gt; commands dispatched by the vertical &lt;strong&gt;ScrollBar&lt;/strong&gt; in the control template for the &lt;strong&gt;ScrollViewer&lt;/strong&gt;. Which, by the way, is a seriously fabulous way for this control to behave. In the event handler I examine incoming command type, then dispatch to the &lt;strong&gt;LineUp&lt;/strong&gt; or &lt;strong&gt;LineDown&lt;/strong&gt; methods as appropriate. However, before that I do a check to see if the control is already fully scrolled to either the top or the bottom of the viewer, and then, depending on the command, call either &lt;strong&gt;ScrollToEnd&lt;/strong&gt; or &lt;strong&gt;ScrollToTop&lt;/strong&gt; to loop the &lt;strong&gt;ScrollViewer&lt;/strong&gt; - all the methods used, and more, already exist on the &lt;strong&gt;ScrollViewer&lt;/strong&gt;, making the coding a very simple affair.&lt;/p&gt;  &lt;p&gt;I've uploaded a sample application that uses the new &lt;strong&gt;ScrollViewer&lt;/strong&gt; here:&lt;/p&gt;  &lt;blockquote&gt;&lt;a href="http://www.box.net/shared/eu0c5o1u2u"&gt;&lt;strong&gt;PaulJ.CyclicListBox.zip&lt;/strong&gt;&lt;/a&gt;&lt;/blockquote&gt;  &lt;p&gt;This sample is clearly incomplete; it only handles vertical scrolling. However, you can see how it could be extended to handle horizontal scrolling too. In fact, I intend to hack on this a little more in the coming weeks and try and create a complete working control... unless another question catches my eye in the meantime ;)&lt;/p&gt;  &lt;p&gt;I may also look into providing a Silverlight version, but that'll largely depend on the comments get back from this post, so let me know if you think that'll be a good idea.&lt;/p&gt;  &lt;p&gt;As always, comments and suggestions very welcome.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-5974476706005612805?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=6o_XZ5Jr7qQ:DpGHep2QQ-U:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=6o_XZ5Jr7qQ:DpGHep2QQ-U:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/6o_XZ5Jr7qQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/5974476706005612805/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=5974476706005612805" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/5974476706005612805?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/5974476706005612805?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/6o_XZ5Jr7qQ/scrollviewer-customization.html" title="ScrollViewer customization" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2009/01/scrollviewer-customization.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUUBSX86eSp7ImA9WxVTEU0.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-6382255865700284016</id><published>2008-12-23T10:15:00.001Z</published><updated>2008-12-24T08:27:38.111Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-24T08:27:38.111Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>WPF - FlagsEnumValueConverter</title><content type="html">&lt;p&gt;I feel a trend starting… another &lt;a href="http://stackoverflow.com/"&gt;http://stackoverflow.com/&lt;/a&gt; answer, here’s the question (&lt;em&gt;massively&lt;/em&gt; snipped):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;I have a nearly functional example of two-way binding a checkbox to an individual bit of a flags enumeration… The problem though is that the binding behaves as if it is one way (UI to DataContext, not vice versa). So effectively the check box does not initialize, but if it is toggled the data source is correctly updated…&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here’s &lt;a href="http://stackoverflow.com/questions/326802/how-can-you-two-way-bind-a-checkbox-to-an-individual-bit-of-a-flags-enumeration"&gt;the full link to the post&lt;/a&gt; for more context, if required.&lt;/p&gt;  &lt;p&gt;The bottom line is that a solution to binding to “bit” flags can be challenging, but the solution initially offered in the question was extremely complex (class with a bunch of &lt;strong&gt;Attached Properties&lt;/strong&gt; yadda, yadda, yadda), when I looked at it thought, I thought &amp;quot;&lt;em&gt;surely that can be done with a value converter&lt;/em&gt;”; after a little bit of hacking I have a simple &lt;strong&gt;IValueConverter&lt;/strong&gt; implementation for any flags enumeration.&lt;/p&gt;  &lt;p&gt;But first, consider the following Enum definition:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;[Flags]      &lt;br /&gt;public enum Department       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; None = 0,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; A = 1,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; B = 2,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; C = 4,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; D = 8       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;My first step was to create a &lt;em&gt;specific&lt;/em&gt; converter for the &lt;strong&gt;Department&lt;/strong&gt; Enum:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;public class DepartmentValueConverter : IValueConverter      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private &lt;strong&gt;Department&lt;/strong&gt; target; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public DepartmentValueConverter()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public object Convert(object value, Type targetType, object parameter, CultureInfo culture)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;strong&gt;Department&lt;/strong&gt; mask = (&lt;strong&gt;Department&lt;/strong&gt;)parameter;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.target = (&lt;strong&gt;Department&lt;/strong&gt;)value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return ((mask &amp;amp; this.target) != 0);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.target ^= (&lt;strong&gt;Department&lt;/strong&gt;)parameter;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return this.target;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The &lt;em&gt;tricky&lt;/em&gt; part, according to the initial question, was the &lt;strong&gt;ConvertBack&lt;/strong&gt; implementation. The solution here is to simply store the incoming value in the &lt;strong&gt;Convert&lt;/strong&gt; method, and when the value is changed the &lt;strong&gt;ConvertBack&lt;/strong&gt; method uses the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/0zbsw2z6(VS.80).aspx"&gt;Exclusive-Or assignment&lt;/a&gt;&lt;/strong&gt; operator to toggle the bit, which works lovely.&lt;/p&gt;  &lt;p&gt;However, I also figured that it should be possible to create a generic version of this converter – this type of converter is not something that you’d be creating everyday, so to have a specific version for each &lt;em&gt;Flags Enum&lt;/em&gt; would probably be a totally acceptable solution… but… this is what I came up with:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;public class FlagsEnumValueConverter : IValueConverter      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private int targetValue; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public FlagsEnumValueConverter()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public object Convert(object value, Type targetType, object parameter, CultureInfo culture)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int mask = (int)parameter;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.targetValue = (int)value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return ((mask &amp;amp; this.targetValue) != 0);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.targetValue ^= (int)parameter;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return Enum.Parse(targetType, this.targetValue.ToString());       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;So the key to this solution is that it works with the underlying type for &lt;em&gt;most&lt;/em&gt; Enum values: &lt;strong&gt;Int32&lt;/strong&gt;. The basic pattern is the same, but it simply replaces the specific Enum value with an &lt;strong&gt;Int32&lt;/strong&gt;; with the only tricky part being in the &lt;strong&gt;ConvertBack: &lt;/strong&gt;When I simply returned an &lt;strong&gt;Int32&lt;/strong&gt;, when an Enum value was expected, WPF did not update the underlying value in the binding. I found I had to convert the &lt;strong&gt;Int32&lt;/strong&gt; to the specific Enum value represented by the &lt;strong&gt;Int32&lt;/strong&gt;; which I simply handled by using the &lt;strong&gt;Enum.Parse&lt;/strong&gt; method.&lt;/p&gt;  &lt;p&gt;The following screenshot then shows how to consume the converter in XAML. Note that the mask value for the Enum value instance is passed in the &lt;strong&gt;CommandParameter&lt;/strong&gt; property on the binding declaration.&lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="FlagsConverterXaml" src="http://static.flickr.com/3089/3132170381_577a60ef14.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;I have uploaded a sample application here:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://www.box.net/shared/8xp0qqsc47"&gt;&lt;strong&gt;PaulJ.FlagsValueConverter.zip&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here’s a screenshot of the app, for what it’s worth given its simplicity :)&lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="FlagsValueConverterScreenShot" src="http://static.flickr.com/3263/3130703228_977a8d6127.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;Comments and questions welcome as always.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-6382255865700284016?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=lsQAMKgbbvs:CWsR1jjdgnM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=lsQAMKgbbvs:CWsR1jjdgnM:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/lsQAMKgbbvs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/6382255865700284016/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=6382255865700284016" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6382255865700284016?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/6382255865700284016?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/lsQAMKgbbvs/wpf-flagsenumvalueconverter.html" title="WPF - FlagsEnumValueConverter" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total><feedburner:origLink>http://compilewith.net/2008/12/wpf-flagsenumvalueconverter.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUERng-fCp7ImA9WxRaFk4.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-7806571495598319957</id><published>2008-12-18T16:48:00.001Z</published><updated>2008-12-18T21:36:47.654Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-18T21:36:47.654Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>Constrained StackPanel</title><content type="html">&lt;p&gt;I&amp;#8217;ve been spending a little time today over on &lt;a href="http://stackoverflow.com/"&gt;stackoverflow.com&lt;/a&gt; and just answered a question about constraining the width of a &lt;strong&gt;StackPanel&lt;/strong&gt;, and I thought I&amp;#8217;d share my solution here too.&lt;/p&gt;&lt;p&gt;The question in its entirety was:&lt;/p&gt; &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;How can I constrain a vertical WPF &lt;code&gt;StackPanel&lt;/code&gt;'s width to the most narrow item it contains. The &lt;code&gt;StackPanel&lt;/code&gt;'s width must not be greater than the width of any other child element.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;&lt;p&gt;My initial thought to try and use a simple &lt;strong&gt;IValueConverter&lt;/strong&gt; implementation; hand the in the child collection at the right time and bingo! constrain the size of the panel. However, that proved to be a little problematic as due to timing and data binding issues. One answer already suggested was to create a custom panel (which had no &lt;em&gt;up votes &lt;/em&gt;for some reason &amp;#8211; go figure); which would have been my next choice after the converter.&lt;/p&gt;&lt;p&gt;So I set about knocking up a &lt;strong&gt;ConstrainedStackPanel&lt;/strong&gt;, which looks something like this:&lt;/p&gt;&lt;pre&gt;public class ConstrainedStackPanel : StackPanel&lt;br /&gt;{&lt;br /&gt;    public ConstrainedStackPanel()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected override Size MeasureOverride(Size constraint)&lt;br /&gt;    {&lt;br /&gt;        foreach (var item in this.Children)&lt;br /&gt;        {&lt;br /&gt;            FrameworkElement element = item as FrameworkElement;&lt;br /&gt;            if (element != null)&lt;br /&gt;                constraint.Width = Math.Min(element.Width, constraint.Width);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return base.MeasureOverride(constraint);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    protected override Size ArrangeOverride(Size arrangeSize)&lt;br /&gt;    {&lt;br /&gt;        foreach (var item in this.Children)&lt;br /&gt;        {&lt;br /&gt;            FrameworkElement element = item as FrameworkElement;&lt;br /&gt;            if (element != null)&lt;br /&gt;                arrangeSize.Width = Math.Min(element.Width, arrangeSize.Width);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return base.ArrangeOverride(arrangeSize);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;Here I&amp;#8217;m simply enumerating the child collection at the right time, being a good WPF citizen and overriding &lt;em&gt;both&lt;/em&gt; &lt;strong&gt;Measure&lt;/strong&gt; and &lt;strong&gt;Arrange&lt;/strong&gt; to get the desired effect, by keeping the smallest &lt;strong&gt;Width&lt;/strong&gt; value at all times during the two stage rendering process. To consume the new panel in XAML, simply use it like any other &lt;strong&gt;StackPanel&lt;/strong&gt;, as shown here:&lt;/p&gt;&lt;p&gt;&lt;font size="2" face="Consolas"&gt;&amp;lt;l:ConstrainedStackPanel x:Name=&amp;quot;panelB&amp;quot;&amp;gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Button Width=&amp;quot;100&amp;quot; Content=&amp;quot;100&amp;quot; /&amp;gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Button Width=&amp;quot;200&amp;quot; Content=&amp;quot;200&amp;quot; /&amp;gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Button Width=&amp;quot;300&amp;quot; Content=&amp;quot;300&amp;quot; /&amp;gt; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Button Width=&amp;quot;400&amp;quot; Content=&amp;quot;400&amp;quot; /&amp;gt; &lt;br /&gt;&amp;lt;/l:ConstrainedStackPanel&amp;gt;&lt;/font&gt; &lt;/p&gt;&lt;p&gt;When compared with a regular &lt;strong&gt;StackPanel&lt;/strong&gt; the results look like the following screenshot:&lt;/p&gt;&lt;p&gt;&lt;img border="0" alt="WidthStackPanel" src="http://static.flickr.com/3133/3118591068_b1edcce6c0.jpg" /&gt;&lt;/p&gt;&lt;p&gt;And there you have it. In terms of requirements for a custom panel they don&amp;#8217;t get much simpler than that, so it was a pretty straight-forward solution, but I hope it helps someone.&lt;/p&gt;&lt;p&gt;To follow the progress of the question and to see what other people come up with here&amp;#8217;s a full link to the question: &lt;a title="http://stackoverflow.com/questions/377523/constrain-stackpanels-width-to-smallest-child-element" href="http://stackoverflow.com/questions/377523/constrain-stackpanels-width-to-smallest-child-element"&gt;http://stackoverflow.com/questions/377523/constrain-stackpanels-width-to-smallest-child-element&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Comments and questions welcome as always.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-7806571495598319957?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=jWVJ-TDytQ8:uVgzS1HTXbw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=jWVJ-TDytQ8:uVgzS1HTXbw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/jWVJ-TDytQ8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/7806571495598319957/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=7806571495598319957" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/7806571495598319957?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/7806571495598319957?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/jWVJ-TDytQ8/constrained-stackpanel.html" title="Constrained StackPanel" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://compilewith.net/2008/12/constrained-stackpanel.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQGSHkyfCp7ImA9WxRUFk8.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-8718788115309759299</id><published>2008-11-25T13:38:00.001Z</published><updated>2008-11-25T13:38:49.794Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-25T13:38:49.794Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Architecture" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net" /><title>Separated Presentation Patterns</title><content type="html">&lt;p&gt;It is generally agreed amongst developers that a good &lt;strong&gt;clean separation&lt;/strong&gt; between the visual elements of an application and the logic of an application is a &lt;strong&gt;good idea&lt;/strong&gt;. To that end a number of patterns have emerged over the years:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Model-view-controller"&gt;Model View Controller&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Model_View_Presenter"&gt;Model View Presenter&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;and more recently:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx"&gt;Model View View-Model&lt;/a&gt; - sometimes incorrectly referred to as &lt;a href="http://martinfowler.com/eaaDev/PresentationModel.html"&gt;Presentation Model&lt;/a&gt;; they are similar but not the same. The MV-VM pattern is more WPF centric.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Over the years I have formed my own ideas as to when, why and where to apply these patterns, and it has been hard going, and to be quite frank, I've been a little inconsistent and vague at times; but recently I have formed more concrete ideas about when, why and where - especially when working with XAML (e.g. WPF and Silverlight) - which I have written down for others to throw stones at, here it is:&lt;/p&gt; &lt;p&gt;&lt;img src="http://farm4.static.flickr.com/3153/3058893642_a8677c3220_o.png"&gt; &lt;/p&gt; &lt;p&gt;In time I plan to add code to illustrate these patterns - as I seem them - to provide more fodder for stone throwing; but in the process hopefully we'll all learn something.&lt;/p&gt; &lt;p&gt;Enjoy! I would love you know what &lt;strong&gt;you&lt;/strong&gt; think and why.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-8718788115309759299?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=MV9hfexc0Lk:QxjXfOSJNRg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=MV9hfexc0Lk:QxjXfOSJNRg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/MV9hfexc0Lk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/8718788115309759299/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=8718788115309759299" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/8718788115309759299?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/8718788115309759299?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/MV9hfexc0Lk/separated-presentation-patterns.html" title="Separated Presentation Patterns" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://compilewith.net/2008/11/separated-presentation-patterns.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UHQHw8fCp7ImA9WxRUFk8.&quot;"><id>tag:blogger.com,1999:blog-9534263.post-5438678411212181005</id><published>2008-11-24T17:01:00.001Z</published><updated>2008-11-25T13:53:51.274Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-25T13:53:51.274Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term=".Net" /><title>More change notification for Dependency Properties</title><content type="html">&lt;p&gt;In &lt;a href="http://compilewith.net/2008/04/change-notification-for.html"&gt;an earlier post &lt;/a&gt;I wrote a little on change notification in relation to dependency properties that you do not own, like those found on a &lt;a href="http://msdn2.microsoft.com/en-us/library/system.windows.controls.textblock"&gt;&lt;strong&gt;TextBlock&lt;/strong&gt;&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.label.aspx"&gt;&lt;strong&gt;Label&lt;/strong&gt;&lt;/a&gt;. In that post I walked you though using a &lt;strong&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.componentmodel.dependencypropertydescriptor"&gt;DependencyPropertyDescriptor&lt;/a&gt;&lt;/strong&gt;, which in essence enables you to add an event handler to a &lt;strong&gt;ValueChanged&lt;/strong&gt; event for any dependency property. &lt;/p&gt; &lt;p&gt;Here's a code example to help illustrate the approach:&lt;/p&gt; &lt;p&gt;&lt;font face="Consolas"&gt;DependencyPropertyDescriptor &lt;strong&gt;descriptor&lt;/strong&gt; = &lt;br&gt;&amp;nbsp; DependencyPropertyDescriptor.FromProperty &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (UIElement.VisibilityProperty, typeof(UIElement)); &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Consolas"&gt;&lt;strong&gt;descriptor&lt;/strong&gt;.AddValueChanged &lt;br&gt;&amp;nbsp; (this.labelShowHide, new EventHandler(VisibilityChanged));&lt;/font&gt; &lt;/p&gt; &lt;p&gt;The example code above creates a instance of a descriptor for the &lt;strong&gt;Visibility&lt;/strong&gt; dependency property owned by the &lt;strong&gt;UIElement&lt;/strong&gt; class, and then adds an event handler called &lt;strong&gt;VisibilityChanged&lt;/strong&gt;. As I pointed out in the previous post there are two issues with this approach:  &lt;p&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The event handler delegate is of type &lt;strong&gt;EventHandler&lt;/strong&gt; and therefore only passes a simple &lt;strong&gt;EventArgs&lt;/strong&gt;, losing the rich information provided by a typical dependency property change notification via the &lt;strong&gt;DependencyPropertyChangedEventArgs&lt;/strong&gt;, which includes data such as the old and new values of the property.  &lt;li&gt;The descriptor approach has a potential memory leak if you're not careful. This is because a reference to your event handler forever &lt;em&gt;roots&lt;/em&gt; your class, in a Garbage Collector sense, because the reference is ultimately stored a static &lt;strong&gt;Hashtable&lt;/strong&gt;. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I also think that there is a third, less concrete, issue with this approach: I don't like it. It just feels all wrong; hacking into the hooks provided for the tooling, which does all work fine, but it left me feeling a little dirty ;) There has to be a better way! And there is... &lt;/p&gt; &lt;p&gt;I discovered the proper way to do this kind of change notification a short while ago; however, this is the first opportunity I've had to write up - primarily for me to remember it in the future. The answer is actually quite simple, and related to the approach you would take extending an existing control by using inheritance... &lt;em&gt;a Metadata override!&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Consolas"&gt;UIElement.OpacityProperty.&lt;strong&gt;OverrideMetadata&lt;/strong&gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; typeof(TextBlock), &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; new &lt;strong&gt;FrameworkPropertyMetadata&lt;/strong&gt;( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.0, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FrameworkPropertyMetadataOptions.Inherits, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new PropertyChangedCallback(&lt;strong&gt;DetailedPropertyChanged&lt;/strong&gt;)));&lt;/font&gt; &lt;/p&gt; &lt;p&gt;The example code above replaces the property metadata for the &lt;strong&gt;Opacity&lt;/strong&gt; dependency property for all &lt;strong&gt;TextBlock&lt;/strong&gt; control instances in scope. The new metadata provides an event handler for change notification, and unlike the descriptor approach the callback is a true dependency property changed event handler:&lt;/p&gt; &lt;p&gt;&lt;font face="Consolas"&gt;private void DetailedPropertyChanged( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DependencyObject d, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;DependencyPropertyChangedEventArgs&lt;/strong&gt; e) &lt;br&gt;{ &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.WriteLine(string.Format( &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "{0}: old value was '{1}' and the new value is '{2}'", &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Property.Name, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;e.OldValue&lt;/strong&gt;.ToString(), &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;e.NewValue&lt;/strong&gt;.ToString())); &lt;br&gt;}&lt;/font&gt; &lt;/p&gt; &lt;p&gt;Providing access to the old and new values, information about the source and the dependency property that has actually been changed. You now have all the information you could possibly need to handle the changed property; this approach has none of the drawbacks of the previous descriptor approach.&lt;/p&gt; &lt;p&gt;The only thing to be aware of when using this approach is that it impacts the overridden dependency property for all instances of the target type that are in scope; but you have a reference to the target object and property in the event handler, so this is easily coded for via a &lt;em&gt;switch&lt;/em&gt; or &lt;em&gt;if&lt;/em&gt; statement - it's just something to be aware of.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.box.net/shared/98g1fpkdvf"&gt;Here's a simple application&lt;/a&gt; that helps to illustrate the approach described here. If you have any comments or questions please leave a comment.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9534263-5438678411212181005?l=compilewith.net' alt='' /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=kKf5zPWBd0o:9G-8x9FuEFk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/Compilewithnet?a=kKf5zPWBd0o:9G-8x9FuEFk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Compilewithnet?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/Compilewithnet/~4/kKf5zPWBd0o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://compilewith.net/feeds/5438678411212181005/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=9534263&amp;postID=5438678411212181005" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/5438678411212181005?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/9534263/posts/default/5438678411212181005?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Compilewithnet/~3/kKf5zPWBd0o/more-change-notification-for-dependency.html" title="More change notification for Dependency Properties" /><author><name>Paul</name><uri>http://www.blogger.com/profile/03844348801538127249</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="10980861331029019103" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://compilewith.net/2008/11/more-change-notification-for-dependency.html</feedburner:origLink></entry></feed>
