<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://wekempf.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fwekempf.spaces.live.com%2fcategory%2fProgramming%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>So long, and thanks for all the chips: Programming</title><description /><link>http://wekempf.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catProgramming</link><language>en-US</language><pubDate>Sat, 06 Sep 2008 07:48:45 GMT</pubDate><lastBuildDate>Sat, 06 Sep 2008 07:48:45 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://wekempf.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>-3347231426831879729</live:id><live:alias>wekempf</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>The "var" controversy</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!428.entry</link><description>&lt;p&gt;There's some blog buzz going on right now about the appropriateness of using the new C# &amp;quot;var&amp;quot; keyword.  I first ran across the meme from Jean-Paul S. Boodhoo's blog, with &lt;a href="http://codebetter.com/blogs/jean-paul_boodhoo/archive/2008/04/22/got-var.aspx"&gt;this&lt;/a&gt; post.  He later linked to a &lt;a href="http://resharper.blogspot.com/2008/03/varification-using-implicitly-typed.html"&gt;post&lt;/a&gt; by Ilya Ryzhenkov on the same subject.  One of the responses on Ilya's blog read: &lt;blockquote&gt; &lt;p&gt;&lt;i&gt;&amp;quot;The upshot here is that vars generate some serious code - all for good reason when using LINQ. But NOT for a good reason if you’re being lazy - which is the point of this whole post. If you find yourself using “var” anywhere that’s not within a LINQ statement, it’s probably not a good idea.&amp;quot;&lt;/i&gt;&lt;/blockquote&gt; &lt;p&gt;This response was quoting a &lt;a href="http://blog.wekeroad.com/2007/08/29/the-c-makeover/"&gt;post&lt;/a&gt; by Rob Conery.  Let me first say, I have not read all of Rob's post (mostly because the formatting is so bad, it makes it hard to read the post, and I don't have the time to spend on the effort).  Maybe this quote is taken out of context, so take what I say next with a grain of salt.  This quote is utter hogwash.  The &amp;quot;var&amp;quot; keyword produces &lt;strong&gt;no&lt;/strong&gt; extra code.  Prove it to yourself.&lt;pre&gt;&lt;span style="color:blue"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af"&gt;Foo
&lt;/span&gt;{
}

&lt;span style="color:blue"&gt;class &lt;/span&gt;&lt;span style="color:#2b91af"&gt;Program
&lt;/span&gt;{
    &lt;span style="color:blue"&gt;static void &lt;/span&gt;Main(&lt;span style="color:blue"&gt;string&lt;/span&gt;[] args)
    {
        &lt;span style="color:#2b91af"&gt;Foo &lt;/span&gt;explicitFoo = &lt;span style="color:blue"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af"&gt;Foo&lt;/span&gt;();
        &lt;span style="color:blue"&gt;var &lt;/span&gt;inferredFoo = &lt;span style="color:blue"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af"&gt;Foo&lt;/span&gt;();
    }
}
&lt;/pre&gt;
&lt;p&gt;The resultant IL that's generated is this.&lt;pre&gt;.method private hidebysig static &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Void"&gt;void&lt;/a&gt; &lt;b&gt;&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Playground:1.0.0.0/Playground.Program/Main(String[])"&gt;Main&lt;/a&gt;&lt;/b&gt;(&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"&gt;string&lt;/a&gt;[] args) cil managed
{
    .entrypoint
    .maxstack 1
    .locals init (
        [0] class &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Playground:1.0.0.0/Playground.Foo"&gt;Playground.Foo&lt;/a&gt; &lt;b&gt;explicitFoo&lt;/b&gt;,
        [1] class &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Playground:1.0.0.0/Playground.Foo"&gt;Playground.Foo&lt;/a&gt; &lt;b&gt;inferredFoo&lt;/b&gt;)
    L_0000: &lt;a&gt;nop&lt;/a&gt; 
    L_0001: &lt;a&gt;newobj&lt;/a&gt; instance &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Void"&gt;void&lt;/a&gt; &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Playground:1.0.0.0/Playground.Foo"&gt;Playground.Foo&lt;/a&gt;::&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Playground:1.0.0.0/Playground.Foo/.ctor()"&gt;.ctor&lt;/a&gt;()
    L_0006: &lt;a&gt;stloc.0&lt;/a&gt; 
    L_0007: &lt;a&gt;newobj&lt;/a&gt; instance &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Void"&gt;void&lt;/a&gt; &lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Playground:1.0.0.0/Playground.Foo"&gt;Playground.Foo&lt;/a&gt;::&lt;a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Playground:1.0.0.0/Playground.Foo/.ctor()"&gt;.ctor&lt;/a&gt;()
    L_000c: &lt;a&gt;stloc.1&lt;/a&gt; 
    L_000d: &lt;a&gt;ret&lt;/a&gt; 
}
&lt;/pre&gt;
&lt;p&gt;The code for the explicitly declared variable and the inferred though &amp;quot;var&amp;quot; variable is identical.  Do &lt;strong&gt;NOT&lt;/strong&gt; fear using &amp;quot;var&amp;quot; because of performance concerns, as there is none.
&lt;p&gt;With that out of the way, where do I fall in opinion on this subject?  Well, reading the various posts in this meme, there seems to be two camps.  I think both are extremes.  The first extreme is the &amp;quot;Microsoft Camp&amp;quot;.
&lt;blockquote&gt;
&lt;p&gt;“Overuse of var can make source code less readable for others. It is recommended to use var only when it is necessary, that is, when the variable will be used to store an anonymous type or a collection of anonymous types.”&lt;/blockquote&gt;
&lt;p&gt;I simply can't agree with this extreme viewpoint.  Tell me how the following code can possibly be considered less readable for others?&lt;pre&gt;&lt;span style="color:blue"&gt;var &lt;/span&gt;inferredFoo = &lt;span style="color:blue"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af"&gt;Foo&lt;/span&gt;();
&lt;/pre&gt;
&lt;p&gt;The other camp, which I'll call the Boodhoo camp, though I don't have proof that Mr. Boodhoo specifically takes this extreme point of view, believe that you should always use &amp;quot;var&amp;quot;.  I can't agree with that extreme either.  Can anyone tell me what the type of the following declaration is?&lt;pre&gt;&lt;span style="color:blue"&gt;var &lt;/span&gt;current = &lt;span style="color:#2b91af"&gt;Foo&lt;/span&gt;.Current;
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;We can have arguments until we're blue in the face about how better naming would have prevented this confusion.  I don't buy the argument, though.  First, names aren't always under your control.  Second, even with better naming it's still possible to find yourself in situations where you don't have enough type information available to you in situations like this.  C# is still a strongly typed language, and knowing the exact type your dealing with is important.  Relying on the IDE is a no go for me, and relying on naming isn't always possible.
&lt;p&gt;So, what do I think?  Out of habit, I'm still not using &amp;quot;var&amp;quot; that frequently, but I see no harm in using it for your typical &amp;quot;new&amp;quot; statements like the first example.  I don't know if I'll get into the habit of doing that or not, but I see no reason to try and talk anyone out of doing so.  For other declarations like the second example, unless the type is anonymous, I'd probably favor the Microsoft guideline of not using &amp;quot;var&amp;quot; here.  You can probably get away with it 80% of the time and I won't care, but that other 20% is enough reason for me to not recommend getting into this habit.
&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt;  From a reply to Ilya's post by &amp;quot;Simon&amp;quot; we get a list of rules much closer to what I think makes sense.
&lt;ul&gt;
&lt;li&gt;Do use &lt;em&gt;var&lt;/em&gt; for anonymous types
&lt;li&gt;Do use &lt;em&gt;var&lt;/em&gt; for initialization from constructors (var list = new List();)
&lt;li&gt;Do use &lt;em&gt;var&lt;/em&gt; for casts (var list = (IList)list;)
&lt;li&gt;Consider using &lt;em&gt;var&lt;/em&gt; where naming implies the type of the variable (var xmlSerializer = GetXmlSerializer();)&lt;/ul&gt;
&lt;p&gt;The last bullet point is the most controversial, but I can agree with it as long as developers are consciously considering the choice.  For the rest, I can see no reason to recommend not using &amp;quot;var&amp;quot; in any of those situations.&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+The+%22var%22+controversy&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!428.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!428.entry</guid><pubDate>Thu, 24 Apr 2008 14:44:48 GMT</pubDate><slash:comments>2</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!428/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!428.entry#comment</wfw:comment><dcterms:modified>2008-04-24T15:00:51Z</dcterms:modified></item><item><title>Hackety, hack... don't talk back</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!389.entry</link><description>&lt;div&gt;I've been working for some time now on implementing a framework to enable coding WPF applications that follow the Model-View-ViewModel pattern.  I've found several &amp;quot;dark corners&amp;quot; of the WPF libraries where the designers have made choices that make it difficult to extend the library.  For instance, the constructors on the routed event arguments are not public, making it very difficult to reroute events back into the ViewModel.  It's been frustrating, but you could always understand why the design was the way it was, even if I thought it was a mistake that should be rectified in some later release.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;However, I just ran into one that just astounds me.  I've been trying to implement a scheme in which the ViewModel would be able to effect navigation with no knowledge of the View.  It's similar in concept to the Java Struts concept where navigation information is stored in a configuration file and is initiated via keywords instead of actual knowledge of the view (if that made sense to anyone).  Anyway, I had something working fairly well, and reached the point where I had to start worrying about getting &amp;quot;return values&amp;quot; back to the VieModel.  This is when I discovered something interesting.  When you follow the normal pattern for handling PageFunction code, like this:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;p&gt;class MyPayge : Page
&lt;p&gt;{ 
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;  // ... other stuff removed&lt;/div&gt;
&lt;div&gt;  void Navigate()&lt;/div&gt;
&lt;div&gt;  {&lt;/div&gt;
&lt;div&gt;     MyPageFunction f = new MyPageFunction();&lt;/div&gt;
&lt;div&gt;     f.Return = MyPageFunction_Return;&lt;/div&gt;
&lt;div&gt;     NavigationService.Navigate(f);&lt;/div&gt;
&lt;div&gt;  }&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;  void MyPageFunction_Return(object sender, PageFunctionEventArgs&amp;lt;int&amp;gt; e)&lt;/div&gt;
&lt;div&gt;  {&lt;/div&gt;
&lt;div&gt;     // what ever&lt;/div&gt;
&lt;div&gt;  }&lt;/div&gt;
&lt;div&gt;}&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;(That was done by memory and likely has several signature and syntax issues... it's for illustration only.)&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Knowing how delegates work, you'd expect that the addition of the MyPageFunction_Return would cause the MyPageFunction instance to maintain a reference to the MyPage instance, keeping it alive, and that's what the method would be called on.  A little experimentation, though, proved this to be wrong.  The old MyPage instance is collected, a new one is created, and that's the instance the MyPageFunction_Return is called on.  I have no idea how it's even possible to do that!  I started to do a Google search, and that's when I discovered something interesting.  Did you know the documentation for the Return event indicates you must only handle the event from a method on the calling page?  If you try and handle it somewhere else, an exception will be raised!  Seems to me they implemented some hack to allow the event handler to be retargeted to the new Page instance when you return (this is the default behavior, unless you assign KeepAlive=&amp;quot;True&amp;quot;).  This hack either required or made it easier for them to document that you must target the calling Page with any event handler.  Does that sound like a hack to you, or what?  Worse, it leads to many dead ends when using PageFunction.  My scenario tries to handle the return event in the ViewModel, but the situation I foundusing Google was trying to encapsulate all of the functionality in a custom control, which seems like a very common thing to want to do.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;I love WPF.  It makes a large part of the development effort simple, while allowing you to still do amazing things with your UI.  However, there's enough of these dark corners to frustrate the heck out of me.&lt;/div&gt;&lt;pre&gt;&lt;/pre&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+Hackety%2c+hack...+don't+talk+back&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!389.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!389.entry</guid><pubDate>Wed, 19 Dec 2007 12:16:56 GMT</pubDate><slash:comments>1</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!389/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!389.entry#comment</wfw:comment><dcterms:modified>2007-12-19T12:16:56Z</dcterms:modified></item><item><title>ViewModelExtension</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!363.entry</link><description>&lt;div&gt;Dr. WPF has an interesting &lt;a href="http://www.drwpf.com/Blog/Default.aspx?tabid=36&amp;amp;EntryID=5"&gt;blog entry&lt;/a&gt; with a MarkupExtension that allows you to reference other objects within the object tree.  It is a nice extension (there are others posted around that do similar things, see the comments on that blog entry for some others).  However, what I found interesting was the specific use case scenario for which Dr. WPF is suggesting the MarkupExtension would be useful.  Why?  Because this use case scenario is the exact same scenario you often find yourself in when trying to use a ViewModel.  You want to set the Window's (or Page or whatever is your root object) DataContext to a new instance of the ViewModel, and said ViewModel might need a reference to the Window in order to do things like specify the parent of dialogs created in &lt;a href="http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!357.entry"&gt;ViewModelCommand&lt;/a&gt; handlers.  Dr. WPF's ObjectReference stuff would work here, but it seems overly engineered for what we're doing here.  I already had a solution that I had been using prior to his post, that I called ViewModelExtension.  Using the ViewModelExtension I can solve the exact problem from his blog entry with code like the following:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;
&lt;p style="margin:0in 0in 0pt"&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;font-family:'Courier New'"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt; &lt;/span&gt;&lt;span style="color:red;font-family:'Courier New'"&gt;Name&lt;/span&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt;=&lt;/span&gt;&lt;span style="font-family:'Courier New'"&gt;&amp;quot;&lt;span style="color:blue"&gt;RssGrid&lt;/span&gt;&amp;quot;&lt;span style="color:blue"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; 
&lt;p style="margin:0in 0in 0pt"&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt;&lt;span&gt;  &lt;/span&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;font-family:'Courier New'"&gt;ListBox&lt;/span&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt; &lt;/span&gt;&lt;span style="color:red;font-family:'Courier New'"&gt;DataSource&lt;/span&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt;=&lt;/span&gt;&lt;span style="font-family:'Courier New'"&gt;&amp;quot;&lt;span style="color:blue"&gt;{loc:ViewModel rss:RssFeeder}&lt;/span&gt;&amp;quot;&lt;/span&gt; 
&lt;p style="margin:0in 0in 0pt"&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt;&lt;span&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span style="color:red;font-family:'Courier New'"&gt;ItemsSource&lt;/span&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt;=&lt;/span&gt;&lt;span style="font-family:'Courier New'"&gt;&amp;quot;&lt;span style="color:blue"&gt;{Binding Path=RecentPosts}&lt;/span&gt;&amp;quot;&lt;span style="color:blue"&gt; &lt;/span&gt;&lt;span style="color:red"&gt;... &lt;/span&gt;&lt;span style="color:blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt; 
&lt;p style="margin:0in 0in 0pt"&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;font-family:'Courier New'"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;font-family:'Courier New'"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;The code for this extension is relatively straightforward:&lt;pre&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; ViewModelExtension : MarkupExtension
{
   &lt;font color="#0000ff"&gt;public&lt;/font&gt; ViewModelExtension()
   {
   }

   &lt;font color="#0000ff"&gt;public&lt;/font&gt; ViewModelExtension(&lt;font color="#2b91af"&gt;Type&lt;/font&gt; modelType)
   {
      type = modelType;
   }

   &lt;font color="#2b91af"&gt;Type&lt;/font&gt; type;
   &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#2b91af"&gt;Type&lt;/font&gt; ModelType
   {
      &lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; type; }
      &lt;font color="#0000ff"&gt;set&lt;/font&gt; { type = &lt;font color="#0000ff"&gt;value&lt;/font&gt;; }
   }

   &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;override&lt;/font&gt; &lt;font color="#0000ff"&gt;object&lt;/font&gt; ProvideValue(&lt;font color="#2b91af"&gt;IServiceProvider&lt;/font&gt; provider)
   {
      IProvideValueTarget provideValue = provider.GetService(&lt;font color="#0000ff"&gt;typeof&lt;/font&gt;(IProvideValueTarget)) &lt;font color="#0000ff"&gt;as&lt;/font&gt; IProvideValueTarget;
      &lt;font color="#0000ff"&gt;object&lt;/font&gt; target = provideValue.TargetObject;
      &lt;font color="#2b91af"&gt;ConstructorInfo&lt;/font&gt; cons = ModelType.GetConstructor(&lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#2b91af"&gt;Type&lt;/font&gt;[] { target.GetType() });
      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (cons != &lt;font color="#0000ff"&gt;null&lt;/font&gt;)
         &lt;font color="#0000ff"&gt;return&lt;/font&gt; cons.Invoke(&lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#0000ff"&gt;object&lt;/font&gt;[] { target });
      cons = ModelType.GetConstructor(&lt;font color="#2b91af"&gt;Type&lt;/font&gt;.EmptyTypes);
      &lt;font color="#0000ff"&gt;if&lt;/font&gt; (cons != &lt;font color="#0000ff"&gt;null&lt;/font&gt;)
         &lt;font color="#0000ff"&gt;return&lt;/font&gt; cons.Invoke(&lt;font color="#0000ff"&gt;null&lt;/font&gt;);
      &lt;font color="#0000ff"&gt;return&lt;/font&gt; &lt;font color="#0000ff"&gt;null&lt;/font&gt;;
   }
}
&lt;/pre&gt;
&lt;p&gt;The general idea here is that the ViewModelExtension will instantiate an object of the type you specify.  It does so by calling a constructor that takes an object of the type of the TargetObject if one exists, or the default constructor otherwise.  This extension has many of the same drawbacks as the ObjectReference extension, since it isn't a binding either.  It also doesn't have all of the funtionality of the ObjectReference, so it can't be used in all of the same scenarios.  However, for this typical scenario it turns out to be a much simpler and cleaner solution. 
&lt;p&gt;I'd love to hear your thoughts on this one.&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+ViewModelExtension&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!363.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!363.entry</guid><pubDate>Tue, 04 Sep 2007 14:44:02 GMT</pubDate><slash:comments>11</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!363/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!363.entry#comment</wfw:comment><dcterms:modified>2007-09-04T15:34:30Z</dcterms:modified></item><item><title>Bazaar and P4Merge</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!304.entry</link><description>&lt;p&gt;Bazaar doesn't do much for you, by default, when it comes to resolving conflicts.  If a conflict occurs, the file in question will be merged with sections of text indicating the conflict.  In addition, three files will be created using the original file name and appending THIS (the file before the merge), OTHER (the file being merged) and BASE (the revision THIS and OTHER have in common).  With this information, it would be possible to manually correct the conflict, but this can be tedious and error prone.  It's easier to use a graphical merge tool to do this.  There's a great merge tool available for free called &lt;a href="http://www.perforce.com/perforce/downloads/ntx86.html"&gt;P4Merge&lt;/a&gt;.  You could manually use P4Merge to open the respective versions of the file in order to perform the merge, but that can be a pain when there's a lot of conflicting files. 
&lt;p&gt;A better solution exists.  There's a Bazaar &lt;a href="http://erik.bagfors.nu/bzr-plugins/extmerge/index.html"&gt;plugin&lt;/a&gt; that adds an extmerge command.  Once this plugin is installed (follow the directions in the plugin link), you need to configure it to use P4Merge.&lt;pre&gt;PS&amp;gt; notepad $env:APPDATA\bazaar\2.0\bazaar.conf&lt;/pre&gt;
&lt;p&gt; Add a line like this.&lt;pre&gt;external_merge = p4merge %b %t %o %r&lt;/pre&gt;
&lt;p&gt;Here's an explanation of the replaceable parameters, in case you want to use a different graphical merge utility. 
&lt;table cellspacing=0 cellpadding=2 width=400 border=0&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign=top width=200&gt;%b 
&lt;td valign=top width=200&gt;BASE file 
&lt;tr&gt;
&lt;td valign=top width=200&gt;%t 
&lt;td valign=top width=200&gt;THIS file 
&lt;tr&gt;
&lt;td valign=top width=200&gt;%o 
&lt;td valign=top width=200&gt;OTHER file 
&lt;tr&gt;
&lt;td valign=top width=200&gt;%r 
&lt;td valign=top width=200&gt;results file, or the original file&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;With this all set up, when a conflict occurs, you simply do this:&lt;pre&gt;PS&amp;gt; bzr extmerge --all
PS&amp;gt; bzr resolve --all&lt;/pre&gt;
&lt;p&gt;This will first run your external merge program and then tell Bazaar that the conflicts have been resolved.  The &amp;quot;--all&amp;quot; option does this for all conflicting files.  You could instead specify which conflicting file to operate on.  Once resolved, you'll still need to commit the changes. 
&lt;div style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Programming" rel=tag&gt;Programming&lt;/a&gt;, &lt;a href="http://technorati.com/tags/RCS" rel=tag&gt;RCS&lt;/a&gt;, &lt;a href="http://technorati.com/tags/DRCS" rel=tag&gt;DRCS&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Bazaar" rel=tag&gt;Bazaar&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+Bazaar+and+P4Merge&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!304.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!304.entry</guid><pubDate>Tue, 24 Jul 2007 20:27:01 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!304/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!304.entry#comment</wfw:comment><dcterms:modified>2007-07-27T18:12:32Z</dcterms:modified></item><item><title>Bazaar on a Stick</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!303.entry</link><description>&lt;p&gt;I thought I'd blog about how I'm actually using Bazaar.  As I mentioned earlier, the reason for learning to use Bazaar was a need to be able to manage a set of scripts between several computers that may not have access to each other or a central server.  A DRCS solution would allow me to track and manage changes to these scripts across these computers through the use of a &amp;quot;central&amp;quot; branch I'll keep on a USB memory stick.  Here's how I set this up, and how I use it on a daily basis. &lt;p&gt;First, we create a new branch on the memory stick.&lt;pre&gt;PS&amp;gt; cd g:\
PS&amp;gt; bzr init scripts
&lt;/pre&gt;
&lt;p&gt; Now, on a central computer in each location I can create a &amp;quot;shared&amp;quot; branch.&lt;pre&gt;PS&amp;gt; cd c:\
PS&amp;gt; bzr branch g:\scripts scripts&lt;/pre&gt;
&lt;p&gt; Now I can make individual branches on each machine and use them normally.&lt;pre&gt;PS&amp;gt; net use \\machine\scripts
PS&amp;gt; bzr co \\machine\scripts scripts&lt;/pre&gt;
&lt;p&gt;If I make a change on one of these machines, I simply have to commit the changes, which will also commit the changes to the &amp;quot;shared&amp;quot; branch.  To push these changes out to machines at this location, all I have to do is run &amp;quot;bzr update&amp;quot;.  To push the changes to other locations requires a little more work, though it's simple and straight forward.&lt;pre&gt;PS&amp;gt; cd g:\scripts
PS&amp;gt; bzr merge c:\scripts
PS&amp;gt; bzr ci -m &amp;quot;Merged changes&amp;quot;&lt;/pre&gt;
&lt;p&gt; This pushes the changes onto the memory stick.  Now at the other locations I can pull the changes off the stick.&lt;pre&gt;PS&amp;gt; cd c:\scripts
PS&amp;gt; bzr pull&lt;/pre&gt;
&lt;p&gt;Now on individual machines at the new location I can simply &amp;quot;bzr update&amp;quot;.
&lt;p&gt;This isn't much different than just copying the scripts around everywhere.  However, Bazaar gives me several benefits over the simple copy.  First, changes are revision controlled, which is always beneficial for code!  Second, because I'm committing and updating to a DRCS instead of just copying files, it's very difficult to accidentally copy over changes made in one location that I forgot to copy out everywhere else.
&lt;div style="padding-right:0px;display:inline;padding-left:0px;float:none;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Programming" rel=tag&gt;Programming&lt;/a&gt;, &lt;a href="http://technorati.com/tags/RCS" rel=tag&gt;RCS&lt;/a&gt;, &lt;a href="http://technorati.com/tags/DRCS" rel=tag&gt;DRCS&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Bazaar" rel=tag&gt;Bazaar&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+Bazaar+on+a+Stick&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!303.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!303.entry</guid><pubDate>Tue, 24 Jul 2007 14:13:03 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!303/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!303.entry#comment</wfw:comment><dcterms:modified>2007-07-24T20:29:07Z</dcterms:modified></item><item><title>Bazaar Terminology</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!302.entry</link><description>&lt;p&gt;I'm finding the terminology used by Bazaar to be both familiar, and confusing.  In particular, there are three terms that, for the most part, have identical meanings to how the terms are used in the centralized RCS solutions I'm used to, but for which there's a slight difference that requires different thinking about them.  These three terms are repository, branch and working tree. &lt;p&gt;A repository is the the storage area that contains all the history information.  The difference here is one that shouldn't be shocking: there is no central repository in a DRCS solution.  However, this fact does require some different thinking.  A given repository may not, for instance, contain a complete history of the &amp;quot;project&amp;quot; under revision control.  Why not?  Because, just as an example, a repository on one machine may not have history that's in a repository on another machine that was created with a branch.  This may be obvious, but the nuances of this can be subtle and surprising at first.  Entirely new ways of managing a project are possible, each with their own sets of pros and cons. &lt;p&gt;A branch is a copy of a project at a point in time, where changes and commits can happen in parelel.  The difference here is that in a centralized RCS solution, there's a &amp;quot;main branch&amp;quot; or &amp;quot;trunk&amp;quot; and all branches exist within the central repository.  In a DRCS solution, there is no &amp;quot;main branch&amp;quot;, except possibly by convention.  In an RCS it's normal to do most development in the main branch.  In fact, there's often a desire to not branch, since branches have a reputation of being difficult to manage and to merge.  In a DRCS, however, it's not possible for multiple developers to work within a project with out branching.  Every developer will have at least one branch to themselves.  Because branches don't exist within a central repository, the relationship between branches is purely logical, and you may not know what branches even exist.  Branching and merging are just part of daily life, and in general are not complex operations.  Another point to keep in mind, at least with Bazaar, is that branches by default will have their own repository, but it's possible (and recommended) for local branches to share a repository (see the init-repo command). &lt;p&gt;A working tree is the copy of files from a specific point in time that modifications can be made to and committed.  The difference here is that the files exist within the same directory as the branch, if they exist at all.  It's possible to have a &amp;quot;treeless&amp;quot; branch, and in fact that's a good strategy for a shared central branch. &lt;p&gt;Keeping in mind the subtle differences in these terms is definitely helpful when learning to use a DRCS solution. &lt;div style="padding-right:0px;display:inline;padding-left:0px;float:none;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Programming" rel=tag&gt;Programming&lt;/a&gt;, &lt;a href="http://technorati.com/tags/RCS" rel=tag&gt;RCS&lt;/a&gt;, &lt;a href="http://technorati.com/tags/DRCS" rel=tag&gt;DRCS&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Bazaar" rel=tag&gt;Bazaar&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+Bazaar+Terminology&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!302.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!302.entry</guid><pubDate>Tue, 24 Jul 2007 13:40:16 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!302/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!302.entry#comment</wfw:comment><dcterms:modified>2007-07-24T20:29:36Z</dcterms:modified></item><item><title>Bazaar</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!295.entry</link><description>&lt;p&gt;I've been evaluating a new (for me) RCS solution, named Bazaar.  I've used plenty of RCS systems in the past: PVCS, CVS, Subversion, ClearCase.  All of these were centralized RCS solutions.  In other words, they all relied upon a central server that acted as the main repository.  This means, in order to use them, you must have access to the server.  For personal use, this means setting up and maintaining a server, which isn't always a trivial task.  Worse, it means the server must be accessible from everywhere that you'll need it.  I'm currently sharing some script files between about 10 machines, not all of which will have easy access to a central server.  This makes maintaining the scripts difficult at best.  So, I went looking for a solution. &lt;p&gt;There's a new breed of RCS solutions known as DRCS, or decentralized revision control systems.  These solutions don't use a central server concept at all.  All of the functionality exists in locally.  Changes are made, applied and tracked locally.  These changes can be pushed or pulled to other locations, in order to facility typical code sharing scenarios that exist in centralized RCS solutions.  A single repository can be located in a centralized location to act much as the centralized server did in those scenarios.  Or you can opt to use entirely new ways of working. &lt;p&gt;In my particular case, I can version control my scripts in a repository that I can move back and forth between work and home using a memory stick.  Then in those two locations I can use a local copy as a central repository for the various machines in those networks.  Changes are moved back and forth between all of the various branches in a fashion that's pretty familiar to CVS or Subversion users.  So far, I'm really liking this solution. &lt;p&gt;There are plenty of DRCS solutions available.  The big names seem to be Git, Mercurial, Bazaar and DARCS, though there are plenty of others.  I settled on Bazaar.  Git is basically a Linux only solution, so it's out.  DARCS is reportedly very slow, and doesn't use a familiar scripting interface.  Mercurial and Bazaar are very comparable.  Mercurial is reportedly faster (and speed is one complaint I have with Bazaar), but I'm impressed with the development community behind Bazaar. &lt;div style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Programming" rel=tag&gt;Programming&lt;/a&gt;, &lt;a href="http://technorati.com/tags/RCS" rel=tag&gt;RCS&lt;/a&gt;, &lt;a href="http://technorati.com/tags/DRCS" rel=tag&gt;DRCS&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Bazaar" rel=tag&gt;Bazaar&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+Bazaar&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!295.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!295.entry</guid><pubDate>Sat, 21 Jul 2007 13:13:35 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!295/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!295.entry#comment</wfw:comment><dcterms:modified>2007-07-24T20:30:55Z</dcterms:modified></item><item><title>The importance of documentation</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!265.entry</link><description>&lt;p&gt;Fran's Bouma has an &lt;a href="http://weblogs.asp.net/fbouma/archive/2007/06/18/maintainable-software-why-you-can-t-live-without-proper-solid-documentation.aspx"&gt;interesting post&lt;/a&gt; about the importance of documentation.  I mostly agree with him.  We developers generally hate to write documentation, and Agile processes lead us to believe that we don't need to.  Our code is the documentation. 
&lt;p&gt;Well, I've used enough frameworks, OpenSource libraries and worked on enough unrelated large, pre-existing products that I can say with certainty that this is simply not true.  Code &lt;strong&gt;is not&lt;/strong&gt; documentation, nor is it enough &amp;quot;information&amp;quot; to get you by.  The amount of time required to become familiar enough with a large code base to be able to just find your way around, let alone to &lt;em&gt;correctly&lt;/em&gt; implement something inside of it, is simply huge.  I think most of us have been there in our careers.  You're on a new project or using some new library, and the source code is all you have.  You get assigned your first defect to work on and &amp;quot;become familiar with the code&amp;quot;.  You have absolutely no idea where to begin to look for the cause of the defect, and have a directory full of thousands of files with millions of lines of code. 
&lt;p&gt;Since we've all been there, we all fall back to the same patterns to &amp;quot;solve&amp;quot; our dilemma.  Out comes grep or some equivalent utility and we search for keywords we *think* will help us to find the area of the code in which to start looking.  If you're monumentally lucky, this will locate a minimum of hits and you can start trying to decipher the code.  Usually, though, you have to refine your search numerous times, and sometimes you'll even have to resort in asking someone else where to look, because you simply can't find anything unique to search on, and reading a million lines of code is obviously out of the question. 
&lt;p&gt;So, you eventually find where to look.  If the code is well designed and maintained, you can probably figure things out with little effort at this point.  But we all know the reality is that the code has likely grown organically and is now &amp;quot;spaghetti&amp;quot; that you have to pick apart.  Always a difficult task, but worse when you're new to the code base. 
&lt;p&gt;Well, you pick it apart and fix your first defect.  Congratulations, that just took you a factor of 10 times the amount of time it should have.  But, that's to be expected, because you're new to the code.  So, on to the next defect.  Rinse and repeat for a month or two. 
&lt;p&gt;Whew.  Now you're &amp;quot;acclimated&amp;quot; to the code base.  You can find your way around fine, so everything's OK now, right?  Nope.  Now you're given more difficult defects to work on, and since you've got nothing but the code to rely on for &amp;quot;documentation&amp;quot; you have to take what you see in the code literally.  The problem is, the code is specific, but not necessarily literal.  There's all kinds of information &amp;quot;between the lines&amp;quot; of the code.  The &amp;quot;why&amp;quot; that Fran's talked about.  So, you change an algorithm in ignorance and cause a meltdown in the code.  Or you &amp;quot;copy&amp;quot; a pattern from one place in the code (and no, I &lt;strong&gt;do not&lt;/strong&gt; mean you copy and paste code blindly and/or fail to refactor to properly reuse code), just to discover that there's details you don't understand that applied only to that specific place in the original code. 
&lt;p&gt;No, code is simply a set of instructions.  It's not documentation.  Documentation is designed to be consumed by humans, code is designed to be consumed by a computer.  Documentation has things code does not, nor can it.  Like a table of contents, a forward, an overview, an index, and figures and diagrams that convey a lot of conceptual information at a glance.  Documentation is understandable by team members who aren't developers, such as QA, sales and business analysts. 
&lt;p&gt;I can consume a large technical manual in a matter of hours.  Personally, I read Petzold's latest book on WPF in roughly 2 hours, cover to cover, and retained most of the information contained in the book.  What's not retained is readily re-discoverable through the table of contents, index and other structural concepts found in documentation that's not found in code.  In contrast, I'm lucky if I can read through a dozen source files in an entire work day with any real &amp;quot;depth of knowledge&amp;quot; on what I read.  That's not because I'm not experienced in reading code, though I will admit there are people who seem to be better at &amp;quot;spelunking code&amp;quot; than I am.  It's because code doesn't convey concepts, it conveys procedures.  Code isn't structured for human consumption, it's structured for machine execution. 
&lt;div&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Programming" rel=tag&gt;Programming&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Design" rel=tag&gt;Design&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+The+importance+of+documentation&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!265.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!265.entry</guid><pubDate>Thu, 21 Jun 2007 16:32:35 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!265/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!265.entry#comment</wfw:comment><dcterms:modified>2007-07-10T20:38:40Z</dcterms:modified></item><item><title>ModelView and Commands</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!255.entry</link><description>&lt;p&gt;I believe very strongly in using the &lt;a href="http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx"&gt;Model-View-ViewModel&lt;/a&gt; (be sure to search the blog site and read all the related articles) design pattern when programming in WPF.  You want your UI to be as &amp;quot;dumb&amp;quot; as possible.  There's two reasons for this.  First, we're moving towards a world where designers will be creating our UIs, so you need to find ways to remove the programming from the UI design entirely.  The designer should be able to use Blend or some other design tool to first mock-up the layout, and then databind the UI to objects provided by the programmer.  If you put logic in the UI directly, it complicates the process for the designer.  Even the idea of letting the developer modify the codebehind after the view has been mocked up isn't enough, since this still makes it difficult for the designer to make large changes to the UI later (such as replacing a ListBox with a Combobox or other such design changes).  Databinding and Commands actually allow the designer to tie controls to data and actions with no regard to the logic involved. &lt;p&gt;The other reason is for testing.  Testing UIs is non-trivial at best.  UI test automation software relies on simulating a user via &amp;quot;robot&amp;quot; scripts.  If you've ever done this, you know that writing these scripts is non-trivial.  Worse, they break with every minor UI change.  This makes doing automated UI testing extremely difficult at best.  However, by not putting real program logic in the UI code at all, it makes testing the full functionality of your application as easy as testing can be.  A little human testing of the actual UI will then suffice. &lt;p&gt;So, after that long diatribe, let's get to the heart of what I wanted to blog about.  I've been working on that MtG Binder application, and actually have an application running now that does everything that &lt;a href="http://gatherer.wizards.com"&gt;Gatherer&lt;/a&gt; does.  Lots of design work needs to be done on it yet, since the current UI is functional but not pretty.  There's also a lot of features that go beyond Gatherer that I plan to add.  In other words, lots of work yet to do.  But I've learned a lot about WPF development by undertaking this endeavor. &lt;p&gt;One of the things I strived to do with this application is to use the M-V-VM pattern.  That's a good thing, since it allowed me to hack together a working &amp;quot;prototype&amp;quot; that's &amp;quot;functional but not pretty&amp;quot;, while allowing me to easily turn it into something &amp;quot;elegant&amp;quot; with out having to touch the code.  The key to this pattern, to my mind, is the VM.  Anyone who's done UI work before is familiar with MVC and it's variants, such as Document-View from MFC.  So there's nothing to learn about proper data modeling, and not much to learn about proper view construction.  What's new with WPF (and yes, I know it's not new to Mac developers and other folks) is how databinding and Commands allow you to really put all of the user interaction logic inside the ViewModel instead of in your View.  Even if you consider the ViewModel to just be the Controller from MVC (I don't think that's accurate, but you can make the argument), with older technologies you still had to put a lot of logic in the View.  Not anymore.  Data, data conversions, data manipulations, and basically anything involving data can now be put into a ViewModel and trivially bound to UI controls.  This means complex control interactions, such as changing data displays in a panel based on the item selected in a listbox no longer needs any event logic at all.  For more complex user interactions, you can use Commands to abstract away the action coupling from the actual action.  A Command that submits data can be bound to the action taken from clicking a button, or to the action of losing focus on a control, all with no event handling logic needing to be coded. &lt;p&gt;My first attempt to do this, however, fell a little flat.  I put the Command definition on the ViewModel, where it belongs.  But when it came to implementing the CommandBindings for the command, I ran into problems.  The various command delegates should logically be defined in the ViewModel as well, but I found that the XAML didn't like wiring it this way (maybe it can do it and I didn't persist in figuring out what the issue was long enough, but I wanted to get things done and not spelunk into code through Reflector).  I knew John Gossman discussed doing this, so I inspected his example code.  To be honest, I didn't totally like what he'd done.  He abstracted out commands into a CommandModel with virtual methods you could override for the delegates on the CommandBinding.  But the actions taken by the commands is almost certainly going to require knowledge of the ViewModel.  I didn't want to create objects with this kind of coupling, especially when the functionality seemed to belong on the ViewModel not on a CommandModel.  So, I hacked his code to turn it &amp;quot;inside out&amp;quot;.  Here's what I wound up with.&lt;pre&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; CommandModel
{
    RoutedCommand command;
    ExecutedRoutedEventHandler executedHandler;
    CanExecuteRoutedEventHandler canExecuteHandler;

    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; CommandModel(ExecutedRoutedEventHandler executedHandler)
    {
        command = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; RoutedCommand();
        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.executedHandler = executedHandler;
    }

    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; CommandModel(ExecutedRoutedEventHandler executedHandler,
        CanExecuteRoutedEventHandler canExecuteHandler)
    {
        command = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; RoutedCommand();
        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.executedHandler = executedHandler;
        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.canExecuteHandler = canExecuteHandler;
    }

    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; RoutedCommand Command
    {
        &lt;span style="color:#0000ff"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; command; }
    }

    &lt;span style="color:#0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; OnQueryEnabled(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; sender, CanExecuteRoutedEventArgs e)
    {
        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (canExecuteHandler != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)
        {
            canExecuteHandler(sender, e);
        }
        &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;
        {
            e.CanExecute = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;;
            e.Handled = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;;
        }
    }

    &lt;span style="color:#0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; OnExecute(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; sender, ExecutedRoutedEventArgs e)
    {
        executedHandler(sender, e);
    }
}&lt;/pre&gt;
&lt;p&gt;This allows me to create the CommandModel within the ViewModel and tie it to event handlers within the ViewModel itself.  I you want to use it in the way illustrated by Mr. Gossman, you still can, but I prefer the functionality to be in the ViewModel.
&lt;p&gt;The only thing I'm left with that still feels a bit kludgy to me is the CreateCommandBinding class with the attached property used to wire up the actual CommandBinding through our CommandModel.  But it works, so I'll live with it until I find a more elegant (to my eye) solution.
&lt;div style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/WPF" rel=tag&gt;WPF&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+ModelView+and+Commands&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!255.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!255.entry</guid><pubDate>Tue, 12 Jun 2007 20:43:27 GMT</pubDate><slash:comments>1</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!255/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!255.entry#comment</wfw:comment><dcterms:modified>2007-06-12T20:43:27Z</dcterms:modified></item><item><title>IronPython as a tool for learning WPF...</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!247.entry</link><description>&lt;p&gt;This isn't anything new.  It's a couple of old screen casts that show using IronPython to learn WPF.  If you haven't seen them, you should.  IronPython turns out to be a great way to &amp;quot;play&amp;quot; with WPF, which is useful even when you're no longer a newbie.  It's a shorter development cycle to test out concepts in script and then implement in your language of choice, then it is to go through the edit/compile/test cycle. &lt;p&gt;The main reason for this post, is so that I have a convenient place to find these resources again. &lt;p&gt;&lt;a title="http://mattgriffith.net/Permalink.aspx?guid=0b9de84a-d84e-484c-b06f-8ff75ab70b9f" href="http://mattgriffith.net/Permalink.aspx?guid=0b9de84a-d84e-484c-b06f-8ff75ab70b9f"&gt;http://mattgriffith.net/Permalink.aspx?guid=0b9de84a-d84e-484c-b06f-8ff75ab70b9f&lt;/a&gt; &lt;p&gt;&lt;a title="http://mattgriffith.net/PermaLink.aspx?guid=a1cb7215-2719-4c38-8ce3-ba7408aa69aa" href="http://mattgriffith.net/PermaLink.aspx?guid=a1cb7215-2719-4c38-8ce3-ba7408aa69aa"&gt;http://mattgriffith.net/PermaLink.aspx?guid=a1cb7215-2719-4c38-8ce3-ba7408aa69aa&lt;/a&gt; &lt;p&gt;  &lt;div style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/IronPython" rel=tag&gt;IronPython&lt;/a&gt;, &lt;a href="http://technorati.com/tags/WPF" rel=tag&gt;WPF&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+IronPython+as+a+tool+for+learning+WPF...&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!247.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!247.entry</guid><pubDate>Wed, 06 Jun 2007 18:21:59 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!247/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!247.entry#comment</wfw:comment><dcterms:modified>2007-06-06T18:21:59Z</dcterms:modified></item><item><title>Layout Is Difficult</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!246.entry</link><description>&lt;p&gt;I've used many UI frameworks.  Some of them have built in layout capabilities, and others don't.  Obviously, building a complex UI, especially one that requires the capability to be resized, is much easier to do in a framework that has layout facilities.  Unfortunately, even the frameworks that I've used that have very rich layout &amp;quot;managers&amp;quot;, it often turns out that creating layouts is still a difficult task.  And I'm not referring to the complexities of design here.  No, I'm talking about actually making your layout match your design through code! 
&lt;p&gt;All of that was just introduction to this post, which is a rant about my current trials and tribulations using WPF.  But don't take this wrong.  This isn't an attempt to bash WPF, because as I said in the first paragraph, I've found every framework I've ever used to be lacking. 
&lt;p&gt;The trouble is that, though layout managers follow strict and rigid rules for how child controls are positioned and sized, there are two things that make using them difficult.  First, the actual rules used aren't always well documented.  Interactions from nested layout managers can cause scenarios that just aren't discussed in the documentation, which generally tries to give a high level description of how layout occurs, rather than explaining the algorithm in detail.  Except for corner cases, though, this issue is one that experience with the framework can overcome rather quickly. 
&lt;p&gt;The bigger issue is that often the layout algorithms are simply incomprehensible.  They don't behave the way you'd expect them to, which makes becoming familiar with the undocumented behavior difficult at best.  In some cases, it seems just impossible to figure out, and you're left with &amp;quot;hacking&amp;quot; the layout to get it to behave, at least close to how you want it to behave, for specific scenarios.  These hacks, however, don't lend themselves to repeated use in similar but different layout scenarios. 
&lt;p&gt;Here's a great example, and one that I'm struggling with in real code, and actually what brought on this rant.  Let's start with a simple layout.  Imagine we have some data we want to present, and just for illustrative purposes we'll say it's data about books we have in stock for resell.  There's lots of data, but what we care about presenting is the title, the price and an excerpt or other lengthy text about the book.  I'm not going to be too specific here, and this is all just for illustrative purposes.  We want to place the title of the book on the first line, and also place the price on this line, but make it right aligned.  Then, on the next line we'll place the excerpt, but we want it to wrap to multiple lines depending on the size of the page. 
&lt;p&gt;All of this sounds rather simple, and in fact it is rather trivial to do in WPF/XAML.  Here's some example code with hard coded data to illustrate the layout.&lt;pre&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;Page&lt;/span&gt; 
  &lt;span style="color:#ff0000"&gt;xmlns&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;
  &lt;span style="color:#ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;x&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;Grid&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;ColumnDefinition&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;ColumnDefinition&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;TextBlock&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Grid&lt;/span&gt;.&lt;span style="color:#ff0000"&gt;Column&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Text&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;Title Here&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;TextBlock&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Grid&lt;/span&gt;.&lt;span style="color:#ff0000"&gt;Column&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Text&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;Price&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;TextAlignment&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;Right&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;Grid&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;TextBlock&lt;/span&gt; &lt;span style="color:#ff0000"&gt;TextWrapping&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;Wrap&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;![CDATA[
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed neque et tellus tincidunt interdum. Morbi diam eros, imperdiet at, volutpat et, vestibulum quis, sem. Curabitur eu tellus vel felis molestie malesuada. Pellentesque nec lacus. Aenean fringilla nonummy sapien. Morbi eu odio at turpis cursus tristique. Integer nec lectus sit amet turpis bibendum feugiat. Cras posuere condimentum sapien. Vivamus accumsan, lacus at bibendum vehicula, magna elit consectetuer diam, ac luctus elit diam non leo. Vestibulum lobortis augue nec nisl. Fusce viverra purus consequat lacus. Nullam elementum mattis tellus. In hac habitasse platea dictumst. Aliquam ac velit sit amet urna placerat fringilla. Fusce mattis arcu eget urna. Sed lacus. 
]]&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;Page&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;This works great, and out layout is easily resizable.  But we don't have a single book, we have a collection of them.  So we want to do this inside a ListBox (or other such ItemsControl).  So, here's the same layout, but placed in our ListBox (again, I'm hard coding things for simplicity, but you'd find the same results using styles/templates and bound data).&lt;pre&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;Page&lt;/span&gt; &lt;br&gt;  &lt;span style="color:#ff0000"&gt;xmlns&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt;&lt;br&gt;  &lt;span style="color:#ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;x&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;ListBox&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;Grid&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;ColumnDefinition&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;          &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;ColumnDefinition&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;TextBlock&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Grid&lt;/span&gt;.&lt;span style="color:#ff0000"&gt;Column&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Text&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;Title Here&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;TextBlock&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Grid&lt;/span&gt;.&lt;span style="color:#ff0000"&gt;Column&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Text&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;Price&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;TextAlignment&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;Right&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;Grid&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;      &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000"&gt;TextBlock&lt;/span&gt; &lt;span style="color:#ff0000"&gt;TextWrapping&lt;/span&gt;=&lt;span style="color:#0000ff"&gt;&amp;quot;Wrap&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;![CDATA[&lt;br&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed neque et tellus tincidunt interdum. Morbi diam eros, imperdiet at, volutpat et, vestibulum quis, sem. Curabitur eu tellus vel felis molestie malesuada. Pellentesque nec lacus. Aenean fringilla nonummy sapien. Morbi eu odio at turpis cursus tristique. Integer nec lectus sit amet turpis bibendum feugiat. Cras posuere condimentum sapien. Vivamus accumsan, lacus at bibendum vehicula, magna elit consectetuer diam, ac luctus elit diam non leo. Vestibulum lobortis augue nec nisl. Fusce viverra purus consequat lacus. Nullam elementum mattis tellus. In hac habitasse platea dictumst. Aliquam ac velit sit amet urna placerat fringilla. Fusce mattis arcu eget urna. Sed lacus. &lt;br&gt;  ]]&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;  &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;ListBox&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000"&gt;Page&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Oops.  When you run this you'll find that, despite the fact we've used identical code for the layout of the data, our text excerpt now fails to wrap!  This behavior is definitely not intuitive, and it makes understanding the logic employed by the layout managers very difficult to learn. 
&lt;p&gt;Searching the web for explanation on this, or at least for a way to achieve what we want, I find posts like &lt;a href="http://www.wiredprairie.us/journal/2007/05/give_me_the_maximum_and_no_mor.html"&gt;this one&lt;/a&gt;.  So, the prevailing &amp;quot;solution&amp;quot; is a hack that removes the horizontal scrollbar.  This works, but I call it a hack for a reason.  This only works in very specific circumstances.  Even in this specific case, it has problems.  Resizing the control to be too small can cause issues with the first line of data.  We really want to limit the width of the Grid to prevent having it sized too small to present the title and the price.  If it gets too small, we want the user to be able to scroll to see all of the data, but in order to do that we have to not disable the scrollbar, resulting in our first problem again! 
&lt;p&gt;I've tried other hacks, such as data binding the Width of the TextBlock to the ActualWidth of the ListBox.  This almost works, though there are some resizing artifacts caused by this.  In any event, that's a fairly draconian solution to what seems to me to be simply a design flaw in WPF layout logic.  I obviously made the TextBlock wrap for a reason, and any panel that ignores that is, IMHO, broken. 
&lt;p&gt;So, now that my rant is over, are there any WPF experts that care to explain how this simple layout should be achieved? 
&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt;  Here's &lt;a href="http://wpfwonderland.wordpress.com/2007/01/14/layout-quirks-in-wpf/"&gt;another great example&lt;/a&gt; of inconsistent layout behavior to illustrate my point.
&lt;p&gt; 
&lt;div&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/WPF" rel=tag&gt;WPF&lt;/a&gt;, &lt;a href="http://technorati.com/tags/XAML" rel=tag&gt;XAML&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+Layout+Is+Difficult&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!246.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!246.entry</guid><pubDate>Mon, 04 Jun 2007 14:04:19 GMT</pubDate><slash:comments>46</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!246/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!246.entry#comment</wfw:comment><dcterms:modified>2007-06-04T14:28:03Z</dcterms:modified></item><item><title>Dynamic LINQ Expression Predicates</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!245.entry</link><description>&lt;p&gt;I searched high and low for code that explained how to create dynamic LINQ queries.  Specifically, all I really needed where's a where filter.  No need for sorting or grouping.  Anyway, I finally ran across &lt;a href="http://www.albahari.com/expressions/"&gt;this wonderful article&lt;/a&gt; with a PredicateBuilder extension class.  Works like a charm.  Thanks, Joseph Albahari. &lt;div style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/LINQ" rel=tag&gt;LINQ&lt;/a&gt;, &lt;a href="http://technorati.com/tags/.NET" rel=tag&gt;.NET&lt;/a&gt;, &lt;a href="http://technorati.com/tags/C#" rel=tag&gt;C#&lt;/a&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+Dynamic+LINQ+Expression+Predicates&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!245.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!245.entry</guid><pubDate>Thu, 31 May 2007 20:52:45 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!245/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!245.entry#comment</wfw:comment><dcterms:modified>2007-05-31T20:52:45Z</dcterms:modified></item><item><title>Vote for lamest new feature in C# 3.0</title><link>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!234.entry</link><description>&lt;pre&gt;&lt;strong&gt;Automatic Properties.&lt;/strong&gt;  Lame.  Very lame.&lt;/pre&gt;
&lt;p&gt;Reading comments on various blogs indicates this is the feature most people seem to be most excited about.  Which is depressing.  Every other language feature being added has me excited, while this one doesn't.  Not at all.  In fact, I doubt I'll ever use it, and any code that I find that does use it will immediately be suspect by me. 
&lt;p&gt;Here's some example code:&lt;pre&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; Foo
{
	&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Bar { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }
}

&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; Program
{
	&lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] args)
	{
		Foo foo = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; Foo();
		foo.Bar = &amp;quot;&lt;span style="color:#8b0000"&gt;Baz&lt;/span&gt;&amp;quot;;
		Console.WriteLine(foo.Bar);
	}
}
&lt;/pre&gt;
&lt;p&gt;This &amp;quot;saves&amp;quot; me from having to write this portion of the code in this way:&lt;pre&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; Foo
{
	&lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; bar;
	&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Bar
	{
		&lt;span style="color:#0000ff"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; bar; }
		&lt;span style="color:#0000ff"&gt;set&lt;/span&gt; { bar = &lt;span style="color:#0000ff"&gt;value&lt;/span&gt;; }
	}
}&lt;/pre&gt;
&lt;p&gt;The problem is, I pretty much never, ever, write code like that above.  &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx"&gt;This&lt;/a&gt; blog post suggests that the above is useful for databinding reasons.  My very first thought about that is, if databinding can't handle fields (it can't), don't you think it would make more sense to &amp;quot;fix&amp;quot; databinding so that it can, rather than add this syntactic sugar for that?  My second thought is, no, even that would be a mistake, and that's at least part of the reason I never have code that looks like that above. 
&lt;p&gt;Huh?  What the heck is this crackpot talking about? 
&lt;p&gt;See, when databinding, I expect my UI to update in response to changes to the data model.  This means INotifyPropertyChanged or other mechanisms will need to be employed any time the data changes, and you can't do that with automatic properties that expose a public setter.  That leaves one minor interesting variation that I could see someone using under rare circumstances:&lt;pre&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; Foo : INotifyPropertyChanged
{
	&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Bar { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }
	&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; DoSomethingThatModifiesBar()
	{
		Bar = &amp;quot;&lt;span style="color:#8b0000"&gt;Baz&lt;/span&gt;&amp;quot;;
		OnPropertyChanged(&amp;quot;&lt;span style="color:#8b0000"&gt;Bar&lt;/span&gt;&amp;quot;);
	}
	&lt;span style="color:#008000"&gt;// snip code for implementing INotifyPropertyChanged&lt;/span&gt;
}&lt;/pre&gt;
&lt;p&gt;But that's not a very common thing, and the syntactic sugar here has saved me very little. In fact, it does make the code a little less robust when it comes to maintenance, because now every place that calls the internal setter must explicitly add code to raise the PropertyChanged event.  If I hand code this instead of using an automatic property, I can put the PropertyChanged code inside the private setter and not have to worry that we'll forget to do it somewhere in the code base. 
&lt;p&gt;So, what if you don't plan to use the class in question in any databinding scenarios?  Or, in other words, you aren't using INotifyPropertyChanged.  OK, fine.  But how many such properties have you ever coded that didn't do some validation or something else in the setter.  Me, I can count the number of times I've written a setter that simply did &amp;quot;_bar = value;&amp;quot; on the fingers of my right hand.  Simple getters, yes, simple setters, no.  So, I can see using the &amp;quot;public get, private set&amp;quot; example above in some cases, such as for the Count property on a custom collection (though even there, the property is often calculated and not a simple getter).  But even for this corner case, the syntactic sugar hasn't really bought me anything.  Slightly less code, but code snippets achieve the same result when writing the code, and the difference in the code when reading isn't enough to make the code any clearer (in fact, I'd argue it makes it less clear).  So, I see no benefit. 
&lt;p&gt;Maybe there's some weird corner case reason for this feature used within LINQ that makes it a useful thing to have added, but I've never seen it blogged about and I can't fathom what such a thing would be.  No, I think this feature was added simply because many people have asked for such a feature.  Most, through ignorance and laziness, not wanting to type as much.  Those are the people who are excited about this new feature, and I they are the ones who scare me.  Good design, as I tried to illustrate above, would dictate this feature would hardly ever be used, so if you're excited about the feature it means you're probably not coding with good design. 
&lt;p&gt;That said, there's another class of people who wanted a feature like this, and they weren't so ignorant.  They've used facilities in other languages that provide syntactic sugar for defining properties that don't make it difficult to properly design them.  Here's a possible variation in C# that would have been useful:&lt;pre&gt;&lt;span style="color:#0000ff"&gt;property string&lt;/span&gt; Bar;&lt;/pre&gt;
&lt;p&gt;This would produce a property named Bar with trivial get and set implementations.  Slightly less code, but so far this doesn't illustrate the difference in the concept yet, and is doing something that, again, good design would dictate you should hardly ever actually do.  So, let's show how we'd make this work as in my INotifyPropertyChanged example above:&lt;pre&gt;&lt;span style="color:#0000ff"&gt;property string&lt;/span&gt; Bar
{
	&lt;span style="color:#0000ff"&gt;get&lt;/span&gt;;
	&lt;span style="color:#0000ff"&gt;set&lt;/span&gt;
	{
		@Bar = &lt;span style="color:#0000ff"&gt;value&lt;/span&gt;;
		OnPropertyChanged(&amp;quot;&lt;span style="color:#8b0000"&gt;Bar&lt;/span&gt;&amp;quot;);
	}
}&lt;/pre&gt;
&lt;p&gt;Here's where we get some power!  I can leave the parts that are trivial out (heck, I think the above should work with out the &amp;quot;get;&amp;quot; line in exactly the same way).  The non-trivial parts can now be explicitly added.  We need a way to access the &amp;quot;hidden&amp;quot; variable generated for us here, and I chose to use the &amp;quot;@&amp;quot; sign that's already available for specifying variable names that are keywords.  This may prove to cause problems in language implementation, and if it does, just change the &amp;quot;@&amp;quot; to &amp;quot;$&amp;quot; or use some other mechanism, I don't care.  The point is, for property generators to be useful in the real world, you need two features missing from C# 3.0's implementation.  You need to be able to access the &amp;quot;hidden&amp;quot; field that was generated by the compiler (possibly even from places other than getter/setter code!), and you need to be able to override individual parts (get/set) of the property to make them non-trivial implementations.  With out these features, I won't ever use automatic properties, and I'd question any code that did.
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;  Jomo Fisher has an article, &amp;quot;&lt;a href="http://blogs.msdn.com/jomo_fisher/archive/2007/07/23/the-least-you-need-to-know-about-c-3-0.aspx"&gt;The Least You Need to Know about C# 3.0&lt;/a&gt;&amp;quot;, where he talks about about this new feature, calling it &amp;quot;one of my favorite new features.&amp;quot;  My first reaction was to roll my eyes.  Then I finished reading the sentence, and you know, he's actually come up with a use for this feature.  It makes it &amp;quot;easier&amp;quot; to implement immutable types.  Doesn't change my mind, because even this use case comes down to simply saving you a little typing, and I think code snippets are a better choice for doing that.  But it's still worthy of acknowledging.&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-3347231426831879729&amp;page=RSS%3a+Vote+for+lamest+new+feature+in+C%23+3.0&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wekempf.spaces.live.com&amp;amp;GT1=wekempf"&gt;</description><comments>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!234.entry#comment</comments><guid isPermaLink="true">http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!234.entry</guid><pubDate>Wed, 16 May 2007 16:31:53 GMT</pubDate><slash:comments>5</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!234/comments/feed.rss</wfw:commentRss><wfw:comment>http://wekempf.spaces.live.com/Blog/cns!D18C3EC06EA971CF!234.entry#comment</wfw:comment><dcterms:modified>2007-08-01T13:31:45Z</dcterms:modified></item></channel></rss>