<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Wandering through the Wilderness</title>
  <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/" />
  <link rel="self" href="http://www.julmar.com/blog/mark/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2010-02-06T09:56:59.6777762-08:00</updated>
  <author>
    <name>Mark Smith</name>
  </author>
  <subtitle>... a journey through WPF, MVVM and .NET4</subtitle>
  <id>http://www.julmar.com/blog/mark/</id>
  <generator uri="http://dasblog.info/" version="2.3.9074.18820">DasBlog</generator>
  <entry>
    <title>ATAPI.NET and ITAPI3 source code availability!</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/02/06/ATAPINETAndITAPI3SourceCodeAvailability.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,a7333798-461f-4471-96b1-d4375c0ee379.aspx</id>
    <published>2010-02-06T09:56:38.4122873-08:00</published>
    <updated>2010-02-06T09:56:59.6777762-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="Tapi" label="Tapi" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Tapi.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I cannot count how many times people have requested the source code to the ATAPI.NET
or ITAPI3 projects.  My response has always been that I was unable to release
it due to ownership issues (it was developed under contract for a client).  I
am pleased to announce this morning that I have worked through those issues and have
been granted permission to release the project in it’s entirety as source code on
CodePlex!
</p>
        <p>
Here’s their new homes:  <a title="http://atapi.codeplex.com/" href="http://atapi.codeplex.com/">http://atapi.codeplex.com/</a> and <a href="http://itapi3.codeplex.com">http://itapi3.codeplex.com</a></p>
        <p>
I’ll open up discussion board access there as well for Q&amp;A.  If you would
like to contribute to the project, shoot me an email and we’ll see about getting you
access!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>MVVM Helpers has a new home!</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/02/06/MVVMHelpersHasANewHome.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,007b3372-0579-4940-8da3-f72131be1c37.aspx</id>
    <published>2010-02-06T07:20:51.5025611-08:00</published>
    <updated>2010-02-06T07:20:51.5025611-08:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ve published it to <a title="http://mvvmhelpers.codeplex.com/" href="http://mvvmhelpers.codeplex.com/">http://mvvmhelpers.codeplex.com/</a> where
I’ll continue to maintain and add to it.  Get the latest release from there!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Blend Behaviors in Styles: DragPositionBehavior</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/02/05/BlendBehaviorsInStylesDragPositionBehavior.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,f6809b09-7c04-4272-99fd-acfa5fc53ad9.aspx</id>
    <published>2010-02-05T15:01:51.6845072-08:00</published>
    <updated>2010-02-05T15:01:51.6845072-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="MVVM" label="MVVM" scheme="http://www.julmar.com/blog/mark/CategoryView,category,MVVM.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the last post, I referred to the <strong>DragPositionBehavior </strong>in the JulMar
MVVM library.  This behavior allows any <strong>UIElement </strong>to be dragged
and repositioned using the mouse without requiring any code logic on your part. 
It’s easy to apply – using the traditional Blend syntax (easiest done by dragging
the behavior onto an element):
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;}??\fs28 \cf1     \cf3 &lt;\cf1 Interactivity\cf3 :\cf1 Interaction.Behaviors\cf3 &gt;\par ??\cf1         \cf3 &lt;\cf1 julmar\cf3 :\cf1 DragPositionBehavior\cf3  /&gt;\par ??\cf1     \cf3 &lt;/\cf1 Interactivity\cf3 :\cf1 Interaction.Behaviors\cf3 &gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Interactivity</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">Interaction.Behaviors</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">julmar</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">DragPositionBehavior</span>
            <span style="color: blue"> /&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Interactivity</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">Interaction.Behaviors</span>
            <span style="color: blue">&gt;</span>
          </p>
        </div>
        <p>
          <br />
This is the simplest way to use this, however it doesn’t work when the behavior is
to be applied with a Style – in my example in the prior post, we need to drag around
the <strong>ListBoxItem</strong> container, not just the content.  So I showed
an alternative syntax to apply the same behavior:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;}??\fs28 \cf1     \cf3 &lt;\cf1 ListBox.ItemContainerStyle\cf3 &gt;\par ??\cf1         \cf3 &lt;\cf1 Style\cf4  TargetType\cf3 ="ListBoxItem"&gt;\par ??\cf1             \cf3 &lt;\cf1 Setter\cf4  Property\cf3 ="julmar:DragPositionBehavior.IsEnabled"\cf4  Value\cf3 ="True" /&gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">ListBox.ItemContainerStyle</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Style</span>
            <span style="color: red"> TargetType</span>
            <span style="color: blue">="ListBoxItem"&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Setter</span>
            <span style="color: red"> Property</span>
            <span style="color: blue">="julmar:DragPositionBehavior.IsEnabled"</span>
            <span style="color: red"> Value</span>
            <span style="color: blue">="True"
/&gt;</span>
          </p>
        </div>
        <p>
          <br />
Here, the behavior is being applied by setting the <strong>IsEnabled attached property</strong> onto
the <strong>ListBoxItem</strong>.  Here’s the implementation for that:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs28 \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??///\cf3  This property allows the behavior to be used as a traditional\par ??\cf1 ///\cf3  attached property behavior.\par ??\cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf4 public\cf0  \cf4 static\cf0  \cf6 DependencyProperty\cf0  IsEnabledProperty =\par ??    \cf6 DependencyProperty\cf0 .RegisterAttached(\cf7 "IsEnabled"\cf0 , \cf4 typeof\cf0 (\cf4 bool\cf0 ), \cf4 typeof\cf0 (\cf6 DragPositionBehavior\cf0 ),\par ??        \cf4 new\cf0  \cf6 FrameworkPropertyMetadata\cf0 (\cf4 false\cf0 , OnIsEnabledChanged));\par ??\par ??\cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??///\cf3  Returns whether DragPositionBehavior is enabled via attached property\par ??\cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??///\cf3  \cf1 &lt;param name="uie"&gt;\cf3 Element\cf1 &lt;/param&gt;\par ??///\cf3  \cf1 &lt;returns&gt;\cf3 True/False\cf1 &lt;/returns&gt;\par ??\cf4 public\cf0  \cf4 static\cf0  \cf4 bool\cf0  GetIsEnabled(\cf6 DependencyObject\cf0  uie)\par ??\{\par ??    \cf4 return\cf0  (\cf4 bool\cf0 )uie.GetValue(IsEnabledProperty);\par ??\}\par ??\par ??\cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??///\cf3  Adds DragPositionBehavior to an element\par ??\cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??///\cf3  \cf1 &lt;param name="uie"&gt;\cf3 Element to apply\cf1 &lt;/param&gt;\par ??///\cf3  \cf1 &lt;param name="value"&gt;\cf3 True/False\cf1 &lt;/param&gt;\par ??\cf4 public\cf0  \cf4 static\cf0  \cf4 void\cf0  SetIsEnabled(\cf6 DependencyObject\cf0  uie, \cf4 bool\cf0  value)\par ??\{\par ??    uie.SetValue(IsEnabledProperty, value);\par ??\}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">static</span>
            <span style="color: #2b91af">DependencyProperty</span> IsEnabledProperty
=
</p>
          <p style="margin: 0px">
    <span style="color: #2b91af">DependencyProperty</span>.RegisterAttached(<span style="color: #a31515">"IsEnabled"</span>, <span style="color: blue">typeof</span>(<span style="color: blue">bool</span>), 
<br />
        <span style="color: blue">typeof</span>(<span style="color: #2b91af">DragPositionBehavior</span>),
</p>
          <p style="margin: 0px">
        <span style="color: blue">new</span><span style="color: #2b91af">FrameworkPropertyMetadata</span>(<span style="color: blue">false</span>,
OnIsEnabledChanged));
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">static</span>
            <span style="color: blue">bool</span> GetIsEnabled(<span style="color: #2b91af">DependencyObject</span> uie)
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: blue">return</span> (<span style="color: blue">bool</span>)uie.GetValue(IsEnabledProperty);
</p>
          <p style="margin: 0px">
}
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">static</span>
            <span style="color: blue">void</span> SetIsEnabled(<span style="color: #2b91af">DependencyObject</span> uie, <span style="color: blue">bool</span> value)
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    uie.SetValue(IsEnabledProperty, value);
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
This is a boilerplate example of an attached property – nothing to see here. 
The magic happens in the <strong>PropertyChange </strong>callback:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs28 \cf1 private\cf0  \cf1 static\cf0  \cf1 void\cf0  OnIsEnabledChanged(\cf4 DependencyObject\cf0  dpo, \cf4 DependencyPropertyChangedEventArgs\cf0  e)\par ??\{\par ??    \cf4 UIElement\cf0  uie = dpo \cf1 as\cf0  \cf4 UIElement\cf0 ;\par ??    \cf1 if\cf0  (uie != \cf1 null\cf0 )\par ??    \{\par ??        \cf1 var\cf0  behColl = \cf4 Interaction\cf0 .GetBehaviors(uie);\par ??        \cf1 var\cf0  existingBehavior = behColl.FirstOrDefault(b =&gt; b.GetType() == \cf1 typeof\cf0 (\cf4 DragPositionBehavior\cf0 )) \cf1 as\cf0  \cf4 DragPositionBehavior\cf0 ;\par ??        \cf1 if\cf0  ((\cf1 bool\cf0 )e.NewValue == \cf1 false\cf0  &amp;&amp; existingBehavior != \cf1 null\cf0 )\par ??        \{\par ??            behColl.Remove(existingBehavior);\par ??        \}\par ??        \cf1 else\cf0  \cf1 if\cf0  ((\cf1 bool\cf0 )e.NewValue == \cf1 true\cf0  &amp;&amp; existingBehavior == \cf1 null\cf0 )\par ??        \{\par ??            behColl.Add(\cf1 new\cf0  \cf4 DragPositionBehavior\cf0 ());\par ??        \}\par ??    \}\par ??\}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">private</span>
            <span style="color: blue">static</span>
            <span style="color: blue">void</span> OnIsEnabledChanged(<span style="color: #2b91af">DependencyObject</span> dpo, 
</p>
          <p style="margin: 0px">
                                       <span style="color: #2b91af">DependencyPropertyChangedEventArgs</span> e)
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: #2b91af">UIElement</span> uie = dpo <span style="color: blue">as</span><span style="color: #2b91af">UIElement</span>;
</p>
          <p style="margin: 0px">
    <span style="color: blue">if</span> (uie != <span style="color: blue">null</span>)
</p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        <span style="color: blue">var</span> behColl
= <span style="color: #2b91af">Interaction</span>.GetBehaviors(uie);
</p>
          <p style="margin: 0px">
        <span style="color: blue">var</span> existingBehavior
= behColl.FirstOrDefault(b =&gt; b.GetType() == 
<br />
              <span style="color: blue">typeof</span>(<span style="color: #2b91af">DragPositionBehavior</span>)) <span style="color: blue">as</span><span style="color: #2b91af">DragPositionBehavior</span>;
</p>
          <p style="margin: 0px">
        <span style="color: blue">if</span> ((<span style="color: blue">bool</span>)e.NewValue
== <span style="color: blue">false</span> &amp;&amp; existingBehavior != <span style="color: blue">null</span>)
</p>
          <p style="margin: 0px">
        {
</p>
          <p style="margin: 0px">
            behColl.Remove(existingBehavior);
</p>
          <p style="margin: 0px">
        }
</p>
          <p style="margin: 0px">
        <span style="color: blue">else</span><span style="color: blue">if</span> ((<span style="color: blue">bool</span>)e.NewValue
== <span style="color: blue">true</span> &amp;&amp; existingBehavior == <span style="color: blue">null</span>)
</p>
          <p style="margin: 0px">
        {
</p>
          <p style="margin: 0px">
            behColl.Add(<span style="color: blue">new</span><span style="color: #2b91af">DragPositionBehavior</span>());
</p>
          <p style="margin: 0px">
        }
</p>
          <p style="margin: 0px">
    }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
Let’s break this down a little.  When we have the IsEnabled property set onto
an element, first we verify it’s a <strong>UIElement </strong>(we cannot drag it on
anything that isn’t because the mouse events are defined at this level).  Next,
we check the behaviors collection on that element – if an existing behavior is there
and we are setting the property to “false”, then we remove the existing behavior from
the collection.  If there is no behavior, and we are setting the property to
“true”, then we add a new <strong>DragPositionBehavior </strong>instance to the collection
here.  This, in effect, is exactly what the first block of XAML is doing, and
it’s what we do as well here in code – so the Style setter works as expected.
</p>
        <p>
This isn’t really a trick – I’m sure others have thought of it as well, but it’s a
useful thing to add into your behaviors so they can be universally used, both by Blend
as well as by developers directly wanting to apply it in places where Blend cannot
today.
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>MVVM: IUIVisualizer and event management with behaviors</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/02/05/MVVMIUIVisualizerAndEventManagementWithBehaviors.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,3d40b8c3-fab0-4e64-90a8-59a3582a2e31.aspx</id>
    <published>2010-02-05T14:43:16.9728914-08:00</published>
    <updated>2010-02-05T15:02:22.184312-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="MVVM" label="MVVM" scheme="http://www.julmar.com/blog/mark/CategoryView,category,MVVM.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In this post, we will look at the <strong>IUIVisualizer</strong>, and bring together
some of the concepts we’ve talked about already through a new sample – a simple picture
viewer:
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_2.png">
            <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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb.png" width="520" height="393" />
          </a>
        </p>
        <p>
The application grabs all the images from the user’s photo folder and then displays
each one onto the surface of a corkboard.  You can change the properties of an
image, remove an image or add additional images.  It’s not designed to be a true
image application ala photoSuru, it’s really more of a sample of MVVM practices with
the helper library.  Here’s some of the coding examples present in the sample:
</p>
        <ul>
          <li>
It registers a <strong>ISelectFile</strong> service and implements it as an OpenFileDialog. 
</li>
          <li>
It displays a “Picture Properties” dialog using the <strong>IUIVisualizer</strong> service. 
</li>
          <li>
It maps mouse DoubleClick on an image into a command in the ViewModel to display the
properties. 
</li>
          <li>
It provides drag support through a behavior on the style.</li>
        </ul>
        <p>
Let’s look at this four features in particular.  Download the sample from here:
</p>
        <p>
          <a href="http://www.julmar.com/samples/PictureViewer.zip" target="_blank">PictureViewer</a>
        </p>
        <p>
Open the project in Visual Studio 2008 SP1, it should build and run without any issues. 
The project structure is pretty much like all the other samples I’ve blogged about
– I’m trying to keep to a consistent model:
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_4.png">
            <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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb_1.png" width="283" height="595" />
          </a>
        </p>
        <h4>Service Registration
</h4>
        <p>
If you look at the <strong>App.xaml.cs</strong> code behind, you’ll find the registration
work being done in the constructor:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red0\green128\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs28 \cf1 public\cf0  App()\par ??\{\par ??    \cf4 // Register the typical services (UI, Error, etc.) for this application.\par ??\cf0     \cf5 ViewModel\cf0 .RegisterKnownServiceTypes();\par ??\par ??    \cf4 // Register the file selector service.\par ??\cf0     \cf5 ViewModel\cf0 .ServiceProvider.Add(\cf1 typeof\cf0 (\cf5 ISelectFile\cf0 ), \cf1 new\cf0  \cf5 OpenFileDialogSelector\cf0 ());\par ??\par ??    \cf4 // Register the UI dialogs.\par ??\cf0     \cf1 var\cf0  uiVisualizer = \cf5 ViewModel\cf0 .ServiceProvider.Resolve&lt;\cf5 IUIVisualizer\cf0 &gt;();\par ??        uiVisualizer.Register(\cf6 "ShowElementProperties"\cf0 , \cf1 typeof\cf0 (\cf5 PropertyWindow\cf0 ));\par ??\}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span> App()
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: green">// Register the typical services (UI,
Error, etc.) for this application.</span></p>
          <p style="margin: 0px">
    <span style="color: #2b91af">ViewModel</span>.RegisterKnownServiceTypes();
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
    <span style="color: green">// Register the file selector service.</span></p>
          <p style="margin: 0px">
    <span style="color: #2b91af">ViewModel</span>.ServiceProvider.Add(<span style="color: blue">typeof</span>(<span style="color: #2b91af">ISelectFile</span>), <span style="color: blue">new</span><span style="color: #2b91af">OpenFileDialogSelector</span>());
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
    <span style="color: green">// Register the UI dialogs.</span></p>
          <p style="margin: 0px">
    <span style="color: blue">var</span> uiVisualizer = <span style="color: #2b91af">ViewModel</span>.ServiceProvider.Resolve&lt;<span style="color: #2b91af">IUIVisualizer</span>&gt;();
</p>
          <p style="margin: 0px">
        uiVisualizer.Register(<span style="color: #a31515">"ShowElementProperties"</span>, <span style="color: blue">typeof</span>(<span style="color: #2b91af">PropertyWindow</span>));
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
First, note that it registers the standard services – that’s something I always do,
even if I don’t anticipate needing them all, it doesn’t hurt to have them there. Next,
it adds the file selector service by calling <strong>ServiceProvider.Add </strong>on
the <strong>ViewModel </strong>class.  The interface is defined as a single method:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs28 \cf1 namespace\cf0  PictureViewer.Interfaces\par ??\{\par ??    \cf1 public\cf0  \cf1 interface\cf0  \cf4 ISelectFile\par ??\cf0     \{\par ??        \cf1 string\cf0  SelectFile(\cf1 string\cf0  fileFilters);\par ??    \}\par ??\}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">namespace</span> PictureViewer.Interfaces
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: blue">public</span><span style="color: blue">interface</span><span style="color: #2b91af">ISelectFile</span></p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        <span style="color: blue">string</span> SelectFile(<span style="color: blue">string</span> fileFilters);
</p>
          <p style="margin: 0px">
    }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
The registration ties this interface to an implementation that displays the <strong>OpenFileDialog</strong>,
for testing purposes, that would be replaced with a minimum of two implementations:
one that returns null/empty and one that returns a valid filename to test both cases.
</p>
        <p>
The final line in the <strong>app.xaml.cs </strong>file registers a UI dialog to display
the properties of the image.  This is done through the <strong>IUIVisualizer </strong>interface
which is defined in the helper library:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs28 \cf1 namespace\cf0  JulMar.Windows.Interfaces\par ??\{\par ??    \cf1 public\cf0  \cf1 interface\cf0  \cf4 IUIVisualizer\par ??\cf0     \{\par ??        \cf1 void\cf0  Register(\cf1 string\cf0  key, \cf4 Type\cf0  winType);\par ??        \cf1 bool\cf0  Unregister(\cf1 string\cf0  key);\par ??        \cf1 bool\cf0  Show(\cf1 string\cf0  key, \cf1 object\cf0  state, \cf1 bool\cf0  setOwner, \cf4 EventHandler\cf0 &lt;UICompletedEventArgs&gt; completedProc);\par ??        \cf1 bool\cf0 ? ShowDialog(\cf1 string\cf0  key, \cf1 object\cf0  state);\par ??    \}\par ??\}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">namespace</span> JulMar.Windows.Interfaces
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: blue">public</span><span style="color: blue">interface</span><span style="color: #2b91af">IUIVisualizer</span></p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        <span style="color: blue">void</span> Register(<span style="color: blue">string</span> key, <span style="color: #2b91af">Type</span> winType);
</p>
          <p style="margin: 0px">
        <span style="color: blue">bool</span> Unregister(<span style="color: blue">string</span> key);
</p>
          <p style="margin: 0px">
        <span style="color: blue">bool</span> Show(<span style="color: blue">string</span> key, <span style="color: blue">object</span> state, <span style="color: blue">bool</span> setOwner,
</p>
          <p style="margin: 0px">
                  <span style="color: #2b91af">EventHandler</span>&lt;UICompletedEventArgs&gt;
completedProc);
</p>
          <p style="margin: 0px">
        <span style="color: blue">bool</span>?
ShowDialog(<span style="color: blue">string</span> key, <span style="color: blue">object</span> state);
</p>
          <p style="margin: 0px">
    }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
Notice the <strong>Register</strong> and <strong>Unregister </strong>methods take
a string defined as a “key”.  This is the key that invokers will use to display
the UI visually; I often use the typename of the View, but you can use any string
here as long as you are consistent in registration vs. invocation.  In this sample,
I’ve used the key <strong>“ShowElementProperties”</strong> – we’ll see in a moment
how it is displayed.  The second parameter for the Register method takes the
Type to display.  The type must be a WPF Window-derived type (i.e. <strong>NavigationWindow </strong>or <strong>Window</strong>)
and will represent the View in our MVVM pattern.
</p>
        <h4>Displaying a UI with IUIVisualizer
</h4>
        <p>
In the <strong>PictureViewModel</strong> type, there is an <strong>ICommand </strong>that
is used to drive the Property window:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs28 \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??///\cf3  Command to show the image properties.\par ??\cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf4 public\cf0  \cf6 ICommand\cf0  ShowPropertiesCommand \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 set\cf0 ; \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green"> Command to show the
image properties.</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;/summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: #2b91af">ICommand</span> ShowPropertiesCommand
{ <span style="color: blue">get</span>; <span style="color: blue">private</span><span style="color: blue">set</span>;
}
</p>
        </div>
        <p>
          <br />
The default constructor fills that in with a <strong>DelegatingCommand </strong>to
jump to a method of the ViewModel:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs28 \cf1 public\cf0  PictureViewModel()\par ??\{\par ??    _picture = \cf1 new\cf0  \cf4 PictureInfo\cf0 ();\par ??    ShowPropertiesCommand = \cf1 new\cf0  \cf4 DelegatingCommand\cf0 (ShowProperties);\par ??    SelectNewImageFile = \cf1 new\cf0  \cf4 DelegatingCommand\cf0 (OnSelectNewFile);\par ??    RemovePicture = \cf1 new\cf0  \cf4 DelegatingCommand\cf0 (() =&gt; SendMessage(\cf4 MainViewModel\cf0 .RemovePictureMessage, \cf1 this\cf0 ));\par ??\}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span> PictureViewModel()
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    _picture = <span style="color: blue">new</span><span style="color: #2b91af">PictureInfo</span>();
</p>
          <p style="margin: 0px">
    ShowPropertiesCommand = <span style="color: blue">new</span><span style="color: #2b91af">DelegatingCommand</span>(ShowProperties);
</p>
          <p style="margin: 0px">
    SelectNewImageFile = <span style="color: blue">new</span><span style="color: #2b91af">DelegatingCommand</span>(OnSelectNewFile);
</p>
          <p style="margin: 0px">
    RemovePicture = <span style="color: blue">new</span><span style="color: #2b91af">DelegatingCommand</span>(
</p>
          <p style="margin: 0px">
                 
() =&gt; SendMessage(<span style="color: #2b91af">MainViewModel</span>.RemovePictureMessage, <span style="color: blue">this</span>));
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs28 \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??///\cf3  Display the UI associated with this picture\par ??\cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf4 internal\cf0  \cf4 void\cf0  ShowProperties()\par ??\{\par ??    \cf4 var\cf0  uiVisualizer = Resolve&lt;\cf6 IUIVisualizer\cf0 &gt;();\par ??    \cf4 if\cf0  (uiVisualizer != \cf4 null\cf0 )\par ??    \{\par ??        uiVisualizer.ShowDialog(\cf7 "ShowElementProperties"\cf0 , \cf4 this\cf0 );\par ??    \}\par ??\}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: gray">
            </span> 
</p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green"> Display the UI associated
with this picture</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;/summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">internal</span>
            <span style="color: blue">void</span> ShowProperties()
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: blue">var</span> uiVisualizer = Resolve&lt;<span style="color: #2b91af">IUIVisualizer</span>&gt;();
</p>
          <p style="margin: 0px">
    <span style="color: blue">if</span> (uiVisualizer != <span style="color: blue">null</span>)
</p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        uiVisualizer.ShowDialog(<span style="color: #a31515">"ShowElementProperties"</span>, <span style="color: blue">this</span>);
</p>
          <p style="margin: 0px">
    }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
The handler method is marked as <strong>internal</strong> because the <strong>MainViewModel </strong>forwards
it’s own command to this same method handler (from the menu and toolbar).  Notice
that the method first gets the <strong>IUIVisualizer</strong> service; you must use
the same service instance where you registered the UI view.  Next, it calls <strong>ShowDialog</strong> to
display a modal view.  It takes two parameters – the view key, and the view model.
</p>
        <p>
A <em>modal view </em>is one that forces the user to interact and dismiss the dialog
before they can continue working with the other elements in the application. 
It is what, as an example, applications often use for Options dialogs.  <strong>ShowDialog</strong> will
display the View associated with the given string key (<strong>“ShowElementProperties”</strong>). 
The second parameter is the ViewModel you want to associate to it – in this case we
are passing the associated picture we want to work with.  The dialog is then
displayed and allows the user to edit the picture properties:
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_6.png">
            <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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb_2.png" width="244" height="228" />
          </a>
        </p>
        <p>
The XAML code for this view is contained in the PropertyWindow.xaml file – it has
a couple of interesting elements to it which you will see when you interact with this
dialog:
</p>
        <p>
1. <strong>Watermarked Text display</strong>: if you remove the title, it will display
some grayed out text in it’s place “Enter the Title Here”:
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_8.png">
            <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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb_3.png" width="244" height="228" />
          </a>
        </p>
        <p>
        </p>
        <p>
2. <strong>Numeric TextBox</strong>:  if you move your mouse cursor over the
X/Y/Width/Height boxes you will see a sizing arrow that allows you to drag and change
the values without typing.  You can also double-click to change the values and
it enforces numeric text box behavior.
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_10.png">
            <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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb_4.png" width="244" height="228" />
          </a>
        </p>
        <p>
Both of these are accomplished with Blend Behaviors. There are plenty of resources
on the web about these so I won’t go into detail on their creation – check the library
source code if you want to see how they work, but using them involves taking a dependency
on two assemblies:
</p>
        <ol>
          <li>
            <strong>System.Windows.Interactivity.dll</strong>
          </li>
          <li>
            <strong>JulMar.Wpf.Behaviors.dll</strong>
          </li>
        </ol>
        <p>
Both of these are included in the Dependencies folder.  The first comes from
the Blend SDK and is freely redistributable with your project.  To use them,
you add the behavior to the visual element in question, for example, the watermarked
textbox behavior gets applied like this:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;}??\fs28 \cf1 &lt;\cf3 TextBox\cf4  Text\cf1 ="\{\cf3 Binding\cf4  Title\cf1 \}"&gt;\par ??\cf3 \tab \cf1 &lt;\cf3 Interactivity\cf1 :\cf3 Interaction.Behaviors\cf1 &gt;\par ??\cf3 \tab \tab \cf1 &lt;\cf3 julmar\cf1 :\cf3 WatermarkTextBoxBehavior\cf4  Text\cf1 ="Enter the Title Here"/&gt;\par ??\cf3 \tab \cf1 &lt;/\cf3 Interactivity\cf1 :\cf3 Interaction.Behaviors\cf1 &gt;\par ??\cf3     \cf1 &lt;\cf3 TextBox.Style\cf1 &gt;\par ??\cf3         \cf1 &lt;\cf3 Style\cf4  TargetType\cf1 ="TextBox"\cf4  BasedOn\cf1 ="\{\cf3 StaticResource\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  TextBox\cf1 \}\}"&gt;\par ??\cf3             \cf1 &lt;\cf3 Setter\cf4  Property\cf1 ="FontStyle"\cf4  Value\cf1 ="Normal" /&gt;\par ??\cf3             \cf1 &lt;\cf3 Style.Triggers\cf1 &gt;\par ??\cf3                 \cf1 &lt;\cf3 Trigger\cf4  Property\cf1 ="julmar:WatermarkTextBoxBehavior.IsWatermarked"\cf4  Value\cf1 ="True"&gt;\par ??\cf3                     \cf1 &lt;\cf3 Setter\cf4  Property\cf1 ="FontStyle"\cf4  Value\cf1 ="Italic" /&gt;\par ??\cf3                     \cf1 &lt;\cf3 Setter\cf4  Property\cf1 ="Foreground"\cf4  Value\cf1 ="LightGray" /&gt;\par ??\cf3                 \cf1 &lt;/\cf3 Trigger\cf1 &gt;\par ??\cf3             \cf1 &lt;/\cf3 Style.Triggers\cf1 &gt;\par ??\cf3         \cf1 &lt;/\cf3 Style\cf1 &gt;\par ??\cf3     \cf1 &lt;/\cf3 TextBox.Style\cf1 &gt;\par ??&lt;/\cf3 TextBox\cf1 &gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">TextBox</span>
            <span style="color: red"> Text</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Title</span>
            <span style="color: blue">}"&gt;</span>
          </p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">    </span>
              <span style="color: blue">&lt;</span>
              <span style="color: #a31515">Interactivity</span>
              <span style="color: blue">:</span>
              <span style="color: #a31515">Interaction.Behaviors</span>
              <span style="color: blue">&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">        </span>
              <span style="color: blue">&lt;</span>
              <span style="color: #a31515">julmar</span>
              <span style="color: blue">:</span>
              <span style="color: #a31515">WatermarkTextBoxBehavior</span>
              <span style="color: red"> Text</span>
              <span style="color: blue">="Enter
the Title Here"/&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">    </span>
              <span style="color: blue">&lt;/</span>
              <span style="color: #a31515">Interactivity</span>
              <span style="color: blue">:</span>
              <span style="color: #a31515">Interaction.Behaviors</span>
              <span style="color: blue">&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">TextBox.Style</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Style</span>
            <span style="color: red"> TargetType</span>
            <span style="color: blue">="TextBox"</span>
            <span style="color: red"> BasedOn</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">StaticResource</span>
            <span style="color: blue"> {</span>
            <span style="color: #a31515">x</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">Type</span>
            <span style="color: red"> TextBox</span>
            <span style="color: blue">}}"&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Setter</span>
            <span style="color: red"> Property</span>
            <span style="color: blue">="FontStyle"</span>
            <span style="color: red"> Value</span>
            <span style="color: blue">="Normal"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Style.Triggers</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Trigger</span>
            <span style="color: red"> Property</span>
            <span style="color: blue">="julmar:WatermarkTextBoxBehavior.IsWatermarked"</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">                        </span>
            <span style="color: red">Value</span>
            <span style="color: blue">="True"&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Setter</span>
            <span style="color: red"> Property</span>
            <span style="color: blue">="FontStyle"</span>
            <span style="color: red"> Value</span>
            <span style="color: blue">="Italic"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Setter</span>
            <span style="color: red"> Property</span>
            <span style="color: blue">="Foreground"</span>
            <span style="color: red"> Value</span>
            <span style="color: blue">="LightGray"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Trigger</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Style.Triggers</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Style</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">TextBox.Style</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">TextBox</span>
            <span style="color: blue">&gt;</span>
          </p>
        </div>
        <p>
          <br />
I’ve also applied a Trigger to change the font/colors when the TextBox is watermarked.
</p>
        <p>
The numeric behavior looks like this:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;}??\fs28 \cf1 &lt;\cf3 TextBox\cf4  Grid.Row\cf1 ="5"\cf4  Text\cf1 ="\{\cf3 Binding\cf4  Width\cf1 ,\cf4  UpdateSourceTrigger\cf1 =PropertyChanged\}"&gt;\par ??\cf3     \cf1 &lt;\cf3 Interactivity\cf1 :\cf3 Interaction.Behaviors\cf1 &gt;\par ??\cf3         \cf1 &lt;\cf3 julmar\cf1 :\cf3 NumericTextBoxBehavior\cf4  AllowMouseDrag\cf1 ="True" /&gt;\par ??\cf3     \cf1 &lt;/\cf3 Interactivity\cf1 :\cf3 Interaction.Behaviors\cf1 &gt;\par ??&lt;/\cf3 TextBox\cf1 &gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">TextBox</span>
            <span style="color: red"> Grid.Row</span>
            <span style="color: blue">="5"</span>
            <span style="color: red"> Text</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Width</span>
            <span style="color: blue">,</span>
            <span style="color: red"> UpdateSourceTrigger</span>
            <span style="color: blue">=PropertyChanged}"&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Interactivity</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">Interaction.Behaviors</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">julmar</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">NumericTextBoxBehavior</span>
            <span style="color: red"> AllowMouseDrag</span>
            <span style="color: blue">="True"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Interactivity</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">Interaction.Behaviors</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">TextBox</span>
            <span style="color: blue">&gt;</span>
          </p>
        </div>
        <p>
          <br />
Notice that I’ve changed the <strong>Binding.UpdateSourceTrigger </strong>to be <strong>PropertyChanged</strong> –
this is so the dragging effect works properly and updates the value in the underlying
view model.
</p>
        <h4>Ways to invoke commands in the view
</h4>
        <p>
So let’s look now at how we get the command executed.  Switching to the <strong>MainWindow.xaml </strong>you
will find three places where the Show Properties command is wired up.
</p>
        <p>
First, it can be invoked using a keyboard accelerator. This requires using a <strong>BindableCommand </strong>from
the library, placing it into resources and then binding against that.  The command
we will be executing is the one on the <strong>MainViewModel </strong>so it requires
the actual picture element as a parameter:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1 &lt;\cf3 Window.Resources\cf1 &gt;\par ??\cf3     \cf1 &lt;\cf3 julmar\cf1 :\cf3 BindableCommand\cf4  x\cf1 :\cf4 Key\cf1 ="propsCommand"\cf4  Command\cf1 ="\{\cf3 Binding\cf4  ShowPropertiesCommand\cf1 \}"\cf0  \par ??                           \cf4  CommandParameter\cf1 ="\{\cf3 Binding\cf4  SelectedPicture\cf1 \}" /&gt;\par ??&lt;/\cf3 Window.Resources\cf1 &gt;\par ??\par ??&lt;\cf3 Window.InputBindings\cf1 &gt;\par ??\cf3     \cf1 &lt;\cf3 KeyBinding\cf4  Key\cf1 ="r"\cf4  Modifiers\cf1 ="Ctrl+Alt"\cf4  Command\cf1 ="\{\cf3 StaticResource\cf4  propsCommand\cf1 \}" /&gt;\par ??&lt;/\cf3 Window.InputBindings\cf1 &gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Window.Resources</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">julmar</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">BindableCommand</span>
            <span style="color: red"> x</span>
            <span style="color: blue">:</span>
            <span style="color: red">Key</span>
            <span style="color: blue">="propsCommand"</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> ShowPropertiesCommand</span>
            <span style="color: blue">}"</span>
          </p>
          <p style="margin: 0px">
                           <span style="color: red">CommandParameter</span><span style="color: blue">="{</span><span style="color: #a31515">Binding</span><span style="color: red"> SelectedPicture</span><span style="color: blue">}"
/&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Window.Resources</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Window.InputBindings</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">KeyBinding</span>
            <span style="color: red"> Key</span>
            <span style="color: blue">="r"</span>
            <span style="color: red"> Modifiers</span>
            <span style="color: blue">="Ctrl+Alt"</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">StaticResource</span>
            <span style="color: red"> propsCommand</span>
            <span style="color: blue">}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Window.InputBindings</span>
            <span style="color: blue">&gt;</span>
          </p>
        </div>
        <p>
          <br />
The MainViewModel simply forwards this command onto the PictureViewModel using a typed <strong>DelegatingCommand</strong>:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs28 ShowPropertiesCommand = \cf3 new\cf0  \cf4 DelegatingCommand\cf0 &lt;\cf4 PictureViewModel\cf0 &gt;(p =&gt; p.ShowProperties(), p =&gt; p != \cf3 null\cf0 );\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
ShowPropertiesCommand = <span style="color: blue">new</span><span style="color: #2b91af">DelegatingCommand</span>&lt;<span style="color: #2b91af">PictureViewModel</span>&gt;(
</p>
          <p style="margin: 0px">
                   
p =&gt; p.ShowProperties(), p =&gt; p != <span style="color: blue">null</span>);
</p>
        </div>
        <p>
          <br />
Next, we can invoke the command using the menu and toolbar:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1     \cf3 &lt;\cf1 MenuItem\cf4  Header\cf3 ="_Edit"&gt;\par ??\cf1         \cf3 &lt;\cf1 MenuItem\cf4  Header\cf3 ="Add _New Picture"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  AddNewCommand\cf3 \}" /&gt;\par ??\cf1         \cf3 &lt;\cf1 MenuItem\cf4  Header\cf3 ="_Remove Picture"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  RemoveCommand\cf3 \}"\cf4  CommandParameter\cf3 ="\{\cf1 Binding\cf4  SelectedPicture\cf3 \}" /&gt;\par ??\cf1         \cf3 &lt;\cf1 Separator\cf3  /&gt;\par ??\cf1         \cf3 &lt;\cf1 MenuItem\cf4  Header\cf3 ="P_roperties"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  ShowPropertiesCommand\cf3 \}"\cf4  CommandParameter\cf3 ="\{\cf1 Binding\cf4  SelectedPicture\cf3 \}" /&gt;\par ??\cf1     \cf3 &lt;/\cf1 MenuItem\cf3 &gt;\par ??\cf1         \cf3 &lt;/\cf1 Menu\cf3 &gt;\par ??\cf1         \par ??    \cf3 &lt;\cf1 ToolBar\cf4  DockPanel.Dock\cf3 ="Top"&gt;\par ??\cf1         \cf3 &lt;\cf1 Button\cf4  ToolTip\cf3 ="Add New Picture"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  AddNewCommand\cf3 \}"\cf4  Content\cf3 ="+"\cf4  FontWeight\cf3 ="Bold" /&gt;\par ??\cf1         \cf3 &lt;\cf1 Button\cf4  ToolTip\cf3 ="Remove Picture"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  RemoveCommand\cf3 \}"\cf4  CommandParameter\cf3 ="\{\cf1 Binding\cf4  SelectedPicture\cf3 \}"\cf4  Content\cf3 ="-"\cf4  FontWeight\cf3 ="Bold" /&gt;\par ??\cf1         \cf3 &lt;\cf1 Button\cf4  ToolTip\cf3 ="Properties"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  ShowPropertiesCommand\cf3 \}"\cf4  CommandParameter\cf3 ="\{\cf1 Binding\cf4  SelectedPicture\cf3 \}"&gt;\par ??\cf1             \cf3 &lt;\cf1 Path\cf4  Width\cf3 ="16"\cf4  Height\cf3 ="16"\cf4  Fill\cf3 ="\{\cf1 julmar\cf3 :\cf1 LinearGradientBrush\cf4  LightGreen\cf3 ,\cf4  DarkGreen\cf3 ,\cf0  90\cf3 \}"\cf4  Stroke\cf3 ="DarkGreen"\par ??\cf0                  \cf4  Data\cf3 ="M1,1 L15,7.5 L1,15 Z" /&gt;\par ??\cf1         \cf3 &lt;/\cf1 Button\cf3 &gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">MenuItem</span>
            <span style="color: red"> Header</span>
            <span style="color: blue">="_Edit"&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">MenuItem</span>
            <span style="color: red"> Header</span>
            <span style="color: blue">="Add
_New Picture"</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> AddNewCommand</span>
            <span style="color: blue">}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">MenuItem</span>
            <span style="color: red"> Header</span>
            <span style="color: blue">="_Remove
Picture"</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> RemoveCommand</span>
            <span style="color: blue">}"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">                 
CommandParameter</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> SelectedPicture</span>
            <span style="color: blue">}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Separator</span>
            <span style="color: blue"> /&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">MenuItem</span>
            <span style="color: red"> Header</span>
            <span style="color: blue">="P_roperties"</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> ShowPropertiesCommand</span>
            <span style="color: blue">}"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">                 
CommandParameter</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> SelectedPicture</span>
            <span style="color: blue">}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">MenuItem</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
   ...
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">ToolBar</span>
            <span style="color: red"> DockPanel.Dock</span>
            <span style="color: blue">="Top"&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Button</span>
            <span style="color: red"> ToolTip</span>
            <span style="color: blue">="Add
New Picture"</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> AddNewCommand</span>
            <span style="color: blue">}"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">               
Content</span>
            <span style="color: blue">="+"</span>
            <span style="color: red"> FontWeight</span>
            <span style="color: blue">="Bold"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Button</span>
            <span style="color: red"> ToolTip</span>
            <span style="color: blue">="Remove
Picture"</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> RemoveCommand</span>
            <span style="color: blue">}"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">           
CommandParameter</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> SelectedPicture</span>
            <span style="color: blue">}"</span>
            <span style="color: red"> Content</span>
            <span style="color: blue">="-"</span>
            <span style="color: red"> FontWeight</span>
            <span style="color: blue">="Bold"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Button</span>
            <span style="color: red"> ToolTip</span>
            <span style="color: blue">="Properties"</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> ShowPropertiesCommand</span>
            <span style="color: blue">}"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">           
CommandParameter</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> SelectedPicture</span>
            <span style="color: blue">}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
   ...
</p>
          <p style="margin: 0px">
 
</p>
        </div>
        <p>
Note that here we are also binding to the <strong>MainViewModel </strong>command –
so we must supply the parameter using the <strong>CommandParameter</strong>. 
The final invocation place is when you double-click on the picture itself.  This
is done a little differently if you’ve not done much WPF work.  
</p>
        <h4>A quick segway – View code behind vs. View Models
</h4>
        <p>
First, the display of images is actually housed in a <strong>ListBox</strong>. 
It turns out that anytime you need to display multiple things grouped somehow, and
allow the user to select one or more of those things, a ListBox is almost always the
way to go.  WPF allows us to customize the visuals however we like, so here the
panel has been replaced with a <strong>Canvas </strong>(allowing pixel positioning),
and each item is drawn as a <strong>DataTemplate</strong>.  The template decides
how to render each item in the ListBox – the PictureViewModel in this case. 
In the sample, it is rendering an image and an optional TextBlock that is turned on
and off through a property (and can be changed through the tool bar).  I encourage
you to look at the code to see how all that is done.  
</p>
        <p>
One of the core things necessary in MVVM is the ability to interact with visuals and
then <em>sometimes</em> push notifications of that interaction back to the view model. 
I say “sometimes” because it’s perfectly acceptable to place code into the code behind
for the XAML as well. Where you put the logic depends on whether it is view-specific
and whether you want to test it independently of the view.  If it’s not view
specific OR you want to test it, then move it into the view model.  An example
of something that we probably don’t care about is closing the application – I’ve wired
it up to a command here just to show that you can, but it’s completely unnecessary
to do that.  The view model isn’t doing any closing logic, so it would be fine
to wire a handler into the MainWindow.xaml.cs and just call “this.Close()” in there.
</p>
        <p>
Ok, so back to the double-click implementation.  In the <strong>DataTemplate</strong> assigned
to the <strong>ListBox.ItemTemplate </strong>property you will find the definition
for the image itself:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1 &lt;\cf3 Image\cf4  x\cf1 :\cf4 Name\cf1 ="imageHolder"\cf4  Width\cf1 ="\{\cf3 Binding\cf4  Width\cf1 \}"\cf4  Height\cf1 ="\{\cf3 Binding\cf4  Height\cf1 \}"\par ??\cf0       \cf4  Source\cf1 ="\{\cf3 Binding\cf4  Image\cf1 \}"\cf4  Stretch\cf1 ="Fill"\par ??\cf0        \cf4  HorizontalAlignment\cf1 ="Center"\cf4  VerticalAlignment\cf1 ="Center"&gt;\par ??\cf3     \cf1 &lt;\cf3 Interactivity\cf1 :\cf3 Interaction.Triggers\cf1 &gt;\par ??\cf3         \cf1 &lt;\cf3 julmar\cf1 :\cf3 DoubleClickTrigger\cf1 &gt;\par ??\cf3             \cf1 &lt;\cf3 julmar\cf1 :\cf3 InvokeCommand\cf4  Command\cf1 ="\{\cf3 Binding\cf4  ShowPropertiesCommand\cf1 \}" /&gt;\par ??\cf3         \cf1 &lt;/\cf3 julmar\cf1 :\cf3 DoubleClickTrigger\cf1 &gt;\par ??\cf3     \cf1 &lt;/\cf3 Interactivity\cf1 :\cf3 Interaction.Triggers\cf1 &gt;\par ??&lt;/\cf3 Image\cf1 &gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Image</span>
            <span style="color: red"> x</span>
            <span style="color: blue">:</span>
            <span style="color: red">Name</span>
            <span style="color: blue">="imageHolder"</span>
            <span style="color: red"> Width</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Width</span>
            <span style="color: blue">}"</span>
            <span style="color: red"> Height</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Height</span>
            <span style="color: blue">}"</span>
          </p>
          <p style="margin: 0px">
      <span style="color: red">Source</span><span style="color: blue">="{</span><span style="color: #a31515">Binding</span><span style="color: red"> Image</span><span style="color: blue">}"</span><span style="color: red"> Stretch</span><span style="color: blue">="Fill"</span></p>
          <p style="margin: 0px">
       <span style="color: red">HorizontalAlignment</span><span style="color: blue">="Center"</span><span style="color: red"> VerticalAlignment</span><span style="color: blue">="Center"&gt;</span></p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">    </span>
              <span style="color: blue">&lt;</span>
              <span style="color: #a31515">Interactivity</span>
              <span style="color: blue">:</span>
              <span style="color: #a31515">Interaction.Triggers</span>
              <span style="color: blue">&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">        </span>
              <span style="color: blue">&lt;</span>
              <span style="color: #a31515">julmar</span>
              <span style="color: blue">:</span>
              <span style="color: #a31515">DoubleClickTrigger</span>
              <span style="color: blue">&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">            </span>
              <span style="color: blue">&lt;</span>
              <span style="color: #a31515">julmar</span>
              <span style="color: blue">:</span>
              <span style="color: #a31515">InvokeCommand</span>
              <span style="color: red"> Command</span>
              <span style="color: blue">="{</span>
              <span style="color: #a31515">Binding</span>
              <span style="color: red"> ShowPropertiesCommand</span>
              <span style="color: blue">}"
/&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">        </span>
              <span style="color: blue">&lt;/</span>
              <span style="color: #a31515">julmar</span>
              <span style="color: blue">:</span>
              <span style="color: #a31515">DoubleClickTrigger</span>
              <span style="color: blue">&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">    </span>
              <span style="color: blue">&lt;/</span>
              <span style="color: #a31515">Interactivity</span>
              <span style="color: blue">:</span>
              <span style="color: #a31515">Interaction.Triggers</span>
              <span style="color: blue">&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Image</span>
            <span style="color: blue">&gt;</span>
          </p>
        </div>
        <p>
          <br />
Note the use of the Interaction.Triggers tag – this is also part of the Blend behavior
implementation.  In this case, we are <em>triggering</em> off something (property
change, event, etc.) and then performance some <em>action</em>.  In the <strong>JulMar.Wpf.Behaviors </strong>assembly
you will find a whole bunch of triggers, behaviors and actions.  In this case,
I am using the <strong>DoubleClickTrigger</strong> which monitors for a quick double
tap of the left mouse button.  When that happens, it runs the list of actions
associated with it – in this case, it invokes the ShowPropertiesCommand.  Now,
here we are defining the trigger behavior on the UI that is bound to an actual <strong>PictureViewModel </strong>(note
the property bindings on the image and you will see that I’m telling you the truth!)
So here the command being invoked is the PictureViewModel command – so no parameter
is necessary.
</p>
        <h4>Drag/Position Behavior
</h4>
        <p>
The last thing I want to point out is the dragging behavior.  This is also done
through a Blend behavior, but it is being applied in a slightly different way: through
a Style.  
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;}??\fs28 \cf1 &lt;\cf3 ListBox.ItemContainerStyle\cf1 &gt;\par ??\cf3     \cf1 &lt;\cf3 Style\cf4  TargetType\cf1 ="ListBoxItem"&gt;\par ??\cf3         \cf1 &lt;\cf3 Setter\cf4  Property\cf1 ="julmar:DragPositionBehavior.IsEnabled"\cf4  Value\cf1 ="True" /&gt;\par ??\cf3         \cf1 &lt;\cf3 Setter\cf4  Property\cf1 ="Canvas.Left"\cf4  Value\cf1 ="\{\cf3 Binding\cf4  X\cf1 ,\cf4  Mode\cf1 =TwoWay\}" /&gt;\par ??\cf3         \cf1 &lt;\cf3 Setter\cf4  Property\cf1 ="Canvas.Top"\cf4  Value\cf1 ="\{\cf3 Binding\cf4  Y\cf1 ,\cf4  Mode\cf1 =TwoWay\}" /&gt;\par ??\cf3         \cf1 &lt;\cf3 Setter\cf4  Property\cf1 ="IsSelected"\cf4  Value\cf1 ="\{\cf3 Binding\cf4  IsSelected\cf1 ,\cf4  Mode\cf1 =TwoWay\}" /&gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">ListBox.ItemContainerStyle</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Style</span>
            <span style="color: red"> TargetType</span>
            <span style="color: blue">="ListBoxItem"&gt;</span>
          </p>
          <p style="margin: 0px">
            <strong>
              <span style="color: #a31515">        </span>
              <span style="color: blue">&lt;</span>
              <span style="color: #a31515">Setter</span>
              <span style="color: red"> Property</span>
              <span style="color: blue">="julmar:DragPositionBehavior.IsEnabled"</span>
              <span style="color: red"> Value</span>
              <span style="color: blue">="True"
/&gt;</span>
            </strong>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Setter</span>
            <span style="color: red"> Property</span>
            <span style="color: blue">="Canvas.Left"</span>
            <span style="color: red"> Value</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> X</span>
            <span style="color: blue">,</span>
            <span style="color: red"> Mode</span>
            <span style="color: blue">=TwoWay}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Setter</span>
            <span style="color: red"> Property</span>
            <span style="color: blue">="Canvas.Top"</span>
            <span style="color: red"> Value</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Y</span>
            <span style="color: blue">,</span>
            <span style="color: red"> Mode</span>
            <span style="color: blue">=TwoWay}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Setter</span>
            <span style="color: red"> Property</span>
            <span style="color: blue">="IsSelected"</span>
            <span style="color: red"> Value</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> IsSelected</span>
            <span style="color: blue">,</span>
            <span style="color: red"> Mode</span>
            <span style="color: blue">=TwoWay}"
/&gt;</span>
          </p>
        </div>
        <p>
...
</p>
        <p>
Now, for those who have used Blend behaviors a lot, you may now that it is currently
not possible to apply behaviors through Styles.  This is a restriction of the
Attached Property definition being used – the collection cannot be associated on a
style.  This is a very unfortunate problem because it makes my scenario very
hard: I want to drag and reposition these items around through the mouse.  If
I put the behavior onto the DataTemplate then I move the <em>content</em> but not
the item container itself (the thing that provides selection and focus rendering) 
So I would end up with a very weird visualization where you click on an item and the
focus rectangle is drawn in a completely different place than the item itself!
</p>
        <p>
So, in my set of behaviors, many of them allow you to setup the behavior <em>both
through Blend</em> and through Style setters (or directly on an element without the
full Blend syntax).  I do this by adding an attached property onto the behavior
class and then injecting my behavior into the element where the attached property
is set.  I’ll show this in a future blog post to give an example for those who’d
like to do the same for their own behaviors.
</p>
        <p>
Another question I’ve fielded is why did I even create this behavior at all when the
Blend sample already exists to do this?  Well, the short answer is because I
had a specific goal in mind here – this behavior knows about Canvas panels. 
If the behavior is attached to an element in a Canvas, it changes the position by
changing the <strong>Canvas.Left </strong>and <strong>Canvas.Top </strong>properties. 
If not, it uses a <strong>RenderTransform</strong>.  The supplied blend sample
only uses RenderTransform<strong></strong>(at least when I last looked at it).
</p>
        <p>
That about covers it, if you have any questions or comments, then contact me!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>MVVM: Introducing the message visualizers</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/02/01/MVVMIntroducingTheMessageVisualizers.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,88843fe1-6503-46de-9be7-51f507dd068e.aspx</id>
    <published>2010-02-01T07:59:35.5743703-08:00</published>
    <updated>2010-02-01T07:59:35.5743703-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="MVVM" label="MVVM" scheme="http://www.julmar.com/blog/mark/CategoryView,category,MVVM.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In this post, I will go over the simple message visualizers available in the MVVM
Helpers toolkit.  Essentially the idea is that it is fairly common to want to
display a simple message from the ViewModel to the user.  Since the VM is supposed
to be testable, we encapsulate this ability into four services, three of which I’ll
focus on here:
</p>
        <table border="1" cellspacing="0" cellpadding="2" width="622">
          <tbody>
            <tr>
              <td valign="top" width="200">
                <strong>IMessageVisualizer</strong>
              </td>
              <td valign="top" width="420">
Displays a title + message to the user and allows them to dismiss it through a set
of user-defined buttons.  The button used to dismiss the dialog is returned as
the result.</td>
            </tr>
            <tr>
              <td valign="top" width="200">
                <strong>IErrorVisualizer</strong>
              </td>
              <td valign="top" width="420">
Displays a title + message to the user to report an error.  The only button displayed
is OK, and the visualizer returns true/false.</td>
            </tr>
            <tr>
              <td valign="top" width="200">
                <strong>INotificationVisualizer</strong>
              </td>
              <td valign="top" width="420">
Used to manage some short operation that will halt the UI briefly.</td>
            </tr>
            <tr>
              <td valign="top" width="200">
                <strong>IUIVisualizer</strong>
              </td>
              <td valign="top" width="420">
Displays a custom modal or modaless UI to the user with an associated ViewModel to
drive it.</td>
            </tr>
          </tbody>
        </table>
        <p>
          <br />
To demonstrate the first three visualizer types, we’ll build a very simple MVVM application
to display messages.  I start with the project template and remove all the ViewModel
and View code to have a blank solution.  Each of the three visualizers we are
going to look at take a <strong>string</strong> Title and Message as their parameters
– we’ll drive it from a unique command for each.  To start with, let’s define
a simple data structure that wraps an <strong>ICommand</strong> and a textual title:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs28 \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??///\cf3  Simple command + title text\par ??\cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf4 public\cf0  \cf4 class\cf0  \cf6 TitledCommand\par ??\cf0 \{\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Title to display\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  \cf4 string\cf0  Title \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 set\cf0 ; \}\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Command to execute\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  \cf6 ICommand\cf0  Command \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 set\cf0 ; \}\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Constructor\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;param name="title"&gt;&lt;/param&gt;\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;param name="cmd"&gt;&lt;/param&gt;\par ??\cf0     \cf4 public\cf0  TitledCommand(\cf4 string\cf0  title, \cf6 ICommand\cf0  cmd)\par ??    \{\par ??        Title = title;\par ??        Command = cmd;\par ??    \}\par ??\}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green"> Simple command + title
text</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;/summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">class</span>
            <span style="color: #2b91af">TitledCommand</span>
          </p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"> Title
to display</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: blue">public</span><span style="color: blue">string</span> Title
{ <span style="color: blue">get</span>; <span style="color: blue">private</span><span style="color: blue">set</span>;
}
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"> Command
to execute</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: blue">public</span><span style="color: #2b91af">ICommand</span> Command
{ <span style="color: blue">get</span>; <span style="color: blue">private</span><span style="color: blue">set</span>;
}
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"> Constructor</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;param
name="title"&gt;&lt;/param&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;param
name="cmd"&gt;&lt;/param&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: blue">public</span> TitledCommand(<span style="color: blue">string</span> title, <span style="color: #2b91af">ICommand</span> cmd)
</p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        Title = title;
</p>
          <p style="margin: 0px">
        Command = cmd;
</p>
          <p style="margin: 0px">
    }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
Next, in the <strong>MainViewModel.cs </strong>file, we need a <strong>Title</strong> string
property – this will be the title for each of the visualziations.  It’s just
a simple field-backed INPC property, we’ll bind it to something in the view:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs28 \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??///\cf3  Main View Model\par ??\cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf4 public\cf0  \cf4 class\cf0  \cf6 MainViewModel\cf0  : \cf6 ViewModel\par ??\cf0 \{\par ??    \cf4 private\cf0  \cf4 string\cf0  _title, _result;\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Title for visualizations\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  \cf4 string\cf0  Title\par ??    \{\par ??        \cf4 get\cf0  \{ \cf4 return\cf0  _title; \}\par ??        \cf4 set\cf0  \{ _title = \cf4 value\cf0 ; OnPropertyChanged(\cf7 "Title"\cf0 ); \}\par ??    \}\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Result\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  \cf4 string\cf0  Result\par ??    \{\par ??        \cf4 get\cf0  \{ \cf4 return\cf0  _result; \}\par ??        \cf4 set\cf0  \{ _result = \cf4 value\cf0 ; OnPropertyChanged(\cf7 "Result"\cf0 );\}\par ??    \}\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Visualization Command list\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  \cf6 IList\cf0 &lt;\cf6 TitledCommand\cf0 &gt; VisualizationCommands \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 set\cf0 ; \}\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Constructor\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  MainViewModel()\par ??    \{\par ??        VisualizationCommands = \cf4 new\cf0  \cf6 List\cf0 &lt;\cf6 TitledCommand\cf0 &gt;\par ??        \{\par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Message"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &lt;\cf4 string\cf0 &gt;(OnShowMessage, \par ??                s =&gt; !\cf4 string\cf0 .IsNullOrEmpty(Title) &amp;&amp; !\cf4 string\cf0 .IsNullOrEmpty(s))),\par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Error"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &lt;\cf4 string\cf0 &gt;(OnShowError,\par ??                s =&gt; !\cf4 string\cf0 .IsNullOrEmpty(Title) &amp;&amp; !\cf4 string\cf0 .IsNullOrEmpty(s))),        \par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Notification"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &lt;\cf4 string\cf0 &gt;(OnShowNotification, \par ??                s =&gt; !\cf4 string\cf0 .IsNullOrEmpty(Title))),\par ??        \};\par ??    \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green"> Main View Model</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;/summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">class</span>
            <span style="color: #2b91af">MainViewModel</span> : <span style="color: #2b91af">ViewModel</span></p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    <span style="color: blue">private</span><span style="color: blue">string</span> _title;
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"> Title
for visualizations</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: blue">public</span><span style="color: blue">string</span> Title
</p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        <span style="color: blue">get</span> { <span style="color: blue">return</span> _title;
}
</p>
          <p style="margin: 0px">
        <span style="color: blue">set</span> {
_title = <span style="color: blue">value</span>; OnPropertyChanged(<span style="color: #a31515">"Title"</span>);
}
</p>
          <p style="margin: 0px">
    }
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
Now we can create a collection of the <strong>TitledCommand </strong>objects and display
them to the user for execution.  We will place this collection into the <strong>MainViewModel.cs</strong>. 
Let’s populate it with a set of delegating commands for each type of visualization
we want to create.  We will use the <strong>DelegatingCommand&lt;T&gt;</strong> version
which allows us to type the parameter being passed.  We will assume the inbound
parameter is always the message to display and there a string:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs28 \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??///\cf3  Main View Model\par ??\cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf4 public\cf0  \cf4 class\cf0  \cf6 MainViewModel\cf0  : \cf6 ViewModel\par ??\cf0 \{\par ??    \cf4 private\cf0  \cf4 string\cf0  _title, _result;\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Title for visualizations\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  \cf4 string\cf0  Title\par ??    \{\par ??        \cf4 get\cf0  \{ \cf4 return\cf0  _title; \}\par ??        \cf4 set\cf0  \{ _title = \cf4 value\cf0 ; OnPropertyChanged(\cf7 "Title"\cf0 ); \}\par ??    \}\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Result\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  \cf4 string\cf0  Result\par ??    \{\par ??        \cf4 get\cf0  \{ \cf4 return\cf0  _result; \}\par ??        \cf4 set\cf0  \{ _result = \cf4 value\cf0 ; OnPropertyChanged(\cf7 "Result"\cf0 );\}\par ??    \}\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Visualization Command list\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  \cf6 IList\cf0 &lt;\cf6 TitledCommand\cf0 &gt; VisualizationCommands \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 set\cf0 ; \}\par ??\par ??    \cf1 ///\cf3  \cf1 &lt;summary&gt;\par ??\cf0     \cf1 ///\cf3  Constructor\par ??\cf0     \cf1 ///\cf3  \cf1 &lt;/summary&gt;\par ??\cf0     \cf4 public\cf0  MainViewModel()\par ??    \{\par ??        VisualizationCommands = \cf4 new\cf0  \cf6 List\cf0 &lt;\cf6 TitledCommand\cf0 &gt;\par ??        \{\par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Message"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &lt;\cf4 string\cf0 &gt;(OnShowMessage, \par ??                s =&gt; !\cf4 string\cf0 .IsNullOrEmpty(Title) &amp;&amp; !\cf4 string\cf0 .IsNullOrEmpty(s))),\par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Error"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &lt;\cf4 string\cf0 &gt;(OnShowError,\par ??                s =&gt; !\cf4 string\cf0 .IsNullOrEmpty(Title) &amp;&amp; !\cf4 string\cf0 .IsNullOrEmpty(s))),        \par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Notification"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &lt;\cf4 string\cf0 &gt;(OnShowNotification, \par ??                s =&gt; !\cf4 string\cf0 .IsNullOrEmpty(Title))),\par ??        \};\par ??    \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green"> Main View Model</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;/summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">class</span>
            <span style="color: #2b91af">MainViewModel</span> : <span style="color: #2b91af">ViewModel</span></p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
    ...
</p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"> Visualization
Command list</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: blue">public</span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">TitledCommand</span>&gt;
VisualizationCommands { <span style="color: blue">get</span>; <span style="color: blue">private</span><span style="color: blue">set</span>;
}
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"> Constructor</span></p>
          <p style="margin: 0px">
    <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
    <span style="color: blue">public</span> MainViewModel()
</p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        VisualizationCommands = <span style="color: blue">new</span><span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">TitledCommand</span>&gt;
</p>
          <p style="margin: 0px">
        {
</p>
          <p style="margin: 0px">
            <span style="color: blue">new</span><span style="color: #2b91af">TitledCommand</span>(<span style="color: #a31515">"Show
Message"</span>, <span style="color: blue">new</span><span style="color: #2b91af">DelegatingCommand</span>&lt;<span style="color: blue">string</span>&gt;(OnShowMessage, 
</p>
          <p style="margin: 0px">
               
s =&gt; !<span style="color: blue">string</span>.IsNullOrEmpty(Title) &amp;&amp; !<span style="color: blue">string</span>.IsNullOrEmpty(s))),
</p>
          <p style="margin: 0px">
            <span style="color: blue">new</span><span style="color: #2b91af">TitledCommand</span>(<span style="color: #a31515">"Show
Error"</span>, <span style="color: blue">new</span><span style="color: #2b91af">DelegatingCommand</span>&lt;<span style="color: blue">string</span>&gt;(OnShowError,
</p>
          <p style="margin: 0px">
               
s =&gt; !<span style="color: blue">string</span>.IsNullOrEmpty(Title) &amp;&amp; !<span style="color: blue">string</span>.IsNullOrEmpty(s))),        
</p>
          <p style="margin: 0px">
            <span style="color: blue">new</span><span style="color: #2b91af">TitledCommand</span>(<span style="color: #a31515">"Show
Notification"</span>, 
</p>
          <p style="margin: 0px">
                <span style="color: blue">new</span><span style="color: #2b91af">DelegatingCommand</span>&lt;<span style="color: blue">string</span>&gt;(OnShowNotification, 
</p>
          <p style="margin: 0px">
               
s =&gt; !<span style="color: blue">string</span>.IsNullOrEmpty(Title))),
</p>
          <p style="margin: 0px">
        };
</p>
          <p style="margin: 0px">
    }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
The <strong>CanExecute</strong> handler for each of them will test the <strong>Title</strong> property
– ensure there is a value there, and the inbound parameter (the Message) and make
sure there is a value there as well.
</p>
        <h4>IMessageVisualizer
</h4>
        <p>
The IMessageVisualizer is used to show a simple message to the user – it takes a title,
message and an enumeration to decide which buttons to display.  The default implementation
of the service displays a <strong>MessageBox</strong>.   
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/image_2.png">
            <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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/image_thumb.png" width="402" height="185" />
          </a>
        </p>
        <p>
The buttons you can display include:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs28     \cf3 public\cf0  \cf3 enum\cf0  \cf4 MessageButtons\par ??\cf0     \{\par ??        OK = 0,\par ??        OKCancel = 1,\par ??        YesNoCancel = 3,\par ??        YesNo = 4\par ??    \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
    <span style="color: blue">public</span><span style="color: blue">enum</span><span style="color: #2b91af">MessageButtons</span></p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        OK = 0,
</p>
          <p style="margin: 0px">
        OKCancel = 1,
</p>
          <p style="margin: 0px">
        YesNoCancel = 3,
</p>
          <p style="margin: 0px">
        YesNo = 4
</p>
          <p style="margin: 0px">
    }
</p>
        </div>
        <p>
          <br />
The result from the service is which button was used to dismiss the dialog:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs28     \cf3 public\cf0  \cf3 enum\cf0  \cf4 MessageResult\par ??\cf0     \{\par ??        None = 0,\par ??        OK = 1,\par ??        Cancel = 2,\par ??        Yes = 6,\par ??        No = 7\par ??    \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
    <span style="color: blue">public</span><span style="color: blue">enum</span><span style="color: #2b91af">MessageResult</span></p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        None = 0,
</p>
          <p style="margin: 0px">
        OK = 1,
</p>
          <p style="margin: 0px">
        Cancel = 2,
</p>
          <p style="margin: 0px">
        Yes = 6,
</p>
          <p style="margin: 0px">
        No = 7
</p>
          <p style="margin: 0px">
    }
</p>
        </div>
        <p>
          <br />
Using the visualizer is very easy – request the service from the service locator using
the <strong>Resolve</strong> method (this requires you derive from the <strong>JulMar.Windows.Mvvm.ViewModel</strong> base
class, or hit the service locator using the static property):
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs28     \cf3 private\cf0  \cf3 void\cf0  OnShowMessage(\cf3 string\cf0  message)\par ??    \{\par ??        \cf3 var\cf0  messageVisualizer = Resolve&lt;\cf4 IMessageVisualizer\cf0 &gt;();\par ??        \cf3 if\cf0  (messageVisualizer != \cf3 null\cf0 )\par ??        \{\par ??            Result = \cf4 Enum\cf0 .GetName(\cf3 typeof\cf0  (\cf4 MessageResult\cf0 ),\par ??                                  messageVisualizer.Show(Title, message, \cf4 MessageButtons\cf0 .YesNoCancel));\par ??        \}\par ??    \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
    <span style="color: blue">private</span><span style="color: blue">void</span> OnShowMessage(<span style="color: blue">string</span> message)
</p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        <span style="color: blue">var</span> messageVisualizer
= Resolve&lt;<span style="color: #2b91af">IMessageVisualizer</span>&gt;();
</p>
          <p style="margin: 0px">
        <span style="color: blue">if</span> (messageVisualizer
!= <span style="color: blue">null</span>)
</p>
          <p style="margin: 0px">
        {
</p>
          <p style="margin: 0px">
            Result = <span style="color: #2b91af">Enum</span>.GetName(<span style="color: blue">typeof</span> (<span style="color: #2b91af">MessageResult</span>),
</p>
          <p style="margin: 0px">
              
messageVisualizer.Show(Title, message, <span style="color: #2b91af">MessageButtons</span>.YesNoCancel));
</p>
          <p style="margin: 0px">
        }
</p>
          <p style="margin: 0px">
    }
</p>
        </div>
        <p>
          <br />
Notice that I test to ensure the visualizer is available – remember that services
can be replaced or removed – I might do this in my unit tests for example (I actually
mock the interface rather than replace it, but you get the point – test to make sure
it’s there).
</p>
        <p>
We want to see the result, so I take the resulting enum and convert it to a string
and assign it to a new <strong>Result</strong> property on the ViewModel.  This,
like <strong>Title</strong>, is just a field-backed string that does a property change
notification.
</p>
        <h4>IErrorVisualizer
</h4>
        <p>
The error visualizer is for cases where you want to display an error dialog to the
user with a title and message.  The default implementation displays a <strong>MessageBox </strong>with
an OK button
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/image_4.png">
            <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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/image_thumb_1.png" width="391" height="183" />
          </a>
        </p>
        <p>
It returns a boolean response indicating that the user clicked the OK button (versus
dismissing using the Close “X” button).   It has a similar interface to
the message visualizer:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs28     \cf3 private\cf0  \cf3 void\cf0  OnShowError(\cf3 string\cf0  errorMessage)\par ??    \{\par ??        \cf3 var\cf0  errorVisualizer = Resolve&lt;\cf4 IErrorVisualizer\cf0 &gt;();\par ??        \cf3 if\cf0  (errorVisualizer != \cf3 null\cf0 )\par ??        \{\par ??            Result = errorVisualizer.Show(Title, errorMessage).ToString();\par ??        \}\par ??    \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
    <span style="color: blue">private</span><span style="color: blue">void</span> OnShowError(<span style="color: blue">string</span> errorMessage)
</p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        <span style="color: blue">var</span> errorVisualizer
= Resolve&lt;<span style="color: #2b91af">IErrorVisualizer</span>&gt;();
</p>
          <p style="margin: 0px">
        <span style="color: blue">if</span> (errorVisualizer
!= <span style="color: blue">null</span>)
</p>
          <p style="margin: 0px">
        {
</p>
          <p style="margin: 0px">
            Result = errorVisualizer.Show(Title,
errorMessage).ToString();
</p>
          <p style="margin: 0px">
        }
</p>
          <p style="margin: 0px">
    }
</p>
        </div>
        <p>
          <br />
We will assign the boolean result to the string Result property as well.
</p>
        <h4>INotificationVisualizer
</h4>
        <p>
This visualizer is for cases where you are doing something in the ViewModel logic,
on the UI thread that takes a moment to process.  Sorting a list, or searching
an in-memory list might be an example.  True long-running operations should always
be on a separate thread and use properties or the message mediator to coordinate with
the UI thread.  That said, there are times when you want to do the logic inline
with the request and you know it’s going to take a second or two to process it. 
Enter the <strong>INotificationVisualizer</strong>.  It takes the same title
and message as it’s cousin visualizers but the default implementation does not use
them – instead, the default implementation simply changes the cursor to an hourglass
(the defacto standard for “please wait”).  This is a service that I often replace
with a custom visualzation – a progress bar, thumbar progress on Windows 7, or even
a dialog overlay.  Invoking it is simple:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs28     \cf3 private\cf0  \cf3 void\cf0  OnShowNotification(\cf3 string\cf0  message)\par ??    \{\par ??        \cf3 var\cf0  notifyVisual = Resolve&lt;\cf4 INotificationVisualizer\cf0 &gt;();\par ??        \cf3 if\cf0  (notifyVisual != \cf3 null\cf0 )\par ??        \{\par ??            \cf3 using\cf0  (notifyVisual.BeginWait(Title, message))\par ??            \{\par ??                \cf5 // Sleep for 2sec, pretending to work\par ??\cf0                 \cf4 Thread\cf0 .Sleep(2000);\par ??            \}\par ??        \}\par ??    \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
    <span style="color: blue">private</span><span style="color: blue">void</span> OnShowNotification(<span style="color: blue">string</span> message)
</p>
          <p style="margin: 0px">
    {
</p>
          <p style="margin: 0px">
        <span style="color: blue">var</span> notifyVisual
= Resolve&lt;<span style="color: #2b91af">INotificationVisualizer</span>&gt;();
</p>
          <p style="margin: 0px">
        <span style="color: blue">if</span> (notifyVisual
!= <span style="color: blue">null</span>)
</p>
          <p style="margin: 0px">
        {
</p>
          <p style="margin: 0px">
            <span style="color: blue">using</span> (notifyVisual.BeginWait(Title,
message))
</p>
          <p style="margin: 0px">
            {
</p>
          <p style="margin: 0px">
                <span style="color: green">//
Sleep for 2sec, pretending to work</span></p>
          <p style="margin: 0px">
                <span style="color: #2b91af">Thread</span>.Sleep(2000);
</p>
          <p style="margin: 0px">
            }
</p>
          <p style="margin: 0px">
        }
</p>
          <p style="margin: 0px">
    }
</p>
        </div>
        <p>
          <br />
The <strong>BeginWait</strong>() method kicks off the notification visual (hourglass
cursor in this case).  It returns a disposable object that you invoke Dispose
on to return to the normal cursor.  Again, let me stress this is not optimal
for a true long-running operation – this locks the UI up until the thread returns
so only use this for very short operations.
</p>
        <h4>Creating the View
</h4>
        <p>
The View for this application will be simple – let’s use an <strong>ItemsControl</strong> to
generate a button for each of the exposed commands, two <strong>TextBoxes</strong> to
hold the Title and Message, and then a <strong>TextBlock</strong> for the result,
here’s what I want it to look like:
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/image_6.png">
            <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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/image_thumb_2.png" width="426" height="320" />
          </a>
        </p>
        <p>
I’ll let you go through the XAML – it’s straightforward and should be pretty easy
to follow.  The only new thing might be that we’ll set focus to the first focusable
element using the <strong>FirstFocusedElement</strong> markup extension:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1 &lt;\cf3 Window\cf4  x\cf1 :\cf4 Class\cf1 ="ServicesTest.Views.MainWindow"\par ??\cf0    \cf4  xmlns\cf1 ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 x\cf1 ="http://schemas.microsoft.com/winfx/2006/xaml"\cf0  \par ??   \cf4  xmlns\cf1 :\cf4 julmar\cf1 ="http://www.julmar.com/wpfhelpers"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 ViewModels\cf1 ="clr-namespace:ServicesTest.ViewModels"\cf0  \par ??   \cf4  Title\cf1 ="Notification Visualizer Test"\cf4  Height\cf1 ="300"\cf4  Width\cf1 ="400"\cf4  Background\cf1 ="LightYellow"\cf0  \par ??   \cf4  WindowStartupLocation\cf1 ="CenterScreen"\cf4  FocusManager.FocusedElement\cf1 ="\{\cf3 julmar\cf1 :\cf3 FirstFocusedElement\cf1 \}"\par ??\cf0    \cf4  DataContext\cf1 ="\{\cf3 julmar\cf1 :\cf3 ViewModelCreator\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ViewModels\cf1 :\cf4 MainViewModel\cf1 \}\}"&gt;\par ??\cf3     \cf1 &lt;\cf3 Grid\cf4  Margin\cf1 ="5"&gt;\par ??\cf3         \cf1 &lt;\cf3 Grid.RowDefinitions\cf1 &gt;\par ??\cf3             \cf1 &lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&gt;\par ??\cf3             \cf1 &lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&gt;\par ??\cf3             \cf1 &lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&gt;\par ??\cf3             \cf1 &lt;\cf3 RowDefinition\cf1  /&gt;\par ??\cf3         \cf1 &lt;/\cf3 Grid.RowDefinitions\cf1 &gt;\par ??\cf3         \par ??        \cf1 &lt;\cf3 Grid.ColumnDefinitions\cf1 &gt;\par ??\cf3             \cf1 &lt;\cf3 ColumnDefinition\cf4  Width\cf1 ="Auto" /&gt;\par ??\cf3             \cf1 &lt;\cf3 ColumnDefinition\cf1  /&gt;\par ??\cf3         \cf1 &lt;/\cf3 Grid.ColumnDefinitions\cf1 &gt;\par ??\cf3         \par ??        \cf1 &lt;\cf3 Label\cf4  Grid.Column\cf1 ="0"\cf4  Grid.Row\cf1 ="0"\cf4  Content\cf1 ="Title:" /&gt;\par ??\cf3         \cf1 &lt;\cf3 TextBox\cf4  Grid.Column\cf1 ="1"\cf4  Grid.Row\cf1 ="0"\cf4  Margin\cf1 ="5,2"\cf4  Text\cf1 ="\{\cf3 Binding\cf4  Title\cf1 \}" /&gt;\par ??\par ??\cf3         \cf1 &lt;\cf3 Label\cf4  Grid.Column\cf1 ="0"\cf4  Grid.Row\cf1 ="1"\cf4  Content\cf1 ="Message:" /&gt;\par ??\cf3         \cf1 &lt;\cf3 TextBox\cf4  x\cf1 :\cf4 Name\cf1 ="tbMessage"\cf4  Grid.Column\cf1 ="1"\cf4  Grid.Row\cf1 ="1"\cf4  Margin\cf1 ="5,2" /&gt;\par ??\par ??\cf3         \cf1 &lt;\cf3 ItemsControl\cf4  Grid.Row\cf1 ="2"\cf4  Grid.ColumnSpan\cf1 ="2"\cf4  Margin\cf1 ="10"\par ??\cf0                      \cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  VisualizationCommands\cf1 \}"&gt;\par ??\cf3             \cf1 &lt;\cf3 ItemsControl.ItemTemplate\cf1 &gt;\par ??\cf3                 \cf1 &lt;\cf3 DataTemplate\cf1 &gt;\par ??\cf3                     \cf1 &lt;\cf3 Button\cf4  Margin\cf1 ="5"\cf4  Content\cf1 ="\{\cf3 Binding\cf4  Title\cf1 \}"\cf4  Command\cf1 ="\{\cf3 Binding\cf4  Command\cf1 \}"\cf4  CommandParameter\cf1 ="\{\cf3 Binding\cf4  ElementName\cf1 =tbMessage,\cf4  Path\cf1 =Text\}" /&gt;\par ??\cf3                 \cf1 &lt;/\cf3 DataTemplate\cf1 &gt;\par ??\cf3             \cf1 &lt;/\cf3 ItemsControl.ItemTemplate\cf1 &gt;\par ??\cf3         \cf1 &lt;/\cf3 ItemsControl\cf1 &gt;\par ??\cf3         \par ??        \cf1 &lt;\cf3 TextBlock\cf4  FontSize\cf1 ="24pt"\cf4  Grid.ColumnSpan\cf1 ="2"\cf4  Grid.Row\cf1 ="3"\cf4  HorizontalAlignment\cf1 ="Center"\cf0  \par ??              \cf4  VerticalAlignment\cf1 ="Center"\cf4  Text\cf1 ="\{\cf3 Binding\cf4  Result\cf1 ,\cf4  FallbackValue\cf1 =None\}" /&gt;\par ??\cf3         \par ??    \cf1 &lt;/\cf3 Grid\cf1 &gt;\par ??&lt;/\cf3 Window\cf1 &gt;\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Window</span>
            <span style="color: red"> x</span>
            <span style="color: blue">:</span>
            <span style="color: red">Class</span>
            <span style="color: blue">="ServicesTest.Views.MainWindow"</span>
          </p>
          <p style="margin: 0px">
   <span style="color: red">xmlns</span><span style="color: blue">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></p>
          <p style="margin: 0px">
   <span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">="http://schemas.microsoft.com/winfx/2006/xaml"</span></p>
          <p style="margin: 0px">
   <span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">julmar</span><span style="color: blue">="http://www.julmar.com/wpfhelpers"</span></p>
          <p style="margin: 0px">
   <span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">ViewModels</span><span style="color: blue">="clr-namespace:ServicesTest.ViewModels"</span></p>
          <p style="margin: 0px">
   <span style="color: red">Title</span><span style="color: blue">="Notification
Visualizer Test"</span><span style="color: red"> Height</span><span style="color: blue">="300"</span><span style="color: red"> Width</span><span style="color: blue">="400"</span><span style="color: red"> Background</span><span style="color: blue">="LightYellow"</span></p>
          <p style="margin: 0px">
   <span style="color: red">WindowStartupLocation</span><span style="color: blue">="CenterScreen"</span><span style="color: red"></span></p>
          <p style="margin: 0px">
            <span style="color: red">   FocusManager.FocusedElement</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">julmar</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">FirstFocusedElement</span>
            <span style="color: blue">}"</span>
          </p>
          <p style="margin: 0px">
   <span style="color: red">DataContext</span><span style="color: blue">="{</span><span style="color: #a31515">julmar</span><span style="color: blue">:</span><span style="color: #a31515">ViewModelCreator</span><span style="color: blue"> {</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Type</span><span style="color: red"> ViewModels</span><span style="color: blue">:</span><span style="color: red">MainViewModel</span><span style="color: blue">}}"&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Grid</span>
            <span style="color: red"> Margin</span>
            <span style="color: blue">="5"&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Grid.RowDefinitions</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">RowDefinition</span>
            <span style="color: red"> Height</span>
            <span style="color: blue">="Auto"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">RowDefinition</span>
            <span style="color: red"> Height</span>
            <span style="color: blue">="Auto"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">RowDefinition</span>
            <span style="color: red"> Height</span>
            <span style="color: blue">="Auto"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">RowDefinition</span>
            <span style="color: blue"> /&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Grid.RowDefinitions</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Grid.ColumnDefinitions</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">ColumnDefinition</span>
            <span style="color: red"> Width</span>
            <span style="color: blue">="Auto"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">ColumnDefinition</span>
            <span style="color: blue"> /&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Grid.ColumnDefinitions</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Label</span>
            <span style="color: red"> Grid.Column</span>
            <span style="color: blue">="0"</span>
            <span style="color: red"> Grid.Row</span>
            <span style="color: blue">="0"</span>
            <span style="color: red"> Content</span>
            <span style="color: blue">="Title:"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">TextBox</span>
            <span style="color: red"> Grid.Column</span>
            <span style="color: blue">="1"</span>
            <span style="color: red"> Grid.Row</span>
            <span style="color: blue">="0"</span>
            <span style="color: red"> Margin</span>
            <span style="color: blue">="5,2"</span>
            <span style="color: red"> Text</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Title</span>
            <span style="color: blue">}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Label</span>
            <span style="color: red"> Grid.Column</span>
            <span style="color: blue">="0"</span>
            <span style="color: red"> Grid.Row</span>
            <span style="color: blue">="1"</span>
            <span style="color: red"> Content</span>
            <span style="color: blue">="Message:"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">TextBox</span>
            <span style="color: red"> x</span>
            <span style="color: blue">:</span>
            <span style="color: red">Name</span>
            <span style="color: blue">="tbMessage"</span>
            <span style="color: red"> Grid.Column</span>
            <span style="color: blue">="1"</span>
            <span style="color: red"> Grid.Row</span>
            <span style="color: blue">="1"</span>
            <span style="color: red"> Margin</span>
            <span style="color: blue">="5,2"
/&gt;</span>
          </p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">ItemsControl</span>
            <span style="color: red"> Grid.Row</span>
            <span style="color: blue">="2"</span>
            <span style="color: red"> Grid.ColumnSpan</span>
            <span style="color: blue">="2"</span>
            <span style="color: red"> Margin</span>
            <span style="color: blue">="10"</span>
          </p>
          <p style="margin: 0px">
                    <span style="color: red">ItemsSource</span><span style="color: blue">="{</span><span style="color: #a31515">Binding</span><span style="color: red"> VisualizationCommands</span><span style="color: blue">}"&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">ItemsControl.ItemTemplate</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">DataTemplate</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                    </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">Button</span>
            <span style="color: red"> Margin</span>
            <span style="color: blue">="5"</span>
            <span style="color: red"> Content</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Title</span>
            <span style="color: blue">}"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">                      
Command</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Command</span>
            <span style="color: blue">}"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">                      
CommandParameter</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> ElementName</span>
            <span style="color: blue">=tbMessage,</span>
            <span style="color: red"> Path</span>
            <span style="color: blue">=Text}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">                </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">DataTemplate</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">            </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">ItemsControl.ItemTemplate</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">ItemsControl</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: #a31515">        </span>
            <span style="color: blue">&lt;</span>
            <span style="color: #a31515">TextBlock</span>
            <span style="color: red"> FontSize</span>
            <span style="color: blue">="24pt"</span>
            <span style="color: red"> Grid.ColumnSpan</span>
            <span style="color: blue">="2"</span>
            <span style="color: red"> Grid.Row</span>
            <span style="color: blue">="3"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">             
HorizontalAlignment</span>
            <span style="color: blue">="Center" </span>
            <span style="color: red">VerticalAlignment</span>
            <span style="color: blue">="Center"</span>
            <span style="color: red">
            </span>
          </p>
          <p style="margin: 0px">
            <span style="color: red">             
Text</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding</span>
            <span style="color: red"> Result</span>
            <span style="color: blue">,</span>
            <span style="color: red"> FallbackValue</span>
            <span style="color: blue">=None}"
/&gt;</span>
          </p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
            <span style="color: #a31515">    </span>
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Grid</span>
            <span style="color: blue">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">&lt;/</span>
            <span style="color: #a31515">Window</span>
            <span style="color: blue">&gt;</span>
          </p>
        </div>
        <p>
          <br />
That should do it – if you’d like to just download the project and play with it, it’s
available here: <a href="http://www.julmar.com/samples/VisulizerTest.zip" target="_blank">VisualizerTest.zip</a>. 
In the next post we’ll take a look at the grand-daddy of the message visualizers in
the MVVM Helper toolkit: the <strong>IUIVisualizer</strong>!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>MVVM: Binding RadioButton groups</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/01/29/MVVMBindingRadioButtonGroups.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,99559ede-2613-43f4-89a5-124081f24baa.aspx</id>
    <published>2010-01-29T10:41:42.563-08:00</published>
    <updated>2010-01-29T10:44:46.5794951-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="MVVM" label="MVVM" scheme="http://www.julmar.com/blog/mark/CategoryView,category,MVVM.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">&lt;p&gt;
A question I got recently was how to manage Radio Buttons with bindings – in this
instance, the sample code was trying to map a single value to a set of Radio Buttons
based on an enumeration set.&amp;nbsp; The original implementation was using a Value Converter
to compare the “bound” value with the enumeration value expected for that radio button
choice – if it was equal then the converter returned true, otherwise false.&amp;nbsp;
Something like this:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1                     \cf3 &amp;lt;\cf1 RadioButton\cf4  Content\cf3 ="Blue"\cf0  \par ??                                \cf4  IsChecked\cf3 ="\{\cf1 Binding\cf4  SelectedValue\cf3 ,\cf4  Converter\cf3 =\{\cf1 StaticResource\cf4  CheckValueAgainst\cf3 \},\cf4  ConverterParameter\cf3 =Blue"/&amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: red"&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Blue"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;IsChecked&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;={&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; CheckValueAgainst&lt;/span&gt;&lt;span style="COLOR: blue"&gt;},&lt;/span&gt;&lt;span style="COLOR: red"&gt; ConverterParameter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=Blue"/&amp;gt;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: red"&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Red"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;IsChecked&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;={&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; CheckValueAgainst&lt;/span&gt;&lt;span style="COLOR: blue"&gt;},&lt;/span&gt;&lt;span style="COLOR: red"&gt; ConverterParameter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=Red"/&amp;gt;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: red"&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Yellow"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;IsChecked&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;={&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; CheckValueAgainst&lt;/span&gt;&lt;span style="COLOR: blue"&gt;},&lt;/span&gt;&lt;span style="COLOR: red"&gt; ConverterParameter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=Yellow"/&amp;gt;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Initially this seemed to work, but as you changed the current enumeration value, the
radio buttons would “lose” the binding – and after a few times you would end up with
none of them selected.
&lt;/p&gt;
&lt;p&gt;
Ultimately, this problem is really an expected behavior from WPF – when a set of Radio
Buttons are placed together, they act as a &lt;em&gt;group&lt;/em&gt; – where only one is expected
to be checked and all the others are unchecked.&amp;nbsp; This happens because the selected
Radio Button itself tells the group to uncheck all the others.&amp;nbsp; This has the
effect of replacing the binding value for &lt;strong&gt;IsChecked&lt;/strong&gt; with a local
value of &lt;strong&gt;false&lt;/strong&gt;.&amp;nbsp; See the problem?&amp;nbsp; Eventually, all of the
buttons in the group have their value replaced and so we end up with all of them unchecked.&amp;nbsp;
The solution was very easy – put each one into a separate group by defining a unique &lt;strong&gt;GroupName&lt;/strong&gt; for
each Radio Button.&amp;nbsp; 
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1                     \cf3 &amp;lt;\cf1 RadioButton\cf4  Content\cf3 ="Blue"\cf0  \par ??                                \cf4  IsChecked\cf3 ="\{\cf1 Binding\cf4  SelectedValue\cf3 ,\cf4  Converter\cf3 =\{\cf1 StaticResource\cf4  CheckValueAgainst\cf3 \},\cf4  ConverterParameter\cf3 =Blue"/&amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: red"&gt;&amp;nbsp;&lt;strong&gt;&lt;span style="COLOR: red"&gt;GroupName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="gBlue"&lt;/span&gt;&lt;/strong&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Blue"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;IsChecked&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;={&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; CheckValueAgainst&lt;/span&gt;&lt;span style="COLOR: blue"&gt;},&lt;/span&gt;&lt;span style="COLOR: red"&gt; ConverterParameter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=Blue"/&amp;gt;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;strong&gt;&lt;span style="COLOR: red"&gt;GroupName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="gRed"&lt;/span&gt;&lt;/strong&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Red"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;IsChecked&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;={&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; CheckValueAgainst&lt;/span&gt;&lt;span style="COLOR: blue"&gt;},&lt;/span&gt;&lt;span style="COLOR: red"&gt; ConverterParameter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=Red"/&amp;gt;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;strong&gt;&lt;span style="COLOR: red"&gt;GroupName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="gYellow"&lt;/span&gt;&lt;/strong&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Yellow"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;IsChecked&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;={&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; CheckValueAgainst&lt;/span&gt;&lt;span style="COLOR: blue"&gt;},&lt;/span&gt;&lt;span style="COLOR: red"&gt; ConverterParameter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=Yellow"/&amp;gt;&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
This solves the problem and required no real code changes, but of course, I didn’t
want to stop there – I just had to whip up a quick MVVM version to show how I’d do
this if I were responsible for the application!
&lt;/p&gt;
&lt;h4&gt;Sample Application Description
&lt;/h4&gt;
&lt;p&gt;
Our goal will be to display a list of children and their details to track their favorite
games.&amp;nbsp; I started by sketching it out with SketchFlow to get a sense of what
I wanted to visually create:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMBindingRadioButtongroups_F849/image_4.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://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMBindingRadioButtongroups_F849/image_thumb_1.png" width=612 height=372&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
The top list is a &lt;strong&gt;ListBox&lt;/strong&gt;, showing each child and the bottom pane
shows the details.&amp;nbsp; Note the &lt;strong&gt;RadioButtons&lt;/strong&gt; used to represent
Gender and Favorite Game.&amp;nbsp; Our goal will be to use a &lt;strong&gt;ListBox&lt;/strong&gt; there
as well – showing the list of Radio Buttons and bound to a ViewModel collection of
data.&amp;nbsp; As a secondary goal, we want to separate the &lt;strong&gt;RadioButton&lt;/strong&gt; &lt;em&gt;value&lt;/em&gt; from
the &lt;em&gt;text displayed&lt;/em&gt;.&amp;nbsp; 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font color=#ff0000&gt;&lt;em&gt;It turns out that anytime you need to display a list or sequence
of something, a ListBox (or ItemsControl if you don’t need the selection capability)
is almost always a good choice.&amp;nbsp; Let’s see if we can make it work here with the
MVVM pattern.&lt;/em&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Now that I have an idea of what I want to build, I created a blank Windows WPF application
and added the JulMar MVVM Helper library and created the directory structure I prefer
(&lt;strong&gt;Views&lt;/strong&gt;, &lt;strong&gt;ViewModels&lt;/strong&gt; and &lt;strong&gt;Dependencies&lt;/strong&gt;).&amp;nbsp;
I moved the Window1.xaml and corresponding code behind into the Views folder and renamed
it &lt;strong&gt;MainWindow.xaml&lt;/strong&gt;.&amp;nbsp; This also required I adjust &lt;strong&gt;App.xaml&lt;/strong&gt; to
point to the correct &lt;strong&gt;StartupUri&lt;/strong&gt; (Views\MainWindow.xaml).&amp;nbsp; As
a quick start you could also just use the JulMar MVVM project template and delete
the XAML and view models.&amp;nbsp; Here’s what I ended up with in the solution:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMBindingRadioButtongroups_F849/GamePrefSolution_2.jpg"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=GamePrefSolution border=0 alt=GamePrefSolution src="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMBindingRadioButtongroups_F849/GamePrefSolution_thumb.jpg" width=226 height=244&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Now, we’re ready to begin our data modeling.&amp;nbsp; In this case, I don’t have a real
data model – I’m not going to store or manage any of the children in a persistent
way so I’m just going to define the View Model definitions for the children and collection.&amp;nbsp;
We’ll start with the child definition.&amp;nbsp; I created a class to manage the properties
of the child I want to display: Name, Dob, Gender, and FavoriteGame.&amp;nbsp; For the
Gender and Favorite Game, I will use &lt;strong&gt;Enums&lt;/strong&gt; to model those as a known
list.&amp;nbsp; I could have used a Boolean for Gender as well, but this serves my underlying
goal so we’ll go with an enumeration.&amp;nbsp; Here’s what I came up with:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs28 \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??///\cf3  Gender flag\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 public\cf0  \cf4 enum\cf0  \cf6 Gender\par ??\cf0 \{\par ??    Male, Female, Unknown\par ??\}\par ??\par ??\cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??///\cf3  Game types\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 public\cf0  \cf4 enum\cf0  \cf6 GameType\par ??\cf0 \{\par ??    Webkinz,\par ??    Playdoh,\par ??    PbsKids,\par ??    Wii\par ??\}\par ??\par ??\cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??///\cf3  ViewModel to represent a single child.\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 public\cf0  \cf4 class\cf0  \cf6 ChildViewModel\cf0  : \cf6 SimpleViewModel\par ??\cf0 \{\par ??\cf4     #region\cf0  Private Data\par ??    \cf4 private\cf0  \cf4 string\cf0  _name;\par ??    \cf4 private\cf0  \cf6 Gender\cf0  _gender;\par ??    \cf4 private\cf0  \cf6 DateTime\cf0  _dob;\par ??    \cf4 private\cf0  \cf6 GameType\cf0  _favoriteGame;\par ??\cf4     #endregion\par ??\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Name\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf4 string\cf0  Name\par ??    \{\par ??        \cf4 get\cf0  \{ \cf4 return\cf0  _name; \}\par ??        \cf4 set\cf0  \{ _name = \cf4 value\cf0 ; OnPropertyChanged(\cf7 "Name"\cf0 ); \}\par ??    \}\par ??\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Gender of child\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf6 Gender\cf0  Gender\par ??    \{\par ??        \cf4 get\cf0  \{ \cf4 return\cf0  _gender; \}\par ??        \cf4 set\cf0  \{ _gender = \cf4 value\cf0 ; OnPropertyChanged(\cf7 "Gender"\cf0 ); \}\par ??    \}\par ??\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Date of birth\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf6 DateTime\cf0  Dob\par ??    \{\par ??        \cf4 get\cf0  \{ \cf4 return\cf0  _dob; \}\par ??        \cf4 set\cf0  \{ _dob = \cf4 value\cf0 ; OnPropertyChanged(\cf7 "Dob"\cf0 ); \}\par ??    \}\par ??\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Game they like to play\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf6 GameType\cf0  FavoriteGame\par ??    \{\par ??        \cf4 get\cf0  \{ \cf4 return\cf0  _favoriteGame; \}\par ??        \cf4 set\cf0  \{ _favoriteGame = \cf4 value\cf0 ; OnPropertyChanged(\cf7 "FavoriteGame"\cf0 ); \}\par ??    \}\par ??\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Returns textual representation of child.\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf4 override\cf0  \cf4 string\cf0  ToString()\par ??    \{\par ??        \cf4 return\cf0  \cf4 string\cf0 .Format(\cf7 "\{0\} is a \{1\}, was born on \{2\} and loves to play \{3\}"\cf0 , Name, Gender, Dob, FavoriteGame);\par ??    \}\par ??\}}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Gender flag&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;enum&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Male, Female, Unknown
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Game types&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;enum&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Webkinz,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Playdoh,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PbsKids,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Wii
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; ViewModel to represent
a single child.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ChildViewModel&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;SimpleViewModel&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _name;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt; _gender;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt; _dob;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt; _favoriteGame;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Name&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Name
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _name;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
_name = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"Name",&lt;span style="COLOR: #a31515"&gt;"Details"&lt;/span&gt;&lt;/span&gt;);
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Gender
of child&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt; Gender
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _gender;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
_gender = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"Gender",&lt;span style="COLOR: #a31515"&gt;"Details"&lt;/span&gt;&lt;/span&gt;);
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Date
of birth&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt; Dob
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _dob;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
_dob = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"Dob",&lt;span style="COLOR: #a31515"&gt;"Details"&lt;/span&gt;&lt;/span&gt;);
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Game
they like to play&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt; FavoriteGame
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _favoriteGame;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
_favoriteGame = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"FavoriteGame"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"Details"&lt;/span&gt;);
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Returns
textual representation of child.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Details
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;.Format(&lt;span style="COLOR: #a31515"&gt;"{0}
is a {1}, was born on {2:D} and loves to play {3}"&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Name, Gender, Dob, FavoriteGame);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Pretty standard stuff – we have field backed properties and raise the &lt;strong&gt;PropertyChange&lt;/strong&gt; notification
on each one.&amp;nbsp; For this case I don’t think we’ll need any additional services
so I derive from the &lt;strong&gt;JulMar.Windows.Mvvm.SimpleViewModel&lt;/strong&gt; class which
just provides &lt;strong&gt;INotifyPropertyChanged&lt;/strong&gt; support.&amp;nbsp; The one extra
thing I’ve added here is a &lt;strong&gt;Details&lt;/strong&gt; property which is a concatenation
of all the other properties – we’ll use this to verify that the data binding is working
properly as a secondary display of the same data.&amp;nbsp; We need to be sure to include
that property invalidation when any of the other properties it depends on changes.&amp;nbsp;
The &lt;strong&gt;OnPropertyChanged &lt;/strong&gt;implementation allows you to pass multiple
strings for this very purpose.
&lt;/p&gt;
&lt;p&gt;
Moving on, I want to display the generated Enumerations above as a list, so we need
a way to encapsulate a value and the text used to represent the value together.&amp;nbsp;
If I were using .NET4 I could use the uber-cool new &lt;strong&gt;Tuple&amp;lt;K,V&amp;gt;&lt;/strong&gt; class
but I want to target .NET 3.5 here so we’ll define a new &lt;strong&gt;ValueAndText&lt;/strong&gt; class
to hold this:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs28 \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??///\cf3  This class wraps a value and string together.\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??///\cf3  \cf1 &amp;lt;typeparam name="T"&amp;gt;\cf3 Type of value\cf1 &amp;lt;/typeparam&amp;gt;\par ??\cf4 public\cf0  \cf4 class\cf0  \cf6 EnumValue\cf0 &amp;lt;T&amp;gt;\par ??\{\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Value to bind to\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  T Value \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 set\cf0 ; \}\par ??\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Text string to present\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf4 string\cf0  Text \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 set\cf0 ; \}\par ??\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Constructor\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;param name="value"&amp;gt;&amp;lt;/param&amp;gt;\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;param name="text"&amp;gt;&amp;lt;/param&amp;gt;\par ??\cf0     \cf4 public\cf0  EnumValue(T value, \cf4 string\cf0  text)\par ??    \{\par ??        Value = value;\par ??        Text = text;\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; This class wraps a
value and string together.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;typeparam
name="T"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Type of value&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;T&amp;gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Value
to bind to&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; T Value { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Text
string to present&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Text
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Constructor&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="value"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="text"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; ValueAndText(T value, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; text)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text = text;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Now, let’s turn to the actual glue – the MainViewModel that pulls it all together.&amp;nbsp; 
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs28 \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??///\cf3  Main View Model that connects it all together.\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 public\cf0  \cf4 class\cf0  \cf6 MainViewModel\cf0  : \cf6 SimpleViewModel\par ??\cf0 \{\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Main View Model that
connects it all together.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;MainViewModel&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;SimpleViewModel&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
Let’s use a SimpleViewModel here as well.&amp;nbsp; The first property we need is a collection
for the children – we won’t be modifying the list (i.e. no adding or deleting) so
the backing storage can just be a &lt;strong&gt;List&amp;lt;T&amp;gt;&lt;/strong&gt;, as part of the constructor
we’ll populate it with some sample data:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs28         \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Collection of children\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf6 IList\cf0 &amp;lt;\cf6 ChildViewModel\cf0 &amp;gt; Children \{ \cf5 get\cf0 ; \cf5 private\cf0  \cf5 set\cf0 ; \}\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Collection of children&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;ChildViewModel&lt;/span&gt;&amp;gt;
Children { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs28         \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Constructor\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  MainViewModel()\par ??        \{\par ??            \cf4 // Fill with sample data.\par ??\cf0             Children = \cf5 new\cf0  \cf6 List\cf0 &amp;lt;\cf6 ChildViewModel\cf0 &amp;gt;\par ??               \{\par ??                   \cf5 new\cf0  \cf6 ChildViewModel\par ??\cf0                    \{\par ??                       Name = \cf7 "Jonathan"\cf0 ,\par ??                       Dob = \cf5 new\cf0  \cf6 DateTime\cf0 (2006, 3, 14),\par ??                       FavoriteGame = \cf6 GameType\cf0 .PbsKids,\par ??                       Gender = \cf6 Gender\cf0 .Male\par ??                   \},\par ??                   \cf5 new\cf0  \cf6 ChildViewModel\par ??\cf0                    \{\par ??                       Name = \cf7 "Amanda"\cf0 ,\par ??                       Dob = \cf5 new\cf0  \cf6 DateTime\cf0 (1999, 9, 8),\par ??                       FavoriteGame = \cf6 GameType\cf0 .Wii,\par ??                       Gender = \cf6 Gender\cf0 .Female\par ??                   \},\par ??                   \cf5 new\cf0  \cf6 ChildViewModel\par ??\cf0                    \{\par ??                       Name = \cf7 "Cassidy"\cf0 ,\par ??                       Dob = \cf5 new\cf0  \cf6 DateTime\cf0 (2004, 1, 14),\par ??                       FavoriteGame = \cf6 GameType\cf0 .Wii,\par ??                       Gender = \cf6 Gender\cf0 .Female\par ??                   \},\par ??                   \cf5 new\cf0  \cf6 ChildViewModel\par ??\cf0                    \{\par ??                       Name = \cf7 "Jack"\cf0 ,\par ??                       Dob = \cf5 new\cf0  \cf6 DateTime\cf0 (2001, 10, 24),\par ??                       FavoriteGame = \cf6 GameType\cf0 .Playdoh,\par ??                       Gender = \cf6 Gender\cf0 .Male\par ??                   \},\par ??               \};\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Constructor&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; MainViewModel()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp; // Fill with sample data.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; Children = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;ChildViewModel&lt;/span&gt;&amp;gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ChildViewModel&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name = &lt;span style="COLOR: #a31515"&gt;"Jonathan"&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dob = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt;(2006,
3, 14),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FavoriteGame = &lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;.PbsKids,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Gender = &lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt;.Male
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp; };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
Next, we want a single child to be the “current” selected child.&amp;nbsp; This is just
a property of type &lt;strong&gt;ChildViewModel&lt;/strong&gt; exposed by the parent view model.
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;\red163\green21\blue21;}??\fs28         \cf3 private\cf0  \cf4 ChildViewModel\cf0  _currentChild;\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  The current (and only for now) child\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  \cf4 ChildViewModel\cf0  CurrentChild\par ??        \{\par ??            \cf3 get\cf0  \{ \cf3 return\cf0  _currentChild; \}\par ??            \cf3 set\par ??\cf0             \{\par ??                \cf3 if\cf0  (_currentChild != \cf3 value\cf0 )\par ??                \{\par ??                    \cf3 if\cf0  (_currentChild != \cf3 null\cf0 )\par ??                        _currentChild.PropertyChanged -= RaiseChildDetailsChange;\par ??                    _currentChild = \cf3 value\cf0 ;\par ??                    \cf3 if\cf0  (_currentChild != \cf3 null\cf0 )\par ??                        _currentChild.PropertyChanged += RaiseChildDetailsChange;\par ??                    OnPropertyChanged(\cf7 "CurrentChild"\cf0 );\par ??                \}\par ??            \}\par ??        \}\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ChildViewModel&lt;/span&gt; _currentChild;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; The current (and only
for now) child&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ChildViewModel&lt;/span&gt; CurrentChild
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp; get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _currentChild;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_currentChild
!= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _currentChild = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"CurrentChild"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
We’ll also set the first child as the current child in the &lt;strong&gt;MainViewModel &lt;/strong&gt;constructor
after we populate the collection:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;}??\fs28             \cf3 // Set the first child as selected.\par ??\cf0             CurrentChild = Children[0];\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// Set the first child as selected.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
CurrentChild = Children[0];
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
We want to have a bindable list of the gender values (and text) and a bindable list
of the game types.&amp;nbsp; In this case, let’s take advantage of the ability to bind
to any IEnumerable data source and just generate the list using the C# 2.0 iterator
support: 
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red128\green128\blue128;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs28 \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??///\cf3  Gets the gender values\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 public\cf0  \cf6 IEnumerable\cf0 &amp;lt;\cf6 EnumValue\cf0 &amp;lt;\cf6 Gender\cf0 &amp;gt;&amp;gt; GenderValues\par ??\{\par ??    \cf4 get\par ??\cf0     \{\par ??        \cf4 yield\cf0  \cf4 return\cf0  \cf4 new\cf0  \cf6 EnumValue\cf0 &amp;lt;\cf6 Gender\cf0 &amp;gt;(\cf6 Gender\cf0 .Male, \cf7 "Boy"\cf0 );\par ??        \cf4 yield\cf0  \cf4 return\cf0  \cf4 new\cf0  \cf6 EnumValue\cf0 &amp;lt;\cf6 Gender\cf0 &amp;gt;(\cf6 Gender\cf0 .Female, \cf7 "Girl"\cf0 );\par ??    \}\par ??\}\par ??\par ??\cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??///\cf3  Gets the game types\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 public\cf0  \cf6 IEnumerable\cf0 &amp;lt;\cf6 EnumValue\cf0 &amp;lt;\cf6 GameType\cf0 &amp;gt;&amp;gt; GameTypes\par ??\{\par ??    \cf4 get\par ??\cf0     \{\par ??        \cf4 yield\cf0  \cf4 return\cf0  \cf4 new\cf0  \cf6 EnumValue\cf0 &amp;lt;\cf6 GameType\cf0 &amp;gt;(\cf6 GameType\cf0 .Webkinz, \cf7 "WebKinz (http://www.webkinz.com)"\cf0 );\par ??        \cf4 yield\cf0  \cf4 return\cf0  \cf4 new\cf0  \cf6 EnumValue\cf0 &amp;lt;\cf6 GameType\cf0 &amp;gt;(\cf6 GameType\cf0 .Playdoh, \cf7 "Loves Playdoh"\cf0 );\par ??        \cf4 yield\cf0  \cf4 return\cf0  \cf4 new\cf0  \cf6 EnumValue\cf0 &amp;lt;\cf6 GameType\cf0 &amp;gt;(\cf6 GameType\cf0 .PbsKids, \cf7 "PBS Kids (http://www.pbskids.com)"\cf0 );\par ??        \cf4 yield\cf0  \cf4 return\cf0  \cf4 new\cf0  \cf6 EnumValue\cf0 &amp;lt;\cf6 GameType\cf0 &amp;gt;(\cf6 GameType\cf0 .Wii, \cf7 "Wii and other console"\cf0 );\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Gets the gender values&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt;&amp;gt;&amp;gt;
GenderValues
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;yield&lt;/span&gt; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt;&amp;gt;(&lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt;.Male, &lt;span style="COLOR: #a31515"&gt;"Boy"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;yield&lt;/span&gt; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt;&amp;gt;(&lt;span style="COLOR: #2b91af"&gt;Gender&lt;/span&gt;.Female, &lt;span style="COLOR: #a31515"&gt;"Girl"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Gets the game types&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;&amp;gt;&amp;gt;
GameTypes
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;yield&lt;/span&gt; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;&amp;gt;(&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;.Webkinz, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"WebKinz
(http://www.webkinz.com)"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;yield&lt;/span&gt; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;&amp;gt;(&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;.Playdoh, &lt;span style="COLOR: #a31515"&gt;"Loves
Playdoh"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;yield&lt;/span&gt; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;&amp;gt;(&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;.PbsKids, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"PBS
Kids (http://www.pbskids.com)"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;yield&lt;/span&gt; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ValueAndText&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;&amp;gt;(&lt;span style="COLOR: #2b91af"&gt;GameType&lt;/span&gt;.Wii, &lt;span style="COLOR: #a31515"&gt;"Wii
and other console"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
That should do it for our logic and data requirements, now let’s turn to the visualization
for it.&amp;nbsp; We have the following properties defined on the &lt;strong&gt;MainViewModel&lt;/strong&gt; to
drive the view:
&lt;/p&gt;
&lt;table border=1 cellspacing=0 cellpadding=2 width=615&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign=top width=200&gt;
&lt;strong&gt;Children&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=413&gt;
Collection of &lt;strong&gt;PersonViewModel&lt;/strong&gt; objects with child details.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=200&gt;
&lt;strong&gt;CurrentChild&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=413&gt;
Current (selected) child&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=200&gt;
&lt;strong&gt;GenderValues&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=413&gt;
Collection of &lt;strong&gt;ValueAndText&lt;/strong&gt; objects to select child gender&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=200&gt;
&lt;strong&gt;GameTypes&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=413&gt;
Collection of &lt;strong&gt;ValueAndText&lt;/strong&gt; objects to select the favorite game&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&lt;br&gt;
&lt;br&gt;
Using the SketchFlow prototype as an example, we’ll start with a &lt;strong&gt;DockPanel&lt;/strong&gt; as
the root element – locking a &lt;strong&gt;StatusBar&lt;/strong&gt; at the bottom, a &lt;strong&gt;ListBox&lt;/strong&gt; at
the top and a &lt;strong&gt;Border&lt;/strong&gt; (which will contain our details pane) as the
fill content.&amp;nbsp; We’ll use the JulMar &lt;strong&gt;ViewModelCreator&lt;/strong&gt; markup
extension to tie this to the &lt;strong&gt;MainViewModel&lt;/strong&gt;, and let’s push the initial
focus into the children &lt;strong&gt;ListBox&lt;/strong&gt; using the &lt;strong&gt;FocusManager.FocusedElement&lt;/strong&gt; attached
property on the window.
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;\red0\green128\blue0;}??\fs28 \cf1 &amp;lt;\cf3 Window\cf4  x\cf1 :\cf4 Class\cf1 ="RadioButtonBinding.Views.MainWindow"\par ??\cf0    \cf4  xmlns\cf1 ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 x\cf1 ="http://schemas.microsoft.com/winfx/2006/xaml"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 julmar\cf1 ="http://www.julmar.com/wpfhelpers"\cf0  \par ??   \cf4  xmlns\cf1 :\cf4 ViewModels\cf1 ="clr-namespace:RadioButtonBinding.ViewModels"\cf0  \par ??   \cf4  xmlns\cf1 :\cf4 Controls\cf1 ="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"\cf0  \par ??   \cf4  DataContext\cf1 ="\{\cf3 julmar\cf1 :\cf3 ViewModelCreator\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ViewModels\cf1 :\cf4 MainViewModel\cf1 \}\}"\par ??\cf0    \cf4  FocusManager.FocusedElement\cf1 ="\{\cf3 Binding\cf4  ElementName\cf1 =lbChildren\}"\par ??\cf0    \cf4  Title\cf1 ="Game Preference Tracker"\cf4  Height\cf1 ="400"\cf4  Width\cf1 ="500"\cf4  Background\cf1 ="OldLace"&amp;gt;\par ??\par ??\cf3     \cf1 &amp;lt;\cf3 Window.Resources\cf1 &amp;gt;\par ??\cf3         \cf6 &amp;lt;!-- Simple style to present RadioButton controls as the ListBox elements.\par ??             The IsChecked state is bound to the selection state - make sure the ListBox uses\par ??             Single-Selection! --&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Style\cf4  x\cf1 :\cf4 Key\cf1 ="radioListBox"\cf4  TargetType\cf1 ="ListBox"\cf4  BasedOn\cf1 ="\{\cf3 StaticResource\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ListBox\cf1 \}\}"&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="BorderThickness"\cf4  Value\cf1 ="0" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Margin"\cf4  Value\cf1 ="5" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="DisplayMemberPath"\cf4  Value\cf1 ="Text" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="SelectedValuePath"\cf4  Value\cf1 ="Value" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Background"\cf4  Value\cf1 ="\{\cf3 x\cf1 :\cf3 Null\cf1 \}" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="ItemContainerStyle"&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="ListBoxItem"\cf4  BasedOn\cf1 ="\{\cf3 StaticResource\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ListBoxItem\cf1 \}\}"&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Template"&amp;gt;\par ??\cf3                             \cf1 &amp;lt;\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3                                 \cf1 &amp;lt;\cf3 ControlTemplate\cf4  TargetType\cf1 ="ListBoxItem"&amp;gt;\par ??\cf3                                     \cf1 &amp;lt;\cf3 Border\cf4  Background\cf1 ="Transparent"&amp;gt;\par ??\cf3                                         \cf1 &amp;lt;\cf3 RadioButton\cf4  Focusable\cf1 ="False"\cf4  IsHitTestVisible\cf1 ="False"\cf4  IsChecked\cf1 ="\{\cf3 TemplateBinding\cf4  IsSelected\cf1 \}"&amp;gt;\par ??\cf3                                             \cf1 &amp;lt;\cf3 ContentPresenter\cf1  /&amp;gt;\par ??\cf3                                         \cf1 &amp;lt;/\cf3 RadioButton\cf1 &amp;gt;\par ??\cf3                                     \cf1 &amp;lt;/\cf3 Border\cf1 &amp;gt;\par ??\cf3                                 \cf1 &amp;lt;/\cf3 ControlTemplate\cf1 &amp;gt;\par ??\cf3                             \cf1 &amp;lt;/\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3                         \cf1 &amp;lt;/\cf3 Setter\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 Setter\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 Window.Resources\cf1 &amp;gt;\par ??\cf3     \par ??    \cf1 &amp;lt;\cf3 DockPanel\cf1 &amp;gt;\par ??\par ??\cf3         \cf6 &amp;lt;!-- List of children we are tracking --&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 ListBox\cf4  x\cf1 :\cf4 Name\cf1 ="lbChildren"\cf4  DockPanel.Dock\cf1 ="Top"\cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  Children\cf1 \}"\cf0  \par ??                \cf4  SelectedItem\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 ,\cf4  Mode\cf1 =TwoWay\}"\par ??\cf0                 \cf4  ScrollViewer.HorizontalScrollBarVisibility\cf1 ="Disabled"&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 ListBox.ItemsPanel\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 ItemsPanelTemplate\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 WrapPanel\cf1  /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 ItemsPanelTemplate\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 ListBox.ItemsPanel\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 ListBox.ItemTemplate\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 DataTemplate\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 Border\cf4  BorderBrush\cf1 ="DarkBlue"\cf4  BorderThickness\cf1 ="2"\cf4  Background\cf1 ="SkyBlue"\cf4  CornerRadius\cf1 ="5"&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 StackPanel\cf4  Margin\cf1 ="10"&amp;gt;\par ??\cf3                             \cf1 &amp;lt;\cf3 TextBlock\cf4  FontWeight\cf1 ="Bold"\cf4  FontSize\cf1 ="12pt"\cf4  Text\cf1 ="\{\cf3 Binding\cf4  Name\cf1 \}" /&amp;gt;\par ??\cf3                             \cf1 &amp;lt;\cf3 TextBlock\cf4  Text\cf1 ="\{\cf3 Binding\cf4  FavoriteGame\cf1 \}" /&amp;gt;\par ??\cf3                         \cf1 &amp;lt;/\cf3 StackPanel\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;/\cf3 Border\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 DataTemplate\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 ListBox.ItemTemplate\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 ListBox\cf1 &amp;gt;\par ??\par ??\cf3         \cf6 &amp;lt;!-- StatusBar just to make sure two-way binding is working properly --&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 StatusBar\cf4  DockPanel.Dock\cf1 ="Bottom"\cf4  BorderBrush\cf1 ="Black"\cf4  BorderThickness\cf1 ="0,1,0,0"&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 TextBlock\cf4  Text\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Details\cf1 \}"\cf4  TextWrapping\cf1 ="Wrap" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 StatusBar\cf1 &amp;gt;\par ??\par ??\cf3         \cf6 &amp;lt;!-- Details pane --&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Border\cf4  Margin\cf1 ="5"\cf4  BorderBrush\cf1 ="LightGray"\cf4  BorderThickness\cf1 ="1"&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Grid\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Grid.Resources\cf1 &amp;gt;\par ??\cf3                     \cf6 &amp;lt;!-- Common style for header labels --&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="Label"&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="HorizontalAlignment"\cf4  Value\cf1 ="Right" /&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="VerticalAlignment"\cf4  Value\cf1 ="Top" /&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="FontWeight"\cf4  Value\cf1 ="Bold" /&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Margin"\cf4  Value\cf1 ="5,2" /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 Grid.Resources\cf1 &amp;gt;\par ??\par ??\cf3                 \cf1 &amp;lt;\cf3 Grid.ColumnDefinitions\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 ColumnDefinition\cf4  Width\cf1 ="Auto" /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 ColumnDefinition\cf1  /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 Grid.ColumnDefinitions\cf1 &amp;gt;\par ??\par ??\cf3                 \cf1 &amp;lt;\cf3 Grid.RowDefinitions\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 Grid.RowDefinitions\cf1 &amp;gt;\par ??\par ??\cf3                 \cf1 &amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="0"\cf4  Content\cf1 ="Name:" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 TextBox\cf4  Grid.Row\cf1 ="0"\cf4  Grid.Column\cf1 ="1"\cf4  Margin\cf1 ="5,2"\cf4  Text\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Name\cf1 \}" /&amp;gt;\par ??\par ??\cf3                 \cf1 &amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="1"\cf4  Content\cf1 ="Gender:" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 ListBox\cf4  Grid.Row\cf1 ="1"\cf4  Grid.Column\cf1 ="1"\cf4  Style\cf1 ="\{\cf3 StaticResource\cf4  radioListBox\cf1 \}"\cf0  \par ??                        \cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  GenderValues\cf1 \}"\cf4  SelectedValue\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Gender\cf1 \}" /&amp;gt;\par ??\par ??\cf3                 \cf1 &amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="2"\cf4  Content\cf1 ="Date Of Birth:" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Controls\cf1 :\cf3 DatePicker\cf4  Grid.Row\cf1 ="2"\cf4  Grid.Column\cf1 ="1"\cf4  Margin\cf1 ="5,2"\cf4  SelectedDate\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Dob\cf1 \}"\cf0  \cf1  /&amp;gt;\par ??\par ??\cf3                 \cf1 &amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="3"\cf4  Content\cf1 ="Favorite Game:" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 ListBox\cf4  Grid.Row\cf1 ="3"\cf4  Grid.Column\cf1 ="1"\cf4  Style\cf1 ="\{\cf3 StaticResource\cf4  radioListBox\cf1 \}"\cf0  \par ??                        \cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  GameTypes\cf1 \}"\cf4  SelectedValue\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 FavoriteGame\cf1 \}" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 Grid\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Border\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 DockPanel\cf1 &amp;gt;\par ??&amp;lt;/\cf3 Window\cf1 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Window&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Class&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="RadioButtonBinding.Views.MainWindow"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;julmar&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="http://www.julmar.com/wpfhelpers"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;ViewModels&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="clr-namespace:RadioButtonBinding.ViewModels"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Controls&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;DataContext&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ViewModelCreator&lt;/span&gt;&lt;span style="COLOR: blue"&gt; {&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Type&lt;/span&gt;&lt;span style="COLOR: red"&gt; ViewModels&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;MainViewModel&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}}"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;FocusManager.FocusedElement&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; ElementName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=lbChildren}"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;Title&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Game
Preference Tracker"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Height&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="400"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Width&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="500"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Background&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="OldLace"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;DockPanel&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: green"&gt;&amp;lt;!--
List of children we are tracking --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="lbChildren"&lt;/span&gt;&lt;span style="COLOR: red"&gt; DockPanel.Dock&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Top"&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: green"&gt;&amp;lt;!--
StatusBar just to make sure two-way binding is working properly --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StatusBar&lt;/span&gt;&lt;span style="COLOR: red"&gt; DockPanel.Dock&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Bottom"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderBrush&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Black"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderThickness&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="0,1,0,0"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StatusBar&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: green"&gt;&amp;lt;!--
Details pane --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Border&lt;/span&gt;&lt;span style="COLOR: red"&gt; Margin&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="5"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderBrush&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="LightGray"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderThickness&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Border&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;DockPanel&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Window&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Next, let’s fill in the top ListBox details.&amp;nbsp; We need to populate it with the
list of children – this is the Children property off our ViewModel, so we’ll bind
the &lt;strong&gt;ItemsSource&lt;/strong&gt; property to that collection.&amp;nbsp; Next, we’ll set
the &lt;strong&gt;SelectedItem&lt;/strong&gt; to the &lt;strong&gt;CurrentChild&lt;/strong&gt; property –
making sure to use a two-way binding:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1         \cf3 &amp;lt;\cf1 ListBox\cf4  x\cf3 :\cf4 Name\cf3 ="lbChildren"\cf4  DockPanel.Dock\cf3 ="Top"\cf4  ItemsSource\cf3 ="\{\cf1 Binding\cf4  Children\cf3 \}"\cf0  \par ??                \cf4  SelectedItem\cf3 ="\{\cf1 Binding\cf4  CurrentChild\cf3 ,\cf4  Mode\cf3 =TwoWay\}"\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="lbChildren"&lt;/span&gt;&lt;span style="COLOR: red"&gt; DockPanel.Dock&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Top"&lt;/span&gt;&lt;span style="COLOR: red"&gt; ItemsSource&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; Children&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;SelectedItem&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CurrentChild&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; Mode&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=TwoWay}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
This will generate a list of items, but won’t have any decent visualization – so we’ll
use a &lt;strong&gt;DataTemplate&lt;/strong&gt; to give us a basic visual, at the same time, let’s
replace the default panel with a &lt;strong&gt;WrapPanel&lt;/strong&gt; so it looks more like
our SketchFlow:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 ListBox\cf4  x\cf1 :\cf4 Name\cf1 ="lbChildren"\cf4  DockPanel.Dock\cf1 ="Top"\cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  Children\cf1 \}"\cf0  \par ??        \cf4  SelectedItem\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 ,\cf4  Mode\cf1 =TwoWay\}"\par ??\cf0         \cf4  ScrollViewer.HorizontalScrollBarVisibility\cf1 ="Disabled"&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 ListBox.ItemsPanel\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 ItemsPanelTemplate\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 WrapPanel\cf1  /&amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 ItemsPanelTemplate\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 ListBox.ItemsPanel\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 ListBox.ItemTemplate\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 DataTemplate\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Border\cf4  BorderBrush\cf1 ="DarkBlue"\cf4  BorderThickness\cf1 ="2"\cf4  Background\cf1 ="SkyBlue"\cf4  CornerRadius\cf1 ="5"&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 StackPanel\cf4  Margin\cf1 ="10"&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 TextBlock\cf4  FontWeight\cf1 ="Bold"\cf4  FontSize\cf1 ="12pt"\cf4  Text\cf1 ="\{\cf3 Binding\cf4  Name\cf1 \}" /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 TextBlock\cf4  Text\cf1 ="\{\cf3 Binding\cf4  FavoriteGame\cf1 \}" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 StackPanel\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 Border\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 DataTemplate\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 ListBox.ItemTemplate\cf1 &amp;gt;\par ??&amp;lt;/\cf3 ListBox\cf1 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="lbChildren"&lt;/span&gt;&lt;span style="COLOR: red"&gt; DockPanel.Dock&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Top"&lt;/span&gt;&lt;span style="COLOR: red"&gt; ItemsSource&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; Children&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;SelectedItem&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CurrentChild&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; Mode&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=TwoWay}"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;ScrollViewer.HorizontalScrollBarVisibility&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Disabled"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox.ItemsPanel&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ItemsPanelTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;WrapPanel&lt;/span&gt;&lt;span style="COLOR: blue"&gt; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ItemsPanelTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox.ItemsPanel&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox.ItemTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Border&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderBrush&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="DarkBlue"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderThickness&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="2"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Background&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="SkyBlue"&lt;/span&gt;&lt;span style="COLOR: red"&gt; CornerRadius&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="5"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="COLOR: red"&gt; Margin&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="10"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="COLOR: red"&gt; FontWeight&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Bold"&lt;/span&gt;&lt;span style="COLOR: red"&gt; FontSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="12pt"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Text&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; Name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="COLOR: red"&gt; Text&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; FavoriteGame&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Border&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox.ItemTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Now, let’s turn our attention to displaying the current child details.&amp;nbsp; Remember
the properties we created on the &lt;strong&gt;ChildViewModel&lt;/strong&gt;:
&lt;/p&gt;
&lt;table border=1 cellspacing=0 cellpadding=2 width=607&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign=top width=99&gt;
&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=506&gt;
Their name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=99&gt;
&lt;strong&gt;Gender&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=506&gt;
Their gender – Male/Female&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=99&gt;
&lt;strong&gt;Dob&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=506&gt;
The date of birth&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=99&gt;
&lt;strong&gt;Details&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=506&gt;
The string with all the details for this child.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&lt;br&gt;
So let’s first use the details – we can bind a &lt;strong&gt;TextBlock&lt;/strong&gt; in the &lt;strong&gt;StatusBar&lt;/strong&gt; to
the &lt;strong&gt;CurrentChild.Details&lt;/strong&gt; property to display the selected child details:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green128\blue0;\red255\green255\blue255;\red0\green0\blue255;\red163\green21\blue21;\red255\green0\blue0;}??\fs28 \cf1 &amp;lt;!-- StatusBar just to make sure two-way binding is working properly --&amp;gt;\par ??\cf3 &amp;lt;\cf4 StatusBar\cf5  DockPanel.Dock\cf3 ="Bottom"\cf5  BorderBrush\cf3 ="Black"\cf5  BorderThickness\cf3 ="0,1,0,0"&amp;gt;\par ??\cf4     \cf3 &amp;lt;\cf4 TextBlock\cf5  Text\cf3 ="\{\cf4 Binding\cf5  CurrentChild\cf3 .\cf5 Details\cf3 \}"\cf5  TextWrapping\cf3 ="Wrap" /&amp;gt;\par ??&amp;lt;/\cf4 StatusBar\cf3 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;lt;!-- StatusBar just to make sure two-way binding is
working properly --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StatusBar&lt;/span&gt;&lt;span style="COLOR: red"&gt; DockPanel.Dock&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Bottom"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderBrush&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Black"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderThickness&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="0,1,0,0"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="COLOR: red"&gt; Text&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CurrentChild&lt;/span&gt;&lt;span style="COLOR: blue"&gt;.&lt;/span&gt;&lt;span style="COLOR: red"&gt;Details&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt;&lt;span style="COLOR: red"&gt; TextWrapping&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Wrap"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StatusBar&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Now, let’s turn our attention to the details – we’ll use a Grid to lay it out within
the Border, the Name and Date Of Birth are pretty easy to just drop in a set of Labels
and TextBox/DatePicker – we’ll need the WPF Toolkit for this.&amp;nbsp; We’ll drop in
two ListBox elements for the Radio Button list.
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 Border\cf4  Margin\cf1 ="5"\cf4  BorderBrush\cf1 ="LightGray"\cf4  BorderThickness\cf1 ="1"&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Grid\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Grid.Resources\cf1 &amp;gt;\par ??\cf3             \cf5 &amp;lt;!-- Common style for header labels --&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="Label"&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="HorizontalAlignment"\cf4  Value\cf1 ="Right" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="VerticalAlignment"\cf4  Value\cf1 ="Top" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="FontWeight"\cf4  Value\cf1 ="Bold" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Margin"\cf4  Value\cf1 ="5,2" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Grid.Resources\cf1 &amp;gt;\par ??\par ??\cf3         \cf1 &amp;lt;\cf3 Grid.ColumnDefinitions\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 ColumnDefinition\cf4  Width\cf1 ="Auto" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 ColumnDefinition\cf1  /&amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Grid.ColumnDefinitions\cf1 &amp;gt;\par ??\par ??\cf3         \cf1 &amp;lt;\cf3 Grid.RowDefinitions\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 RowDefinition\cf4  Height\cf1 ="Auto" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Grid.RowDefinitions\cf1 &amp;gt;\par ??\par ??\cf3         \cf1 &amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="0"\cf4  Content\cf1 ="Name:" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 TextBox\cf4  Grid.Row\cf1 ="0"\cf4  Grid.Column\cf1 ="1"\cf4  Margin\cf1 ="5,2"\cf4  Text\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Name\cf1 \}" /&amp;gt;\par ??\par ??\cf3         \cf1 &amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="1"\cf4  Content\cf1 ="Gender:" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 ListBox\cf4  Grid.Row\cf1 ="1"\cf4  Grid.Column\cf1 ="1"\cf4  Style\cf1 ="\{\cf3 StaticResource\cf4  radioListBox\cf1 \}"\cf0  \par ??                \cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  GenderValues\cf1 \}"\cf4  SelectedValue\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Gender\cf1 \}" /&amp;gt;\par ??\par ??\cf3         \cf1 &amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="2"\cf4  Content\cf1 ="Date Of Birth:" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Controls\cf1 :\cf3 DatePicker\cf4  Grid.Row\cf1 ="2"\cf4  Grid.Column\cf1 ="1"\cf4  Margin\cf1 ="5,2"\cf4  SelectedDate\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Dob\cf1 \}"\cf0  \cf1  /&amp;gt;\par ??\par ??\cf3         \cf1 &amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="3"\cf4  Content\cf1 ="Favorite Game:" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 ListBox\cf4  Grid.Row\cf1 ="3"\cf4  Grid.Column\cf1 ="1"\cf4  Style\cf1 ="\{\cf3 StaticResource\cf4  radioListBox\cf1 \}"\cf0  \par ??                \cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  GameTypes\cf1 \}"\cf4  SelectedValue\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 FavoriteGame\cf1 \}" /&amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 Grid\cf1 &amp;gt;\par ??&amp;lt;/\cf3 Border\cf1 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Border&lt;/span&gt;&lt;span style="COLOR: red"&gt; Margin&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="5"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderBrush&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="LightGray"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BorderThickness&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid.Resources&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: green"&gt;&amp;lt;!--
Common style for header labels --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Label"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="HorizontalAlignment"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Right"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="VerticalAlignment"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Top"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="FontWeight"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Bold"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Margin"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="5,2"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid.Resources&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ColumnDefinition&lt;/span&gt;&lt;span style="COLOR: red"&gt; Width&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Auto"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ColumnDefinition&lt;/span&gt;&lt;span style="COLOR: blue"&gt; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RowDefinition&lt;/span&gt;&lt;span style="COLOR: red"&gt; Height&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Auto"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RowDefinition&lt;/span&gt;&lt;span style="COLOR: red"&gt; Height&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Auto"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RowDefinition&lt;/span&gt;&lt;span style="COLOR: red"&gt; Height&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Auto"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RowDefinition&lt;/span&gt;&lt;span style="COLOR: red"&gt; Height&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Auto"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Label&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="0"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Name:"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TextBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="0"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Column&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Margin&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="5,2"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Text&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CurrentChild&lt;/span&gt;&lt;span style="COLOR: blue"&gt;.&lt;/span&gt;&lt;span style="COLOR: red"&gt;Name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Label&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Gender:"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Column&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Label&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="2"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Date
Of Birth:" /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Controls&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;DatePicker&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="2"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Column&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Margin&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="5,2"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
SelectedDate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CurrentChild&lt;/span&gt;&lt;span style="COLOR: blue"&gt;.&lt;/span&gt;&lt;span style="COLOR: red"&gt;Dob&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Label&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="3"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Content&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Favorite
Game:" /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="3"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Column&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Border&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Let’s focus on the Gender list first – the same concepts will apply to the game list.&amp;nbsp;
We have an &lt;strong&gt;IEnumerable&lt;/strong&gt; list of &lt;strong&gt;ValueAndText&lt;/strong&gt; objects
– each object has a Value property (corresponding to the underlying &lt;strong&gt;enum&lt;/strong&gt; value
tracked in the &lt;strong&gt;ChildViewModel&lt;/strong&gt;) and a Text property which is what
we want displayed in the &lt;strong&gt;RadioButton&lt;/strong&gt; choice.&amp;nbsp; First, let’s set
it up so we get a list of &lt;strong&gt;RadioButtons&lt;/strong&gt; – we can do this by changing
the &lt;strong&gt;ControlTemplate&lt;/strong&gt; for each item in the list itself – that is, change
the &lt;strong&gt;ListBoxItem&lt;/strong&gt; control template.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
As a bit of background, anytime you add an element to an &lt;strong&gt;ItemsControl&lt;/strong&gt; (&lt;strong&gt;ListBox&lt;/strong&gt;, &lt;strong&gt;ComboBox&lt;/strong&gt;, &lt;strong&gt;TreeView&lt;/strong&gt;, &lt;strong&gt;Menu&lt;/strong&gt;,
etc.) a special wrapper is internally created around your data to provide the special
UI properties necessary to drive the functionality – things like focus, selection,
mouse-over, etc. are all provided by this wrapper.&amp;nbsp; In the case of the &lt;strong&gt;ListBox&lt;/strong&gt;,
the created wrapper is a &lt;strong&gt;ListBoxItem&lt;/strong&gt; class and we can control it’s
properties by overriding the &lt;strong&gt;ItemContainerStyle&lt;/strong&gt; on the &lt;strong&gt;ListBox&lt;/strong&gt; itself.&amp;nbsp;
So, to start off, we’ll create a new &lt;strong&gt;Style&lt;/strong&gt; for the &lt;strong&gt;ListBox&lt;/strong&gt;,
set some basic properties and then override the &lt;strong&gt;ListBoxItem&lt;/strong&gt; style
inside that:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 Style\cf4  x\cf1 :\cf4 Key\cf1 ="radioListBox"\cf4  TargetType\cf1 ="ListBox"\cf4  BasedOn\cf1 ="\{\cf3 StaticResource\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ListBox\cf1 \}\}"&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="BorderThickness"\cf4  Value\cf1 ="0" /&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Margin"\cf4  Value\cf1 ="5" /&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="DisplayMemberPath"\cf4  Value\cf1 ="Text" /&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="SelectedValuePath"\cf4  Value\cf1 ="Value" /&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Background"\cf4  Value\cf1 ="\{\cf3 x\cf1 :\cf3 Null\cf1 \}" /&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="ItemContainerStyle"&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="ListBoxItem"\cf4  BasedOn\cf1 ="\{\cf3 StaticResource\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ListBoxItem\cf1 \}\}"&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Template"&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 ControlTemplate\cf4  TargetType\cf1 ="ListBoxItem"&amp;gt;\par ??\cf3                             \cf1 &amp;lt;\cf3 Border\cf4  Background\cf1 ="Transparent"&amp;gt;\par ??\cf3                                 \cf1 &amp;lt;\cf3 RadioButton\cf4  Focusable\cf1 ="False"\cf4  IsHitTestVisible\cf1 ="False"\cf4  IsChecked\cf1 ="\{\cf3 TemplateBinding\cf4  IsSelected\cf1 \}"&amp;gt;\par ??\cf3                                     \cf1 &amp;lt;\cf3 ContentPresenter\cf1  /&amp;gt;\par ??\cf3                                 \cf1 &amp;lt;/\cf3 RadioButton\cf1 &amp;gt;\par ??\cf3                             \cf1 &amp;lt;/\cf3 Border\cf1 &amp;gt;\par ??\cf3                         \cf1 &amp;lt;/\cf3 ControlTemplate\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;/\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 Setter\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 Setter\cf1 &amp;gt;\par ??&amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Key&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="radioListBox"&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ListBox"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BasedOn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: blue"&gt; {&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Type&lt;/span&gt;&lt;span style="COLOR: red"&gt; ListBox&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="BorderThickness"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="0"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Margin"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="5"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Background"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Null&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ItemContainerStyle"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ListBoxItem"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
BasedOn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: blue"&gt; {&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Type&lt;/span&gt;&lt;span style="COLOR: red"&gt; ListBoxItem&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Since this is going to list a group of radio buttons, we’ll drop the border off the &lt;strong&gt;ListBox&lt;/strong&gt; and
the &lt;strong&gt;Background&lt;/strong&gt; color as well so that our parent’s background shows
through.&amp;nbsp; We’ll throw a &lt;strong&gt;Margin&lt;/strong&gt; on there to give it a little
spacing. Next, to change the visualization of the &lt;strong&gt;ListBoxItem&lt;/strong&gt;, we’ll
override it’s &lt;strong&gt;ControlTemplate&lt;/strong&gt; (the thing that generates the visual
tree for the item).&amp;nbsp; This, like all Controls in WPF, is done by overriding the &lt;strong&gt;Template&lt;/strong&gt; property.
What we want is put a Radio Button in there:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="ListBoxItem"\cf4  BasedOn\cf1 ="\{\cf3 StaticResource\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ListBoxItem\cf1 \}\}"&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Template"&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 ControlTemplate\cf4  TargetType\cf1 ="ListBoxItem"&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Border\cf4  Background\cf1 ="Transparent"&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 RadioButton\cf4  Focusable\cf1 ="False"\cf4  IsHitTestVisible\cf1 ="False"\cf4  IsChecked\cf1 ="\{\cf3 TemplateBinding\cf4  IsSelected\cf1 \}"&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 ContentPresenter\cf1  /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;/\cf3 RadioButton\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 Border\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 ControlTemplate\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 Setter\cf1 &amp;gt;\par ??&amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ListBoxItem"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BasedOn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: blue"&gt; {&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Type&lt;/span&gt;&lt;span style="COLOR: red"&gt; ListBoxItem&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Template"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ControlTemplate&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ListBoxItem"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;IsChecked&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TemplateBinding&lt;/span&gt;&lt;span style="COLOR: red"&gt; IsSelected&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ContentPresenter&lt;/span&gt;&lt;span style="COLOR: blue"&gt; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ControlTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
In order to get the &lt;strong&gt;IsChecked&lt;/strong&gt; state properly setup, we’ll bind it
to the&lt;strong&gt; ListBoxItem.IsSelected&lt;/strong&gt; property – so if the item is selected
according to the ListBox, then the Radio Button will be checked.&amp;nbsp; We also drop
a &lt;strong&gt;ContentPresenter &lt;/strong&gt;into the &lt;strong&gt;RadioButton &lt;/strong&gt;so it displays
whatever the data bound value is – this will provide for any &lt;strong&gt;DataTemplate &lt;/strong&gt;visualization
if one is present.&amp;nbsp; This will achieve the visualization we desire, but it won’t
work properly as we interact with it.&amp;nbsp; The problem is that the Radio button will
override this state when it is clicked – exactly the problem we had originally!
&lt;/p&gt;
&lt;p&gt;
To fix this, let’s make the radio button invisible to the mouse and keyboard.. we
can do this by setting the &lt;strong&gt;Focusable &lt;/strong&gt;and &lt;strong&gt;IsHitTestable &lt;/strong&gt;properties
to false – however this makes them non-interactive and now we can’t select the ListBoxItem
with the mouse.. so, let’s wrap it in something that is selectable – anything should
work, so we’ll just throw it into a Grid.&amp;nbsp; Set the Grid.Background to transparent
so you can click on it and we end up with:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="ListBoxItem"\cf4  BasedOn\cf1 ="\{\cf3 StaticResource\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ListBoxItem\cf1 \}\}"&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Template"&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 ControlTemplate\cf4  TargetType\cf1 ="ListBoxItem"&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Grid\cf4  Background\cf1 ="Transparent"&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 RadioButton\cf4  Focusable\cf1 ="False"\cf4  IsHitTestVisible\cf1 ="False"\cf4  IsChecked\cf1 ="\{\cf3 TemplateBinding\cf4  IsSelected\cf1 \}"&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 ContentPresenter\cf1  /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;/\cf3 RadioButton\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 Grid\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 ControlTemplate\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Setter.Value\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 Setter\cf1 &amp;gt;\par ??&amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ListBoxItem"&lt;/span&gt;&lt;span style="COLOR: red"&gt; BasedOn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: blue"&gt; {&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Type&lt;/span&gt;&lt;span style="COLOR: red"&gt; ListBoxItem&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Template"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ControlTemplate&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ListBoxItem"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="COLOR: red"&gt; Background&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Transparent"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: red"&gt; Focusable&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="False"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
IsHitTestVisible&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="False"&lt;/span&gt;&lt;span style="COLOR: red"&gt; IsChecked&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TemplateBinding&lt;/span&gt;&lt;span style="COLOR: red"&gt; IsSelected&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ContentPresenter&lt;/span&gt;&lt;span style="COLOR: blue"&gt; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;RadioButton&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ControlTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
This does exactly what we want – clicking on the radio button changes the selection
in the &lt;strong&gt;ListBox&lt;/strong&gt; and, in turn, checks or unchecks the radio button
in question.&amp;nbsp; Now, let’s wire it up to our data – remember we have a Value and
Text.&amp;nbsp; We want to bind to the Value but display the Text.&amp;nbsp; It turns out
the &lt;strong&gt;ListBox&lt;/strong&gt; already has this feature backed in – there is a &lt;strong&gt;SelectedItem&lt;/strong&gt; property
we normally use, but there is also a &lt;strong&gt;SelectedValue&lt;/strong&gt; property that
makes the distinction between the item in the collection and the value used to select
it.&amp;nbsp; There is also a &lt;strong&gt;DisplayMemberPath&lt;/strong&gt; and &lt;strong&gt;SelectedValuePath&lt;/strong&gt; property
used for data binding purposes when generating the content from an &lt;strong&gt;ItemsSource&lt;/strong&gt; supplied
value.&amp;nbsp; Pulling these things together we can do this:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 ListBox\cf4  Grid.Row\cf1 ="1"\cf4  Grid.Column\cf1 ="1"\cf4  Style\cf1 ="\{\cf3 StaticResource\cf4  radioListBox\cf1 \}"\cf0  \par ??        \cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  GenderValues\cf1 \}"\cf4  SelectedValue\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Gender\cf1 \}" /&amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Column&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; radioListBox&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DisplayMemberPath&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Text&lt;/span&gt;&lt;span style="COLOR: blue"&gt;"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedValuePath&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; GenderValues&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CurrentChild&lt;/span&gt;&lt;span style="COLOR: blue"&gt;.&lt;/span&gt;&lt;span style="COLOR: red"&gt;Gender&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Testing this, it works perfectly!&amp;nbsp; Since the &lt;strong&gt;DisplayMemberPath/SelectedValuePath&lt;/strong&gt; are
the same for the two lists, we can move that to our radioListBox style, leaving us
with the two &lt;strong&gt;ListBox&lt;/strong&gt; definitions being:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 ListBox\cf4  Grid.Row\cf1 ="1"\cf4  Grid.Column\cf1 ="1"\cf4  Style\cf1 ="\{\cf3 StaticResource\cf4  radioListBox\cf1 \}"\cf0  \par ??\cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  GenderValues\cf1 \}"\cf4  SelectedValue\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Gender\cf1 \}" /&amp;gt;\par ??\par ??&amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="2"\cf4  Content\cf1 ="Date Of Birth:" /&amp;gt;\par ??&amp;lt;\cf3 Controls\cf1 :\cf3 DatePicker\cf4  Grid.Row\cf1 ="2"\cf4  Grid.Column\cf1 ="1"\cf4  Margin\cf1 ="5,2"\cf4  SelectedDate\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 Dob\cf1 \}"\cf0  \cf1  /&amp;gt;\par ??\par ??&amp;lt;\cf3 Label\cf4  Grid.Row\cf1 ="3"\cf4  Content\cf1 ="Favorite Game:" /&amp;gt;\par ??&amp;lt;\cf3 ListBox\cf4  Grid.Row\cf1 ="3"\cf4  Grid.Column\cf1 ="1"\cf4  Style\cf1 ="\{\cf3 StaticResource\cf4  radioListBox\cf1 \}"\cf0  \par ??        \cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  GameTypes\cf1 \}"\cf4  SelectedValue\cf1 ="\{\cf3 Binding\cf4  CurrentChild\cf1 .\cf4 FavoriteGame\cf1 \}" /&amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Column&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; radioListBox&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ItemsSource&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; GenderValues&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CurrentChild&lt;/span&gt;&lt;span style="COLOR: blue"&gt;.&lt;/span&gt;&lt;span style="COLOR: red"&gt;Gender&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;...&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="3"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Column&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="1"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; radioListBox&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; GameTypes&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedValue&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CurrentChild&lt;/span&gt;&lt;span style="COLOR: blue"&gt;.&lt;/span&gt;&lt;span style="COLOR: red"&gt;FavoriteGame&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
And the completed application looks like:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMBindingRadioButtongroups_F849/image_8.png"&gt;&lt;img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMBindingRadioButtongroups_F849/image_thumb_3.png" width=478 height=383&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
You can download the completed project here: &lt;a href="http://www.julmar.com/samples/RadioButtonBinding.zip" target=_blank&gt;RadioButtonBinding
Test&lt;/a&gt;
&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>rCAT 2.0 is online, 3.0 is coming</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/01/28/rCAT20IsOnline30IsComing.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,9250b94b-00c5-4e83-86ea-31359f1e4170.aspx</id>
    <published>2010-01-28T12:58:46.9350085-08:00</published>
    <updated>2010-01-29T10:45:42.6888701-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="MVVM" label="MVVM" scheme="http://www.julmar.com/blog/mark/CategoryView,category,MVVM.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
The main project I’ve been working on the past few months has been a rRNA sequencing
application.  It’s a joint project involving Microsoft Research and the University
of Texas in Austin.  The goal being to produce lightning fast visualizations
(nucleotide, 2D and 3D) with very large (100,000 sequence) data sets on WPF. 
It’s been a big learning experience for me in many ways because the traditional mechanisms
for dealing with things in WPF just flat out fail when we load big datasets and start
scrolling them around.  So, we’ve had to invent data virtualization schemes,
our own UI virtualization for scrolling, several custom controls and a variety of
other elements to pull it off so far.  rCAT 4.0 (coming in March) is even more
ambitious with editing support for the sequences!
</p>
        <p>
All that said, our current effort is now online with full source code – it’s interesting
stuff to browse through even if you aren’t into molecular biology – check it out at <a href="http://rcat.codeplex.com/" target="_blank">http://rcat.codeplex.com/</a></p>
        <p>
Here’s a nice screen shot showing some of the elements – dockable tabs and sidebar
items, birds-eye viewer, taxonomy viewer and custom colorization of nucelotide data. 
And it, of course, is all MVVM.  Fun stuff!
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/rCAT2.0isonline3.0iscoming_D2A1/CATUI.Overview.Shrink_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CATUI.Overview.Shrink" border="0" alt="CATUI.Overview.Shrink" src="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/rCAT2.0isonline3.0iscoming_D2A1/CATUI.Overview.Shrink_thumb.png" width="654" height="392" />
          </a>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>MVVM: Rename TreeView nodes</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/01/28/MVVMRenameTreeViewNodes.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,276acdbc-7308-416c-a4ca-b75e43ac54bd.aspx</id>
    <published>2010-01-28T09:13:52.5361449-08:00</published>
    <updated>2010-01-29T10:46:15.9388701-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="MVVM" label="MVVM" scheme="http://www.julmar.com/blog/mark/CategoryView,category,MVVM.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">&lt;p&gt;
I know I said I was going to cover some services next, but I got a request last night
to show how to rename TreeView nodes (ala Explorer) using the MVVM pattern in WPF.&amp;nbsp;
The solution is quite easy and elegant and I thought I’d share it here.
&lt;/p&gt;
&lt;p&gt;
First, the idea is we want to be able to double-click on the text portion of the &lt;strong&gt;TreeViewItem&lt;/strong&gt; and
have it allow us to type in a new name, replacing the current text.&amp;nbsp; This involves
changing the visual template out (from a &lt;strong&gt;TextBlock&lt;/strong&gt; to a &lt;strong&gt;TextBox&lt;/strong&gt;)
and then detecting that the edit is complete.
&lt;/p&gt;
&lt;p&gt;
I started with the &lt;a href="http://www.julmar.com/blog/mark/2010/01/20/MVVMHelpersProjectTemplate.aspx" target="_blank"&gt;MVVM
project template&lt;/a&gt;, creating the default File Explorer view.&amp;nbsp; The &lt;strong&gt;TreeView&lt;/strong&gt; on
the left is displaying folders – so I opened the &lt;strong&gt;DirectoryViewModel.cs&lt;/strong&gt; that
drives the data.
&lt;/p&gt;
&lt;p&gt;
First, let’s add a property to indicate whether we are in “editing” mode or not.&amp;nbsp;
This is a simple field-backed property that raises the PropertyChange notification:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red163\green21\blue21;}??\fs28         \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  True/False whether we are changing the name of the directory\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf5 bool\cf0  IsEditingName\par ??        \{\par ??            \cf5 get\cf0  \{ \cf5 return\cf0  _isEditingName; \}\par ??            \cf5 set\cf0  \{ _isEditingName = \cf5 value\cf0 ; OnPropertyChanged(\cf6 "IsEditingName"\cf0 ); \}\par ??        \}\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; True/False whether
we are changing the name of the directory&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; IsEditingName
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; _isEditingName;
}
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;set&lt;/span&gt; { _isEditingName = &lt;span style="color: blue"&gt;value&lt;/span&gt;;
OnPropertyChanged(&lt;span style="color: #a31515"&gt;"IsEditingName"&lt;/span&gt;); }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
I also added the private field (_isEditingName) into the class.&amp;nbsp; Next, locate
the &lt;strong&gt;Name&lt;/strong&gt; property that is being used to display the name.&amp;nbsp; Here
we need to add a setter that renames the directory.&amp;nbsp; We want it to be robust,
so we do some upfront checks and make sure to catch any I/O exceptions that occur:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs28         \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Name of the directory\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf5 string\cf0  Name\par ??        \{\par ??            \cf5 get\cf0  \{ \cf5 return\cf0  _data.Name; \}\par ??\par ??            \cf4 // Code to rename directory\par ??\cf0             \cf5 set\par ??\cf0             \{\par ??                \cf5 string\cf0  newValue = \cf5 value\cf0 ;\par ??                \cf5 if\cf0  (!\cf5 string\cf0 .IsNullOrEmpty(newValue))\par ??                \{\par ??                    \cf4 // Remove any trailing backslash.\par ??\cf0                     \cf5 string\cf0  fullName = _data.FullName.TrimEnd(\cf6 Path\cf0 .DirectorySeparatorChar);\par ??\par ??                    \cf4 // Determine the new directory name\par ??\cf0                     \cf5 string\cf0  directoryPath = fullName.Substring(0, fullName.Length - _data.Name.Length);\par ??                    \cf5 if\cf0  (!\cf5 string\cf0 .IsNullOrEmpty(directoryPath) &amp;amp;&amp;amp; directoryPath != fullName)\par ??                    \{\par ??                        \cf5 string\cf0  newFullName = \cf6 Path\cf0 .Combine(directoryPath, newValue);\par ??                        \cf5 try\par ??\cf0                         \{\par ??                            _data.MoveTo(newFullName);\par ??                        \}\par ??                        \cf5 catch\cf0  (\cf6 IOException\cf0  ex)\par ??                        \{\par ??                            \cf5 var\cf0  errorVisualizer = Resolve&amp;lt;\cf6 IErrorVisualizer\cf0 &amp;gt;();\par ??                            \cf5 if\cf0  (errorVisualizer != \cf5 null\cf0 )\par ??                            \{\par ??                                errorVisualizer.Show(\cf7 "Cannot rename directory"\cf0 , ex.Message);\par ??                            \}\par ??                        \}\par ??                    \}\par ??                \}\par ??\par ??                \cf4 // Tell WPF the name has changed.  Note if the same control is being used to display vs. edit then the\par ??\cf0                 \cf4 // binding will need to force WPF3x to re-read the property value.  This is done by using a RefreshValueConverter; \par ??\cf0                 \cf4 // under .NET4 this won't be necessary.\par ??\cf0                 OnPropertyChanged(\cf7 "Name"\cf0 );\par ??\par ??                \cf4 // Flip off the editing bit\par ??\cf0                 IsEditingName = \cf5 false\cf0 ;\par ??            \}\par ??        \}\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; Name of the directory&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; Name
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; get&lt;/span&gt; { &lt;span style="color: blue"&gt;return&lt;/span&gt; _data.Name;
}
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// Code to rename directory&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;set&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt; newValue = &lt;span style="color: blue"&gt;value&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(newValue))
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// Remove
any trailing backslash.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt; fullName
= _data.FullName.TrimEnd(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.DirectorySeparatorChar);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// Determine
the new directory name&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt; directoryPath
= fullName.Substring(0, fullName.Length - _data.Name.Length);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(directoryPath)
&amp;amp;&amp;amp; directoryPath != fullName)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;string&lt;/span&gt; newFullName
= &lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(directoryPath, newValue);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_data.MoveTo(newFullName);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;catch&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;IOException&lt;/span&gt; ex)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;var&lt;/span&gt; errorVisualizer
= Resolve&amp;lt;&lt;span style="color: #2b91af"&gt;IErrorVisualizer&lt;/span&gt;&amp;gt;();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (errorVisualizer
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
errorVisualizer.Show(&lt;span style="color: #a31515"&gt;"Cannot rename directory"&lt;/span&gt;,
ex.Message);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// Tell WPF the name has
changed.&amp;nbsp; Note if the same control &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // is being used to display
vs. edit then the&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// binding will need to
force WPF3x to re-read the property value.&amp;nbsp; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is done by using
a RefreshValueConverter; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// under .NET4 this won't
be necessary.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OnPropertyChanged(&lt;span style="color: #a31515"&gt;"Name"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: green"&gt;// Flip off the editing bit&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IsEditingName = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Notice how changes the editing flag at the end – we assume that once the rename has
occurred we are out of editing mode.&amp;nbsp; Finally, we need a way to transition from
“normal” to “edit” mode and back.&amp;nbsp; In the VM these kinds of things are driven
with commands – so, let’s define an &lt;strong&gt;ICommand&lt;/strong&gt; that takes us in and
out of edit mode:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs28         \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Command used to switch to editing mode\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf6 ICommand\cf0  SwitchToEditingMode \{ \cf5 get\cf0 ; \cf5 private\cf0  \cf5 set\cf0 ; \}\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; Command used to switch
to editing mode&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ICommand&lt;/span&gt; SwitchToEditingMode
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
And then finally initialize it in the default constructor – we also now need to chain
to that constructor from the parameterized version since we always want this initialization
to happen (you could also do the initialization in both, but I prefer this approach):
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs28         \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Constructor for the marker directory.  This is used to detect an expansion.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 private\cf0  DirectoryViewModel()\par ??        \{\par ??            \cf4 // Command that switches us into editing mode.\par ??\cf0             SwitchToEditingMode = \cf5 new\cf0  \cf6 DelegatingCommand\cf0 (() =&amp;gt; IsEditingName = !IsEditingName, () =&amp;gt; _data.FullName != _data.Name);\par ??        \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Public constructor\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;param name="di"&amp;gt;\cf4 DirectoryInfo to pull information from\cf3 &amp;lt;/param&amp;gt;\par ??\cf0         \cf5 public\cf0  DirectoryViewModel(\cf6 DirectoryInfo\cf0  di) : \cf5 this\cf0 ()\par ??        \{\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; Constructor for the
marker directory.&amp;nbsp; This is used to detect an expansion.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;private&lt;/span&gt; DirectoryViewModel()
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp; // Command that switches us into editing mode.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; SwitchToEditingMode = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegatingCommand&lt;/span&gt;(
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
() =&amp;gt; IsEditingName = !IsEditingName, 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
() =&amp;gt; _data.FullName != _data.Name);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; Public constructor&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: gray"&gt;///&lt;/span&gt;&lt;span style="color: green"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param
name="di"&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;DirectoryInfo to pull information from&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;public&lt;/span&gt; DirectoryViewModel(&lt;span style="color: #2b91af"&gt;DirectoryInfo&lt;/span&gt; di)
: &lt;span style="color: blue"&gt;this&lt;/span&gt;()
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
...
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
That’s all the code changes we need for this – now let’s switch to the View and see
how we will wire this up!&amp;nbsp; Open the &lt;strong&gt;MainWindow.xaml&lt;/strong&gt; file and
look at the &lt;strong&gt;DataTemplate&lt;/strong&gt; used by the &lt;strong&gt;TreeView&lt;/strong&gt;.&amp;nbsp;
All of our changes will go into this template. First, we need to add a &lt;strong&gt;TextBox&lt;/strong&gt; into
the template that sits in the same space as the &lt;strong&gt;TextBlock&lt;/strong&gt; that displays
the name.&amp;nbsp; Then we need some way to switch between these two elements – I use
Visibility here, you could also swap out the entire template.&amp;nbsp; We’ll use a &lt;strong&gt;DataTrigger&lt;/strong&gt; and
drive it off our new &lt;strong&gt;IsEditingName&lt;/strong&gt; property:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue0;}??\fs28 \cf1         \cf3 &amp;lt;\cf1 HierarchicalDataTemplate\cf4  x\cf3 :\cf4 Key\cf3 ="DirectoryTemplate"\cf4  ItemsSource\cf3 ="\{\cf1 Binding\cf4  Subdirectories\cf3 \}"&amp;gt;\par ??\cf1             \cf3 &amp;lt;\cf1 StackPanel\cf4  Orientation\cf3 ="Horizontal"&amp;gt;\par ??\cf1                 \cf3 &amp;lt;\cf1 Image\cf4  Width\cf3 ="16"\cf4  Height\cf3 ="16"\cf4  Source\cf3 ="\{\cf1 Binding\cf4  FullName\cf3 ,\cf4  Converter\cf3 =\{\cf1 StaticResource\cf4  iconConverter\cf3 \}\}" /&amp;gt;\par ??\cf1                 \cf3 &amp;lt;\cf1 Grid\cf4  Margin\cf3 ="5,0"&amp;gt;\par ??\cf1                     \cf3 &amp;lt;\cf1 Grid.Resources\cf3 &amp;gt;\par ??\cf1                         \cf5 &amp;lt;!-- Put here so it inherits the data context properly.  We want the command to execute on\par ??                             directory view model --&amp;gt;\par ??\cf1                         \cf3 &amp;lt;\cf1 julmar\cf3 :\cf1 BindableCommand\cf4  x\cf3 :\cf4 Key\cf3 ="EditingModeCommand"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  SwitchToEditingMode\cf3 \}" /&amp;gt;\par ??\cf1                     \cf3 &amp;lt;/\cf1 Grid.Resources\cf3 &amp;gt;\par ??\cf1                     \cf3 &amp;lt;\cf1 TextBlock\cf4  x\cf3 :\cf4 Name\cf3 ="tb"\cf4  Text\cf3 ="\{\cf1 Binding\cf4  Name\cf3 \}"&amp;gt;\par ??\cf1                         \cf3 &amp;lt;\cf1 Interactivity\cf3 :\cf1 Interaction.Triggers\cf3 &amp;gt;\par ??\cf1                             \cf5 &amp;lt;!-- DoubleClick activates editing mode --&amp;gt;\par ??\cf1                             \cf3 &amp;lt;\cf1 julmar\cf3 :\cf1 DoubleClickTrigger\cf3 &amp;gt;\par ??\cf1                                 \cf3 &amp;lt;\cf1 julmar\cf3 :\cf1 InvokeCommand\cf4  Command\cf3 ="\{\cf1 Binding\cf4  SwitchToEditingMode\cf3 \}" /&amp;gt;\par ??\cf1                             \cf3 &amp;lt;/\cf1 julmar\cf3 :\cf1 DoubleClickTrigger\cf3 &amp;gt;\par ??\cf1                         \cf3 &amp;lt;/\cf1 Interactivity\cf3 :\cf1 Interaction.Triggers\cf3 &amp;gt;\par ??\cf1                     \cf3 &amp;lt;/\cf1 TextBlock\cf3 &amp;gt;\par ??\cf1                     \cf5 &amp;lt;!-- Editing text box --&amp;gt;\par ??\cf1                     \cf3 &amp;lt;\cf1 TextBox\cf4  x\cf3 :\cf4 Name\cf3 ="etb"\cf4  Visibility\cf3 ="Collapsed"\cf4  MinWidth\cf3 ="100"\cf0  \par ??                            \cf4  Text\cf3 ="\{\cf1 Binding\cf4  Name\cf3 ,\cf4  UpdateSourceTrigger\cf3 =LostFocus,\cf4  Converter\cf3 =\{\cf1 julmar\cf3 :\cf1 RefreshValueConverter\cf3 \}\}"&amp;gt;\par ??\cf1                         \cf5 &amp;lt;!-- Pressing ENTER in the TextBox turns off editing mode.  \par ??                             Tab or clicking away will do the same thing --&amp;gt;\par ??\cf1                         \cf3 &amp;lt;\cf1 TextBox.InputBindings\cf3 &amp;gt;\par ??\cf1                             \cf3 &amp;lt;\cf1 KeyBinding\cf4  Key\cf3 ="Enter"\cf4  Command\cf3 ="\{\cf1 StaticResource\cf4  EditingModeCommand\cf3 \}" /&amp;gt;\par ??\cf1                         \cf3 &amp;lt;/\cf1 TextBox.InputBindings\cf3 &amp;gt;\par ??\cf1                     \cf3 &amp;lt;/\cf1 TextBox\cf3 &amp;gt;\par ??\cf1                 \cf3 &amp;lt;/\cf1 Grid\cf3 &amp;gt;\cf1  \par ??            \cf3 &amp;lt;/\cf1 StackPanel\cf3 &amp;gt;\cf1  \par ??            \cf3 &amp;lt;\cf1 HierarchicalDataTemplate.Triggers\cf3 &amp;gt;\par ??\cf1                 \cf3 &amp;lt;\cf1 DataTrigger\cf4  Binding\cf3 ="\{\cf1 Binding\cf4  IsSelected\cf3 \}"\cf4  Value\cf3 ="True"&amp;gt;\par ??\cf1                     \cf3 &amp;lt;\cf1 Setter\cf4  TargetName\cf3 ="tb"\cf4  Property\cf3 ="FontWeight"\cf4  Value\cf3 ="Bold" /&amp;gt;\par ??\cf1                 \cf3 &amp;lt;/\cf1 DataTrigger\cf3 &amp;gt;\par ??\cf1                 \cf5 &amp;lt;!-- When editing mode is turned on, get rid of the TextBlock and make the TextBlock visible. --&amp;gt;\par ??\cf1                 \cf3 &amp;lt;\cf1 DataTrigger\cf4  Binding\cf3 ="\{\cf1 Binding\cf4  IsEditingName\cf3 \}"\cf4  Value\cf3 ="True"&amp;gt;\par ??\cf1                     \cf3 &amp;lt;\cf1 Setter\cf4  TargetName\cf3 ="tb"\cf4  Property\cf3 ="Visibility"\cf4  Value\cf3 ="Collapsed" /&amp;gt;\par ??\cf1                     \cf3 &amp;lt;\cf1 Setter\cf4  TargetName\cf3 ="etb"\cf4  Property\cf3 ="Visibility"\cf4  Value\cf3 ="Visible" /&amp;gt;\par ??\cf1                 \cf3 &amp;lt;/\cf1 DataTrigger\cf3 &amp;gt;\par ??\cf1             \cf3 &amp;lt;/\cf1 HierarchicalDataTemplate.Triggers\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;/\cf1 HierarchicalDataTemplate\cf3 &amp;gt;\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;HierarchicalDataTemplate&lt;/span&gt;&lt;span style="color: red"&gt; x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;="DirectoryTemplate"&lt;/span&gt;&lt;span style="color: red"&gt; ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; Subdirectories&lt;/span&gt;&lt;span style="color: blue"&gt;}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="color: red"&gt; Orientation&lt;/span&gt;&lt;span style="color: blue"&gt;="Horizontal"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Image&lt;/span&gt;&lt;span style="color: red"&gt; Width&lt;/span&gt;&lt;span style="color: blue"&gt;="16"&lt;/span&gt;&lt;span style="color: red"&gt; Height&lt;/span&gt;&lt;span style="color: blue"&gt;="16"&lt;/span&gt;&lt;span style="color: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Source&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; FullName&lt;/span&gt;&lt;span style="color: blue"&gt;,&lt;/span&gt;&lt;span style="color: red"&gt; Converter&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color: red"&gt; iconConverter&lt;/span&gt;&lt;span style="color: blue"&gt;}}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: red"&gt; Margin&lt;/span&gt;&lt;span style="color: blue"&gt;="5,0"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: red"&gt; x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;="tb"&lt;/span&gt;&lt;span style="color: red"&gt; Text&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; Name&lt;/span&gt;&lt;span style="color: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--
Editing text box --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox&lt;/span&gt;&lt;span style="color: red"&gt; x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;="etb"&lt;/span&gt;&lt;span style="color: red"&gt; Visibility&lt;/span&gt;&lt;span style="color: blue"&gt;="Collapsed"&lt;/span&gt;&lt;span style="color: red"&gt; MinWidth&lt;/span&gt;&lt;span style="color: blue"&gt;="100"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; Name&lt;/span&gt;&lt;span style="color: blue"&gt;,&lt;/span&gt;&lt;span style="color: red"&gt; UpdateSourceTrigger&lt;/span&gt;&lt;span style="color: blue"&gt;=LostFocus,&lt;/span&gt;&lt;span style="color: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;RefreshValueConverter&lt;/span&gt;&lt;span style="color: blue"&gt;}}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;HierarchicalDataTemplate.Triggers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTrigger&lt;/span&gt;&lt;span style="color: red"&gt; Binding&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; IsSelected&lt;/span&gt;&lt;span style="color: blue"&gt;}"&lt;/span&gt;&lt;span style="color: red"&gt; Value&lt;/span&gt;&lt;span style="color: blue"&gt;="True"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: red"&gt; TargetName&lt;/span&gt;&lt;span style="color: blue"&gt;="tb"&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="FontWeight"&lt;/span&gt;&lt;span style="color: red"&gt; Value&lt;/span&gt;&lt;span style="color: blue"&gt;="Bold"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTrigger&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- When editing mode
is turned on, get rid of the TextBlock and &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
make the TextBlock visible. --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTrigger&lt;/span&gt;&lt;span style="color: red"&gt; Binding&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; IsEditingName&lt;/span&gt;&lt;span style="color: blue"&gt;}"&lt;/span&gt;&lt;span style="color: red"&gt; Value&lt;/span&gt;&lt;span style="color: blue"&gt;="True"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: red"&gt; TargetName&lt;/span&gt;&lt;span style="color: blue"&gt;="tb"&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="Visibility"&lt;/span&gt;&lt;span style="color: red"&gt; Value&lt;/span&gt;&lt;span style="color: blue"&gt;="Collapsed"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: red"&gt; TargetName&lt;/span&gt;&lt;span style="color: blue"&gt;="etb"&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="Visibility"&lt;/span&gt;&lt;span style="color: red"&gt; Value&lt;/span&gt;&lt;span style="color: blue"&gt;="Visible"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTrigger&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;HierarchicalDataTemplate.Triggers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;HierarchicalDataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
The other thing we need to do is set the &lt;strong&gt;TextBox&lt;/strong&gt; binding (which also
uses the &lt;strong&gt;Name&lt;/strong&gt; property) to apply any changes when the control loses
focus – that way we don’t rename as the user types!&amp;nbsp; This is done by changing
the &lt;strong&gt;UpdateSourceTrigger&lt;/strong&gt; on the binding to “&lt;strong&gt;LostFocus&lt;/strong&gt;”.
This happens to be the default setting for WPF – but not for Silverlight, so I tend
to be deliberate when I want to ensure a specific behavior.&amp;nbsp; I’ve also added
a converter onto the binding above – the RefreshValueConverter.&amp;nbsp; This is a no-op
converter, but it forces WPF to re-read the property value after the setter is called,
without it, the &lt;strong&gt;TextBox&lt;/strong&gt; will have stale data if the rename fails.&amp;nbsp;
Note that this is unnecessary in WPF4 which now always re-reads the property values
automatically.&amp;nbsp; Since this targets WPF3.5, this converter will ensure proper
behavior.
&lt;/p&gt;
&lt;p&gt;
The final thing we need to do is somehow get in and out of editing mode.&amp;nbsp; We
want this to happen when we double-click on the text element – so let’s add a JulMar
behavior and action to the &lt;strong&gt;TextBlock&lt;/strong&gt;:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;\red0\green128\blue0;}??\fs28 \cf1                     \cf3 &amp;lt;\cf1 TextBlock\cf4  x\cf3 :\cf4 Name\cf3 ="tb"\cf4  Text\cf3 ="\{\cf1 Binding\cf4  Name\cf3 \}"&amp;gt;\par ??\cf1                         \cf3 &amp;lt;\cf1 Interactivity\cf3 :\cf1 Interaction.Triggers\cf3 &amp;gt;\par ??\cf1                             \cf5 &amp;lt;!-- DoubleClick activates editing mode --&amp;gt;\par ??\cf1                             \cf3 &amp;lt;\cf1 julmar\cf3 :\cf1 DoubleClickTrigger\cf3 &amp;gt;\par ??\cf1                                 \cf3 &amp;lt;\cf1 julmar\cf3 :\cf1 InvokeCommand\cf4  Command\cf3 ="\{\cf1 Binding\cf4  SwitchToEditingMode\cf3 \}" /&amp;gt;\par ??\cf1                             \cf3 &amp;lt;/\cf1 julmar\cf3 :\cf1 DoubleClickTrigger\cf3 &amp;gt;\par ??\cf1                         \cf3 &amp;lt;/\cf1 Interactivity\cf3 :\cf1 Interaction.Triggers\cf3 &amp;gt;\par ??\cf1                     \cf3 &amp;lt;/\cf1 TextBlock\cf3 &amp;gt;\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: red"&gt; x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;="tb"&lt;/span&gt;&lt;span style="color: red"&gt; Text&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; Name&lt;/span&gt;&lt;span style="color: blue"&gt;}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;strong&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Triggers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- DoubleClick
activates editing mode --&amp;gt;&lt;/strong&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;strong&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DoubleClickTrigger&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;strong&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;InvokeCommand&lt;/span&gt;&lt;span style="color: red"&gt; Command&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; SwitchToEditingMode&lt;/span&gt;&lt;span style="color: blue"&gt;}"
/&amp;gt;&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;strong&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DoubleClickTrigger&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;strong&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Triggers&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
This also requires you define the proper namespace on the Window element:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red255\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;}??\fs28 \cf1 xmlns\cf3 :\cf1 Interactivity\cf3 ="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
I’d also like to drop &lt;em&gt;out&lt;/em&gt; of editing mode when you press ENTER in the &lt;strong&gt;TextBox&lt;/strong&gt;.
To accomplish this, let’s add an &lt;strong&gt;InputBinding&lt;/strong&gt; to the &lt;strong&gt;TextBox&lt;/strong&gt; for
the ENTER key that invokes our &lt;strong&gt;SwitchToEditingMode&lt;/strong&gt; command – in WPF
3.5 we need to go through a resource-based binding helper to get access to the ViewModel
(which is our &lt;strong&gt;DataContext&lt;/strong&gt;).&amp;nbsp; So, let’s defined a &lt;strong&gt;BindableCommand&lt;/strong&gt; in
the &lt;strong&gt;Grid &lt;/strong&gt;resources (so we get the &lt;strong&gt;DirectoryViewModel&lt;/strong&gt; as
the DataContext) and then bind the input command to that:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red0\green128\blue0;\red255\green0\blue0;}??\fs28 \cf1                     \cf3 &amp;lt;\cf1 Grid.Resources\cf3 &amp;gt;\par ??\cf1                         \cf4 &amp;lt;!-- Put here so it inherits the data context properly.  We want the command to execute on\par ??                             directory view model --&amp;gt;\par ??\cf1                         \cf3 &amp;lt;\cf1 julmar\cf3 :\cf1 BindableCommand\cf5  x\cf3 :\cf5 Key\cf3 ="EditingModeCommand"\cf5  Command\cf3 ="\{\cf1 Binding\cf5  SwitchToEditingMode\cf3 \}" /&amp;gt;\par ??\cf1                     \cf3 &amp;lt;/\cf1 Grid.Resources\cf3 &amp;gt;\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;lt;!-- Put here so it inherits the data context properly.&amp;nbsp;
We want the command to execute on&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; directory view model --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;BindableCommand&lt;/span&gt;&lt;span style="color: red"&gt; x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;="EditingModeCommand"&lt;/span&gt;&lt;span style="color: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Command&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; SwitchToEditingMode&lt;/span&gt;&lt;span style="color: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;strong&gt;… &lt;/strong&gt;
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;\red0\green0\blue0;\red0\green128\blue0;}??\fs28 \cf1                     \cf3 &amp;lt;\cf1 TextBox\cf4  x\cf3 :\cf4 Name\cf3 ="etb"\cf4  Visibility\cf3 ="Collapsed"\cf4  MinWidth\cf3 ="100"\cf0  \par ??                            \cf4  Text\cf3 ="\{\cf1 Binding\cf4  Name\cf3 ,\cf4  UpdateSourceTrigger\cf3 =LostFocus,\cf4  Converter\cf3 =\{\cf1 julmar\cf3 :\cf1 RefreshValueConverter\cf3 \}\}"&amp;gt;\par ??\cf1                         \cf6 &amp;lt;!-- Pressing ENTER in the TextBox turns off editing mode.  \par ??                             Tab or clicking away will do the same thing --&amp;gt;\par ??\cf1                         \cf3 &amp;lt;\cf1 TextBox.InputBindings\cf3 &amp;gt;\par ??\cf1                             \cf3 &amp;lt;\cf1 KeyBinding\cf4  Key\cf3 ="Enter"\cf4  Command\cf3 ="\{\cf1 StaticResource\cf4  EditingModeCommand\cf3 \}" /&amp;gt;\par ??\cf1                         \cf3 &amp;lt;/\cf1 TextBox.InputBindings\cf3 &amp;gt;\par ??\cf1                     \cf3 &amp;lt;/\cf1 TextBox\cf3 &amp;gt;\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox&lt;/span&gt;&lt;span style="color: red"&gt; x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;="etb"&lt;/span&gt;&lt;span style="color: red"&gt; Visibility&lt;/span&gt;&lt;span style="color: blue"&gt;="Collapsed"&lt;/span&gt;&lt;span style="color: red"&gt; MinWidth&lt;/span&gt;&lt;span style="color: blue"&gt;="100"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="color: red"&gt; Name&lt;/span&gt;&lt;span style="color: blue"&gt;,&lt;/span&gt;&lt;span style="color: red"&gt; UpdateSourceTrigger&lt;/span&gt;&lt;span style="color: blue"&gt;=LostFocus,&lt;/span&gt;&lt;span style="color: red"&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;RefreshValueConverter&lt;/span&gt;&lt;span style="color: blue"&gt;}}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Pressing ENTER in the TextBox turns
off editing mode.&amp;nbsp; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Tab or clicking
away will do the same thing --&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox.InputBindings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;KeyBinding&lt;/span&gt;&lt;span style="color: red"&gt; Key&lt;/span&gt;&lt;span style="color: blue"&gt;="Enter"&lt;/span&gt;&lt;span style="color: red"&gt; Command&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color: red"&gt; EditingModeCommand&lt;/span&gt;&lt;span style="color: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox.InputBindings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
And that’s it!&amp;nbsp; If you run the app and double-click on a directory name (except
the root) you can rename it!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMRenameTreeViewnodes_9D40/RenameTreeNodePic_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="RenameTreeNodePic" border="0" alt="RenameTreeNodePic" src="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMRenameTreeViewnodes_9D40/RenameTreeNodePic_thumb.jpg" width="244" height="196"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Here’s the finished solution: &lt;a href="http://www.julmar.com/samples/RenameTreeNode.zip" target="_blank"&gt;RenameTreeNode.zip&lt;/a&gt;
&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>MVVM: Service Locator</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/01/27/MVVMServiceLocator.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,82d77370-a501-48dc-b561-33c7a32b84e3.aspx</id>
    <published>2010-01-27T09:25:00.8243714-08:00</published>
    <updated>2010-01-27T09:25:00.8243714-08:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In this post, we’ll explore the service locator (called <strong>ServiceProvider</strong> in
the library) and introduce the specific services included with the MVVM Helper library
(as of 1.05 anyway).  
</p>
        <h4>What is the Service Locator?
</h4>
        <p>
In a nutshell, the service locator is a <em>resolver</em> for services that your application
might need or use.  It relates a type key to a specific object implementation. 
This is nothing new – the service locator design pattern has been around forever and
is considered a core J2EE pattern (see <a title="http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html" href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html" target="_blank">ServiceLocator.html</a> for
that definition).  In the MVVM Helpers library, this pattern is implemented in
the <strong>JulMar.Windows.Mvvm.ServiceProvider</strong> class in <strong>JulMar.Wpf.Helpers.dll</strong>. 
In retrospect, I’d prefer it be in a different namespace, but that’s where I stuck
it initially.  Here’s what it looks like:
</p>
        <p>
          <a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMServiceLocator_A05C/ServiceProviderDefinition_2.jpg">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ServiceProviderDefinition" border="0" alt="ServiceProviderDefinition" src="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMServiceLocator_A05C/ServiceProviderDefinition_thumb.jpg" width="154" height="240" />
          </a>
        </p>
        <p>
Notice that it implements the <strong>IServiceProvider</strong> interface – this is
a base .NET interface used for service resolution and a form of it can be found in
the Visual Studio extensibility API, Windows Workflow and a variety of other projects. 
The basis for the interface is you call the <strong>GetService</strong> method, passing
a System.Type (generally an interface or abstract class type) and it returns the concrete
implementation if the resolver knows about it.  This model allows the host to
decide what the concrete implementation should be – for example in the Workflow world,
the system needs to treat output completely differently for a Console App vs. a web
application.  So, a console host might add a service for output that prints a
string to the console window, while a web application might define the same service
as a redirection to an output page.
</p>
        <h4>Ok, I get that, now how do I use it?
</h4>
        <p>
It’s easy.  From a client perspective, you simply request a service using the
interface or class key.  As an example, in the <a href="http://www.julmar.com/blog/mark/2010/01/22/MVVMHelpers1ViewsAndViewModels.aspx" target="_blank">previous
post</a> I mentioned the <strong>IMessageVisualizer</strong> interface which allows
a ViewModel to popup a message box to notify the user about something.  Given
that the VM is supposed to be somewhat technology agnostic and unit testable, we want
to hide the implementation of displaying output behind an interface and that’s exactly
what <strong>IMessageVisualizer</strong> is for.  To get the concrete implementation,
we ask the <strong>ServiceProvider</strong>.  To do that, we need to define an
instance of a provider – each instance has it’s own private collection of services
that it manages.
</p>
        <p>
For simplicity, the base <strong>JulMar.Windows.Mvvm.ViewModel</strong> class defines
a public static <strong>ServiceProvider</strong> property:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;}??\fs28     \cf3 public\cf0  \cf3 class\cf0  \cf4 ViewModel\cf0  : \cf4 SimpleViewModel\cf0 , \cf4 IDisposable\par ??\cf0     \{\par ??        \cf5 ///\cf6  \cf5 &lt;summary&gt;\par ??\cf0         \cf5 ///\cf6  Service resolver for view models.  Allows derived types to add/remove\par ??\cf0         \cf5 ///\cf6  services from mapping.\par ??\cf0         \cf5 ///\cf6  \cf5 &lt;/summary&gt;\par ??\cf0         \cf3 public\cf0  \cf3 static\cf0  \cf3 readonly\cf0  \cf4 ServiceProvider\cf0  ServiceProvider = \cf3 new\cf0  \cf4 ServiceProvider\cf0 ();\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">class</span>
            <span style="color: #2b91af">ViewModel</span> : <span style="color: #2b91af">SimpleViewModel</span>, <span style="color: #2b91af">IDisposable</span></p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
            <span style="color: gray">   ///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;summary&gt;</span>
          </p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"> Service
resolver for view models.  Allows derived </span></p>
          <p style="margin: 0px">
            <span style="color: green">   <span style="color: gray">///</span><span style="color: green"></span>types
to add/remove</span>
          </p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"> services
from mapping.</span></p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
   <span style="color: blue">public</span><span style="color: blue">static</span><span style="color: blue">readonly</span><span style="color: #2b91af">ServiceProvider</span> ServiceProvider;
</p>
        </div>
        <p>
          <br />
This property can be accessed anywhere in your project and it’s the specific instance
that the default services are registered in (more on that in a second).  To get
the message visualizer you could do this:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red0\green128\blue0;}??\fs28             \cf3 IMessageVisualizer\cf0  messageVisualizer = ServiceProvider.Resolve&lt;\cf3 IMessageVisualizer\cf0 &gt;();\par ??            \cf4 if\cf0  (messageVisualizer != \cf4 null\cf0 )\par ??            \{\par ??                \cf5 // Use message visualizer\par ??\cf0             \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">var</span> messageVisualizer = ViewModel.ServiceProvider.GetService(typeof(<span style="color: #2b91af">IMessageVisualizer</span>))
as <span style="color: #2b91af">IMessageVisualizer</span>;
</p>
          <p style="margin: 0px">
            <span style="color: blue">if</span> (messageVisualizer != <span style="color: blue">null</span>)
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
            <span style="color: green">   // Use message visualizer</span>
          </p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
This invokes the <strong>IServiceProvider.GetService</strong> method to retrieve the
service. Since that’s somewhat verbose, there is a typed helper method that cuts down
your keystrokes and casts the return type automatically:
</p>
        <p>
        </p>
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <span style="color: blue">var</span> messageVisualizer
= ViewModel.ServiceProvider.Resolve&lt;<span style="color: #2b91af">IMessageVisualizer</span>&gt;(); 
</div>
        <p>
        </p>
        <p>
As a shortcut, if you are deriving from the <strong>ViewModel</strong> base class
it provides a convenience <strong>Resolve&lt;T&gt;</strong> method that cuts it to:
</p>
        <p>
        </p>
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <span style="color: blue">var</span> messageVisualizer
= Resolve&lt;<span style="color: #2b91af">IMessageVisualizer</span>&gt;();
</div>
        <p>
        </p>
        <p>
Notice the null check to see if the service exists?  This is because services
are dynamic, you register services with the service provider – so if the type key
has not been registered the <strong>Resolve</strong> will return null to indicate
an unsupported service.
</p>
        <h4>Service Registration
</h4>
        <p>
That brings us to registering and unregistering services.  This is accomplished
through the <strong>ServiceProvider.Add</strong> and <strong>ServiceProvider.Remove </strong>methods:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;\red163\green21\blue21;}??\fs28     \cf3 public\cf0  \cf3 class\cf0  \cf4 ServiceProvider\cf0  : \cf4 IServiceProvider\par ??\cf0     \{\par ??        \cf3 private\cf0  \cf3 readonly\cf0  \cf4 Dictionary\cf0 &lt;\cf4 Type\cf0 , \cf3 object\cf0 &gt; _services = \cf3 new\cf0  \cf4 Dictionary\cf0 &lt;\cf4 Type\cf0 , \cf3 object\cf0 &gt;();\par ??\par ??        \cf5 ///\cf6  \cf5 &lt;summary&gt;\par ??\cf0         \cf5 ///\cf6  Adds a new service to the resolver list\par ??\cf0         \cf5 ///\cf6  \cf5 &lt;/summary&gt;\par ??\cf0         \cf5 ///\cf6  \cf5 &lt;param name="type"&gt;\cf6 Service Type (typically an interface)\cf5 &lt;/param&gt;\par ??\cf0         \cf5 ///\cf6  \cf5 &lt;param name="value"&gt;\cf6 Object that implements service\cf5 &lt;/param&gt;\par ??\cf0         \cf3 public\cf0  \cf3 void\cf0  Add(\cf4 Type\cf0  type, \cf3 object\cf0  value)\par ??        \{\par ??            \cf3 if\cf0  (type == \cf3 null\cf0 )\par ??                \cf3 throw\cf0  \cf3 new\cf0  \cf4 ArgumentNullException\cf0 (\cf7 "type"\cf0 );\par ??            \cf3 if\cf0  (value == \cf3 null\cf0 )\par ??                \cf3 throw\cf0  \cf3 new\cf0  \cf4 ArgumentNullException\cf0 (\cf7 "value"\cf0 );\par ??\par ??            \cf3 lock\cf0 (_services)\par ??            \{\par ??                \cf6 // Replacing existing service\par ??\cf0                 \cf3 if\cf0  (_services.ContainsKey(type))\par ??                    _services[type] = value;\par ??                \cf6 // Adding new service\par ??\cf0                 \cf3 else\par ??\cf0                     _services.Add(type, value);\par ??            \}\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &lt;summary&gt;\par ??\cf0         \cf5 ///\cf6  Remove a service\par ??\cf0         \cf5 ///\cf6  \cf5 &lt;/summary&gt;\par ??\cf0         \cf5 ///\cf6  \cf5 &lt;param name="type"&gt;\cf6 Type to remove\cf5 &lt;/param&gt;\par ??\cf0         \cf3 public\cf0  \cf3 void\cf0  Remove(\cf4 Type\cf0  type)\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">class</span>
            <span style="color: #2b91af">ServiceProvider</span> : <span style="color: #2b91af">IServiceProvider</span></p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
            <span style="color: gray">   ///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;summary&gt;</span>
          </p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"> Adds
a new service to the resolver list</span></p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;param
name="type"&gt;</span></p>
          <p style="margin: 0px">
            <span style="color: gray">
            </span>
            <span style="color: green">   <span style="color: gray">///</span><span style="color: green"></span>Service
Type (typically an interface)</span>
            <span style="color: gray">&lt;/param&gt;</span>
          </p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;param
name="value"&gt;</span><span style="color: green">Object that implements service</span><span style="color: gray">&lt;/param&gt;</span></p>
          <p style="margin: 0px">
   <span style="color: blue">public</span><span style="color: blue">void</span> Add(<span style="color: #2b91af">Type</span> type, <span style="color: blue">object</span> value);
</p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;summary&gt;</span></p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"> Remove
a service</span></p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;/summary&gt;</span></p>
          <p style="margin: 0px">
   <span style="color: gray">///</span><span style="color: green"></span><span style="color: gray">&lt;param
name="type"&gt;</span><span style="color: green">Type to remove</span><span style="color: gray">&lt;/param&gt;</span></p>
          <p style="margin: 0px">
   <span style="color: blue">public</span><span style="color: blue">void</span> Remove(<span style="color: #2b91af">Type</span> type);
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
The <strong>Add</strong> method takes a type – you want to use an interface or abstract/virtual
base class for extensibility, and an object that implements that interface/base class.
</p>
        <p>
Once the type is registered, future calls to <strong>GetService</strong> (or <strong>Resolve&lt;T&gt;</strong>)
will return the given object instance.  Note that some implementations of this
pattern allow for lazy instantiation and per-call instance services (i.e. where you
get a unique instance on each call to <strong>GetService</strong>).  I’ve not
found a need for either of these and so this implementation is very simple. 
Thinking about it, I’d probably register an instance that has a method to create the
per-call items I need anyway.
</p>
        <p>
The <strong>Remove</strong> method takes the type key and throws away the instance
it is associated with – future calls made to retrieve the service will return null.
</p>
        <h4>An Example: Spell Checking
</h4>
        <p>
Say for instance you needed a spell checking service for your application, and multiple
ViewModels (and perhaps even view code behind files) will need access to it. 
You could use the <strong>ServiceProvider</strong> to cache off your service and then
access that instance as a singleton anywhere in your application – or even in other
modules that are aware of the interface type.  That’s the idea behind this pattern,
it allows you to loosely connect things together and bind them at runtime very easily.
</p>
        <p>
So, first, I’d define a spell checking service interface (note this is an example
so I’m keeping it <em>very</em> simple):
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs28     \cf3 public\cf0  \cf3 interface\cf0  \cf4 ISpellCheckService\par ??\cf0     \{\par ??        \cf3 bool\cf0  CheckSpelling(\cf3 string\cf0  text);\par ??    \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">interface</span>
            <span style="color: #2b91af">ISpellCheckService</span>
          </p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
            <span style="color: blue">   bool</span> CheckSpelling(<span style="color: blue">string</span> text);
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
Next, I’d have some concrete implementation of the above interface.  Let’s pretend
I called it <strong>DictionarySpellChecker</strong>.  Then, somewhere in my application
I add this service to the <strong>ServiceProvider</strong>, I might do this in my <strong>Application</strong> class:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs28     \cf3 public\cf0  \cf3 partial\cf0  \cf3 class\cf0  \cf4 App\par ??\cf0     \{\par ??        \cf3 public\cf0  App()\par ??        \{\par ??            \cf5 // Register the typical services (UI, Error, etc.) for this application.\par ??\cf0             \cf4 ViewModel\cf0 .RegisterKnownServiceTypes();\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">partial</span>
            <span style="color: blue">class</span>
            <span style="color: #2b91af">App</span>
          </p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
            <span style="color: blue">   public</span> App()
</p>
          <p style="margin: 0px">
   {
</p>
          <p style="margin: 0px">
      <span style="color: green">// Register the spell checker
service</span></p>
          <p style="margin: 0px">
            <span style="color: green">
            </span>      <span style="color: #2b91af">ViewModel</span>.ServiceProvider.Add(<font color="#0000ff">typeof</font>(<span style="color: #2b91af">ISpellCheckService</span>), 
</p>
          <p style="margin: 0px">
                    <font color="#0000ff">new</font> DictionarySpellChecker());
</p>
          <p style="margin: 0px">
   }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
Then, any class that needs access to the spell check service simply needs to access
the proper <strong>ServiceProvider:</strong></p>
        <p>
          <span style="color: blue">var</span> spellChecker = <span style="color: #2b91af">ViewModel</span>.ServiceProvider.Resolve&lt;<span style="color: #2b91af">ISpellCheckService</span>&gt;();
</p>
        <h4>
        </h4>
        <h4>Creating your own ServiceProvider instance
</h4>
        <p>
Note that here I’m using the ViewModel’s service provider – but that’s just because
I know it’s there.  You can use the service provider independently of the ViewModel
class.  All you need to do is:
</p>
        <ol>
          <li>
Create an instance of the <strong>ServiceProvider</strong> class 
</li>
          <li>
Register your services against that specific instance 
</li>
          <li>
Make the instance available to anyone who needs the services (i.e. through a singleton
property. 
</li>
        </ol>
        <p>
You can create as many service providers as you need to encapsulate your services.
</p>
        <h4>Built in services
</h4>
        <p>
The last thing I want to touch on are the built in services in the MVVM Helper library. 
There are several services that can be registered, used or replaced in the library
for your convenience.  In future blog posts I will detail each service specifically,
but I’ll mention them here because they use the <strong>ServiceProvider</strong> as
a resolver.
</p>
        <p>
In the project template it registers all the services through a static method call
– this is done in the Application constructor:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs28     \cf3 ///\cf4  \cf3 &lt;summary&gt;\par ??\cf0     \cf3 ///\cf4  Interaction logic for App.xaml\par ??\cf0     \cf3 ///\cf4  \cf3 &lt;/summary&gt;\par ??\cf0     \cf5 public\cf0  \cf5 partial\cf0  \cf5 class\cf0  \cf6 App\par ??\cf0     \{\par ??        \cf5 public\cf0  App()\par ??        \{\par ??            \cf4 // Register the typical services (UI, Error, etc.) for this application.\par ??\cf0             \cf6 ViewModel\cf0 .RegisterKnownServiceTypes();\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">partial</span>
            <span style="color: blue">class</span>
            <span style="color: #2b91af">App</span>
          </p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
            <span style="color: blue">   public</span> App()
</p>
          <p style="margin: 0px">
   {
</p>
          <p style="margin: 0px">
      <span style="color: green">// Register the typical
services (UI, Error, etc.)</span></p>
          <p style="margin: 0px">
      <span style="color: #2b91af">ViewModel</span>.RegisterKnownServiceTypes();
</p>
          <p style="margin: 0px">
       ...
</p>
          <p style="margin: 0px">
   }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
This call to <strong>ViewModel.RegisterKnownServiceTypes</strong> is required to use
the built-in services; without it, none of them are registered.  If you look
into the <strong>ViewModel</strong> source code, the definition for this method is:
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs28         \cf3 ///\cf4  \cf3 &lt;summary&gt;\par ??\cf0         \cf3 ///\cf4  This method registers known WPF services with the service provider.\par ??\cf0         \cf3 ///\cf4  \cf3 &lt;/summary&gt;\par ??\cf0         \cf5 public\cf0  \cf5 static\cf0  \cf5 void\cf0  RegisterKnownServiceTypes()\par ??        \{\par ??            ServiceProvider.Add(\cf5 typeof\cf0 (\cf6 IErrorVisualizer\cf0 ), \cf5 new\cf0  \cf6 ErrorVisualizer\cf0 ());\par ??            ServiceProvider.Add(\cf5 typeof\cf0 (\cf6 IMessageVisualizer\cf0 ), \cf5 new\cf0  \cf6 MessageVisualizer\cf0 ());\par ??            ServiceProvider.Add(\cf5 typeof\cf0 (\cf6 INotificationVisualizer\cf0 ), \cf5 new\cf0  \cf6 NotificationVisualizer\cf0 ());\par ??            ServiceProvider.Add(\cf5 typeof\cf0 (\cf6 IUIVisualizer\cf0 ), \cf5 new\cf0  \cf6 UIVisualizer\cf0 ());\par ??            ServiceProvider.Add(\cf5 typeof\cf0 (\cf6 IMessageMediator\cf0 ), \cf5 new\cf0  \cf6 MessageMediator\cf0 ());\par ??        \}\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green"> This method registers
known WPF services with the </span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: green">service
provider.</span>
          </p>
          <p style="margin: 0px">
            <span style="color: gray">///</span>
            <span style="color: green">
            </span>
            <span style="color: gray">&lt;/summary&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">static</span>
            <span style="color: blue">void</span> RegisterKnownServiceTypes()
</p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
   ServiceProvider.Add(<span style="color: blue">typeof</span>(<span style="color: #2b91af">IErrorVisualizer</span>), 
</p>
          <p style="margin: 0px">
                       <span style="color: blue">new</span><span style="color: #2b91af">ErrorVisualizer</span>());
</p>
          <p style="margin: 0px">
   ServiceProvider.Add(<span style="color: blue">typeof</span>(<span style="color: #2b91af">IMessageVisualizer</span>), 
</p>
          <p style="margin: 0px">
                       <span style="color: blue">new</span><span style="color: #2b91af">MessageVisualizer</span>());
</p>
          <p style="margin: 0px">
   ServiceProvider.Add(<span style="color: blue">typeof</span>(<span style="color: #2b91af">INotificationVisualizer</span>), 
<br />
                       <span style="color: blue">new</span><span style="color: #2b91af">NotificationVisualizer</span>());
</p>
          <p style="margin: 0px">
   ServiceProvider.Add(<span style="color: blue">typeof</span>(<span style="color: #2b91af">IUIVisualizer</span>), <span style="color: blue">new</span><span style="color: #2b91af">UIVisualizer</span>());
</p>
          <p style="margin: 0px">
   ServiceProvider.Add(<span style="color: blue">typeof</span>(<span style="color: #2b91af">IMessageMediator</span>), 
</p>
          <p style="margin: 0px">
                       <span style="color: blue">new</span><span style="color: #2b91af">MessageMediator</span>());
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
As you can see, it’s just doing what what you would expect – registering a specific
implementation for each service interface type.  The services are:
</p>
        <table border="1" cellspacing="0" cellpadding="2" width="400">
          <tbody>
            <tr>
              <td valign="top" width="149">
                <strong>
                  <font color="#0080ff">Service Interface</font>
                </strong>
              </td>
              <td valign="top" width="251">
                <strong>
                  <font color="#0080ff">Description</font>
                </strong>
              </td>
            </tr>
            <tr>
              <td valign="top" width="149">
                <strong>IErrorVisualizer</strong>
              </td>
              <td valign="top" width="251">
Presents an error dialog as a <strong>MessageBox</strong> with an OK button to dismiss
it.</td>
            </tr>
            <tr>
              <td valign="top" width="149">
                <strong>IMessageVisualizer</strong>
              </td>
              <td valign="top" width="251">
Presents a message dialog as a <strong>MessageBox</strong> with a selectable button
set.</td>
            </tr>
            <tr>
              <td valign="top" width="149">
                <strong>INotificationVisualizer</strong>
              </td>
              <td valign="top" width="251">
Allows long-running modal operations to present some wait notification (defaults to
changing the cursor to an hourglass).</td>
            </tr>
            <tr>
              <td valign="top" width="149">
                <strong>IUIVisualizer</strong>
              </td>
              <td valign="top" width="251">
Presents a custom modal or modeless dialog to the user associated with a <strong>ViewModel</strong>.</td>
            </tr>
            <tr>
              <td valign="top" width="149">
                <strong>IMessageMediator</strong>
              </td>
              <td valign="top" width="251">
Message transfer service that allows loosely connecting <strong>ViewModels</strong> together.</td>
            </tr>
          </tbody>
        </table>
        <h4>
          <br />
Replace services
</h4>
        <p>
Each service interface has a default implementation registered against it.  If
you don’t like the implementation, or prefer to have your own custom implementation,
simply add the service again <em>after it was registered</em>.
</p>
        <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs28     \cf3 public\cf0  \cf3 partial\cf0  \cf3 class\cf0  \cf4 App\par ??\cf0     \{\par ??        \cf3 public\cf0  App()\par ??        \{\par ??            \cf5 // Register the typical services (UI, Error, etc.) for this application.\par ??\cf0             \cf4 ViewModel\cf0 .RegisterKnownServiceTypes();\par ??\par ??            \cf5 // Replace the notification visualizer with our cool version..\par ??\cf0             \cf4 ViewModel\cf0 .ServiceProvider.Add(\cf3 typeof\cf0 (\cf4 INotificationVisualizer\cf0 ), \cf3 new\cf0  \cf4 NotifyWaitBox\cf0 ());\par ??}
-->
        <div style="font-family: consolas; background: white; color: black; font-size: 10pt">
          <p style="margin: 0px">
            <span style="color: blue">public</span>
            <span style="color: blue">partial</span>
            <span style="color: blue">class</span>
            <span style="color: #2b91af">App</span>
          </p>
          <p style="margin: 0px">
{
</p>
          <p style="margin: 0px">
            <span style="color: blue">   public</span> App()
</p>
          <p style="margin: 0px">
   {
</p>
          <p style="margin: 0px">
      <span style="color: green">// Register the typical
services (UI, Error, etc.) </span></p>
          <p style="margin: 0px">
            <span style="color: green">      // for this application.</span>
          </p>
          <p style="margin: 0px">
      <span style="color: #2b91af">ViewModel</span>.RegisterKnownServiceTypes();
</p>
          <p style="margin: 0px">
 
</p>
          <p style="margin: 0px">
      <span style="color: green">// Replace the notification
visualizer with our cool version..</span></p>
          <p style="margin: 0px">
      <span style="color: #2b91af">ViewModel</span>.ServiceProvider.Add( 
<br />
           <span style="color: blue">typeof</span>(<span style="color: #2b91af">INotificationVisualizer</span>), <span style="color: blue">new</span><span style="color: #2b91af">NotifyWaitBox</span>());
</p>
          <p style="margin: 0px">
   }
</p>
          <p style="margin: 0px">
}
</p>
        </div>
        <p>
          <br />
This will replace the default instance with a new provider – any future calls to retrieve
the service will return your new instance.  This can be done at any time, and
as many times as you like (as an example, consider a theme service you dynamically
replace at runtime as the user selects the theme).
</p>
        <h4>Final Warnings
</h4>
        <p>
There is one warning I need to impart on the service locator.  It holds hard
references to the registered instances.  That means if you want the instance
to be Garbage Collected prior to the application terminating, you must remove the
key from the service provider. This normally isn’t an issue as most services are lifetime
services and are intended to be around until the end, but if you are using a transient
service and only need it for a short period please remember this point so you don’t
create an unintentional memory “leak”.
</p>
        <p>
In the next post we’ll cover the Message, Error and Notification visualization services. 
Stay tuned MVVM fans!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>MVVM: Views and ViewModels</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/01/22/MVVMViewsAndViewModels.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,513ec8da-076b-4f88-91be-2151f0010610.aspx</id>
    <published>2010-01-22T14:35:37.576-08:00</published>
    <updated>2010-01-27T09:26:11.6685748-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="MVVM" label="MVVM" scheme="http://www.julmar.com/blog/mark/CategoryView,category,MVVM.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">&lt;p&gt;
In the previous post, I provided a link to the project template you can use to start
a new MVVM project using the JulMar MVVM library. Here's the two links in case you
didn't get them before: 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/samples/mvvmhelpers.zip"&gt;MVVM Helpers Distribution&lt;/a&gt; 
&lt;br&gt;
&lt;a href="http://www.julmar.com/samples/WpfMvvmApplication.zip"&gt;Project Template&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Copy the project template into your Visual Studio 2008 templates directory located
off your user documents - mine is at &lt;strong&gt;%UserProfile%\Documents\Visual Studio
2008\Templates\ProjectTemplates\Visual C#\Windows&lt;/strong&gt;. 
&lt;/p&gt;
&lt;p&gt;
Ok, so once you have these installed, what can you do with them? Well, for starters,
you can now generate a starter project that provides a nice template for an MVVM application.
The starter template creates a simple "Explorer" like program - it looks like this: 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.julmar.com/blog/mark/content/binary/images/sample-run1.jpg" width=600&gt; 
&lt;/p&gt;
&lt;p&gt;
Notice there are two sections - a &lt;strong&gt;TreeView&lt;/strong&gt; listing all the directories,
and a &lt;strong&gt;ListView&lt;/strong&gt; showing all the files in the selected directory. Let's
look a little closer at the project structure. There are four directories in the solution:
&lt;/p&gt;
&lt;table border=1 cellspacing=0 cellpadding=2 width=588&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign=top width=113&gt;
&lt;strong&gt;Converters&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=473&gt;
This has a simple &lt;font face="Courier new"&gt;ValueConverter&lt;/font&gt; that takes a filename
and returns an icon as an &lt;strong&gt;ImageSource&lt;/strong&gt;. 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=118&gt;
&lt;strong&gt;Dependencies&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=468&gt;
This is the binary dependencies the project requires, specifically it contains the
JulMar MVVM libraries and Blend action libraries.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=123&gt;
&lt;strong&gt;ViewModels&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=464&gt;
This directory contains all the business logic in the form of ViewModels.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign=top width=127&gt;
&lt;strong&gt;Views&lt;/strong&gt;&lt;/td&gt;
&lt;td valign=top width=461&gt;
Finally, this directory contains all the UI (XAML) for the application.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4&gt;Views
&lt;/h4&gt;
&lt;p&gt;
Let's start with the last folder - the Views. Views are the UI presentation of data
- in the case of a WPF/Silverlight application this is most commonly the XAML and
XAML code behind files (they are considered a single element together). We want to
have UI-specific code and designer elements present in these files. Generally we prefer
to place business logic and testable elements into the ViewModel area.
&lt;/p&gt;
&lt;p&gt;
In this starter project, we have a single view &lt;strong&gt;MainWindow.xaml&lt;/strong&gt;. This
is what presents the main UI shown above. The code behind file contains the required
boilerplate code (essentially a constructor and call to &lt;strong&gt;InitializeComponent&lt;/strong&gt;). 
&lt;/p&gt;
&lt;p&gt;
If you open the view (note that the designer will choke on it until you compile the
project), you will find fairly straightforward XAML that creates the UI, let’s break
it down as we go:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 Window\cf4  x\cf1 :\cf4 Class\cf1 ="WpfMVVMApplication1.Views.MainWindow"\par ??\cf0    \cf4  xmlns\cf1 ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 x\cf1 ="http://schemas.microsoft.com/winfx/2006/xaml"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 julmar\cf1 ="http://www.julmar.com/wpfhelpers"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 ViewModels\cf1 ="clr-namespace:WpfMVVMApplication1.ViewModels"\par ??\cf0    \cf4  xmlns\cf1 :\cf4 Converters\cf1 ="clr-namespace:WpfMVVMApplication1.Converters"\par ??\cf0    \cf4  DataContext\cf1 ="\{\cf3 julmar\cf1 :\cf3 ViewModelCreator\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  ViewModels\cf1 :\cf4 MainViewModel\cf1 \}\}"\par ??\cf0    \cf4  Title\cf1 ="File Explorer"\cf4  Height\cf1 ="400"\cf4  Width\cf1 ="500"&amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 14pt"&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Window&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Class&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="WpfMVVMApplication1.Views.MainWindow"&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;font size=2&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;font size=2&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;font size=2&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;julmar&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="http://www.julmar.com/wpfhelpers"&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;font size=2&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;ViewModels&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="clr-namespace:WpfMVVMApplication1.ViewModels"&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;font size=2&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt; xmlns&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Converters&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="clr-namespace:WpfMVVMApplication1.Converters"&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;font size=2&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt; &lt;strong&gt;&lt;u&gt;&lt;em&gt;DataContext&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;ViewModelCreator&lt;/span&gt;&lt;span style="COLOR: blue"&gt; {&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Type&lt;/span&gt;&lt;span style="COLOR: red"&gt; ViewModels&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;MainViewModel&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}}"&lt;/span&gt;&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="MARGIN: 0px"&gt;&lt;font size=2&gt;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt; Title&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="File
Explorer"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Height&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="400"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Width&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="500"&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
First, notice how the &lt;strong&gt;DataContext&lt;/strong&gt; is established – through a custom &lt;strong&gt;MarkupExtension&lt;/strong&gt; called &lt;strong&gt;ViewModelCreator&lt;/strong&gt;.&amp;nbsp;
This extension is responsible for creating an associated ViewModel for this view (where
our testable business logic should go) and also wiring up a couple of special event
handlers that will allow the ViewModel to activate the view and close the view respectively.
&lt;/p&gt;
&lt;p&gt;
Next, let’s check out the resources:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red0\green128\blue0;\red255\green0\blue0;}??\fs28 \cf1     \cf3 &amp;lt;\cf1 Window.Resources\cf3 &amp;gt;\par ??\cf1         \cf4 &amp;lt;!-- Bindable commands sit in resources and allow keyboard input to target ViewModel commands --&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 julmar\cf3 :\cf1 BindableCommand\cf5  x\cf3 :\cf5 Key\cf3 ="CloseCommand"\cf5  Command\cf3 ="\{\cf1 Binding\cf5  CloseAppCommand\cf3 \}" /&amp;gt;\par ??\cf1         \par ??        \cf3 &amp;lt;\cf1 Converters\cf3 :\cf1 FilenameToIconConverter\cf5  x\cf3 :\cf5 Key\cf3 ="iconConverter" /&amp;gt;\par ??\cf1         \par ??        \cf3 &amp;lt;\cf1 HierarchicalDataTemplate\cf5  x\cf3 :\cf5 Key\cf3 ="DirectoryTemplate"\cf5  ItemsSource\cf3 ="\{\cf1 Binding\cf5  Subdirectories\cf3 \}"&amp;gt;\par ??\cf1             \cf3 &amp;lt;\cf1 StackPanel\cf5  Orientation\cf3 ="Horizontal"&amp;gt;\par ??\cf1                 \cf3 &amp;lt;\cf1 Image\cf5  Width\cf3 ="16"\cf5  Height\cf3 ="16"\cf5  Source\cf3 ="\{\cf1 Binding\cf5  FullName\cf3 ,\cf5  Converter\cf3 =\{\cf1 StaticResource\cf5  iconConverter\cf3 \}\}" /&amp;gt;\par ??\cf1                 \cf3 &amp;lt;\cf1 TextBlock\cf5  x\cf3 :\cf5 Name\cf3 ="tb"\cf5  Margin\cf3 ="5,0"\cf5  Text\cf3 ="\{\cf1 Binding\cf5  Name\cf3 \}" /&amp;gt;\par ??\cf1             \cf3 &amp;lt;/\cf1 StackPanel\cf3 &amp;gt;\cf1  \par ??            \cf3 &amp;lt;\cf1 HierarchicalDataTemplate.Triggers\cf3 &amp;gt;\par ??\cf1                 \cf3 &amp;lt;\cf1 DataTrigger\cf5  Binding\cf3 ="\{\cf1 Binding\cf5  IsSelected\cf3 \}"\cf5  Value\cf3 ="True"&amp;gt;\par ??\cf1                     \cf3 &amp;lt;\cf1 Setter\cf5  TargetName\cf3 ="tb"\cf5  Property\cf3 ="FontWeight"\cf5  Value\cf3 ="Bold" /&amp;gt;\par ??\cf1                 \cf3 &amp;lt;/\cf1 DataTrigger\cf3 &amp;gt;\par ??\cf1             \cf3 &amp;lt;/\cf1 HierarchicalDataTemplate.Triggers\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;/\cf1 HierarchicalDataTemplate\cf3 &amp;gt;\par ??\par ??\cf1     \cf3 &amp;lt;/\cf1 Window.Resources\cf3 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 14pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Window.Resources&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;lt;!-- Bindable commands sit in resources
and allow keyboard input to target ViewModel commands --&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;julmar&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;BindableCommand&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Key&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="CloseCommand"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Command&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; CloseAppCommand&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Converters&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;FilenameToIconConverter&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Key&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="iconConverter"
/&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;HierarchicalDataTemplate&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Key&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="DirectoryTemplate"&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
ItemsSource&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; Subdirectories&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="COLOR: red"&gt; Orientation&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Horizontal"&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Image&lt;/span&gt;&lt;span style="COLOR: red"&gt; Width&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="16"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Height&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="16"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Source&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; FullName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: red"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Converter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;={&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; iconConverter&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}}"
/&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="COLOR: red"&gt; x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: red"&gt;Name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="tb"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Margin&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="5,0"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Text&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; Name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;HierarchicalDataTemplate.Triggers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;DataTrigger&lt;/span&gt;&lt;span style="COLOR: red"&gt; Binding&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; IsSelected&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="True"&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="tb"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="FontWeight"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Bold"
/&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;DataTrigger&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;HierarchicalDataTemplate.Triggers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;HierarchicalDataTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font size=2&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Window.Resources&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Here we find three defined resources – first we have a JulMar MVVM &lt;strong&gt;BindableCommand&lt;/strong&gt;.&amp;nbsp;
This is a special &lt;strong&gt;ICommand&lt;/strong&gt; instance that can be data bound and forwards
to the specified binding.&amp;nbsp; We use this a bit later in the keyboard accelerator
to close the application.&amp;nbsp; Next, there is the converter that takes a filename
and converts it to an icon – that’s the source code in the &lt;strong&gt;Converters&lt;/strong&gt; folder
mentioned earlier.&amp;nbsp; I use a converter here because this is very UI-centric and
not very testable – so the converter will data bind to a string (filename) property
of the ViewModel and retrieve the icon for the UI to display.&amp;nbsp; That way, my ViewModel
sticks with base (non-WPF) types.&amp;nbsp; This isn’t a hard rule – but it’s a good one
to try to follow.
&lt;/p&gt;
&lt;p&gt;
Finally, there is a &lt;strong&gt;DataTemplate&lt;/strong&gt; that is used to display the directory
structure – this is what the &lt;strong&gt;TreeView&lt;/strong&gt; uses to display it’s data.&amp;nbsp;
Notice it data binds to a couple of properties – &lt;strong&gt;FullName&lt;/strong&gt;, Name and &lt;strong&gt;IsSelected&lt;/strong&gt;.&amp;nbsp;
All of these, as you will see, exist in our ViewModel definition.&amp;nbsp; The View takes
the data from the ViewModel and displays it onto the UI for the user to interact with.
&lt;/p&gt;
&lt;p&gt;
Next in the XAML is the input bindings – this is where we define keyboard and mouse
gesture accelerators, and it’s where I use the bindable command I defined earlier:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red163\green21\blue21;\red255\green255\blue255;\red0\green0\blue255;\red255\green0\blue0;}??\fs28 \cf1     \cf3 &amp;lt;\cf1 Window.InputBindings\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 KeyBinding\cf4  Key\cf3 ="X"\cf4  Modifiers\cf3 ="ALT"\cf4  Command\cf3 ="\{\cf1 StaticResource\cf4  CloseCommand\cf3 \}" /&amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Window.InputBindings\cf3 &amp;gt;\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Window.InputBindings&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;KeyBinding&lt;/span&gt;&lt;span style="COLOR: red"&gt; Key&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="X"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Modifiers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ALT"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Command&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; CloseCommand&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Window.InputBindings&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Here you can see that instead of trying to bind to the command, we use &lt;strong&gt;{StaticResource}&lt;/strong&gt; to
get it from the resources.&amp;nbsp; This is necessary under WPF 3.5 because the &lt;strong&gt;KeyBinding&lt;/strong&gt; will
not inherit the &lt;strong&gt;DataContext &lt;/strong&gt;and so cannot bind directly to the command
– but resources can, and specifically Freezable resources can – that’s what the &lt;strong&gt;BindableCommand&lt;/strong&gt; provides
– a Freezable resource that forwards the &lt;strong&gt;ICommand&lt;/strong&gt; implementation
onto a command defined in the DataContext ViewModel.&amp;nbsp; This is not necessary under
WPF4 – this is actually one of the new features they’ve added: to inherit the DataContext
in your input bindings!&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
The remainder of the view is fairly traditional – we use bindings to connect the UI
up to the ViewModel definitions, so let’s go look at what those are.
&lt;/p&gt;
&lt;h4&gt;ViewModels
&lt;/h4&gt;
&lt;p&gt;
The ViewModel folder contains three source code files – &lt;strong&gt;DirectoryViewModel.cs&lt;/strong&gt;, &lt;strong&gt;FileViewModel.cs&lt;/strong&gt;,
and &lt;strong&gt;MainViewModel.cs&lt;/strong&gt;.&amp;nbsp; If you recall from above, &lt;strong&gt;MainViewModel&lt;/strong&gt; is
the primary ViewModel that is data bound to the view.&amp;nbsp; The other two are child
view models used to represent the files and folders respectively.&amp;nbsp; Let’s look
at FileViewModel as an example:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;}??\fs28     \cf3 public\cf0  \cf3 class\cf0  \cf4 FileViewModel\cf0  : \cf4 SimpleViewModel\par ??\cf0     \{\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  File expansion marker used by the directory\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 internal\cf0  \cf3 static\cf0  \cf4 FileViewModel\cf0  MarkerFile = \cf3 new\cf0  \cf4 FileViewModel\cf0 ();\par ??\par ??\cf3         #region\cf0  Internal Data\par ??        \cf3 private\cf0  \cf3 readonly\cf0  \cf4 FileInfo\cf0  _data;\par ??\cf3         #endregion\par ??\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  File name\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  \cf3 string\cf0  Name\par ??        \{\par ??            \cf3 get\cf0  \{ \cf3 return\cf0  _data.Name; \}\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Full path + filename\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  \cf3 string\cf0  FullPath\par ??        \{\par ??            \cf3 get\cf0  \{ \cf3 return\cf0  _data.FullName; \}\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Size of the file in bytes\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  \cf3 long\cf0  Size\par ??        \{\par ??            \cf3 get\cf0  \{ \cf3 return\cf0  _data.Length; \}\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Internal constructor used to create the file marker.\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 private\cf0  FileViewModel()\par ??        \{\par ??            _data = \cf3 null\cf0 ;\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Public constructor that captures a list of files.\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;param name="fi"&amp;gt;\cf6 FileInfo to grab file information from\cf5 &amp;lt;/param&amp;gt;\par ??\cf0         \cf3 public\cf0  FileViewModel(\cf4 FileInfo\cf0  fi)\par ??        \{\par ??            _data = fi;\par ??        \}\par ??    \}\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;SimpleViewModel&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Marker
file that signals expansion of the tree.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt; MarkerFile
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;readonly&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileInfo&lt;/span&gt; _data;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; File
name&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Name
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _data.Name;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Full
path + filename&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; FullPath
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _data.FullName;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Size
of the file in bytes&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;long&lt;/span&gt; Size
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _data.Length;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Private
constructor used to create marker file.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; FileViewModel()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Public
constructor that captures a list of files.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="fi"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;FileInfo to grab file information from&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; FileViewModel(&lt;span style="COLOR: #2b91af"&gt;FileInfo&lt;/span&gt; fi)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _data = fi;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As you can see, it is &lt;em&gt;very&lt;/em&gt; simple – it is simply a wrapper around a piece
of data, a &lt;strong&gt;FileInfo&lt;/strong&gt; that represents a file on disk.&amp;nbsp; It exposes
properties that are data bindable.&amp;nbsp; There is one element (&lt;strong&gt;MarkerFile&lt;/strong&gt;)
that I want you to ignore for a moment – we’ll get to it in a second.&amp;nbsp; Notice
that it extends &lt;strong&gt;SimpleViewModel&lt;/strong&gt;.&amp;nbsp; This is one of three primary
VM classes in the MVVM helper library.&amp;nbsp; &lt;strong&gt;SimpleViewModel&lt;/strong&gt; is intended
for cases where you need the bare minimum support – specifically support for &lt;strong&gt;INotifyPropertyChanged&lt;/strong&gt;.&amp;nbsp;
No other services are provided by this base class, and as such it is very light.&amp;nbsp;
Let’s look at the directory class next:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red128\green128\blue128;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs28     \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0     \cf3 ///\cf4  Sample ViewModel that wraps a Directory.\par ??\cf0     \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf5 public\cf0  \cf5 class\cf0  \cf6 DirectoryViewModel\cf0  : \cf6 ViewModel\par ??\cf0     \{\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  String used to send message to main view model about directory selection.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 internal\cf0  \cf5 const\cf0  \cf5 string\cf0  SelectedDirectoryChangedMessage = \cf7 @"SelectedDirectoryChanged"\cf0 ;\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Marker directory that signals expansion of the tree.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 internal\cf0  \cf5 static\cf0  \cf6 DirectoryViewModel\cf0  MarkerDirectory = \cf5 new\cf0  \cf6 DirectoryViewModel\cf0 ();\par ??\par ??\cf5         #region\cf0  Internal Data\par ??        \cf5 private\cf0  \cf5 bool\cf0  _isSelected, _isExpanded;\par ??        \cf5 private\cf0  \cf5 readonly\cf0  \cf6 DirectoryInfo\cf0  _data;\par ??        \cf5 private\cf0  \cf5 readonly\cf0  \cf6 ObservableCollection\cf0 &amp;lt;\cf6 FileViewModel\cf0 &amp;gt; _files;\par ??        \cf5 private\cf0  \cf5 readonly\cf0  \cf6 ObservableCollection\cf0 &amp;lt;\cf6 DirectoryViewModel\cf0 &amp;gt; _subdirs;\par ??\cf5         #endregion\par ??\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Name of the directory\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf5 string\cf0  Name\par ??        \{\par ??            \cf5 get\cf0  \{ \cf5 return\cf0  _data.Name; \}\par ??        \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Full path + name of the directory\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf5 string\cf0  FullName\par ??        \{\par ??            \cf5 get\cf0  \{ \cf5 return\cf0  _data.FullName; \}\par ??        \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  True/False whether the directory is selected (i.e. current).\par ??\cf0         \cf3 ///\cf4  Selecting the directory causes it to populate it's file collection.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf5 bool\cf0  IsSelected\par ??        \{\par ??            \cf5 get\cf0  \{ \cf5 return\cf0  _isSelected; \}\par ??            \cf5 set\par ??\cf0             \{\par ??                \cf5 if\cf0  (_isSelected != \cf5 value\cf0 )\par ??                \{\par ??                    _isSelected = \cf5 value\cf0 ;\par ??\par ??                    \cf5 if\cf0  (_isSelected)\par ??                    \{\par ??                        \cf5 if\cf0  (_files.Count == 1 &amp;amp;&amp;amp; _files[0] == \cf6 FileViewModel\cf0 .MarkerFile)\par ??                        \{\par ??                            _files.Clear();\par ??                            _data.GetFiles()\par ??                                .Where(f =&amp;gt; (f.Attributes &amp;amp; (\cf6 FileAttributes\cf0 .Hidden | \cf6 FileAttributes\cf0 .System)) == 0)\par ??                                .ForEach(f =&amp;gt; _files.Add(\cf5 new\cf0  \cf6 FileViewModel\cf0 (f)));\par ??                            OnPropertyChanged(\cf7 "TotalFiles"\cf0 , \cf7 "TotalFileSize"\cf0 );\par ??                        \}\par ??                        SendMessage(SelectedDirectoryChangedMessage, \cf5 this\cf0 );\par ??                    \}\par ??                    \cf5 else\par ??\cf0                     \{\par ??                        _files.Clear();\par ??                        _files.Add(\cf6 FileViewModel\cf0 .MarkerFile);\par ??                    \}\par ??\par ??                    OnPropertyChanged(\cf7 "IsSelected"\cf0 );\par ??                \}\par ??            \}\par ??        \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  True/False if the directory is expanded. Expanding the directory causes it\par ??\cf0         \cf3 ///\cf4  to fill it's subdirectory collection.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf5 bool\cf0  IsExpanded\par ??        \{\par ??            \cf5 get\cf0  \{ \cf5 return\cf0  _isExpanded; \}\par ??            \cf5 set\par ??\cf0             \{\par ??                \cf5 if\cf0  (_isExpanded != \cf5 value\cf0 )\par ??                \{\par ??                    _isExpanded = \cf5 value\cf0 ;\par ??                    \cf5 if\cf0  (_isExpanded)\par ??                    \{\par ??                        \cf5 if\cf0  (_subdirs.Count == 1 &amp;amp;&amp;amp; _subdirs[0] == \cf6 DirectoryViewModel\cf0 .MarkerDirectory)\par ??                        \{\par ??                            _subdirs.Clear();\par ??                            _data.GetDirectories()\par ??                                .Where(d =&amp;gt; (d.Attributes &amp;amp; (\cf6 FileAttributes\cf0 .Hidden | \cf6 FileAttributes\cf0 .System)) == 0)\par ??                                .ForEach(d =&amp;gt; _subdirs.Add(\cf5 new\cf0  \cf6 DirectoryViewModel\cf0 (d)));\par ??                        \}\par ??                    \}\par ??                    \cf4 // Throw them away to recollect later - implements a refresh.\par ??\cf0                     \cf5 else\par ??\cf0                     \{\par ??                        _subdirs.Clear();\par ??                        _subdirs.Add(\cf6 DirectoryViewModel\cf0 .MarkerDirectory);\par ??                    \}\par ??                \}\par ??\par ??                OnPropertyChanged(\cf7 "IsExpanded"\cf0 );\par ??            \}\par ??        \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  List of files in this directory.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf6 IList\cf0 &amp;lt;\cf6 FileViewModel\cf0 &amp;gt; Files \{ \cf5 get\cf0  \{ \cf5 return\cf0  _files; \} \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  List of subdirectories in this directory.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf6 IList\cf0 &amp;lt;\cf6 DirectoryViewModel\cf0 &amp;gt; Subdirectories \{ \cf5 get\cf0  \{ \cf5 return\cf0  _subdirs; \} \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Count of files in this directory.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf5 int\cf0  TotalFiles \{ \cf5 get\cf0  \{ \cf5 return\cf0  _files.Count; \} \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Total size of all files in this directory.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 public\cf0  \cf5 long\cf0  TotalFileSize \{ \cf5 get\cf0  \{ \cf5 return\cf0  _files.Sum(file =&amp;gt; file.Size); \} \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Constructor for the marker directory.  This is used to detect an expansion.\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 private\cf0  DirectoryViewModel()\par ??        \{\par ??            _data = \cf5 null\cf0 ;\par ??        \}\par ??\par ??        \cf3 ///\cf4  \cf3 &amp;lt;summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  Public constructor\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 ///\cf4  \cf3 &amp;lt;param name="di"&amp;gt;\cf4 DirectoryInfo to pull information from\cf3 &amp;lt;/param&amp;gt;\par ??\cf0         \cf5 public\cf0  DirectoryViewModel(\cf6 DirectoryInfo\cf0  di)\par ??        \{\par ??            \cf5 if\cf0  (di == \cf5 null\cf0 )\par ??                \cf5 throw\cf0  \cf5 new\cf0  \cf6 ArgumentNullException\cf0 (\cf7 "di"\cf0 );\par ??\par ??            _data = di;\par ??            _files = \cf5 new\cf0  \cf6 ObservableCollection\cf0 &amp;lt;\cf6 FileViewModel\cf0 &amp;gt; \{ \cf6 FileViewModel\cf0 .MarkerFile \};\par ??            _subdirs = \cf5 new\cf0  \cf6 ObservableCollection\cf0 &amp;lt;\cf6 DirectoryViewModel\cf0 &amp;gt; \{ \cf6 DirectoryViewModel\cf0 .MarkerDirectory \};\par ??        \}\par ??    \}\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Sample
ViewModel that wraps a Directory.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;ViewModel&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; String
used to send message to main view model about directory selection.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; SelectedDirectoryChangedMessage
= &lt;span style="COLOR: #a31515"&gt;@"SelectedDirectoryChanged"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Marker
directory that signals expansion of the tree.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt; MarkerDirectory
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; _isSelected,
_isExpanded;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;readonly&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryInfo&lt;/span&gt; _data;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;readonly&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt;&amp;gt;
_files;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;readonly&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;&amp;gt;
_subdirs;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Name
of the directory&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Name
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _data.Name;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Full
path + name of the directory&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; FullName
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _data.FullName;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; True/False
whether the directory is selected (i.e. current).&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Selecting
the directory causes it to populate it's file collection.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; IsSelected
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _isSelected;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_isSelected
!= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_isSelected = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_isSelected)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_files.Count
== 1 &amp;amp;&amp;amp; _files[0] == &lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt;.MarkerFile)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_files.Clear();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_data.GetFiles()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
.Where(f =&amp;gt; (f.Attributes &amp;amp; (&lt;span style="COLOR: #2b91af"&gt;FileAttributes&lt;/span&gt;.Hidden
| &lt;span style="COLOR: #2b91af"&gt;FileAttributes&lt;/span&gt;.System)) == 0)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
.ForEach(f =&amp;gt; _files.Add(&lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt;(f)));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"TotalFiles"&lt;/span&gt;, &lt;span style="COLOR: #a31515"&gt;"TotalFileSize"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
SendMessage(SelectedDirectoryChangedMessage, &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_files.Clear();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_files.Add(&lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt;.MarkerFile);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"IsSelected"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; True/False
if the directory is expanded. Expanding the directory causes it&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; to
fill it's subdirectory collection.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; IsExpanded
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _isExpanded;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_isExpanded
!= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_isExpanded = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_isExpanded)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_subdirs.Count
== 1 &amp;amp;&amp;amp; _subdirs[0] == &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;.MarkerDirectory)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_subdirs.Clear();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_data.GetDirectories()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
.Where(d =&amp;gt; (d.Attributes &amp;amp; (&lt;span style="COLOR: #2b91af"&gt;FileAttributes&lt;/span&gt;.Hidden
| &lt;span style="COLOR: #2b91af"&gt;FileAttributes&lt;/span&gt;.System)) == 0)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
.ForEach(d =&amp;gt; _subdirs.Add(&lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;(d)));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Throw them away to recollect later - implements a refresh.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_subdirs.Clear();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
_subdirs.Add(&lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;.MarkerDirectory);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"IsExpanded"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; List
of files in this directory.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt;&amp;gt;
Files { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _files;
} }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; List
of subdirectories in this directory.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;&amp;gt;
Subdirectories { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _subdirs;
} }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Count
of files in this directory.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; TotalFiles
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _files.Count;
} }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Total
size of all files in this directory.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;long&lt;/span&gt; TotalFileSize
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _files.Sum(file
=&amp;gt; file.Size); } }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Constructor
for the marker directory.&amp;nbsp; This is used to detect an expansion.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; DirectoryViewModel()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _data = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Public
constructor&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="di"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;DirectoryInfo to pull information from&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; DirectoryViewModel(&lt;span style="COLOR: #2b91af"&gt;DirectoryInfo&lt;/span&gt; di)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (di
== &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"di"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _data = di;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _files = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt;&amp;gt;
{ &lt;span style="COLOR: #2b91af"&gt;FileViewModel&lt;/span&gt;.MarkerFile };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _subdirs = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;&amp;gt;
{ &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;.MarkerDirectory };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This file is a bit more complicated – like the &lt;strong&gt;FileViewModel&lt;/strong&gt;, this
wraps a simple data object (a &lt;strong&gt;DirectoryInfo&lt;/strong&gt; in this case).&amp;nbsp;
Notice that it too exposes properties to provide access to various bits of information.&amp;nbsp;
Here you can see that it is creating new properties such as &lt;strong&gt;TotalFileSize&lt;/strong&gt; which
is the sum of all the files sizes in this directory.&amp;nbsp; That’s one of the jobs
of the ViewModel – to provide easily bindable properties for the bits of information
we want to display.&amp;nbsp; In this case, the &lt;strong&gt;TotalFiles&lt;/strong&gt; and &lt;strong&gt;TotalFileSize&lt;/strong&gt; gets
displayed in the &lt;strong&gt;StatusBar&lt;/strong&gt; of the window when the directory has files.
&lt;/p&gt;
&lt;p&gt;
Notice that the directory exposes files and subdirectories in &lt;strong&gt;ObservableCollections&lt;/strong&gt; –
but they are delay populated.&amp;nbsp; This is done so that the &lt;strong&gt;TreeView&lt;/strong&gt; comes
up quickly and we don’t have to enumerate the entire disk to retrieve the directories
and files!&amp;nbsp; When you expand and collapse the nodes in the tree, it is populating
the data.&amp;nbsp; This is done through the &lt;strong&gt;IsExpanded&lt;/strong&gt; property – if
you look back in the View, you will see that the &lt;strong&gt;TreeView&lt;/strong&gt; actually
binds the &lt;strong&gt;TreeViewItem.IsExpanded&lt;/strong&gt; to this property:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs28 \cf1 &amp;lt;\cf3 TreeView\cf4  Grid.Column\cf1 ="0"\cf4  ItemsSource\cf1 ="\{\cf3 Binding\cf4  RootDirectory\cf1 \}"\cf0  \par ??                 \cf4  ItemTemplate\cf1 ="\{\cf3 StaticResource\cf4  DirectoryTemplate\cf1 \}"&amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 TreeView.ItemContainerStyle\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="TreeViewItem"&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="IsSelected"\cf4  Value\cf1 ="\{\cf3 Binding\cf4  IsSelected\cf1 ,\cf4  Mode\cf1 =TwoWay\}" /&amp;gt;\par ??\cf3                         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="IsExpanded"\cf4  Value\cf1 ="\{\cf3 Binding\cf4  IsExpanded\cf1 ,\cf4  Mode\cf1 =TwoWay\}" /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 TreeView.ItemContainerStyle\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 TreeView\cf1 &amp;gt;}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TreeView&lt;/span&gt;&lt;span style="COLOR: red"&gt; Grid.Column&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="0"&lt;/span&gt;&lt;span style="COLOR: red"&gt; ItemsSource&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; RootDirectory&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;ItemTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="COLOR: red"&gt; DirectoryTemplate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;}"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TreeView.ItemContainerStyle&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: red"&gt; TargetType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="TreeViewItem"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="IsSelected"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; IsSelected&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; Mode&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=TwoWay}"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;u&gt;&lt;em&gt;&amp;lt;&lt;/em&gt;&lt;/u&gt;&lt;/span&gt;&lt;u&gt;&lt;em&gt;&lt;span style="COLOR: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="COLOR: red"&gt; Property&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="IsExpanded"&lt;/span&gt;&lt;span style="COLOR: red"&gt; Value&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="{&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Binding&lt;/span&gt;&lt;span style="COLOR: red"&gt; IsExpanded&lt;/span&gt;&lt;span style="COLOR: blue"&gt;,&lt;/span&gt;&lt;span style="COLOR: red"&gt; Mode&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=TwoWay}"
/&amp;gt;&lt;/span&gt;&lt;/em&gt;&lt;/u&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Style&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TreeView.ItemContainerStyle&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;TreeView&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Notice it also binds up the &lt;strong&gt;IsSelected&lt;/strong&gt; property – this is when we
populate the files collection.&amp;nbsp; Since they are observable, they will force the
UI to update when new items are added or removed and we see the Explorer effect we
desire.
&lt;/p&gt;
&lt;p&gt;
Lastly, before we leave this file, notice that when a directory is selected, it makes
a method call to a function called &lt;strong&gt;SendMessage&lt;/strong&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;SendMessage(SelectedDirectoryChangedMessage, &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;);&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
It passes a string (the key) and an object (the data).&amp;nbsp; This is a built-in service
of the &lt;strong&gt;ViewModel&lt;/strong&gt; base class and it’s the reason why this ViewModel
does not derive from &lt;strong&gt;SimpleViewModel&lt;/strong&gt;, but instead from &lt;strong&gt;ViewModel&lt;/strong&gt; which
is the full version.&amp;nbsp; One of the services provided is a &lt;em&gt;Message Mediator&lt;/em&gt;.&amp;nbsp;
This service basically allows you to loosely couple various objects together – we’ll
see how the target registers, but for now, just notice the sender – it passes a string
key and an object.&amp;nbsp; Any target registered for the given key will receive the
object.&amp;nbsp; There are several overrides for the message mediator which I’ll detail
in a later post.
&lt;/p&gt;
&lt;p&gt;
Ok, let’s switch to the final file – the MainViewModel:
&lt;/p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;\red163\green21\blue21;}??\fs28     \cf3 public\cf0  \cf3 class\cf0  \cf4 MainViewModel\cf0  : \cf4 ViewModel\par ??\cf0     \{\par ??\cf3         #region\cf0  Internal Data\par ??        \cf3 private\cf0  \cf4 DirectoryViewModel\cf0  _selectedDirectory;\par ??\cf3         #endregion\par ??\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Root directory - can be bound to an ItemsControl on the UI.\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  \cf4 DirectoryViewModel\cf0 [] RootDirectory \{ \cf3 get\cf0 ; \cf3 private\cf0  \cf3 set\cf0 ; \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Selected (active) directory\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  \cf4 DirectoryViewModel\cf0  SelectedDirectory\par ??        \{\par ??            \cf3 get\cf0  \{ \cf3 return\cf0  _selectedDirectory; \}\par ??            \cf3 set\cf0  \{ _selectedDirectory = \cf3 value\cf0 ; OnPropertyChanged(\cf7 "SelectedDirectory"\cf0 ); \}\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Command to display the About Box.\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  \cf4 ICommand\cf0  DisplayAboutCommand \{ \cf3 get\cf0 ; \cf3 private\cf0  \cf3 set\cf0 ; \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Command to end the application\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  \cf4 ICommand\cf0  CloseAppCommand \{ \cf3 get\cf0 ; \cf3 private\cf0  \cf3 set\cf0 ; \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  Main constructor\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 public\cf0  MainViewModel()\par ??        \{\par ??            \cf6 // Register this instance with the message mediator so it can receive\par ??\cf0             \cf6 // messages from other views/viewmodels.\par ??\cf0             RegisterWithMessageMediator();\par ??\par ??            \cf6 // Create our commands\par ??\cf0             DisplayAboutCommand = \cf3 new\cf0  \cf4 DelegatingCommand\cf0 (OnShowAbout);\par ??            CloseAppCommand = \cf3 new\cf0  \cf4 DelegatingCommand\cf0 (OnCloseApp);\par ??\par ??            \cf6 // Fill in the root directory from C:\par ??\cf0             RootDirectory = \cf3 new\cf0 [] \{ \cf3 new\cf0  \cf4 DirectoryViewModel\cf0 (\cf3 new\cf0  \cf4 DirectoryInfo\cf0 (\cf7 @"C:\\"\cf0 )) \{ IsSelected = \cf3 true\cf0  \} \};\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  This method closes the application window.\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 private\cf0  \cf3 void\cf0  OnCloseApp()\par ??        \{\par ??            \cf6 // Ask the view to close.\par ??\cf0             RaiseCloseRequest();\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  This method displays the About Box.\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf3 private\cf0  \cf3 void\cf0  OnShowAbout()\par ??        \{\par ??            \cf6 // Get the message visualizer service from the service resolver.\par ??\cf0             \cf6 // All services can be replaced, so make sure to check if we have something\par ??\cf0             \cf6 // registered.\par ??\cf0             \cf4 IMessageVisualizer\cf0  messageVisualizer = Resolve&amp;lt;\cf4 IMessageVisualizer\cf0 &amp;gt;();\par ??            \cf3 if\cf0  (messageVisualizer != \cf3 null\cf0 )\par ??            \{\par ??                \cf6 // Show a message box.\par ??\cf0                 messageVisualizer.Show(\cf7 "About File Explorer Sample"\cf0 , \cf7 "File Explorer Sample 1.0"\cf0 , \cf4 MessageButtons\cf0 .OK);\par ??            \}\par ??        \}\par ??\par ??        \cf5 ///\cf6  \cf5 &amp;lt;summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  This method is invoked by the message mediator when a DirectoryViewModel is selected.\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;/summary&amp;gt;\par ??\cf0         \cf5 ///\cf6  \cf5 &amp;lt;param name="newDirectory"&amp;gt;\cf6 DirectoryViewModel that is now active\cf5 &amp;lt;/param&amp;gt;\par ??\cf0         [\cf4 MessageMediatorTarget\cf0 (\cf4 DirectoryViewModel\cf0 .SelectedDirectoryChangedMessage)]\par ??        \cf3 private\cf0  \cf3 void\cf0  OnCurrentDirectoryChanged(\cf4 DirectoryViewModel\cf0  newDirectory)\par ??        \{\par ??            SelectedDirectory = newDirectory;\par ??        \}\par ??    \}\par ??}
--&gt;
&lt;div style="FONT-FAMILY: consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;MainViewModel&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;ViewModel&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt; _selectedDirectory;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Root
directory - can be bound to an ItemsControl on the UI.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;[]
RootDirectory { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Selected
(active) directory&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt; SelectedDirectory
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _selectedDirectory;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
_selectedDirectory = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; OnPropertyChanged(&lt;span style="COLOR: #a31515"&gt;"SelectedDirectory"&lt;/span&gt;);
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Command
to display the About Box.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ICommand&lt;/span&gt; DisplayAboutCommand
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Command
to end the application&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ICommand&lt;/span&gt; CloseAppCommand
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Main
constructor&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; MainViewModel()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Register this instance with the message mediator so it can receive&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
messages from other views/viewmodels.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RegisterWithMessageMediator();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Create our commands&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DisplayAboutCommand
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DelegatingCommand&lt;/span&gt;(OnShowAbout);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CloseAppCommand
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DelegatingCommand&lt;/span&gt;(OnCloseApp);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Fill in the root directory from C:&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RootDirectory = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt;[]
{ &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DirectoryInfo&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;@"C:\"&lt;/span&gt;))
{ IsSelected = &lt;span style="COLOR: blue"&gt;true&lt;/span&gt; } };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; This
method closes the application window.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; OnCloseApp()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Ask the view to close.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RaiseCloseRequest();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; This
method displays the About Box.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; OnShowAbout()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Get the message visualizer service from the service resolver.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
All services can be replaced, so make sure to check if we have something&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
registered.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;IMessageVisualizer&lt;/span&gt; messageVisualizer
= Resolve&amp;lt;&lt;span style="COLOR: #2b91af"&gt;IMessageVisualizer&lt;/span&gt;&amp;gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (messageVisualizer
!= &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Show a message box.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
messageVisualizer.Show(&lt;span style="COLOR: #a31515"&gt;"About File Explorer Sample"&lt;/span&gt;, &lt;span style="COLOR: #a31515"&gt;"File
Explorer Sample 1.0"&lt;/span&gt;, &lt;span style="COLOR: #2b91af"&gt;MessageButtons&lt;/span&gt;.OK);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; This
method is invoked by the message mediator when a DirectoryViewModel is selected.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="newDirectory"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;DirectoryViewModel that is
now active&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;MessageMediatorTarget&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt;.SelectedDirectoryChangedMessage)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; OnCurrentDirectoryChanged(&lt;span style="COLOR: #2b91af"&gt;DirectoryViewModel&lt;/span&gt; newDirectory)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedDirectory
= newDirectory;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Here you can see the same basic principle – it exposes properties the UI binds to.&amp;nbsp;
In particular here we see Commands being exposed as properties.&amp;nbsp; Commands is
what drives a UI – it allows a UI to trigger actions in the ViewModel.&amp;nbsp; We are
using two basic commands here – &lt;strong&gt;CloseAppCommand&lt;/strong&gt; and &lt;strong&gt;DisplayAboutCommand&lt;/strong&gt;.&amp;nbsp;
If you look at the constructor, you will see they are backed by a &lt;strong&gt;DelegatingCommand&lt;/strong&gt; object.&amp;nbsp;
This is a common pattern found in almost every MVVM framework out there, but it’s
essentially a pair of delegates that are called when the command is checked and when
it is invoked.&amp;nbsp; In our cases here, we always allow the command to execute so
we only provide the execution handler (a second parameter would define the typical &lt;strong&gt;CanExecute&lt;/strong&gt; handler).&amp;nbsp;
There are a couple of overrides for this object as well – one that provides type safety
for the parameter and one that always uses object and allows for any object as data.&amp;nbsp;
Again here we are being simple and not using any parameters so our bound methods are
both no-parameter methods.
&lt;/p&gt;
&lt;p&gt;
The &lt;strong&gt;CloseAppCommand &lt;/strong&gt;command invokes the &lt;strong&gt;OnCloseApp&lt;/strong&gt; method
– which in turn calls &lt;strong&gt;RaiseCloseRequest&lt;/strong&gt;.&amp;nbsp; This JulMar ViewModel
method will close the view associated with the ViewModel &lt;em&gt;if you associated the
two using the &lt;strong&gt;ViewModelCreator&lt;/strong&gt;&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;
The &lt;strong&gt;OnShowAbout&lt;/strong&gt; method is called by the &lt;strong&gt;DisplayAboutCommand.&amp;nbsp; &lt;/strong&gt;It
uses another registered service in the library called &lt;strong&gt;IMessageVisualizer&lt;/strong&gt;.&amp;nbsp;
The message visualizer is used to display a simple message box from the ViewModel.&amp;nbsp;
Here we use it to display an about box.&amp;nbsp; There are several other services I’ll
talk about in the next post.
&lt;/p&gt;
&lt;p&gt;
Notice that the &lt;strong&gt;RootDirectory&lt;/strong&gt; property which is data bound to the &lt;strong&gt;TreeView.ItemsSource&lt;/strong&gt; is
exposes as an array – this is because the &lt;strong&gt;TreeView&lt;/strong&gt; always expects
a collection of items even though we always have a single root item.&amp;nbsp; So we wrap
a single &lt;strong&gt;DirectoryViewModel&lt;/strong&gt; into a collection and return it as the
property.
&lt;/p&gt;
&lt;p&gt;
If you look at the end of the file you will find our message mediator target – &lt;strong&gt;OnCurrentDirectoryChanged&lt;/strong&gt;.&amp;nbsp;
We use this as a way to see when a new directory has been selected in the tree.&amp;nbsp;
For a &lt;strong&gt;ListBox&lt;/strong&gt;, we could&amp;nbsp; have just data bound the &lt;strong&gt;SelectedItem&lt;/strong&gt; to
the property, but &lt;strong&gt;TreeView&lt;/strong&gt; isn’t a selector and doesn’t expose a &lt;strong&gt;SelectedItem&lt;/strong&gt; property.&amp;nbsp;
Instead you either have to catch an event (I’ll show how you can do that in a future
blog entry about the MVVM helpers library) or use this little mediator trick.
&lt;/p&gt;
&lt;p&gt;
The &lt;strong&gt;[MessageMediatorTarget]&lt;/strong&gt; attribute is the secret sauce here –
it tells the message mediator to wire this method up to the passed string key.&amp;nbsp;
When that key is used in a &lt;strong&gt;SendMessage&lt;/strong&gt; call &lt;em&gt;and&lt;/em&gt; the parameter
type is a &lt;strong&gt;DirectoryViewModel&lt;/strong&gt; (or derived type), the mediator will
invoke this method.&amp;nbsp; This all happens without any direct linkage between the &lt;strong&gt;DirectoryViewModel&lt;/strong&gt; and
the &lt;strong&gt;MainViewModel&lt;/strong&gt;.&amp;nbsp; The delegate instance is held in a weak
reference so there’s no concern for memory leaks.
&lt;/p&gt;
&lt;p&gt;
The second part of the magic is in the constructor – the message mediator is an opt-in
service, so notice the call to &lt;strong&gt;RegisterWithMessageMediator()&lt;/strong&gt;.&amp;nbsp;
This is what causes this instance to be noticed by the mediator.&amp;nbsp; There is a
balancing &lt;strong&gt;UnregisterWithMessageMediator&lt;/strong&gt; if you ever want to unhook
the instance.&amp;nbsp; You can also use methods to directly wire up handlers (without
attributes).&amp;nbsp; This is useful when you are dynamically linking things together
at runtime vs. compile time.
&lt;/p&gt;
&lt;p&gt;
Well, that covers the basics of the framework Views + ViewModels.&amp;nbsp; In the next
post, I will detail the service registration and basic service mechanism that’s built
into the framework for you to use.&amp;nbsp; Until then, ciao!
&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>MVVM Helpers Project Template</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/01/20/MVVMHelpersProjectTemplate.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,f4fd7f33-fba2-472e-8491-8b5a7ee06000.aspx</id>
    <published>2010-01-20T15:35:13.245-08:00</published>
    <updated>2010-01-20T15:39:41.6222825-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">To start off this new series, I have created
a MVVM Helpers project template - this is a Visual Studio 2008 template which will
create the starter project I will be using as an example. It shows off the primary
usage of the MVVM library and has directories and references to required assemblies
already established so it's a nice starting point for any MVVM WPF app using the helpers. 
<br /><br />
Download it from <a href="http://www.julmar.com/samples/WpfMvvmApplication.zip">here</a> and
copy the zip file into your template directory. 
<br /><br />
As an example, if your user name was "Mark", like me and you are running Windows 7
it would be: 
<div><strong>"C:\Users\Mark\Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual
C#\Windows"</strong></div><br />
Here's what my directory looks like: 
<br /><br /><img border="0" alt="templatedir.jpg" align="center" src="http://www.julmar.com/blog/mark/content/binary/images/templatedir.jpg" width="500" /><p>
With that in place you should be able to fire up Visual Studio 2008 and create a sample
MVVM project: 
</p><p><img border="0" alt="project_screen.jpg" align="center" src="http://www.julmar.com/blog/mark/content/binary/images/project_screen.jpg" width="500" /></p><p>
Let it generate a project and the build it -- running the program will give you a
simple file explorer using the MVVM design pattern and WPF:
</p><p>
 <img border="0" alt="sample-run1.jpg" align="center" src="http://www.julmar.com/blog/mark/content/binary/images/sample-run1.jpg" width="700" />  
</p><p>
In tomorrow's post, we'll break the sample down and see how I built it. See you then! 
</p><p>
 
</p></div>
    </content>
  </entry>
  <entry>
    <title>MVVM Helpers 1.05</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2010/01/20/MVVMHelpers105.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,8913b470-bc63-4c27-b8c0-48af7ef1093e.aspx</id>
    <published>2010-01-20T12:22:12.233-08:00</published>
    <updated>2010-01-20T15:42:10.920113-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
With this post I am starting a new series - I hope to be more consistent in posting
at least once or twice a week. To that end, I am going to focus on the WPF/MVVM helper
library I use daily. I released an earlier version of it onto the web and have gotten
a lot of comments which has been great, so I am releasing the latest version which
has a <strong>lot</strong> of changes. So, without further ado, here's the code for
you to download and play with, this compiles with <strong>Visual Studio 2008 SP1</strong>,
or with <strong>Visual Studio 2010 Beta 2</strong>. 
</p>
        <p>
          <a href="http://www.julmar.com/samples/mvvmhelpers.zip">mvvmhelpers.zip</a>
        </p>
        <p>
Read on for the basics of the project structure and files. 
</p>
        <h2>Project Structure
</h2>
        <div>The code is broken into two assemblies: <strong>Julmar.Wpf.Helpers</strong> and <strong>Julmar.Wpf.Behaviors</strong>.
The helpers assembly contains core WPF helper classes and MVVM support and the behaviors
assembly depends on the <strong>System.Windows.Interactivity</strong> support and
provides Blend-based behaviors for a variety of situations. 
</div>
        <table>
          <tbody>
            <tr>
              <td valign="top" width="400">
                <h3>Building and Usage
</h3>
There are pre-built assemblies included in the distribution, but you are free to build
the source on your own - I don't include the certificate file (so I can tell versions
that I have built) but you are free to delete the certificate from the solution or
replace it with your own and build your own binaries from the source code. Or you
can take any of the source code, modify it however you like and add it directly to
your project. 
<h3>Credits
</h3>
As with most projects, this library has benefited significantly from the community.
The WPF Disciples list on has been a particular source for ideas and even source code.
There are some source files in the project that I did not author, or where I took
a bit of code and modified it to suit my purposes. I have tried to make sure people
get credit where appropriate in the source code itself, if I missed anyone I am truly
sorry. 
<h3>Documentation
</h3>
As I mentioned earlier, my goal is to produce a set of blog posts that detail how
to use the library, but there is also some documentation on each class included in
the distribution in the form of a .CHM (Windows Help File). I encourage anyone who
wants to use this library to check that out. 
</td>
              <td valign="top">
                <img border="0" alt="Solution.jpg" align="center" src="http://www.julmar.com/blog/mark/content/binary/images/Solution.jpg" width="322" height="543" />
              </td>
            </tr>
          </tbody>
        </table>
        <br />
      </div>
    </content>
  </entry>
  <entry>
    <title>Deferred bindings in WPF (ala Deferred Scrolling)</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/08/11/DeferredBindingsInWPFAlaDeferredScrolling.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,a5520286-2d34-4cde-9a37-fa4dca818cdd.aspx</id>
    <published>2009-08-11T15:54:00.9977126-07:00</published>
    <updated>2009-08-11T15:54:00.9977126-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the new features added to WPF 3.5 SP1 was the <strong>ScrollViewer.IsDeferredScrollingEnabled</strong> property
which allows you to scroll through large amounts of data without taking the actual
scrolling hit until the user stops moving the scroll thumb.  This is essential
when you have complex visualizations, or if the data itself is virtualized and the
load time is expensive.  You can get information on this feature here:
</p>
        <p>
          <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.isdeferredscrollingenabled.aspx">http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.isdeferredscrollingenabled.aspx</a>
        </p>
        <p>
Recently, I was working on a project where I have a Slider that is controlling a grouping
option.  When the user changes the slider value, the visuals are regrouped based
on the position of the slider itself.  The problem I ran into was it's an expensive
operation to do the grouping and if the user tries to quickly drag the slider I ended
up doing a whole bunch of non-essential groupings of my data for no reason. 
They are expensive enough that the actual drag of the slider was impacted by it -
not to mention the CPU and rendering!  So, my initial response in these situations
is to turn on asynchronous data binding - that's as simple as throwing the <strong>Binding.IsAsync </strong>flag. 
This essentially causes the binding transfer to occur on a background thread and will
often improve responsiveness in situations like this.
</p>
        <p>
          <img border="0" src="http://www.julmar.com/blog/mark/content/binary/TaxViewer1.jpg" />
        </p>
        <p>
In this case, however, it didn't really help because I was still doing all the intermediate
calculations.  What I really need is some way to <em>defer</em> the binding transfer
until the slider stops. There's no option for that however so I whipped up a
simple class which allows me to bind two properties together and place a timer between
them to indicate how long it should wait before transferring the <strong>Source</strong> to
the <strong>Target</strong>.  I could have done it in the code - it's just a
timer solution after all, but I wanted something reuseable.
</p>
        <p>
Here's an example usage:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">&lt;StackPanel&gt;
&lt;StackPanel.Resources&gt; &lt;DeferredBinder:DeferredBinding x:<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Key</span>="dbTest"
Timeout="1" /&gt; &lt;/StackPanel.Resources&gt; &lt;TextBlock x:Name="tb" <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Text</span>="{Binding
Source={StaticResource dbTest}, Path=Target}" FontSize="48pt" HorizontalAlignment="Center"
/&gt; &lt;Slider x:Name="slider" Margin="10" HorizontalAlignment="Center" Width="200"
Minimum="0" Maximum="100" Value="{Binding Source={StaticResource dbTest}, Path=Source,
Mode=OneWayToSource}" /&gt; &lt;/StackPanel&gt; </span>
        </pre>
        <p>
In this case, the slider's value is transferred 1 second after the final update (i.e.
it waits 1 second for the user to stop sliding).
</p>
        <p>
Here's a sample project to try out:
</p>
        <p>
          <a href="http://www.julmar.com/samples/DeferredBindingSample.zip">DeferredBindingSample.zip</a>
        </p>
        <p>
 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Correcting the WPF Themes</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/08/11/CorrectingTheWPFThemes.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,695a9497-12aa-48d8-881f-ac40bce1827f.aspx</id>
    <published>2009-08-11T09:30:13.4529638-07:00</published>
    <updated>2009-08-11T09:30:13.4529638-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm a big fan of themes in WPF -- and I think it's great that Microsoft has released
a whole set of themes for Silverlight and WPF at <a href="http://www.codeplex.com/wpf">www.codeplex.com/wpf</a></p>
        <p>
However, in using some of those themes, I've run into an annoying bug in the RadioButton
template - specifically, the checked state doesn't always show up initially. 
Looking at the template, it turns out to be an easy fix.  The "CheckIcon" is
set to an opacity of zero initially (so it's not shown) and then a trigger is used
to apply an animation to change the value.  Unfortunately, it looks like the
animation is switched - it applies when the checkbox is UNCHECKED vs. CHECKED. 
So, two ways to fix it -- either change the initial opacity to "1" for the "CheckIcon"
element in the control template, or go to the triggers in the control template for
the RadioButton and swap the states so it looks like this:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">&lt;<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Trigger</span> Property="IsChecked"
Value="false" /&gt; &lt;<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Trigger</span> Property="IsChecked"
Value="True"&gt; &lt;<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Trigger</span>.EnterActions&gt;
&lt;BeginStoryboard x:Name="CheckedOn_BeginStoryboard" Storyboard="{StaticResource
CheckedOn}"/&gt; &lt;/<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Trigger</span>.EnterActions&gt;
&lt;<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Trigger</span>.ExitActions&gt;
&lt;BeginStoryboard x:Name="CheckedOff_BeginStoryboard" Storyboard="{StaticResource
CheckedOff}"/&gt; &lt;/<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Trigger</span>.ExitActions&gt;<br /></span>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">&lt;/<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Trigger</span>&gt; </span>
        </pre>
      </div>
    </content>
  </entry>
  <entry>
    <title>MVVM Helpers v1.03</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/08/04/MVVMHelpersV103.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,27a95721-cf5e-4f75-9d90-d8ced629ae78.aspx</id>
    <published>2009-08-04T11:14:38.796-07:00</published>
    <updated>2009-08-04T11:14:56.702549-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <category term="MVVM" label="MVVM" scheme="http://www.julmar.com/blog/mark/CategoryView,category,MVVM.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just put the latest version of the MVVM helpers online - <a href="http://www.julmar.com/samples/mvvmhelpers.zip">mvvmhelpers.zip</a></p>
        <p>
There's a bunch of new stuff in it - check the release notes for the highlights. 
There's a set of breaking changes in it as well, specifically I've moved several of
the attached behaviors into the new Blend model.  Originally in my local version
I did it to the JulMar.Wpf.Helpers.dll and got a dependency against System.Windows.Interactivity.dll.
</p>
        <p>
I decided that for this release I didn't want to force that dependency so I created
a secondary assembly JulMar.Wpf.Behaviors.dll which has all those behaviors in it. 
The breaking change is I removed the original attached behaviors from the library
(DoubleClickBehavior, NumericTextBehavior, MouseDragBehavior) in favor of using these
new versions.  I did update the sample to show how they get used.
</p>
        <p>
In a recent Essential WPF class, one of the students wanted an ObservableDictionary
which we whipped up there - I cleaned up that implementation somewhat and added it
into this library along with some unit tests for it.
</p>
        <p>
Again, please check the readme included in the .zip file -- as always you are free
to do whatever you like with this code.  If you do anything interesting or fun,
let me know!
</p>
        <p>
 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Using Rx (Linq to Events) with WPF</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/08/03/UsingRxLinqToEventsWithWPF.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,43b8da4d-a392-46f9-9e03-939950798b41.aspx</id>
    <published>2009-08-03T08:56:03.910523-07:00</published>
    <updated>2009-08-03T08:56:03.910523-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A recent series of blog entries at <a href="http://themechanicalbride.blogspot.com/">http://themechanicalbride.blogspot.com/</a> introduced
the Rx framework (System.Reactive.dll) which is an assembly used in the Silverlight
toolkit for UI testing purposes.  It essentially provides a mechanism to do event
driven programming through LINQ.  I'll refer you to the blog referenced above
for all the gory details - frankly I'm still trying to wrap my mind around it!
</p>
        <p>
Silverlight isn't my favorite technology however, I much prefer working in WPF and
so I spent some time rebuilding Rx for the desktop CLR!  My original approach
was to take my favorite exploration tool, reflector (available for free from <a href="http://www.redgate.com">www.redgate.com</a>),
and disassemble all the classes into C#, placing them into a project file.  I
found however that Reflector choked on some of the more complicated structures - requiring
me to go and hand-edit a bunch of the code.  I realized while I was doing this
that there was a much easier way to convert a Silverlight assembly to a WPF assembly.
</p>
        <p>
As you probably already know, Silverlight shares the same assembly format as the desktop
CLR - there is no difference in the IL or structure of the assembly itself. 
The difference is in the dependency on mscorlib and other references.  Specifically,
when you add an assembly via VS2008, it looks at the <strong>version</strong> of the
referenced mscorlib to determine whether it's a desktop CLR assembly or Silverlight
assembly.  
</p>
        <p>
Here's the header of a Silverlight assembly examined through ILDASM:
</p>
        <font size="3">
          <p>
            <font face="Courier New">
              <strong>// Metadata version: v2.0.50727<br />
.assembly extern mscorlib<br />
{<br />
   .publickeytoken = (7C EC 85 D7 BE A7 79 8E ) // |.....y.<br />
   .ver 2:0:5:0<br />
}</strong>
            </font>
          </p>
          <p>
            <font size="2">Here is a desktop assembly:</font>
          </p>
          <p>
            <font face="Courier New">
              <strong>// Metadata version: v2.0.50727<br />
.assembly extern mscorlib<br />
{<br />
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                        
// .z\V.4..<br />
  .ver 2:0:0:0<br />
}<br /></strong>
            </font>
            <font face="Courier New">
              <font size="2" face="Verdana">
                <br />
Notice the version difference .. Silverlight uses 2.0.5.0 of mscorlib and the desktop
CLR uses 2.0.0.0.  The public key is also different, but this is really just
used for loading purposes.</font>
            </font>
          </p>
          <p>
            <font size="2">Assuming the assembly doesn't use something Silverlight specific, we
can modify the assembly references and allow the asembly to be used in the desktop
CLR fairly easily.  </font>
          </p>
          <p>
            <font size="2">Here's how I did it for System.Reactive.dll:</font>
          </p>
          <font face="Courier New">
            <p>
              <font size="2">
                <strong>ILDASM System.Reactive.dll /out:SR.il</strong>
              </font>
            </p>
            <p>
              <font size="2" face="Verdana">change the assembly references in the resulting IL text
file (for mscorlib, system and system.core)</font>
            </p>
            <p>
              <font size="2">
                <strong>ILASM SR.il /resource=sr.res /output=WPF/System.Reactive.dll</strong>
              </font>
            </p>
            <p>
              <font size="2" face="Verdana">That gave me a desktop version of the assembly without
modifying anything in the code itself - much easier than my original reflector route!</font>
            </p>
            <p>
              <font size="2" face="Verdana">Next, I took a couple of the samples from the blog and
ported them to WPF - specifically, I took the events sample listed here <a href="http://themechanicalbride.blogspot.com/2009/07/developing-with-rx-part-1-extension.html">http://themechanicalbride.blogspot.com/2009/07/developing-with-rx-part-1-extension.html</a> and
ported it to WPF to test it.  I made very few changes, primarily just switching
Application.Current.MainWindow for Application.Current.RootVisual.  Here is the
resulting project and switched assembly for anyone who is interested in it. </font>
            </p>
            <p>
              <a href="http://www.julmar.com/blog/mark/content/binary/ExtensionEvents.zip">ExtensionEvents.zip
(44.62 KB)</a>
            </p>
            <p>
              <font size="2" face="Verdana">I think Rx is a fascinating piece of code, although
it will take me a bit of time to realize just what I can do with it I suspect. 
I'm looking forward to building more with this using WPF now that's for sure!</font>
            </p>
          </font>
        </font>
      </div>
    </content>
  </entry>
  <entry>
    <title>Playing with WPF Behaviors - a WatermarkText behavior</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/07/24/PlayingWithWPFBehaviorsAWatermarkTextBehavior.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,7953f9ef-2003-444e-8f8a-f9a138bb030f.aspx</id>
    <published>2009-07-24T12:14:52.4417294-07:00</published>
    <updated>2009-07-24T12:14:52.4417294-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the coolest new features of Blend 3 is the inclusion of behaviors. This
new feature formalizes the "attached behavior" model that has become so prevelant
in WPF (and Silverlight) development.  I won't go into details on the architecture
- instead I'll refer you to a nice reference:
</p>
        <p>
          <a href="http://blogs.msdn.com/expression/archive/2009/05/19/link-round-up-behaviors-related-posts.aspx">http://blogs.msdn.com/expression/archive/2009/05/19/link-round-up-behaviors-related-posts.aspx</a>
        </p>
        <p>
To play with this new support, I built a WatermarkTextBehavior which places a watermark
into a TextBox when it has no entered data.  I've included this new behavior
into the current build of my MVVM toolkit which I'll release soon, but for now, let's
look at the behavior:
</p>
        <p>
First, we derive from <strong>System.Windows.Interactivity.Behavior&lt;T&gt;</strong> -
the placeholder parameter is the Visual type you want the behavior to act on. 
This can be <strong>UIElement</strong> for anything WPF, or more restrictive if necessary
based on the events you intend to hook up.  For our purposes here, we will set
the restricted type to <strong>TextBox</strong>.
</p>
        <font color="#0000ff" size="4">
          <font color="#0000ff" size="4">
            <p>
              <font size="3" face="Courier New">public</font>
            </p>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#000000">
            </font>
            <font color="#0000ff">
              <font color="#0000ff">class</font>
            </font>
            <font color="#000000">
            </font>
            <font color="#2b91af">
              <font color="#2b91af">WatermarkTextBehavior</font>
            </font>
            <font color="#000000"> : </font>
            <font color="#2b91af">
              <font color="#2b91af">Behavior</font>
            </font>
            <font color="#000000">&lt;</font>
            <font color="#2b91af">
              <font color="#2b91af">TextBox</font>
            </font>
            <font color="#000000">&gt;</font>
          </font>
          <font size="4">
          </font>
        </font>
        <p>
Next, you override the<strong> OnAttached()</strong> and<strong> OnDetaching()</strong> methods
to hook up your event behaviors you desire.  Call the base implementation first,
and then the <strong>AssociatedObject</strong> property will be the element you've
been attached to (the <strong>TextBox</strong> in this case).  In our case we
want to hook the <strong>GotFocus</strong> and <strong>LostFocus</strong> events -
this is where we trigger our behavior.
</p>
        <font color="#0000ff" size="4">
          <font color="#0000ff" size="4">
            <p>
              <font size="3" face="Courier New">protected</font>
            </p>
          </font>
        </font>
        <font size="3">
          <font face="Courier New">
            <font color="#000000">
            </font>
            <font color="#0000ff">
              <font color="#0000ff">override</font>
            </font>
            <font color="#000000">
            </font>
            <font color="#0000ff">
              <font color="#0000ff">void</font>
            </font>
          </font>
          <font color="#000000" face="Courier New"> OnAttached()<br /></font>
        </font>
        <font size="3" face="Courier New">{<br />
   </font>
        <font size="3">
          <font color="#0000ff">
            <font color="#0000ff" face="Courier New">base</font>
          </font>
          <font face="Courier New">.OnAttached();<br />
   </font>
        </font>
        <font size="3" face="Courier New">AssociatedObject.GotFocus
+= OnGotFocus;<br />
   </font>
        <font size="3" face="Courier New">AssociatedObject.LostFocus +=
OnLostFocus;<br />
   </font>
        <font size="3">
          <font face="Courier New">...</font>
          <font face="Courier New">
            <br />
          </font>
        </font>
        <font size="3" face="Courier New">}</font>
        <font size="3" face="Courier New">
          <font color="#0000ff" size="4">
            <font color="#0000ff" size="4">
              <p>
                <font size="3">protected</font>
              </p>
            </font>
          </font>
          <font color="#000000">
          </font>
          <font color="#0000ff">
            <font color="#0000ff">override</font>
          </font>
          <font color="#000000">
          </font>
          <font color="#0000ff">
            <font color="#0000ff">void</font>
          </font>
          <font color="#000000"> OnDetaching()<br /></font>{<br /><font color="#0000ff"><font color="#0000ff">   base</font></font>.OnDetaching();<br />
   AssociatedObject.GotFocus -= OnGotFocus;<br />
   AssociatedObject.LostFocus -= OnLostFocus;<br />
}
</font>
        <p>
Finally, we can provide any properties necessary to drive our behavior.  These
should be done in the form of Dependency Properties so they are bindable and interact
nicely with WPF.  The base<strong> Behavior&lt;T&gt;</strong> derives from <strong>Freezable</strong> and
inherits the DataContext automatically to enable this support.  In our implementation
we will have a Text property to indicate the watermark, and an attached property which
we will place onto the TextBox so it can be styled when the watermark is being used.
</p>
        <font size="4">
          <p>
          </p>
        </font>
        <font size="3">
          <font face="Courier New">
            <font color="#0000ff">
              <font color="#0000ff">public</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">static</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">readonly</font>
            </font>
            <font color="#2b91af">
              <font color="#2b91af">DependencyProperty</font>
            </font>
          </font>
          <font face="Courier New"> TextProperty
=<br />
   </font>
        </font>
        <font size="3">
          <font face="Courier New">
            <font color="#2b91af">
              <font color="#2b91af">DependencyProperty</font>
            </font>.Register(<font color="#a31515"><font color="#a31515">"Text"</font></font>, <font color="#0000ff"><font color="#0000ff">typeof</font></font> (<font color="#0000ff"><font color="#0000ff">string</font></font>), <font color="#0000ff"><font color="#0000ff">typeof</font></font> (<font color="#2b91af"><font color="#2b91af">WatermarkTextBehavior</font></font></font>
          <font face="Courier New">),<br />
                      </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">new</font>
            </font>
            <font color="#2b91af">
              <font color="#2b91af">FrameworkPropertyMetadata</font>
            </font>(<font color="#0000ff"><font color="#0000ff">string</font></font>.Empty));</font>
        </font>
        <p>
Next we can hook it up in Blend through the Asset panel - all known assets are shown
here (either registered, in the Blend directory, or project references).  Drag
our <strong>WatermarkTextBehavior</strong> onto any <strong>TextBox</strong> and set
the <strong>Text</strong> property and it will generate the following XAML:
</p>
        <font color="#a31515" size="4">
          <font color="#a31515" size="4">
            <p>
            </p>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">&lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">TextBox</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">  
&lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">TextBox.Style</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">     
&lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Style</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> TargetType</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="TextBox"</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> BasedOn</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="{</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">StaticResource</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff"> {</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">x</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">:</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Type</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> TextBox</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">}}"&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">        
&lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Style.Triggers</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">           
&lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Trigger</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> Property</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="julmar:WatermarkTextBehavior.IsWatermarked"</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> Value</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="True"&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">              
&lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Setter</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> Property</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="Foreground"</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> Value</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="Gray"
/&gt;</font>
            </font>
          </font>
        </font>
        <font color="#a31515">
          <font color="#a31515">
            <font size="3" face="Courier New"> <br /></font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">               &lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Setter</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> Property</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="FontStyle"</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> Value</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="Italic"
/&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">            &lt;/</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Trigger</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">         &lt;/</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Style.Triggers</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">      &lt;/</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Style</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">   &lt;/</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">TextBox.Style</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">  
&lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">i</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">:</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Interaction.Behaviors</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">     
&lt;</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">julmar</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">:</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">WatermarkTextBehavior</font>
            </font>
            <font color="#ff0000">
              <font color="#ff0000"> Text</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">="Enter
a name here" /&gt;<br /></font>
            </font>
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">  
&lt;/</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">i</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">:</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">Interaction.Behaviors</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;<br /></font>
            </font>
          </font>
        </font>
        <font color="#a31515">
          <font color="#a31515">
          </font>
        </font>
        <font face="Courier New">
          <font size="3">
            <font color="#0000ff">
              <font color="#0000ff">&lt;/</font>
            </font>
            <font color="#a31515">
              <font color="#a31515">TextBox</font>
            </font>
            <font color="#0000ff">
              <font color="#0000ff">&gt;
</font>
            </font>
          </font>
        </font>
        <p>
Here is the complete source code to the behavior:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Windows; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Windows.Controls; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.Windows.Interactivity; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">namespace</span> JulMar.Windows.Interactivity
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
This behavior associates a watermark onto a TextBox indicating what the user should</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
provide as input.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> WatermarkTextBehavior
: Behavior&lt;TextBox&gt; { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
The watermark text</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">static</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">readonly</span> DependencyProperty
TextProperty <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> DependencyProperty.Register(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Text"</span>, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>), <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span> (WatermarkTextBehavior), <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> FrameworkPropertyMetadata(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Empty)); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">static</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">readonly</span> DependencyPropertyKey
IsWatermarkedPropertyKey <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> DependencyProperty.RegisterAttachedReadOnly(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"IsWatermarked"</span>, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">bool</span>), <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(WatermarkTextBehavior), <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> FrameworkPropertyMetadata(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">false</span>)); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
This readonly property is applied to the TextBox and indicates whether the watermark</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
is currently being displayed. It allows a style to change the visual appearanve of
the</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
TextBox.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">static</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">readonly</span> DependencyProperty
IsWatermarkedProperty <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> IsWatermarkedPropertyKey.DependencyProperty; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
Retrieves the current watermarked state of the TextBox.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;param name="tb"&gt;&lt;/param&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;returns&gt;&lt;/returns&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">static</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">bool</span> GetIsWatermarked(TextBox
tb) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">bool</span>)
tb.GetValue(IsWatermarkedProperty); } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
Retrieves the current watermarked state of the TextBox.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">bool</span> IsWatermarked
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> GetIsWatermarked(AssociatedObject);
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span> set
{ AssociatedObject.SetValue(IsWatermarkedPropertyKey, value);} } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
The watermark text</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> Text
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">base</span>.GetValue(TextProperty);
} set { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">base</span>.SetValue(TextProperty,
value); } } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
Called after the behavior is attached to an AssociatedObject.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;remarks&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
Override this to hook up functionality to the AssociatedObject.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/remarks&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">protected</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">override</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> OnAttached()
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">base</span>.OnAttached();
AssociatedObject.GotFocus += OnGotFocus; AssociatedObject.LostFocus += OnLostFocus;
OnLostFocus(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">null</span>, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">null</span>);
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
Called when the behavior is being detached from its AssociatedObject, but before it
has actually occurred.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;remarks&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
Override this to unhook functionality from the AssociatedObject.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/remarks&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">protected</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">override</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> OnDetaching()
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">base</span>.OnDetaching();
AssociatedObject.GotFocus -= OnGotFocus; AssociatedObject.LostFocus -= OnLostFocus;
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
This method is called when the textbox gains focus. It removes the watermark.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;param name="sender"&gt;&lt;/param&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;param name="e"&gt;&lt;/param&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> OnGotFocus(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">object</span> sender,
RoutedEventArgs e) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Compare(AssociatedObject.Text, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">this</span>.Text,
StringComparison.OrdinalIgnoreCase) == 0) { AssociatedObject.Text <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Empty;
IsWatermarked <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">false</span>;
} } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
This method is called when focus is lost from the TextBox. It puts the watermark</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
into place if no text is in the textbox.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;/summary&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;param name="sender"&gt;&lt;/param&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">///
&lt;param name="e"&gt;&lt;/param&gt;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> OnLostFocus(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">object</span> sender,
RoutedEventArgs e) { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.IsNullOrEmpty(AssociatedObject.Text))
{ AssociatedObject.Text <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">this</span>.Text;
IsWatermarked <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">true</span>;
} } } } </span>
        </pre>
        <p>
 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Demos from last weeks WPF class</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/07/20/DemosFromLastWeeksWPFClass.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,2899284a-769d-4fbf-b623-a47503b3a20a.aspx</id>
    <published>2009-07-20T07:19:31.193-07:00</published>
    <updated>2009-07-20T07:19:31.1932082-07:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Thanks to all of you who attended my class last week in Chicago - here are the demos:
</p>
        <p>
          <a href="http://files.me.com/mark.c.smith/ty3x8t">files.me.com/mark.c.smith/ty3x8t</a>
        </p>
        <p>
and here is that final presentation which was not in the books:
</p>
        <p>
          <a href="http://files.me.com/mark.c.smith/0wdurs">files.me.com/mark.c.smith/0wdurs</a>
        </p>
        <p>
The password for both is your company name in lower case.
</p>
        <p>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>rCAT 1.0 beta is online</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/07/06/rCAT10BetaIsOnline.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,3e5e25ec-d3e6-4a15-9fbb-aeb7e354583e.aspx</id>
    <published>2009-07-06T11:24:44.087-07:00</published>
    <updated>2009-07-06T11:24:44.0877654-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="Real World" label="Real World" scheme="http://www.julmar.com/blog/mark/CategoryView,category,RealWorld.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A project I've been working on for the last two months is finally online in beta form
- check out
</p>
        <p>
          <a href="http://rcat.codeplex.com/">http://rcat.codeplex.com/</a>
        </p>
        <p>
It's essentially a biological alignment viewer for RNA sequences.  Here's a couple
of screen shots:
</p>
        <p>
          <strong>Alignment Viewer</strong>
        </p>
        <p>
          <img style="WIDTH: 648px; HEIGHT: 383px" border="0" src="http://www.julmar.com/blog/mark/content/binary/rCat001.jpg" width="830" height="488" />
        </p>
        <p>
          <strong>2D Structure Viewer</strong>
        </p>
        <p>
          <img style="WIDTH: 720px; HEIGHT: 441px" border="0" src="http://www.julmar.com/blog/mark/content/binary/rCat002.jpg" width="812" height="495" />
        </p>
        <p>
          <strong>2D Circle relationship Viewer</strong>
        </p>
        <p>
          <img style="WIDTH: 767px; HEIGHT: 403px" border="0" src="http://www.julmar.com/blog/mark/content/binary/rCat003.jpg" width="883" height="489" />
        </p>
        <p>
You can download the source code from the above link to play with it - it's a MVVM
implementation and has quite a bit of interesting optimizations in it for performance
purposes, including a read-only data virtualization for large sequence manipulation. 
The next release will include a full read/write implementation so watch the project
if you are interested!
</p>
        <p>
 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Menus and MVVM (2)</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/04/29/MenusAndMVVM2.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,f096a7d7-fdae-4e7b-ab43-70dadf817800.aspx</id>
    <published>2009-04-29T06:30:51.278-07:00</published>
    <updated>2009-04-29T07:08:04.7570279-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the previous post, I wrote about using the MVVM pattern with Context Menus, but
you can use it with top-level menus too -- for example, perhaps I'd like to manage
a set of options through a set of checkboxes.  First, let's start with my list
of options - for simplicity, we'll just make it an enumeration:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">enum</span> Test<br />
{<br />
   A,<br />
   B,<br />
   C,<br />
   D,<br />
   E,<br />
   F<br />
}</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Next,
let's define a ViewModel to wrap this - each entry should support a single value
and a boolean binding to determine whether it is checked:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> CheckValues<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span> Test Value { get; set; }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Text
{ get { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> Value.ToString();
} }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> IsChecked
{ get; set; }<br />
}<br /></span>
          </p>
        </span>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">Very
likely this object would also implement INotifyPropertyChanged and fire change notifications,
in this case it's not necessary since we aren't changing the values from code behind. 
The next step is to expose this as a bindable collection - since it's not changing
we'll just use a <strong>List&lt;T&gt;</strong>.</font>
            </span>
          </p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <p>
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public
List&lt;CheckValues&gt; EnumValues { get; set; }<br /></span>
              </p>
              <p>
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">...
</span>
              </p>
            </font>
          </span>
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <font color="#000000">EnumValues </font>=</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> List&lt;CheckValues&gt;();<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">foreach</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> t <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> Enum.GetValues(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">typeof</span> (Test)))<br />
{<br />
   EnumValues.Add(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> CheckValues
{Value <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (Test)
t});<br />
}</span>
          </p>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Finally,
in the XAML itself we want to databind to the collection of CheckValues, supplying
the appropriate support for each MenuItem to bind the menu checks to the collection:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;Menu
DockPanel.Dock="<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Top</span>"&gt;<br />
   &lt;MenuItem Header="Enum <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Values</span>"
ItemsSource="{Binding EnumValues}"&gt;<br />
      &lt;MenuItem.ItemContainerStyle&gt;<br />
         &lt;Style TargetType="MenuItem"&gt;<br />
            &lt;Setter Property="Header"
Value="{Binding <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Text</span>}"
/&gt;<br />
            &lt;Setter Property="IsCheckable"
Value="True" /&gt;<br />
            &lt;Setter Property="IsChecked"
Value="{Binding IsChecked}" /&gt;<br />
         &lt;/Style&gt;<br />
      &lt;/MenuItem.ItemContainerStyle&gt;<br />
   &lt;/MenuItem&gt;<br />
&lt;/Menu&gt;</span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">That
gives us our nice "checkable" menu - when the user clicks a checkmark, it sets the
appropriate boolean in the code behind which could trigger logic, set values, etc.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">But
wait!  Often with checkboxes you want mutual exclusive choices - like the RadioButton
groups.  This was a feature of Windows Forms which unfortunately did not make
it into WPF, but we can make it work that way.  We could use the above logic
and have the selection of a specific CheckValue unselect any others, or we could take
advantage of RadioButtons to do this -- unfortunately I've not found a way that doesn't
invoice a little code behind so it's not quite as clean as I'd like it to be, but
it is possible.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">First,
let's define an exclusive ViewModel object, here we will track the "current" selection:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> ExclusiveCheckValues<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span> Test
SelectedValue { get; set; }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span> Test Value { get; set; }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Text
{ get { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> Value.ToString();
} }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> IsChecked<br />
   {<br />
      get { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> Value
== SelectedValue; }<br />
      set<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        
if</span> (value)<br />
            SelectedValue <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Value;<br />
      }<br />
   }<br />
}<br /></span>
          </p>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Next,
we populate it into a bindable collection just as before and then we create some slightly
more complex XAML for our menu items.  The trick here is to put a RadioButton
into the menu item and associate it with a group.  I have to give a shout out
to Dr. WPF from the wpf-disciples list some kudos here - he posted this trick on the
MSDN forums (<a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/76c14163-9462-44d6-b0eb-6f22a006b423">http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/76c14163-9462-44d6-b0eb-6f22a006b423</a>). 
It turns out the MenuItem.Icon is positioned just where the normal check mark would
be so if we place a styled RadioButton as the MenuItem.Icon we can make it look just
like the checkmark:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;Menu
DockPanel.Dock="<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Top</span>"&gt;<br /><br />
   &lt;Menu.Resources&gt;<br />
      &lt;RadioButton x:<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Key</span>="rb"
x:Shared="false" HorizontalAlignment="<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Left</span>" 
<br />
                  
GroupName="MenuGroup" IsChecked="{Binding IsChecked}"&gt;<br />
         &lt;RadioButton.Template&gt;<br />
            &lt;ControlTemplate
TargetType="{x:Type RadioButton}"&gt;<br />
              
&lt;Path x:Name="<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">check</span>"
Margin="7,0,0,0" Visibility="Collapsed" VerticalAlignment="Center"<br />
                     
Fill="{TemplateBinding MenuItem.Foreground}" FlowDirection="LeftToRight"<br />
                     
Data="M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z"/&gt;<br />
              
&lt;ControlTemplate.Triggers&gt;<br />
                  
&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Trigger</span> Property="IsChecked"
Value="True"&gt;<br />
                     
&lt;Setter TargetName="<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">check</span>"
Property="Visibility" Value="Visible" /&gt;<br />
                  
&lt;/<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Trigger</span>&gt;<br />
                &lt;/ControlTemplate.Triggers&gt;<br />
             &lt;/ControlTemplate&gt;<br />
          &lt;/RadioButton.Template&gt;<br />
       &lt;/RadioButton&gt;<br />
    &lt;/Menu.Resources&gt;<br /><br />
    &lt;MenuItem Header="Single <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Select</span> Enum <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Values</span>"
ItemsSource="{Binding ExclusiveEnumValues}"&gt;<br />
       &lt;MenuItem.ItemContainerStyle&gt;<br />
          &lt;Style TargetType="MenuItem"&gt;<br />
             &lt;Setter
Property="Header" Value="{Binding <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Text</span>}"
/&gt;<br />
             &lt;Setter
Property="Icon" Value="{DynamicResource rb}" /&gt;<br />
             &lt;EventSetter
Event="Click" Handler="OnMenuItemClick" /&gt;<br />
          &lt;/Style&gt;<br />
       &lt;/MenuItem.ItemContainerStyle&gt;<br />
    &lt;/MenuItem&gt;<br />
&lt;/Menu&gt;</span>
          </p>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Here,
we've placed the RadioButton into our resources - but marked it as non-shareable. 
The issue is that Styles always share property setters - and if you tried to do this:</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <font face="Courier New">
                <font color="#000000">&lt;Style
TargetType="MenuItem"&gt;<br />
   &lt;Setter Property="Icon"</font>
                <font color="#000000">&gt;<br />
     &lt;Setter.Value&gt;<br />
       &lt;RadioButton ... /&gt;<br />
     &lt;/Setter.Value&gt;<br />
   &lt;/Setter&gt;</font>
              </font>
            </font>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <br />
            </font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">You
will get a very strange error message: "Cannot assigned type 'RadioButton' to type
'object'".  Which makes absolutely no sense until you realize the XAML parser
is trying to assign the <strong>same</strong> RadioButton to every MenuItem.Icon. 
The non-shareable resource fixes that issue.  The last step is to set the check
-- this is done through the EventSetter in the above template.  It's wired to
the little bit of code behind:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> OnMenuItemClick(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
RoutedEventArgs e)<br />
{<br />
   ((RadioButton) ((MenuItem) sender).Icon).IsChecked <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>;<br />
}<br /></span>
          </p>
        </span>
        <p>
          <font face="Verdana" color="#003300" size="2">This then sets the IsChecked property
which will, in turn, select that item.  Now you can look at <strong>ExclusiveCheckValue.SelectedValue</strong> to get
the current item.  This isn't the most elegant solution, nor is it the only solution
but it's an interesting one to think on.  If I were truly building this into
a production application, I'd probably look at controlling the selection in the ModelView
(i.e. enumerate through my other choices and deliberately turn them off). 
But this does illustrate how powerful WPF is! </font>
        </p>
        <p>
          <font face="Verdana" color="#003300" size="2">
            <a href="http://www.julmar.com/samples/menucheckbox.zip">Here's
the example project with both styles.</a>
          </font>
        </p>
        <p>
          <br />
 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Using MVVM with Menus in WPF</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/04/21/UsingMVVMWithMenusInWPF.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,4c8fb326-39fc-4ef2-8872-8128cc329bd9.aspx</id>
    <published>2009-04-21T15:35:59.426-07:00</published>
    <updated>2009-05-14T10:50:17.3589045-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
One question I've fielded a couple of times is how to manage menus, primarily context
menus, with the MVVM pattern.  It turns out to be pretty easy once you know the
"trick".  The key thing to keep in mind is that menus are just <strong>ItemsControls</strong> -
they support data templating and binding like any other ItemsControl.  However,
the part where people get lost is in hooking up the commands.  Here's the trick:
</p>
        <p>
          <strong>Step 1:</strong> Define some code behind construct to manage each menu item
in a hiearchial fashion.  Here's one I've used:
</p>
        <font size="4">
          <p>
          </p>
        </font>
        <font color="#0000ff">
          <font color="#0000ff">public</font>
        </font>
        <font color="#0000ff">
          <font color="#0000ff">class</font>
        </font>
        <font color="#2b91af">
          <font color="#2b91af">MenuItem<br /></font>
        </font>{<br />
   <font color="#0000ff"><font color="#0000ff">public</font></font><font color="#0000ff"><font color="#0000ff">string</font></font> Text
{ <font color="#0000ff"><font color="#0000ff">get</font></font>; <font color="#0000ff"><font color="#0000ff">set</font></font>;
}<br />
   <font color="#0000ff"><font color="#0000ff">public</font></font><font color="#2b91af"><font color="#2b91af">List</font></font>&lt;<font color="#2b91af"><font color="#2b91af">MenuItem</font></font>&gt;
Children { <font color="#0000ff"><font color="#0000ff">get</font></font>; <font color="#0000ff"><font color="#0000ff">private</font></font><font color="#0000ff"><font color="#0000ff">set</font></font>;
}<br />
   <font color="#0000ff"><font color="#0000ff">public</font></font><font color="#2b91af"><font color="#2b91af">ICommand</font></font> Command
{ <font color="#0000ff"><font color="#0000ff">get</font></font>; <font color="#0000ff"><font color="#0000ff">set</font></font>;
}<br />
   
<br />
   <font color="#0000ff"><font color="#0000ff">public</font></font> MenuItem(<font color="#0000ff"><font color="#0000ff">string</font></font> item) 
<br />
   {<br />
       Text = item; 
<br />
       Children = <font color="#0000ff"><font color="#0000ff">new</font></font><font color="#2b91af"><font color="#2b91af">List</font></font>&lt;<font color="#2b91af"><font color="#2b91af">MenuItem</font></font>&gt;();<br />
   }<br />
}
<span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><p></p></span></span><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font face="Verdana"><font size="2"><strong>Step
2:</strong> Create your menu structure using the above container.</font></font><p><font face="Verdana" size="2">This involves just creating a <strong>List&lt;MenuItem&gt;</strong> which
holds the root nodes and using a <strong>DelegatingCommand</strong> to wire up some
code behind method.  Here's an example:</font></p><font face="Verdana" size="2"><font size="4"><p></p></font><font color="#0000ff"><font color="#0000ff">public</font></font><font color="#2b91af"><font color="#2b91af">List</font></font>&lt;<font color="#2b91af"><font color="#2b91af">MenuItem</font></font>&gt;
MenuOptions<br />
{<br />
    <font color="#0000ff"><font color="#0000ff">get  </font></font>{
<p><font color="#0000ff"><font color="#0000ff">       var</font></font> menu
= <font color="#0000ff"><font color="#0000ff">new</font></font><font color="#2b91af"><font color="#2b91af">List</font></font>&lt;<font color="#2b91af"><font color="#2b91af">MenuItem</font></font>&gt;();<br />
       <font color="#0000ff"><font color="#0000ff">if</font></font> (SupportedFileFormats.Count
&gt; 0)<br />
      {<br />
          <font color="#0000ff"><font color="#0000ff">var</font></font> mi
= <font color="#0000ff"><font color="#0000ff">new</font></font><font color="#2b91af"><font color="#2b91af">MenuItem</font></font>(<font color="#a31515"><font color="#a31515">"O_pen"</font></font>);<br />
          <font color="#0000ff"><font color="#0000ff">foreach</font></font>(<font color="#0000ff"><font color="#0000ff">var</font></font> fl <font color="#0000ff"><font color="#0000ff">in</font></font> SupportedFileFormats)<br />
          {<br />
               var
sff = fl;<br />
              
mi.Children.Add(<font color="#0000ff"><font color="#0000ff">new</font></font><font color="#2b91af"><font color="#2b91af">MenuItem</font></font>(fl.Attributes.Description) <br />
                      {
Command = <font color="#0000ff"><font color="#0000ff">new</font></font><font color="#2b91af"><font color="#2b91af">DelegatingCommand</font></font>(()
=&gt; { LoadFromFormat(sff); })});<br />
          }<br />
          menu.Add(mi);<br />
       }
</p><p>
       menu.Add(<font color="#0000ff"><font color="#0000ff">new</font></font><font color="#2b91af"><font color="#2b91af">MenuItem</font></font>(<font color="#a31515"><font color="#a31515">"Close
_All"</font></font>) { Command = <font color="#0000ff"><font color="#0000ff">new</font></font><font color="#2b91af"><font color="#2b91af">DelegatingCommand</font></font>(OnCloseAll,
() =&gt; FileList.Count &gt; 0)});<br />
       <font color="#0000ff"><font color="#0000ff">return</font></font> menu;<br />
    }
</p><p>
}
</p></font></span><p><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font face="Verdana" color="#003300" size="2">Note
the use of an anonymous method to suck the correct file format into the command handler. 
A nice trick so the command is executed with some contextual information of what you
clicked on.</font></span></p><p><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font face="Verdana" color="#003300" size="2">Finally,
you need to setup the context menu style:</font></span></p><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font color="#a31515" size="4"><font color="#a31515" size="4"><p></p></font></font><strong><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Style</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> x</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">:</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4">Key</font></font></strong><strong><font color="#0000ff" size="4"><font color="#0000ff" size="4">="ContextMenuItemStyle"&gt;<br />
   </font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Setter</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Property</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="MenuItem.Header"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Value</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="{</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Binding</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Text</font></font></strong><strong><font color="#0000ff" size="4"><font color="#0000ff" size="4">}"/&gt;<br />
   </font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Setter</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Property</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="MenuItem.ItemsSource"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Value</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="{</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Binding</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Children</font></font></strong><strong><font color="#0000ff" size="4"><font color="#0000ff" size="4">}"/&gt;<br />
   </font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Setter</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Property</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="MenuItem.Command"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Value</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="{</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Binding</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Command</font></font></strong><strong><font color="#0000ff" size="4"><font color="#0000ff" size="4">}"
/&gt;<br /></font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;/</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Style</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&gt;</font></font></strong><p><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font face="Verdana" color="#003300" size="2">And
then use the style where you want the menu to appear:</font></span></p><font color="#a31515" size="4"><font color="#a31515" size="4"></font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4"></font></font><p><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">StackPanel</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Orientation</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="Horizontal"&gt;<br />
    </font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Image</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Source</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="{</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Binding</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Image</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">}"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Width</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="16"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Height</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="16"
/&gt;<br />
    </font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">TextBlock</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Margin</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="5"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> HorizontalAlignment</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="Left"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> VerticalAlignment</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="Center"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Text</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="{</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Binding</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> Header</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">}"
/&gt;<br />
    </font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">StackPanel.ContextMenu</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&gt;<br />
       </font></font><strong><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">ContextMenu</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> ItemContainerStyle</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="{</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">StaticResource</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> ContextMenuItemStyle</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">}"</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> ItemsSource</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">="{</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">Binding</font></font><font color="#ff0000" size="4"><font color="#ff0000" size="4"> MenuOptions</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">}"</font></font><font size="4"></font></strong><font color="#0000ff" size="4"><font color="#0000ff" size="4"><strong>/&gt;<br /></strong>    </font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;/</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">StackPanel.ContextMenu</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&gt;<br /></font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;/</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">StackPanel</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&gt;
</font></font></p><font color="#a31515" size="4"><font color="#a31515" size="4"><p></p></font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&lt;/</font></font><font color="#a31515" size="4"><font color="#a31515" size="4">HierarchicalDataTemplate</font></font><font color="#0000ff" size="4"><font color="#0000ff" size="4">&gt;
<p><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font face="Verdana" color="#003300" size="2">Now
the context menu is populated and properly dispatches to your ViewModel commands!</font></span></p><p><span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font face="Verdana" color="#003300" size="2"><strong>Edit:</strong> added
intermediate object in LINQ query to fix deferred query issue pointed out in comments.</font></span></p></font></font><br />
 
</span></div>
    </content>
  </entry>
  <entry>
    <title>More MVVM love</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/04/21/MoreMVVMLove.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,a53ec32e-5190-411e-9950-dfc3aedadb7e.aspx</id>
    <published>2009-04-21T12:29:47.183-07:00</published>
    <updated>2009-04-21T12:30:41.6835938-07:00</updated>
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently wrote about the mini-library I tend to use, but <b>Bill Kempf</b> (one
of the WPF disciples) released a MVVM library for WPF called <b>Onyx</b> which looks
very appealing. I especially like his use of static reflection to implement <b>INotifyPropertyChanged</b>.
Sweet Bill! Thanks for sharing! 
</p>
        <br />
        <p>
Check it out: <a href="http://www.codeplex.com/wpfonyx">WPF Onyx</a></p>
      </div>
    </content>
  </entry>
  <entry>
    <title>WPF MVVM Helper Library (WPF + MVVM = testability)</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/04/17/WPFMVVMHelperLibraryWPFMVVMTestability.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,8b3e4279-70a5-431e-8fa3-4c1e047df311.aspx</id>
    <published>2009-04-17T09:06:09.056-07:00</published>
    <updated>2009-04-29T06:35:11.5928493-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">&lt;p&gt;
There's been a lot of talk about the Model-View-ViewModel pattern recently and it's
usage around the WPF and Silverlight technology stack.&amp;nbsp; When teaching WPF, I
always introduce students to MVVM as part of the Essential WPF class, it's an incredibly
useful pattern that really separates the UI from the code behind behavior.&amp;nbsp; One
of the things I give the students is a library to do MVVM - I also use it in my consulting
work.&amp;nbsp; With all the focus on it lately, I figured maybe it's time to release
it to the public.
&lt;/p&gt;
&lt;p&gt;
A bit of history -- the library is really just a place where I dump all kinds of useful
utility classes, helpers, wrappers, etc. that I tend to use a lot.&amp;nbsp; I started
it about 3 years ago and&amp;nbsp;it wasn't originally intended to be just an MVVM implementation
so&amp;nbsp;you'll find it's got all kinds of stuff in it, not all of which is MVVM specific.&amp;nbsp;
It's evolution owes a lot to various blog posts, WPF Disciples, and other WPF leaders;
I certainly didn't invent anything radically new but borrowed heavily from all kinds
of places as I built various classes I needed for my own work.&amp;nbsp; These classes
tended to evolve with new functionality (either due to necessity, or because a good
idea occurred to me or someone else).&amp;nbsp;For example, there was a recent thread
on the Mediator pattern (initiated by Marlon Grech and added on by Josh Smith, Laurent
Bugnion and others); I already had a message mediator in place but the idea of using
an attribute to hook it up was a great one that I adopted into my library just because
I like the idea.&amp;nbsp; The Delegating command pattern is one you see in a lot of places
- including the Prism implementation.&amp;nbsp; The event routing attached behavior was
made possible by a couple of blog posts by Mike Hilberg and John Gossman.&amp;nbsp;So,
be aware that as you use this code, it owes a lot to a variety of people.&amp;nbsp; That
said, any bugs or issues are completely mine and I take full credit for them.
&lt;/p&gt;
&lt;p&gt;
So, what all is here?&amp;nbsp; Well, quite a bit.&amp;nbsp; As I said, this is a collection
of helpers I've built and reused over the years doing WPF consulting and instruction.&amp;nbsp;
When MVVM came to my notice I worked on trying to completely separate the XAML side
so I'll focus on those classes here.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
The basic idea is to derive your ViewModel classes from one of three base classes
depending on what you need:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;JulMar.Windows.Mvvm.ViewModel&lt;/strong&gt; - supports basic &lt;strong&gt;INotifyPropertyChanged&lt;/strong&gt; and
Close/Activate eventing to the view.&lt;br&gt;
&lt;strong&gt;JulMar.Windows.Mvvm.ValidatingViewModel&lt;/strong&gt; - supports everything above,
adds Validation through &lt;strong&gt;IDataErrorInfo&lt;/strong&gt;&amp;nbsp;support&lt;br&gt;
&lt;strong&gt;JulMar.Windows.Mvvm.EditingViewModel&lt;/strong&gt; - supports basic + validation
+ &lt;strong&gt;IEditableObject&lt;/strong&gt;
&lt;br&gt;
&lt;br&gt;
Next, in each view (XAML) you&amp;nbsp;set the DataContext property to your view model,
the library has a MarkupExtension to do the work for you - 
&lt;/p&gt;
&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt; 
&lt;p&gt;
&amp;lt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Window&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; x&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;Class&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="TestMvvm.MainWindow" 
&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;xmlns&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="&lt;a href="http://www.julmar.com/wpfhelpers"&gt;http://www.julmar.com/wpfhelpers&lt;/a&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;&amp;nbsp;
xmlns&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;me&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="clr-namespace:TestMvvm"&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;DataContext&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;ViewModelCreator&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; ViewModelType&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;={&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;x&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Type&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; me&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;WinViewModel&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}}"&amp;gt;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;
&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;
&lt;/p&gt;
&gt;&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
This creates the view and also wires up support for closing the view and activating
the view through the ViewModel class (using the &lt;strong&gt;RaiseCloseRequest&lt;/strong&gt; and &lt;strong&gt;RaiseActivateRequest&lt;/strong&gt; methods).
&lt;/p&gt;
&lt;p&gt;
Everything is driven off ICommand - you can bind commands to the lifetime of the view
(so you can detect activation, deactivation, loading, closing) through the &lt;strong&gt;LifetimeEvents&lt;/strong&gt; attached
behavior:
&lt;/p&gt;
&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt; 
&lt;p&gt;
&amp;lt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Window&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; x&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;Class&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="TestMvvm.MainWindow"&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;&amp;nbsp;&amp;nbsp; julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;LifetimeEvent.Activated&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Binding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; ActivatedCommand&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;LifetimeEvent.Close&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Binding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; CloseCommand&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;LifetimeEvent.Loaded&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Binding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; LoadedCommand&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt;LifetimeEvent.Deactivated&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Binding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; DeactivatedCommand&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"
&amp;gt;&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size=4&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p&gt;
These execute the bound command in the ViewModel when those events occur in the view.&amp;nbsp;
If you need other events styles you can use the EventCommander attached behavior which
allows any arbitrary event to be wired to a command.&amp;nbsp; This can be placed on any
UIElement:
&lt;/p&gt;
&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;EventCommander.Mappings&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;CommandEvent&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Command&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Binding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; MouseEnterCommand&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Event&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="MouseEnter"
/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;CommandEvent&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Command&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Binding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; MouseLeaveCommand&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Event&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="MouseLeave"
/&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&lt; FONT&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;EventCommander.Mappings&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;
&lt;font color=#000000 size=2&gt;You can also wire up keyboard and mouse gestures to commands
using the &lt;strong&gt;InputBinder&lt;/strong&gt; attached property:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;InputBinder.Bindings&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;KeyBinding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Command&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Binding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; ExitCommand&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Key&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="F3"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Modifiers&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="ALT"
/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;MouseBinding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Command&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Binding&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; ExitCommand&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Gesture&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="Control+RightClick"
/&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&lt; FONT&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;InputBinder.Bindings&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;gt;
&lt;/p&gt;
&lt;/font&gt;&gt; 
&lt;p&gt;
&lt;font color=#000000 size=2&gt;This replaces the traditional &lt;strong&gt;InputBindings&lt;/strong&gt; collection
with a data bindable version - it also supports &lt;strong&gt;CommandParameter&lt;/strong&gt; objects
on each &lt;strong&gt;KeyBinding&lt;/strong&gt; or &lt;strong&gt;MouseBinding&lt;/strong&gt;.&amp;nbsp; You can
use it on any element which supports input bindings. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;There are some helper classes implemented through interfaces
and a (very) simple &lt;strong&gt;ServiceProvider&lt;/strong&gt; to locate them:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2&gt;&lt;font color=#000000&gt;&lt;strong&gt;IErrorVisualizer &lt;/strong&gt;- to display errors
(title + message).&amp;nbsp; Default implementation displays MessageBox with OK button.&lt;br&gt;
&lt;strong&gt;IMessageVisualer&lt;/strong&gt; - to display messages with a prompt.&amp;nbsp; Default
implementation uses MessgeBox.&lt;br&gt;
&lt;strong&gt;INotificationVisualizer&lt;/strong&gt; - to display a wait prompt.&amp;nbsp; Default
implemation uses an hourglass cursor.&lt;br&gt;
&lt;strong&gt;IUIVisualizer&lt;/strong&gt; - to display other views through a key.&amp;nbsp; Supports
both modal and modaless display.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;You use the &lt;strong&gt;ServiceProvider&lt;/strong&gt; to find the
services - the base ViewModel class has support built in for it:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=4&gt;&lt;font color=#a31515&gt;Resolve&amp;lt;&lt;font color=#ff0000&gt;IErrorVisualizer&lt;/font&gt;&amp;gt;().Show&lt;font color=#0000ff&gt;("An
Error Occurred"&lt;/font&gt;, e.Description);&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;You can register the default implementation for all of
the above in the App.xaml.cs file - &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=4&gt;&lt;font color=#a31515&gt;ViewModel.RegisterKnownServiceTypes();&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;You can also provide your own implementation through the &lt;strong&gt;ServiceProvider &lt;/strong&gt;itself.&amp;nbsp;
The &lt;strong&gt;ViewModel&lt;/strong&gt; class has a public static field:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=4&gt;&lt;font color=#a31515&gt;ServiceProvider.Add(&lt;font color=#0000ff&gt;typeof&lt;/font&gt;(&lt;font color=#ff0000&gt;IErrorVisualizer&lt;/font&gt;), &lt;font color=#0000ff&gt;new&lt;/font&gt; &lt;font color=#ff0000&gt;MyErrorVisualizer&lt;/font&gt;());&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;This replaces or adds the given service (using the type
as the key) to the registry database.&amp;nbsp; You then use &lt;strong&gt;Resolve&lt;T&gt;
&lt;/strong&gt; to find the service at runtime in any view.&amp;nbsp; Creating secondary views
is done through the &lt;strong&gt;IUIVisualizer&lt;/strong&gt; interface.&amp;nbsp; The default implementation
provides a registry and must be added explicitly to use it:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=4&gt;&lt;font color=#a52a2a&gt;IUIVisualizer&lt;/font&gt;&amp;nbsp;&lt;font color=#ff0000&gt;controller&lt;/font&gt; = &lt;font color=#0000ff&gt;new&lt;/font&gt; &lt;font color=#a52a2a&gt;UIVisualizer&lt;/font&gt;(&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;STRING, Type&gt; Dictionary&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{Dialogs.AddNewPage, typeof(AddNewPageWindow)},&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{Dialogs.ManagePages, typeof(BrowseWindow)},&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{Dialogs.NewLogon, typeof(LoginDialog)}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
});&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=4&gt;&lt;font color=#a52a2a&gt;ServiceProvider.Add&lt;/font&gt;(&lt;font color=#0000ff&gt;typeof&lt;/font&gt;(&lt;font color=#ff0000&gt;IUIVisualizer&lt;/font&gt;), &lt;font color=#ff0000&gt;controller&lt;/font&gt;);&lt;br&gt;
&lt;/font&gt;
&lt;br&gt;
&lt;font color=#000000 size=2&gt;This adds three UI dialogs to the visualizer - the key
is a simple string, the second parameter is a &lt;strong&gt;Type&lt;/strong&gt; object that represents
the &lt;strong&gt;Window&lt;/strong&gt; to create.&amp;nbsp; You then get the window to display through
the &lt;strong&gt;IUIVisualizer&lt;/strong&gt; interface:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=4&gt;&lt;font color=#a52a2a&gt;LoginViewData&lt;/font&gt; ld = &lt;font color=#0000ff&gt;new&lt;/font&gt; LoginViewData();&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=4&gt;&lt;font color=#a52a2a&gt;IUIVisualizer&lt;/font&gt;&amp;nbsp;&lt;font color=#ff0000&gt;uiController&lt;/font&gt; = &lt;font color=#a52a2a&gt;ServiceProvider.Resolve&lt;IUIVISUALIZER &gt;
&lt;/font&gt;();&lt;br&gt;
if (&lt;font color=#ff0000&gt;uiController&lt;/font&gt;.ShowDialog(&lt;font color=#ff0000&gt;Dialogs.NewLogon&lt;/font&gt;, &lt;font color=#a52a2a&gt;ld&lt;/font&gt;).&lt;font color=#0000ff&gt;Value &lt;/font&gt;== &lt;font color=#0000ff&gt;true&lt;/font&gt;)&lt;br&gt;
{&lt;br&gt;
}&lt;br&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;This shows the login dialog, using the &lt;strong&gt;LoginViewData&lt;/strong&gt; as
the &lt;strong&gt;DataContext&lt;/strong&gt; (ViewModel).&amp;nbsp; It displays it as a modal dialog
and returns the final result.&amp;nbsp; You can also display modaless dialogs which take
an optional completion proc:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New" color=#000000 size=3&gt;&lt;strong&gt;public bool Show(string key,
object state, bool setOwner, EventHandler&lt;UICOMPLETEDEVENTARGS&gt;
completedProc)
&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;The completed procedure is invoked when/if the window ever
closes.&amp;nbsp; Again, the state passed is the data context and if it derives from ViewModel
the appropriate Closing/Activated events will be wired up to the events in the ViewModel.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;I've been using this library for quite a while and it works
great (for me).&amp;nbsp; I provide it here with full source code so you can diagnose
any issues you have, or just look through it.&amp;nbsp; Feel free to use it however you
like.&amp;nbsp; I don't claim this to be the end-all implementation - as I said much of
the ideas expressed in here&amp;nbsp;can be found&amp;nbsp;elsewhere. &amp;nbsp;There is also
a help file provided and a simple example of how to use some of the classes provided
that I whipped up for fun.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/samples/mvvmhelpers.zip"&gt;Here's the download with everything
packaged.&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;Enjoy - let me know if you have any issues or think of
a good addition!&amp;nbsp; Just remember I put no guarentee on this code - consider it
a sample for you to do whatever you like with.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000 size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;font color=#a52a2a&gt;&lt;/font&gt;&gt;&gt;</content>
  </entry>
  <entry>
    <title>Adding to an ObservableCollection from a background thread</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/04/01/AddingToAnObservableCollectionFromABackgroundThread.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,81cff507-980a-4086-bcd5-ece419ca33d4.aspx</id>
    <published>2009-04-01T10:17:37.33-07:00</published>
    <updated>2009-04-08T10:18:04.7677908-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
One annoying thing about <strong>ObservableCollection&lt;T&gt;</strong> is that it
doesn't support modifications from background threads.  That is to say, the <strong>CollectionChanged</strong> notification
doesn't marshal to the proper thread when it is raised and it causes the exception
"<strong>This type of CollectionView does not support changes to its SourceCollection
from a thread different from the Dispatcher thread</strong>".  
</p>
        <p>
I ran into this problem a while back and searched out to see if someone else had solved
it. I found a solution from Tamir Khason (a fellow WPF disciple), he wrote
a thread-safe version (<a href="http://blogs.microsoft.co.il/blogs/tamir/archive/2007/04/22/Thread-safe-observable-collection.aspx">http://blogs.microsoft.co.il/blogs/tamir/archive/2007/04/22/Thread-safe-observable-collection.aspx</a>),
but I didn't want to add the locking into the collection itself (I want to manage
it at a higher level myself).  Really, all I want is to do the notification on
the proper (Dispatcher) thread.  
</p>
        <p>
It turns out to be pretty easy, here's my solution:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> MTObservableCollection&lt;T&gt;
: ObservableCollection&lt;T&gt;<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">event</span> NotifyCollectionChangedEventHandler
CollectionChanged;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
protected</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> OnCollectionChanged(NotifyCollectionChangedEventArgs
e)<br />
   {<br />
      var eh <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> CollectionChanged;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
if</span> (eh !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
      {<br />
         Dispatcher dispatcher <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (from
NotifyCollectionChangedEventHandler nh <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> eh.GetInvocationList()<br />
                
let dpo <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> nh.Target <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">as</span> DispatcherObject<br />
                
where dpo !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span><br />
                
select dpo.Dispatcher).FirstOrDefault();<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">       
if</span> (dispatcher !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span> &amp;&amp;
dispatcher.CheckAccess() == <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">false</span>)<br />
        {<br />
           dispatcher.Invoke(DispatcherPriority.DataBind,
(Action)(() =&gt; OnCollectionChanged(e)));<br />
        }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        else</span><br />
        {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">          
foreach</span> (NotifyCollectionChangedEventHandler nh <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> eh.GetInvocationList())<br />
              nh.Invoke(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>,
e);<br />
        }<br />
     }<br />
  }<br /></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">}<br /></span>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>LINQ is just freaking cool</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/03/05/LINQIsJustFreakingCool.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,06efbdab-d87c-43d3-8f85-fbeadb197159.aspx</id>
    <published>2009-03-05T09:27:19.076-08:00</published>
    <updated>2009-03-05T09:29:08.7790956-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A couple of weeks ago, Jason Whittington (a fellow instructor at <a href="http://www.develop.com">Developmentor</a>) and
I were doing a talk on asynchronous programming and we started with a very simple
example of the APM -- using two loops to create and then consume the IAsyncResult
work:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> TwoLoopMain(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>[]
args)<br />
{<br />
   Queue&lt;IAsyncResult&gt; ars <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Queue&lt;IAsyncResult&gt;();<br />
   Func&lt;int,int,int&gt; mathProc <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Multiply;</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">for</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> i <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 1;
i &lt;= 20; i++)<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">    
 for</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> j <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 1;
j &lt;= 20; j++)<br />
         ars.Enqueue(mathProc.BeginInvoke(i,
j, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>));<br />
   }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
for</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> i <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 1;
i &lt;= 20; i++)<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      for</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> j <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 1;
j &lt;= 20; j++)<br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        
int</span> result <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> mathProc.EndInvoke(ars.Dequeue());<br />
         Console.SetCursorPosition(i <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">*</span> 3,
j);<br />
         Console.Write(result);<br />
     }<br />
  }<br />
}<br /><br /></span>
        </p>
        <p>
We had already presented a talk on LINQ earlier in the week and so I thought we might
be able to do the above in a single expression with LINQ - kind of a challenge ..
here's what we came up with:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> LinqTest()<br />
{<br />
   Func&lt;int,int,int&gt; mathProc <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Multiply;<br /><br />
   (from i <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> Enumerable.Range(1,
20)<br />
    from j <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> Enumerable.Range(1,
20)<br />
    select <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> {
i, j, ar <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> mathProc.BeginInvoke(i,
j, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)
})<br /></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
.ToList()<br />
      .ForEach(e =&gt; {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">       
int</span> result <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> mathProc.EndInvoke(e.ar);<br />
        Console.SetCursorPosition(e.i <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">*</span> 3,
e.j);<br />
        Console.Write(result);<br />
     });<br />
}<br /></span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">It's
not easily readable (and so I wouldn't promote this for production code), but it's
way cool and an example of how LINQ (and functional programming in general) is really
changing the way programmers think about code.. just freaking cool..</font>
            <br />
          </span>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Adding NAS folders to Windows 7 libraries</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/02/24/AddingNASFoldersToWindows7Libraries.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,da6b915b-69ea-4396-beae-cba2315bfce2.aspx</id>
    <published>2009-02-23T18:33:36.254-08:00</published>
    <updated>2009-02-23T18:36:02.5972254-08:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I use a lot of virtual machines - and it's always handy to store files onto the real
machine through shared folders. With Windows 7 and the new library feature I thought
it would be really cool to add the shares to the Documents Library but found that
the underlying system must be running Indexing Server 4.0 -- not an option for my
OSX based system! 
</p>
        <p>
Here's a nice little workaround that lets you add non-indexed folders though: 
</p>
To add a non-indexed UNC as a library to Windows 7 Beta: 
<br /><br />
1. Create a folder on your hard drive for shares. I used <b>c:\users\Mark\Shares\Documents</b>.<br />
2. Add the new folder to your library using Explorer.<br />
3. Delete the folder using a command prompt window.<br />
4. Use the mklink command to create a symbolic link with the Documents name to your
share. In my case the proper command was:<br /><p><b>mklink /D Documents \\.Host\Documents</b></p><p>
Note that mklink.exe requires administrator access so start the command prompt by
holding SHIFT+CTRL and clicking on it (or use the "Run As Administrator" option)
</p><br />
Voila! Explorer keeps the folder in the library even though it's not indexed.
</div>
    </content>
  </entry>
  <entry>
    <title>It's been such a long time.. [WPF + Windows 7]</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2009/01/29/ItsBeenSuchALongTimeWPFWindows7.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,eca611aa-f16c-4db9-b84b-5149984d9f3b.aspx</id>
    <published>2009-01-29T10:02:21.328-08:00</published>
    <updated>2009-06-29T09:51:35.6379786-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <b>Update</b>
        <br />
Microsoft has released the API code pack including Windows 7 support -- get it here: <a href="http://code.msdn.microsoft.com/WindowsAPICodePack">http://code.msdn.microsoft.com/WindowsAPICodePack</a><br /><br />
Well, it's been a while since I posted anything, I'm sorry! 
<br /><br />
I've been busy working with Windows 7 and Microsoft Surface touch-computing. To that
end, I needed to get access to some of the new Windows 7 APIs in managed code ...
which isn't supported yet (but is coming). 
<br /><br />
So I built an interop library to access: <strong><br /><br /></strong><ul><li><strong>Scenic Ribbon (native Win32 ribbon) in Windows Forms</strong></li><li><strong> Native WM_TOUCH and WM_GESTURE messages</strong></li><li><strong> Sensor API</strong></li><li><strong> Shell APIs (jump lists, thumbnail buttons, libraries) </strong></li></ul><strong>One note:</strong> I make no guarantee that everything is correct (it's hard
to do that on a shifting beta with minimal docs, but in addition I'm not sure I've
gotten 100% coverage with everything anyway). Here's the interop library with source
code: 
<br /><br /><a href="http://www.julmar.com/samples/win7Interop.zip">Windows 7 Beta 1 Interop Library
for .NET 2.0</a><br /><br />
I'll be posting more details and samples a bit later, here's a couple to get you started. 
<br /><br />
Here's a simple example of using the Scenic Ribbon and native touch support to create
a (very) simple Windows Forms finger<br />
paint program:<br /><br /><img src="http://www.julmar.com/blog/mark/content/binary/touch_img.jpg" alt="touch_img.jpg" border="0" height="469" width="699" /><br /><br /><a href="http://www.julmar.com/samples/touch_sample.zip">Multi Touch example with
Windows Forms</a><br /><br />
Here's a simple example of using the gestures and library support in a WPF application.
It grabs all the directories in your Pictures Library and then shows you each picture
and lets you use the swipe gesture to move between then, pinch to scale and of course,
rotate. 
<br /><br /><img src="http://www.julmar.com/blog/mark/content/binary/gesture_img.jpg" alt="gesture_img.jpg" border="0" height="372" width="498" /><br /><br /><a href="http://www.julmar.com/samples/gesture_sample.zip">Gesture example with WPF</a><br /><br />
Both of these samples work with the HP Touchmate (and multi-touch drivers) and Windows
7 Beta 1. Have fun! -mark
</div>
    </content>
  </entry>
  <entry>
    <title>Using the ImplicitStyleManager with Headered controls</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/11/13/UsingTheImplicitStyleManagerWithHeaderedControls.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,2b285ed0-c431-4d9d-b9b9-0948588bb4f7.aspx</id>
    <published>2008-11-13T07:42:01.1036853-08:00</published>
    <updated>2008-11-13T07:42:01.1036853-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been playing with the Silverlight toolkit (released at PDC) this week and ran
across a pretty nasty edge case related to HeaderedContentControl and the implicit
style manager.  If you create something like this, where the Header is set to
a Visual of some kind:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;UserControl
x:Class="SilverlightPrototype.Page"<br />
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
<br />
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
    xmlns:sys="clr-namespace:System;assembly=mscorlib"<br />
    xmlns:Controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"&gt;<br /><br />
&lt;StackPanel x:Name="LayoutRoot" Background="White"&gt;<br />
   &lt;Button Click="Button_Click" Content="Change Style" /&gt;<br />
   &lt;Controls:HeaderedContentControl&gt;<br /><font color="#0000ff">      &lt;Controls:HeaderedContentControl.Header&gt;<br />
         &lt;TextBlock <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Text</span>="Header"
Foreground="DarkBlue" FontWeight="Bold" /&gt;<br />
      &lt;/Controls:HeaderedContentControl.Header&gt;<br /></font>      &lt;TextBlock <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Text</span>="Body"
/&gt;<br />
   &lt;/Controls:HeaderedContentControl&gt;<br />
&lt;/StackPanel&gt;<br /></span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;/UserControl&gt;</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">And
then you change the style of the headered control when the button is clicked:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span>
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Button_Click(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
RoutedEventArgs e)<br />
{            <br />
    Uri uri <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Uri(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">@"SilverlightPrototype;component/theming/simplestyle.xaml"</span>,
UriKind.Relative);<br />
    ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri);<br />
    ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.OneTime);<br />
    ImplicitStyleManager.Apply(LayoutRoot);<br />
}<br /></span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Where
the style is just a simple ContentPresenter or ContentControl for the header
and the body:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;Style
TargetType="Controls:HeaderedContentControl"&gt;<br />
   &lt;Setter Property="Template"&gt;<br />
      &lt;Setter.Value&gt;<br />
        &lt;ControlTemplate TargetType="Controls:HeaderedContentControl"&gt;<br />
           &lt;StackPanel Orientation="Horizontal"&gt;<br />
              &lt;ContentPresenter
Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}"
Margin="10" /&gt;<br />
              &lt;ContentPresenter
Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"
Margin="10" /&gt;<br />
           &lt;/StackPanel&gt;<br />
        &lt;/ControlTemplate&gt;<br />
     &lt;/Setter.Value&gt;<br />
   &lt;/Setter&gt;<br />
&lt;/Style&gt;<br /></span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Silverlight
will crash deep in the <strong>DependencyProperty.SetValue</strong> code with an <strong>ArgumentException</strong> indicating
that the TextBlock for the header is invalid.  The issue appears to be that the
TextBlock defined as the header content is already part of the visual tree and therefore
cannot be bound to the new control template.  Content works fine so there is
some other path being taken for that property.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">The
workaround is pretty easy, just use a non-visual in the header and then supply a DataTemplate
to give it the appropriate visual tree.  Silverlight will re-create the visual
tree each time from the data template so we don't have the reuse issue:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;StackPanel
x:Name="LayoutRoot" Background="White"&gt;<br /><br />
&lt;StackPanel.Resources&gt;<br />
   &lt;!<span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Header works as long as template is supplied - i.e. non-visual element applied directly
to header --&gt;</span><br />
   &lt;DataTemplate x:<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Key</span>="HeaderTemplate"&gt;<br />
      &lt;TextBlock Foreground="DarkBlue" FontWeight="Bold" <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Text</span>="{Binding}"
/&gt;<br />
   &lt;/DataTemplate&gt;<br />
&lt;/StackPanel.Resources&gt;<br /><br />
&lt;Button Click="Button_Click" Content="Change Style" /&gt;<br /><br />
&lt;Controls:HeaderedContentControl <strong><font color="#0000ff">HeaderTemplate="{StaticResource
HeaderTemplate}"</font></strong>&gt;<br /><font color="#0000ff">   &lt;Controls:HeaderedContentControl.Header&gt;<br />
      &lt;sys:String&gt;Header <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Text</span>&lt;/sys:String&gt;<br />
   &lt;/Controls:HeaderedContentControl.Header&gt;<br /></font><br />
   &lt;TextBlock <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Text</span>="Body"
/&gt;<br />
&lt;/Controls:HeaderedContentControl&gt;<br /><br />
&lt;/StackPanel&gt;<br /></span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <font face="Verdana" color="#003300" size="2">If
you need more than a string, then just define an object and assign that instead -
for example:</font>
              </span>
            </font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <p>
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> HeaderStuff<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Text
{ get; set; }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span> IsChecked
{ get; set; }<br />
}<br /><br />
&lt;DataTemplate x:Key=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"HeaderStuff"</span>&gt;<br />
   &lt;StackPanel&gt;<br />
      &lt;Rectangle Fill=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Blue"</span> Stroke=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Yellow"</span> Width=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"50"</span> ...
/&gt;<br />
      &lt;CheckBox IsChecked=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"{Binding
IsChecked}"</span> Content=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"{Binding
Text}"</span> /&gt;<br />
   &lt;/StackPanel&gt;<br />
&lt;/DataTemplate&gt;<br /><br />
...<br /><br />
&lt;Controls:HeaderedContentControl HeaderTemplate=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"{StaticResource
HeaderStuff}"</span>&gt;<br />
   &lt;Controls:HeaderedContentControl.Header&gt;<br />
      &lt;me:HeaderStuff IsChecked=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"True"</span> Text=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"This
is a checkbox"</span> /&gt;<br />
   &lt;/Controls:HeaderedContentControl.Header&gt;<br />
&lt;/Controls:HeaderedContentControl.Header&gt;<br /></span>
              </p>
            </span>
          </font>
          <p>
            <br />
          </p>
        </span>
      </div>
    </content>
  </entry>
  <entry>
    <title>Debugging WPF with VS2010</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/11/12/DebuggingWPFWithVS2010.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,f2689d26-2062-4b7b-a077-4912b976d637.aspx</id>
    <published>2008-11-12T11:06:04.185-08:00</published>
    <updated>2008-11-12T11:15:17.6506206-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">One of the coolest new debugging features
included with VS2010 CTP1 is the management of WPF event traces directly in the IDE. 
With this feature you can turn specific event traces on and off and have them show
up in the debug window.  The default setting is to just show data binding errors
- the existing behavior.  But now you can view resource lookups, routed event
creation, etc. Here's the dialog:<br /><br /><br /><p></p><img src="http://www.julmar.com/blog/mark/content/binary/NewDebugFeatures11.jpg" border="0" /></div>
    </content>
  </entry>
  <entry>
    <title>Demos from Silverlight 2 class this week</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/10/02/DemosFromSilverlight2ClassThisWeek.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,3c68e467-d5cf-4624-8566-f849026444b6.aspx</id>
    <published>2008-10-02T07:04:48.613355-07:00</published>
    <updated>2008-10-02T07:04:48.613355-07:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <a href="http://www.julmar.com/DMStuff/sl2_demos.zip">Here
are the demos</a> for the guys who attended the 2-day binding + network Silverlight2
training in Boston.  Thanks guys!<br /><br /><br /><p></p></div>
    </content>
  </entry>
  <entry>
    <title>GNET demos from LA</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/09/22/GNETDemosFromLA.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,39b19479-d49d-4f4c-b1b5-af2a8ef59ade.aspx</id>
    <published>2008-09-22T06:33:32.824-07:00</published>
    <updated>2008-09-22T06:33:32.8240922-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Thanks to all who attended - it was great
to meet all of you and hang out until the wee hours and play Rock Band!  
<br /><br /><a href="http://www.julmar.com/DMStuff/demos.zip">Here are the demos from the class</a> -
I removed most of the binaries to bring it down to a reasonable size.<br /><br />
I also put the <a href="http://www.flickr.com/gp/62167965@N00/84Y4ba">pictures online
at Flickr</a><br /><br />
Thanks again everyone!<br /><br /><br /><p></p></div>
    </content>
  </entry>
  <entry>
    <title>Outlined Text in WPF</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/09/13/OutlinedTextInWPF.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,824270c5-fa20-4e46-a0d6-ae609d875617.aspx</id>
    <published>2008-09-12T20:52:21.779-07:00</published>
    <updated>2008-09-12T20:53:15.8110718-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Helvetica','sans-serif'"&gt;&lt;font color=#000000&gt;One
thing that's kind of cool in WPF is that you can use brushes to fill almost anything
and that there are some really cool brushes in the toolkit.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;It
always blows people away when you show them a piece of text filled with a live video
complements of a Visual Brush.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Helvetica','sans-serif'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Helvetica','sans-serif'"&gt;&lt;font color=#000000&gt;But,
unfortunately text doesn't have a stroke property - only a fill so you can't add an
edge to it.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You can layer another piece
of text under it, but often it doesn't quite match up size-wise when you do this.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The
solution is to convert the text to a &lt;strong&gt;Path&lt;/strong&gt; which has both a fill and
stroke and it turns out it's pretty easy to do.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Helvetica','sans-serif'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Helvetica','sans-serif'"&gt;&lt;font color=#000000&gt;If
you just have one piece of text you are better off using Blend's "Convert to Path"
option -- it will do the one-time conversion for you and you can just insert the shape
into your UI.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If you have more than one
element though it can be tedious, and it doesn't work at all for dynamic pieces of
text - that's where this &lt;strong&gt;TextPath&lt;/strong&gt; class comes in handy.&amp;nbsp;&amp;nbsp;
With it you can create text like this:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Helvetica','sans-serif'"&gt;&lt;font color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;img src="http://www.julmar.com/blog/mark/content/binary/wpf_rocks.jpg" border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
Notice how the text is outlined in a different color -- any brush could be used so
you could do wacky things like have the "WPF" part be ringed in fire&amp;nbsp;(using the
Dreamscene fire video for example).&amp;nbsp; 
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
The class is dead simple to use, it's a Shape class so you can simply insert it right
into your XAML and set the font properties and text:
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;StackPanel&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; Orientation&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="Horizontal"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; &lt;strong&gt;TextElement.FontWeight&lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;&lt;strong&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="Bold"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; TextElement.FontSize&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&lt;strong&gt;="72pt&lt;/strong&gt;"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;me&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;TextPath&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; FontFamily&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="Consolas,Courier
New"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; Margin&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="5" &lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt;Text&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="WPF"&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt;StrokeThickness&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="3"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; Fill&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="Gold"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; Stroke&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="Red"
/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;me&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;TextPath&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; FontFamily&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="Balloon"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; Margin&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="5"&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt;Text&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="Rocks" &lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt;StrokeThickness&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="3"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; Stroke&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="Black"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;lt;&lt;font color=#a31515&gt;me&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;TextPath.Fill&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;ImageBrush&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;&lt;font color=#ff0000 size=2&gt; ImageSource&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;="rocks.jpg"
/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;me&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;TextPath.Fill&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;me&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;TextPath&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=2&gt;&lt;font color=#a31515 size=2&gt;StackPanel&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;&amp;nbsp;
&lt;/p&gt;
&gt;&gt; 
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
Notice it uses the same font dependency properties as all other text-based framework
elements - that allows us to inherit the property values which is useful.&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-pagination: none; tab-stops: .5in 1.0in 1.5in 2.0in 2.5in 3.0in 3.5in 4.0in 4.5in 5.0in 5.5in 6.0in; mso-layout-grid-align: none"&gt;
Here's the sample project which full source code:&amp;nbsp; &lt;a href="http://www.julmar.com/blog/mark/content/binary/OutlineTextTest.zip"&gt;OutlineTextTest.zip
(1.54 MB)&lt;/a&gt;
&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Part 3: Shifting focus to the first available element in WPF</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/09/12/Part3ShiftingFocusToTheFirstAvailableElementInWPF.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,03722678-882a-4bb4-928f-4fe0d35f051e.aspx</id>
    <published>2008-09-12T05:49:20.719-07:00</published>
    <updated>2008-09-12T08:07:18.1062218-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We've seen how to programatically control focus and that's all great stuff, but one
thing I like to do with WPF is see how much of the repetitive or UI-specific code
I can move into the XAML and keep out of the code behind.  We can use the <strong>FocusManager.FocusedElement</strong> property
to shift focus in XAML but it only works when the element exists in the main XAML
file.  If you use UserControls it turns out that the approach doesn't work because
that element is loaded separately and not available when the initial focus is being
determined.
</p>
        <p>
In my specific case, I have a wizard-style application which utilizes a TabControl
to move between the pages.  The first page looks like this:
</p>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/TabPage_01.jpg" border="0" />
        </p>
        <p>
The XAML layout for window1.xaml looks something like this:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;TabControl
x:Name="Pages" SelectedIndex="0"&gt;<br />
   &lt;FocusTest:Page1 /&gt;<br />
   &lt;FocusTest:Page2 /&gt;<br />
   &lt;FocusTest:FinalPage /&gt;<br />
&lt;/TabControl&gt;</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">What
I want is to have focus immediately positioned within the first text box but it turns
out that you can't get WPF to do this directly from XAML - because the TextBox isn't
a direct descendent of Window - it's part of the Page1 user control.  You can
try putting the focus shift into the user control but it turns out that it won't work
there either - it's got to be assigned to the focus scope which is the window.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">So
it might seem we are stuck with adding code behind logic (blech!) but all is not lost! 
When I hit situations like this, I try to think about how to solve the problem generically
so I can reuse my solution.  In this case, I decided to build a <strong>MarkupExtension</strong> to
locate the first focusable element descendent.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">If
you are not familiar with markup extensions, they are a corner piece in the XAML extensibility
story.  They allow for dynamic property assignment - where the value is determined
at runtime vs. XAML compile time.  That's exactly what I need here - I want to
find that TextBox at runtime and shift focus to it - just like I would have done in
the code behind.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Creating
a markup extension is trivial - you just extend the <strong>MarkupExtension</strong> base
class and implement the <strong>ProvideValue</strong> method.  In this case,
when provide value is called, I have to do several steps:</font>
          </span>
        </p>
        <ol>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">If
the element we are bound to is not loaded yet, we need to wait for it.  We won't
be able to find the child in the visual tree if the parent isn't yet loaded.</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">Once
it <strong>is</strong> loaded, search the children and find the first control
we can give focus to.  That means, the control is visible, focusable and enabled.</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">Assign
logical focus to the new control in the closest focus scope parent, or just return
the value if the property being assigned to is not <strong>FocusManager.FocusedElement</strong>.</font>
            </span>
          </li>
        </ol>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">I
decided to try to make a generic markup extension that could be used outside my scenario
so I added a little bit of code to see if we are assigning to <strong>FocusManager.FocusedElement</strong> and
act differently in that specific case - otherwise the extension just returns the value.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">With
this new extension, I can now add a single line of code to each user control:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;UserControl
x:Class="FocusTest.Page2"<br />
   xmlns:FocusTest="clr-namespace:FocusTest"<br />
   <strong><font color="#ff0000">FocusManager.FocusedElement="{FocusTest:FirstFocusedElement}</font></strong>"&gt;</span>
          </p>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Now,
when I run the application, focus is always assigned to the first control it can be
assigned to.  It turns out that I can go one step better and <strong>always </strong>assign
focus when the page becomes visible in my wizard - remember we have to wait for the
control to finish loading to find the element.. this is done by hooking the <strong>FrameworkElement.Loaded</strong> event. 
This event is raised each time the TabControl shifts to a new tab - so if we never
unhook our handler, our focus management code is called each time the tab page becomes
visible.  This might not be the required behavior so I added a simple property
to the markup extension called OneTime to control that behavior.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">There's
a bit too much code to blog here, but if you want to try this out yourself, here's
the test project.. feel free to use this however you like.  <a href="http://www.julmar.com/blog/mark/content/binary/FocusTest.zip">FocusTest.zip
(17.88 KB)</a></font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <strong>Update: </strong>
                <a href="http://agsmith.wordpress.com/category/wpf/">Andrew
Smith</a> pointed out that the code would assign focus to a focus scope if it
ran across one - which could happen if you have a toolbar or menu present in the UI. 
I didn't in the sample (or in my production app) but I could certainly see that being
a common reality.  I changed the above code to deliberately skip focus scopes
and their children and keep going down the tree until it finds the first child. 
Thanks Andrew!</font>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <br />
          </span>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Part 2: Changing WPF focus in code</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/09/04/Part2ChangingWPFFocusInCode.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx</id>
    <published>2008-09-04T13:44:44.597-07:00</published>
    <updated>2008-09-04T14:03:42.0959366-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the <a href="http://www.julmar.com/blog/mark/PermaLink,guid,2974164f-97c1-4e20-85f9-416cf6bed219.aspx">last
post</a>, I wrote about how focus is generally managed in WPF - we have focus scopes
to track a single element within that scope for logical focus, and then one of those
elements is given physical, or keyboard focus.
</p>
        <p>
Now, let's talk a little about how you can influence that programatically.  First,
you can always determine which element has logical focus in your application through
the <strong>FocusManager.GetFocusedElement</strong> method -- pass it the window in
question and it will return which element has logical focus in that window. 
Remember that logical focus != keyboard focus at all times -- toolbars and menus track
their own focus so if you are currently interacting with a menu then the menu has
physical focus.  But in general, the following code will tell you which element
WPF thinks has focus in the window:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IInputElement
focusedElement <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> FocusManager.GetFocusedElement(thisWindow);</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">To
determine whether this element has keyboard focus, we can check the IsKeyboardFocused
property - if it's set to true, then that element currently has the keyboard focus
(as well as being the logical focus for that focus scope).</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Keyboard
focus is most often set through runtime activity - the user clicks on an element,
or uses the TAB key to move around the UI.  You can also set it programatically
a couple of ways.  First, there is a <strong>Keyboard</strong> class
in WPF which exposes several methods and properties.  There is a <strong>Keyboard.FocusedElement</strong> read-only
property which returns the current keyboard focused element, and there is a <strong>Keyboard.Focus</strong> method
which attempts to change keyboard focus.  It returns the element that now has
focus - so you can check to see if your request was fulfilled or ignored.  So,
for example, you can change focus during your application initialization:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> OnLoaded(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
RoutedEventArgs e)<br />
{<br />
   Keyboard.Focus(firstTextBox);<br />
}</span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Notice
that we uses the <strong>Loaded</strong> event - this is because no focus requests
will be accepted prior to the element being initialized and loaded.  That's the
first place in the application where you can make focus changes.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">When
would setting focus fail?  Well, it can fail for a lot of reasons, but the most
common are:</font>
          </span>
        </p>
        <ol>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">The
element has Focusable = false</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">The
element has Enabled = false</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">The
element has IsVisible = false</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">The
element has not been loaded yet</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">The
currently focused element will not release focus.</font>
            </span>
          </li>
        </ol>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">That
final one is important, changing focus involves potentially taking it away from an
existing element - they receive a <strong>PreviewLostKeyboardFocus</strong> and <strong>LostKeyboardFocus</strong> event. 
If they handle the preview event, focus will not change.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">You
can also manipulate focus through programatic keyboard navigation - simulating the
user pressing TAB to cycle through the focusable elements.  This is controlled
through the <strong>KeyboardNavigation</strong> class which is used when the user
presses a key that changes focus (TAB, SHIFT+TAB, Up, Down, etc.).</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">Controls can set
a <strong>TabIndex</strong> property assignment which determines the tabbing order. 
The default is to tab through them in order of declaration.  You can also use
the <strong>KeyboardNavigation.TabIndex</strong> attached property which works for
any element - not just controls.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">To
control navigation, the <strong>KeyboardNavigation</strong> class has an attached
property <strong>TabNavigation</strong> allowing you to change how navigation
occurs within a container.  You can set it to:</font>
          </span>
        </p>
        <ol>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <strong>Continue</strong> -
each focusable element receives focus and the container is exited when the edge is
reached.</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <strong>Cycle</strong> -
focus does not leave the container but wraps around the edges</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <strong>Once</strong> -
the container itself is treated as a single focusable element where only the first
child receives focus</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <strong>Local</strong> -
uses TabIndex locally within the container - independant of any outside elements.</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <strong>Contained</strong> -
focus statys in the container but does not wrap (stays at edges when top/bottom are
reached)</font>
            </span>
          </li>
          <li>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <strong>None</strong> -
no keyboard navigation allowed in the container</font>
            </span>
          </li>
        </ol>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">The
default is <strong>Continue</strong>, but you can set the attached property on any
element to change it for that element and any children. </font>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">To
see this in action, paste the following into your XAML editor of choice and change
the ComboBox while tabbing through the TextBlock elements.</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
<br />
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
<br />
        xmlns:sys="clr-namespace:System;assembly=mscorlib"<br />
        Title="Simple Focus"</span>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&gt;<br /><br />
&lt;Window.Resources&gt;<br />
   &lt;Style TargetType="TextBox"&gt;<br />
      &lt;Setter Property="Margin" Value="10" /&gt;<br />
      &lt;Setter Property="Width" Value="100" /&gt;<br />
   &lt;/Style&gt;<br />
&lt;/Window.Resources&gt;<br /><br />
&lt;StackPanel&gt;<br />
   &lt;ComboBox x:Name="tabStyles" SelectedIndex="0" Focusable="False"&gt;<br />
      &lt;sys:String&gt;None&lt;/sys:String&gt;<br />
      &lt;sys:String&gt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><font color="#000000">Continue</font></span>&lt;/sys:String&gt;<br />
      &lt;sys:String&gt;Cycle&lt;/sys:String&gt;<br />
      &lt;sys:String&gt;Once&lt;/sys:String&gt;<br />
      &lt;sys:String&gt;Local&lt;/sys:String&gt;<br /></span>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
&lt;sys:String&gt;Contained&lt;/sys:String&gt;<br />
   &lt;/ComboBox&gt;<br /></span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
&lt;TextBox TabIndex="1" /&gt;<br />
   &lt;TextBox TabIndex="2" /&gt;<br />
   &lt;StackPanel 
<br />
        </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <strong>
              <font color="#ff0000">KeyboardNavigation.TabNavigation="{Binding
ElementName=tabStyles,Path=SelectedItem}"</font>
            </strong>&gt;<br />
      &lt;TextBox TabIndex="1" /&gt;<br />
      &lt;TextBox TabIndex="2" /&gt;<br />
   &lt;/StackPanel&gt;<br />
&lt;/StackPanel&gt;<br />
&lt;/Window&gt;<br /></span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <font face="Verdana" color="#003300" size="2">You
can have the system ignore specific elements (but still allow them to have focus)
by setting the <strong>KeyboardNavigation.IsTabStop="false"</strong> attached property. 
This will cause keyboard navigation to "jump" over the control as if it were not present.</font>
              </span>
            </font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <font face="Verdana" color="#003300" size="2">Three
methods are exposed by UIElement and FrameworkElement to programatically
shift focus: <strong>Focus</strong>, <strong>MoveFocus</strong> and <strong>PredictFocus</strong>.</font>
              </span>
            </font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font face="Verdana" color="#003300" size="2">
                    <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                      <font face="Verdana" color="#003300" size="2">To
force focus to a specific element, you can call <strong>Focus</strong> on it. 
For example, above we set the keyboard focus by calling Keyboard.Focus(), but the
same effect can be achieved like this:</font>
                    </span>
                  </font>
                </span>
              </span>
            </font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <font face="Verdana" color="#003300" size="2">
                  <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                    <p>
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> OnLoaded(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> sender,
RoutedEventArgs e)<br />
{<br />
   firstTextBox.Focus();<br />
}</span>
                    </p>
                  </span>
                </font>
              </span>
            </span>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font face="Verdana" color="#003300" size="2">
                    <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                      <font face="Verdana" color="#003300" size="2">This
method attempts to set focus using Keyboard.Focus().  If that fails, but the
element is Focusable and enabled, it finds the focus scope for the element and
sets logical focus there (so that keyboard focus will eventually end up on the control).</font>
                    </span>
                  </font>
                </span>
              </span>
            </font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font face="Verdana" color="#003300" size="2">
                    <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                      <font face="Verdana" color="#003300" size="2">
                        <strong>FrameworkElement.MoveFocus</strong> is
used to change the keyboard focus in the application using the same algorithm
as the TAB traversal.  You pass in the direction (specified through a TraversalRequest
object) and the method returns true/false to indicate success.   Under the
covers it actually uses the KeyboardNavigation class, but it's an easy way to push
focus around the window:</font>
                    </span>
                  </font>
                </span>
              </span>
            </font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <font face="Verdana" color="#003300" size="2">
                  <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                    <p>
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">firstTextBox.MoveFocus(<br />
            </span>
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> TraversalRequest(FocusNavigationDirection.Next));<br /></span>
                    </p>
                  </span>
                </font>
              </span>
            </span>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <strong>PredictFocus</strong> works
the same way, but instead of actually shifting focus, it returns what <em>would </em>be
the focused item if you were to execute MoveFocus.</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">So,
up to this point, we've seen a lot of code to change focus.  However, the most
common request is to set initial focus to a specific control - remember that WPF doesn't
do that by default.  You can do it in code, just like the above example where
we use the Loaded event.  Or, it turns out you can do it in XAML too.  The
key to remember is that the FocusedElement of the main focus scope (the Window) is
the one that will get initial focus.  That is (by default) null, but you can
set it in XAML using the attached property syntax.  Using the above XAML example,
we can supply a name for one of the TextBox controls and then a little data binding
magic to set that onto the Window:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">&lt;Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
<br />
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
<br />
        xmlns:sys="clr-namespace:System;assembly=mscorlib"<br />
        Title="Simple Focus"<br />
        <strong><font color="#ff0000">FocusManager.FocusedElement="{Binding
ElementName=tb2}"</font></strong>&gt;<br /></span>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"> 
...<br />
    &lt;TextBox TabIndex="1" /&gt;<br />
    &lt;TextBox <font color="#ff0000">x:Name="tb2"</font> TabIndex="2"
/&gt;<br />
  ...<br />
&lt;/Window&gt;<br /></span>
          </p>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <font face="Verdana" color="#003300" size="2">Now
when you run the application, focus is placed into <em>the </em>second text box in
the window.  This technique works great as long as the element you want
to assign focus to is declared here in the same XAML file.  However, a popular
way to develop WPF applications is to separate out chunks of UI into separate UserControls. 
When you do that, the above trick fails -- even if you put the FocusManager.FocusedElement
binding into the UserControl!</font>
              </span>
            </font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <font face="Verdana" color="#003300" size="2">How
we solve that is what we'll look at in the next post!  Stay tuned...</font>
              </span>
            </font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              </span>
            </font>
          </span> 
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
            </font> 
</span>
        </p>
        <p>
          <br />
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Part 1: It's Basically Focus</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/09/02/Part1ItsBasicallyFocus.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,2974164f-97c1-4e20-85f9-416cf6bed219.aspx</id>
    <published>2008-09-02T12:55:39.44-07:00</published>
    <updated>2008-11-13T06:43:38.0167302-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#0000ff" face="Calibri" size="5"&gt;&lt;strong&gt;Focus Types&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;As you may know, in WPF&amp;nbsp;there are&amp;nbsp;two
types of focus: &lt;b style=""&gt;logical&lt;/b&gt; focus and &lt;b style=""&gt;keyboard&lt;/b&gt; focus.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;strong&gt;Keyboard
focus &lt;/strong&gt;is the easiest to grasp: the element with keyboard focus is where any
keystrokes will end up.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Only &lt;u&gt;one&lt;/u&gt; element can have
keyboard focus at any particular time, and it’s possible that no element currently
has keyboard focus (this happens most commonly when the application itself is not
the activated application).&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;&lt;strong&gt;Logical focus&lt;/strong&gt; is a
little murkier.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Logical focus represents where keyboard
focus &lt;i style=""&gt;could&lt;/i&gt; go within a group of elements.&lt;span style=""&gt;&amp;nbsp; There
may be multiple elements with logical focus within the application and one of them
likely has keyboard focus.&amp;nbsp; Having keyboard focus automtically indicates logical
focus but not vice-versa.&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;&lt;span style=""&gt;This distinction is modeled
after Win32 itself --&amp;nbsp;each thread has one HWND it has identified to have focus
but only one of them really has input focus at any given point in time.&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;&lt;span style=""&gt;&lt;/span&gt;In WPF, logical
focus is tracked and managed by a &lt;i style=""&gt;Focus Scope&lt;/i&gt;.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;A
focus scope is created by certain elements to keep track of which element should have
focus.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;There can be multiple focus scopes within the application
– each&amp;nbsp;identifying a single element that has logical focus.&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;Focus
scopes are created and managed by the FocusManager class.&amp;nbsp; It exposes two attached
properties and the requisite static method wrappers to access them:&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;&lt;span style=""&gt;&lt;strong&gt;IsFocusScope&lt;/strong&gt; -
determines whether the current object is a focus scope.&lt;br&gt;
&lt;strong&gt;FocusedElement&lt;/strong&gt; - returns which element child of the given focus scope
object has logical focus.&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font size="3"&gt;&lt;font color="#000000"&gt;&lt;font face="Calibri"&gt;It also exposes a handy
method to find the focus scope for a given element - &lt;strong&gt;GetFocusScope&lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font size="3"&gt;&lt;font color="#000000"&gt;&lt;font face="Calibri"&gt;So what creates a focus
scope and why do we need more than one?&amp;nbsp; Well, t&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="3"&gt;&lt;font color="#000000"&gt;&lt;font face="Calibri"&gt;he
elements in WPF that create focus scopes by default are &lt;/font&gt;&lt;b style=""&gt;&lt;span style="font-family: 'Courier New';"&gt;Window&lt;/span&gt;&lt;/b&gt;&lt;font face="Calibri"&gt;, &lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;b style=""&gt;&lt;span style="font-family: 'Courier New';"&gt;Menu&lt;/span&gt;&lt;/b&gt;&lt;font face="Calibri"&gt;, &lt;/font&gt;&lt;b style=""&gt;&lt;span style="font-family: 'Courier New';"&gt;ContextMenu&lt;/span&gt;&lt;/b&gt;&lt;font face="Calibri"&gt; and &lt;/font&gt;&lt;b style=""&gt;&lt;span style="font-family: 'Courier New';"&gt;ToolBar&lt;/span&gt;&lt;/b&gt;&lt;font face="Calibri"&gt;.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The
reason we need more than one is to ensure your application&amp;nbsp;works the way you
expect it to.&amp;nbsp;&amp;nbsp;When you are typing in a &lt;/font&gt;&lt;b style=""&gt;&lt;span style="font-family: 'Courier New';"&gt;TextBox&lt;/span&gt;&lt;/b&gt;&lt;font face="Calibri"&gt; and
click a menu item, you really want focus to&amp;nbsp;return&amp;nbsp;to the&amp;nbsp;original &lt;/font&gt;&lt;span style="font-family: 'Courier New';"&gt;&lt;strong&gt;TextBox &lt;/strong&gt;&lt;font face="Calibri"&gt;once
the menu is dismissed&lt;/font&gt;&lt;/span&gt;&lt;font face="Calibri"&gt;.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;That’s
focus scopes in action – the Window maintains &lt;i style=""&gt;logical focus&lt;/i&gt; in the &lt;/font&gt;&lt;b style=""&gt;&lt;span style="font-family: 'Courier New';"&gt;TextBox&lt;/span&gt;&lt;/b&gt;&lt;font face="Calibri"&gt; and
when you click on the menu, keyboard focus shifts to the menu.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Since
it maintains its own focus scope, it has its own logically focused element that WPF
sets focus to (the menu and menu items in this case).&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Once
you shift back to the window, keyboard focus moves back to that focus scope’s logical
focus: the text box.&amp;nbsp; Without focus scopes to track the original focus holder,
WPF wouldn't know where focus should go.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;Focus scopes are also critical to command
routing – often execution of commands depends upon focus.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Some
commands become active because a specific control which has a handler for the command
has focus.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Without focus scopes, we could not have menu
items and toolbar buttons initiate those commands – they would steal focus away from
the target, making the command unavailable.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;However, when
WPF encounters a focus scope it checks the element that has logical focus in that
scope to see if it can handle the command.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;If not, the
command continues routing up to the parent of the focus scope.&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;To show all of this behavior, I have
rigged up a sample application with two windows.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The first
is a traditional text editor window with a menu and toolbar and a RichEdit control
for the content.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It looks like:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img alt="ste001.jpg" src="http://www.julmar.com/blog/mark/content/binary/ste001.jpg" border="0" height="286" width="391"&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;Forgive my 5-minute graphics for the
buttons – I just threw them together in Visual Studio, a real project would use Blend
to generate the graphics.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;&lt;span style=""&gt;Regardless of it's look, &lt;/span&gt;the
application functions the way you expect – you can type in the text field, click buttons
and select menu choices to Open, Cut, Copy and Paste content.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The
Cut/Copy/Paste commands are only available when the TextBox is in the appropriate
state:&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;&lt;strong&gt;Cut:&lt;/strong&gt;&amp;nbsp;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;TextBox
has focus and has some text selected.&lt;br&gt;
&lt;strong&gt;Copy:&lt;/strong&gt; &lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;TextBox has focus and has
some text selected.&lt;br&gt;
&lt;strong&gt;Paste:&lt;/strong&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; T&lt;/span&gt;extBox has focus
and text exists on the clipboard.&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;This is all an artifact of the routed
command system in WPF – the TextBox has command handlers registered for &lt;strong&gt;ApplicationCommands.Cut&lt;/strong&gt;, &lt;strong&gt;ApplicationCommands.Copy &lt;/strong&gt;and &lt;strong&gt;ApplicationCommands.Paste&lt;/strong&gt; and
when it has focus (and the above criteria is met) those commands &lt;i style=""&gt;could&lt;/i&gt; be
executed.&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;When you click on a button or a menu
choice, it executes the command it is associated with and WPF decides which handler
should be called.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This normally involves walking the visual
tree:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img alt="ste002.jpg" src="http://www.julmar.com/blog/mark/content/binary/ste002.jpg" border="0" height="154" width="250"&gt;
&lt;/p&gt;
&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"&gt;&lt;/v:path&gt;
&lt;o:lock v:ext="edit" aspectratio="t"&gt;&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;v:shape id="Picture_x0020_5" style="margin-top: 1.35pt; z-index: -1; visibility: visible; margin-left: 1.5pt; width: 183pt; position: absolute; height: 111pt;" stroked="t" strokecolor="windowText" wrapcoords="-177 -292 -177 21892 21777 21892 21777 -292 -177 -292" o:spid="_x0000_s1026" type="#_x0000_t75"&gt;
&lt;v:imagedata src="file:///C:%5CUsers%5CMark%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_image001.png" o:title=""&gt;&lt;/v:imagedata&gt;
&lt;w:wrap type="tight"&gt;&lt;/w:wrap&gt;
&lt;/v:shape&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;In this case, if the menu item for “Cut”
were selected, it would start looking at the menu, then move up the tree consulting
each parent and looking for a &lt;strong&gt;CommandBinding&lt;/strong&gt; to handle the command.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;If
that were the whole story then the Cut command would never happen because nothing
in the visual tree above the menu has a binding to execute the Cut command.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;But,
of course, &amp;nbsp;it’s not the whole story – in this case, WPF sees that the Window
is a focus scope and so it gets the logically focused element from the Window and
looks for a CommandBinding there.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;That happens to be our
RichTextBox – which is where the command ultimately gets handled.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;To see all of this in action, the second
part of the application is a focus scope monitor window.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;img alt="ste004.jpg" src="http://www.julmar.com/blog/mark/content/binary/ste004.jpg" border="0" height="242" width="424"&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font face="Calibri"&gt;&lt;font size="3"&gt;It shows all the known focus scopes and what the
active focused element is, as well as whether that element has keyboard focus.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The
window is live so as you click around in the text editor you can see focus shifting
and changing.&amp;nbsp; &lt;font color="#000000" face="Calibri"&gt;The element with keyboard
focus is the Paste menu item – notice that the rich text box is the logically focused
item for “Window1” but does not have keyboard focus.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Once
you select the menu choice (or cancel) then keyboard focus shifts back to Window1
which assigns it to the RichTextBox.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;font face="Calibri"&gt;&lt;/font&gt; 
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;img alt="ste003.jpg" src="http://www.julmar.com/blog/mark/content/binary/ste003.jpg" border="0" height="141" width="161"&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;If you'd like to play with this sample,
you can get the full source code &lt;a href="http://www.julmar.com/blog/mark/Content/binary/simpleeditor.zip"&gt;here&lt;/a&gt;.&lt;/font&gt;
&lt;/p&gt;
&lt;p class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;
&lt;font color="#000000" face="Calibri" size="3"&gt;In the next blog post, I’ll write about
how you can programmatically assign and control focus in code and XAML.&lt;/font&gt;
&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Focusing on WPF:  How to deal with Focus() in the WPF world</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/09/01/FocusingOnWPFHowToDealWithFocusInTheWPFWorld.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,507386bd-a72e-455e-b345-315e0dcf35e9.aspx</id>
    <published>2008-09-01T12:07:39.7-07:00</published>
    <updated>2008-09-12T05:51:31.455071-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p class="MsoNormal" style="MARGIN: 0in 0in 10pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">Recently I was involved
in a project where we needed to build a multi-step input application where each step
showed progress and you could proceed forward and backward through the pages.<span style="mso-spacerun: yes">  </span>I
looked at the Navigation support in WPF (which is nice) but ultimately decided to
model it around a styled </font>
              <b style="mso-bidi-font-weight: normal">
                <span style="FONT-FAMILY: 'Courier New'">TabControl</span>
              </b>
              <font face="Calibri"> –
each page being a tab and the progress noted through the custom </font>
              <b style="mso-bidi-font-weight: normal">
                <span style="FONT-FAMILY: 'Courier New'">TabItem</span>
              </b>
              <font face="Calibri"> visuals
across the top.<span style="mso-spacerun: yes">  </span>It all works great and
looks fabulous.</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 10pt">
          <font face="Calibri" color="#000000" size="3">
            <img height="446" src="http://www.julmar.com/blog/mark/content/binary/navpage_ss.jpg.jpg" width="611" border="0" />
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 10pt">
          <font face="Calibri" color="#000000" size="3">One of the bugs that was logged against
the application and got assigned to me was related to focus – the initial keyboard
focus was not being placed into the first control, instead it appeared that nothing
had focus which is totally accurate.  </font>
          <font face="Calibri" color="#000000" size="3">Those
that are new to WPF might be surprised that it does not assign initial focus to any
particular child control – you must deliberately click or tab into a control to give
it focus.<span style="mso-spacerun: yes">  </span><span style="mso-spacerun: yes"> </span>You
can, of course, also assign focus programmatically but it turns out to not be as easy
as you’d think.<span style="mso-spacerun: yes">  In fact, I encountered several
nasty gotchas trying to get it to work exactly the way I wanted it to. </span></font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 10pt">
          <font face="Calibri" color="#000000" size="3">
            <span style="mso-spacerun: yes">
            </span>My
frustrations with focus and how WPF manages it have resulted in this set of blog posts</font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 10pt">
          <font face="Calibri" color="#000000" size="3">
            <a href="http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx">Part
1:<span style="mso-spacerun: yes">  </span>Focus Basics<br />
Part 2:<span style="mso-spacerun: yes">  </span>Setting focus in code and XAML</a>
            <br />
            <a href="http://www.julmar.com/blog/mark/PermaLink,guid,03722678-882a-4bb4-928f-4fe0d35f051e.aspx">Part
3:<span style="mso-spacerun: yes">  </span>Getting a little smarter – setting
focus to the first focusable control<br /></a>Part 4:<span style="mso-spacerun: yes">  </span>Setting focus to template
items</font>
        </p>
        <p>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>(Possibly) better validations in WPF</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/08/25/PossiblyBetterValidationsInWPF.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,b919500f-b0b7-4abf-8059-be5719e259f8.aspx</id>
    <published>2008-08-25T07:45:20.185-07:00</published>
    <updated>2008-09-08T07:45:20.1855638-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've never cared much for the built-in validation mechanisms provided by WPF. 
I just don't think any of them feel natural to the way we build WPF applications today. 
Basically, there are essentially three mechanisms built into WPF for validations:
</p>
        <ol>
          <li>
Validation Rules</li>
          <li>
Exceptions</li>
          <li>
IDataErrorInfo</li>
        </ol>
        <p>
Validation rules are checked prior to transferring the value from the bound control
to your source (typically the business object).  Exceptions are a form of validation
rule - if the property setter throws an exception, it fails validation.  Finally, <strong>IDataErrorInfo</strong> was
added with WPF 3.5 to support validations inside the business objects directly. 
Often, you will use one or several of these validation techniques in your WPF application
to check the input.
</p>
        <p>
It's this last scenario (<strong>IDataErrorInfo</strong>) I want to focus
on in this post.  I actually like having validations in the business object -I
think it makes the most sense in most scenarios.  However, the interface
itself feels clunky to me - it looks like this:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">interface</span> IDataErrorInfo<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
string</span> Error { get; }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
string</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>[<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> columnName];<br />
}</span>
        </p>
        <p>
It's a weird one for sure.  I think the thing I dislike about it is the indexer
- it forces your validation code to look like the old 90's style switch statements
for Win32 message processing.  WPF calls the indexer just after applying the
value to the bound property - the validation method is responsible for checking the
value and returning a string indicating the failure, or null/empty if no failure occurred.
</p>
        <p>
In building WPF applications, I've used the above interface many times to validate
business objects and I found myself writing the same code over and over - most validations
are pretty common:
</p>
        <ol>
          <li>
Something must be there</li>
          <li>
It's a certain required length</li>
          <li>
It's a certain required pattern</li>
          <li>
It's a certain range (numeric)</li>
        </ol>
        <p>
And I thought to myself, "surely there's a better way!"  And so I came up with
an attribute-based validation system.  It piggy-backs onto the <strong>IDataErrorInfo</strong> interface,
but delegates off to a helper class which looks for attributes applied to the properties. 
The attributes them provide the validation for you.  Here's the idea:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">interface</span> IValidator<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
string</span> Validate(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> name, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> value);<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">abstract</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> ValidatorBase
: Attribute, IValidator<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">abstract</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Validate(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> name, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> value);<br />
}</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">The <strong>IValidator</strong> interface
represents the validation to occur.  It get's passed the name of the property
and the current value.  We wrap that in an abstract class called ValidatorBase
for most attributes to derive from.  Here's a couple of examples:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> RequiredAttribute
: ValidatorBase<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Validate(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> name, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> value)<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
return</span> value == <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span> ||
value.ToString().Length == 0 ? name <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">+</span><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
must be supplied."</span> : <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br />
   }<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> RequiredLengthAttribute
: ValidatorBase<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> Minimum
{ get; set; }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> Maximum
{ get; set; }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">override</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Validate(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> name, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> value)<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
if</span> (value == <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        
return</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
int</span> len <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> value.ToString().Length;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        
return</span> (len &gt;= Minimum &amp;&amp; len &lt;= Maximum)<br />
            ? <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span><br />
            : <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>.Format(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Length
of {0} must be between {1} and {2}."</span>, name, Minimum, Maximum);<br />
   }<br />
}</span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">You
could get as complicated as you like - I have in my toolbox a bunch more (Regex validator,
range validator, etc.)  Next, we use a validation manager class to do the validations
for us, this is what will implement the logic for <strong>IDataErrorInfo</strong>:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span>
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> ValidationManager<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Validate(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> name, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> instance)<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
if</span> (instance == <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        
throw</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ArgumentNullException(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"instance"</span>);<br /><br />
      Type type <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> instance.GetType();<br />
      var errorList <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> List&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>&gt;();<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
if</span> (!<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>.IsNullOrEmpty(name))<br />
      {<br />
         ValidateProperty(name, instance,
errorList);<br />
      }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
else</span><br />
      {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        
foreach</span> (PropertyInfo pi <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> type.GetProperties(BindingFlags.Public <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">|</span> BindingFlags.Instance))<br />
            ValidateProperty(pi.Name,
instance, errorList);<br />
      }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
return</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>.Join(Environment.NewLine,
errorList.ToArray());<br />
    }<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">    static</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> ValidateProperty(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> name, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span> instance,
ICollection&lt;<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>&gt;
errorList)<br />
    {<br />
       Type type <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> instance.GetType();<br />
       PropertyInfo pi <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> type.GetProperty(name,
BindingFlags.Public <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">|</span> BindingFlags.Instance);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      
if</span> (pi !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
       {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         
object</span> value <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> pi.GetValue(instance, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         
foreach</span> (Attribute att <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</span> pi.GetCustomAttributes(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">true</span>))<br />
          {<br />
             var iv <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> att <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">as</span> IValidator;<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            
if</span> (iv !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
             {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">               
string</span> err <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> iv.Validate(name,
value);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">                if</span> (!<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>.IsNullOrEmpty(err))<br />
                  
errorList.Add(err);<br />
             }<br />
          }<br />
       } <br />
    }<br /></span>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">}<br /></span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">It's
pretty simple - it just uses reflection to walk through the properties and look for
the <strong>IValidator</strong> interface on any attributes.  If it finds any,
it executes the Validate logic and returns a string indicating the failure(s).</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">To
use the above code, you add the attributes to your business object properties. 
For example, here is a simple Person object which uses the two validators for it's
name property:</font>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <font face="Verdana" color="#003300" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Person
: INotifyPropertyChanged, IDataErrorInfo<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> _name;<br /><strong><font color="#ff0000">   [Required]<br />
   [RequiredLength(Minimum=2, Maximum=10)]<br /></font></strong><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> Name<br />
   {<br />
      get { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> _name;
}<br />
      set { _name <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> value;
OnPropertyChanged(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Name"</span>);
}<br />
   }<br />
   ...<br />
}</span>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <br />
              </span>
            </p>
          </font>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            </span>
            <font face="Verdana" color="#003300" size="2">Finally,
you implement the IDataErrorInfo by utilizing the ValidationManager class.  If
you have a base class for your business objects, it could be done directly in the
base class and then propogate throughout your heirarchy:</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">#region</span> IDataErrorInfo
Members<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> IDataErrorInfo.Error<br />
{<br />
   get { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> ValidationManager.Validate(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>);
}<br />
}<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> IDataErrorInfo.<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>[<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> columnName]<br />
{<br />
   get {<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"> return</span> ValidationManager.Validate(columnName, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span>);
}<br />
}<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">#endregion</span><br /><br /></span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">That's
it!  Now, you have an extensible validation mechanism which is reusable and easy
to apply.  Plus, it makes it much more obvious what the validation rules are
for the business object - and code clarity is important in large projects with multiple
devs.  Feel free to use the above code in your own projects, if you create any
really cool validators, please share!</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
            </font>
          </span> 
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
            </font>
          </span> 
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
            </font>
          </span> 
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          </span> 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Implementing Drag/Drop with TabControl</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/07/25/ImplementingDragDropWithTabControl.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,adc227ac-2da6-4ad4-8b7e-e7d5aee32fb2.aspx</id>
    <published>2008-07-25T13:09:45.374-07:00</published>
    <updated>2008-07-25T13:09:45.3745642-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">It's been a long time since I blogged anything
specific on WPF -- I've been doing a lot of it lately, along with some Silverlight. 
Recently I was experimenting with dragging tabs around on a TabControl at runtime. 
My end goal is really to implement it with Silverlight 2, but I've found it's much
easier to prototype things in WPF and then port them over because the debugging experience
is easier with WPF.<br /><br />
I didn't want to create derived implementations of any classes - I wanted something
that was non-intrusive to my code so I decided to use an <a href="http://msdn.microsoft.com/en-us/library/ms749011.aspx">attached
property</a>.  Attached properties are basically property values "attached" to
a class at runtime - where the property itself isn't defined on the target but instead
on some other type.  The cool thing about attached properties is they can register
a change notification handler which gives them a reference to the object they are
being placed on -- this is how the Spell Checker works with the TextBox in WPF. 
All the code for the spell checking lives in the SpellChecker class and when you add
the SpellCheck.IsEnabled property onto the TextBox, it adds handlers to the TextBlock's
TextChanged property and adds all the nifty spell checking goodness <i>without changing
the code in TextBox</i>.<br /><br />
Back to my drag/drop prototype.  So with this code, I can add the property to
any TabControl and get a nice, simple drag/drop experience.  It's far from complete
- it would be cooler if the tabs moved around as you dragged (they don't), but I was
just prototyping here.<br /><br />
Here's the code:<br /><br /><br /><p><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"></span><br /></span></p><br /><p></p><!-- code formatted by http://manoli.net/csharpformat/ --><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}

.csharpcode .lnum { color: #606060; }
</style><pre class="csharpcode"><span class="kwrd">using</span> System; <span class="kwrd">using</span> System.Diagnostics; <span class="kwrd">using</span> System.Windows; <span class="kwrd">using</span> System.Windows.Controls; <span class="kwrd">using</span> System.Windows.Input; <span class="kwrd">using</span> System.Windows.Media; <span class="kwrd">namespace</span> WpfApplication1
{ <span class="kwrd">public</span><span class="kwrd">class</span> DragDropTabManager
{ <span class="kwrd">private</span><span class="kwrd">static</span><span class="kwrd">readonly</span> DependencyProperty
ManagerProperty = DependencyProperty.Register(<span class="kwrd">typeof</span> (DragDropTabManager).ToString(), <span class="kwrd">typeof</span> (DragDropTabManager), <span class="kwrd">typeof</span> (DragDropTabManager)); <span class="kwrd">public</span><span class="kwrd">static</span><span class="kwrd">readonly</span> DependencyProperty
EnabledProperty = DependencyProperty.RegisterAttached(<span class="str">"Enabled"</span>, <span class="kwrd">typeof</span>(<span class="kwrd">bool</span>), <span class="kwrd">typeof</span>(DragDropTabManager), <span class="kwrd">new</span> PropertyMetadata(<span class="kwrd">false</span>,
DDTM_EnabledChanged)); <span class="kwrd">private</span><span class="kwrd">static</span><span class="kwrd">void</span> DDTM_EnabledChanged(DependencyObject
d, DependencyPropertyChangedEventArgs e) { var tc = d <span class="kwrd">as</span> TabControl; <span class="kwrd">if</span> (tc
!= <span class="kwrd">null</span>) { var oldValue = (<span class="kwrd">bool</span>)
e.OldValue; var newValue = (<span class="kwrd">bool</span>) e.NewValue; <span class="kwrd">if</span> (oldValue
== <span class="kwrd">true</span> &amp;&amp; newValue == <span class="kwrd">false</span>)
{ var ddtm = tc.GetValue(ManagerProperty) <span class="kwrd">as</span> DragDropTabManager; <span class="kwrd">if</span> (ddtm
!= <span class="kwrd">null</span>) { tc.PreviewMouseDown -= ddtm.TabItem_PreviewMouseDown;
tc.SetValue(ManagerProperty, <span class="kwrd">null</span>); } } <span class="kwrd">else</span><span class="kwrd">if</span> (oldValue
== <span class="kwrd">false</span> &amp;&amp; newValue == <span class="kwrd">true</span>)
{ var ddtm = <span class="kwrd">new</span> DragDropTabManager(); tc.SetValue(ManagerProperty,
ddtm); tc.PreviewMouseDown += ddtm.TabItem_PreviewMouseDown; } } } <span class="kwrd">public</span><span class="kwrd">static</span><span class="kwrd">bool</span> GetEnabled(DependencyObject
obj) { <span class="kwrd">return</span> (<span class="kwrd">bool</span>)obj.GetValue(EnabledProperty);
} <span class="kwrd">public</span><span class="kwrd">static</span><span class="kwrd">void</span> SetEnabled(DependencyObject
obj, <span class="kwrd">bool</span><span class="kwrd">value</span>) { obj.SetValue(EnabledProperty, <span class="kwrd">value</span>);
} <span class="kwrd">private</span><span class="kwrd">bool</span> isMoving; <span class="kwrd">private</span> TabItem
movingTabItem; <span class="kwrd">private</span> TabItem lastTab; <span class="kwrd">private</span> Point
ptStart; <span class="kwrd">void</span> TabItem_PreviewMouseDown(<span class="kwrd">object</span> sender,
MouseEventArgs e) { var ti = e.Source <span class="kwrd">as</span> TabItem; <span class="kwrd">if</span> (ti
!= <span class="kwrd">null</span> &amp;&amp; e.LeftButton == MouseButtonState.Pressed)
{ var tc = ti.Parent <span class="kwrd">as</span> TabControl; <span class="kwrd">if</span> (tc
!= <span class="kwrd">null</span>) { tc.MouseMove += tc_MouseMove; tc.MouseLeftButtonUp
+= tc_MouseLeftButtonUp; ptStart = e.GetPosition(tc); movingTabItem = ti; } } } <span class="kwrd">void</span> tc_MouseMove(<span class="kwrd">object</span> sender,
MouseEventArgs e) { var tc = sender <span class="kwrd">as</span> TabControl; <span class="kwrd">if</span> (tc
== <span class="kwrd">null</span>) <span class="kwrd">return</span>; Point pt = e.GetPosition(tc); <span class="kwrd">if</span> (isMoving
== <span class="kwrd">false</span>) { <span class="kwrd">if</span> (Math.Abs(pt.X
- ptStart.X) &gt; 10) { movingTabItem.IsHitTestVisible = <span class="kwrd">false</span>;
movingTabItem.RenderTransformOrigin = <span class="kwrd">new</span> Point(.5, .5);
movingTabItem.RenderTransform = <span class="kwrd">new</span> TranslateTransform(0,
0); tc.Cursor = Cursors.Hand; Panel.SetZIndex(movingTabItem, 1); isMoving = <span class="kwrd">true</span>;
tc.CaptureMouse(); } <span class="kwrd">return</span>; } TabItem newPos = FindTabItem(tc,
pt); <span class="kwrd">if</span> (newPos == <span class="kwrd">null</span>) tc.Cursor
= Cursors.No; <span class="kwrd">else</span> { lastTab = newPos; var xform = movingTabItem.RenderTransform <span class="kwrd">as</span> TranslateTransform; <span class="kwrd">if</span> (xform
!= <span class="kwrd">null</span>) xform.X = pt.X - ptStart.X; tc.Cursor = Cursors.Hand;
} } <span class="kwrd">void</span> tc_MouseLeftButtonUp(<span class="kwrd">object</span> sender,
MouseButtonEventArgs e) { var tc = sender <span class="kwrd">as</span> TabControl;
Debug.Assert(tc != <span class="kwrd">null</span>); tc.ReleaseMouseCapture(); tc.MouseMove
-= tc_MouseMove; tc.MouseLeftButtonUp -= tc_MouseLeftButtonUp; <span class="kwrd">if</span> (isMoving
== <span class="kwrd">true</span>) { isMoving = <span class="kwrd">false</span>; tc.Cursor
= Cursors.Arrow; movingTabItem.RenderTransform = <span class="kwrd">null</span>; movingTabItem.IsHitTestVisible
= <span class="kwrd">true</span>; Panel.SetZIndex(movingTabItem, 0); <span class="kwrd">if</span> (lastTab
!= <span class="kwrd">null</span>) { <span class="kwrd">if</span> (lastTab != <span class="kwrd">null</span> &amp;&amp;
movingTabItem != lastTab) { <span class="kwrd">int</span> targetIndex = tc.Items.IndexOf(lastTab);
tc.Items.Remove(movingTabItem); tc.Items.Insert(targetIndex, movingTabItem); movingTabItem.Focus();
} } } movingTabItem = lastTab = <span class="kwrd">null</span>; } <span class="kwrd">private</span><span class="kwrd">static</span> TabItem
FindTabItem(UIElement parent, Point pt) { var fe = parent.InputHitTest(pt) <span class="kwrd">as</span> FrameworkElement; <span class="kwrd">while</span> (fe
!= <span class="kwrd">null</span> &amp;&amp; fe.GetType() != <span class="kwrd">typeof</span>(TabItem))
fe = VisualTreeHelper.GetParent(fe) <span class="kwrd">as</span> FrameworkElement; <span class="kwrd">return</span> fe <span class="kwrd">as</span> TabItem;
} } } </pre></div>
    </content>
  </entry>
  <entry>
    <title>ATAPI assembly updated!</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/07/23/ATAPIAssemblyUpdated.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,599288b9-351f-471d-abda-f75ba99219e8.aspx</id>
    <published>2008-07-23T10:54:45.907-07:00</published>
    <updated>2008-07-23T10:55:11.892661-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Tapi" label="Tapi" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Tapi.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's been a while since I updated the ATAPI assembly, I've fixed a couple of minor
bugs that were reported and updated the samples to compile with VS2008.  I've
also added two new events onto the TapiPhone class so you can see state changes and
button presses - somehow I missed that when I added the phone support.
</p>
        <p>
Finally, there's now online documentation available at 
</p>
        <p>
          <a href="http://www.julmar.com/atapi_help/index.aspx">http://www.julmar.com/atapi_help/index.aspx</a>
        </p>
        <p>
You can download the updated assembly, help file and samples from 
</p>
        <p>
          <a href="http://www.julmar.com/tapi/atapinet.zip">http://www.julmar.com/tapi/atapinet.zip</a>
        </p>
        <p>
Have fun!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Adding ILDasm to VS.NET with a keyboard shortcut</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/05/13/AddingILDasmToVSNETWithAKeyboardShortcut.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,d18594fb-c544-4398-821d-1c0391129f88.aspx</id>
    <published>2008-05-13T12:13:09-07:00</published>
    <updated>2008-05-13T08:02:11.5049441-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I often show students in my classes how to add ILDasm to their tools menu - it's handy
because you can then click on ILDasm and it will open the current module allowing
you to look at the manifest, IL, etc.<br /><br />
1. Select Tools | External Tools. You’ll get the tools dialog:
</p>
        <div align="left">
          <img src="http://www.julmar.com/blog/mark/content/binary/Tools1.png" width="325" height="366" alt="Tools1.png" />
          <br />
          <br />
2. Enter ILDASM for the title and set the Command to the path for ILDASM. The path
varies a bit from version to version of Visual Studio. For VS2008 you will find it
at <b>C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\ildasm.exe</b><br /><br />
3. Click the button to the right of Arguments and select "Target Path" and select
the "Use Output Window" checkbox.<br /><br /><img src="http://www.julmar.com/blog/mark/content/binary/Tools2.png" border="0" height="298" width="354" name="Tools2.png" style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-left-color: rgb(0, 0, 0); border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid;" id="Tools2.png" /><br /><br />
5. You should now be able to access Tools | ILDASM.<br /><br />
One student in another class recently asked how to get a keyboard shortcut to this. <a href="http://www.michaelckennedy.net">Michael
Kennedy</a> - our resident VS.NET shortcut king showed exactly how to do this. It
turns out to be really simple -- go to Tools | Options and select Keyboard. Then 1,2,3:<br /></div>
        <br />
        <img src="http://www.julmar.com/blog/mark/content/binary/CustomLauncher.png" border="0" width="484" height="282" />
        <br />
      </div>
    </content>
  </entry>
  <entry>
    <title>Demos from Guerrilla .NET</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/05/12/DemosFromGuerrillaNET.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,4990c08c-16d7-4592-a4c3-123d0caece7f.aspx</id>
    <published>2008-05-12T11:10:09.8233013-07:00</published>
    <updated>2008-05-12T11:10:09.8233013-07:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Thanks to all who attended the Guerrilla
.NET event in Boston last week. Speaking as one of the instructors, it was a blast
to get to know each of you! As promised, <a href="http://www.julmar.com/DMStuff/GNET_demos.zip">here
are the demos</a> -- ping me using email if you have any questions!
</div>
    </content>
  </entry>
  <entry>
    <title>Creating Extensible Applications with MAF (System.AddIn)</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/05/06/CreatingExtensibleApplicationsWithMAFSystemAddIn.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,4e4f6f4e-ca26-48e3-b096-c8dfc282209f.aspx</id>
    <published>2008-05-06T14:46:26.238-07:00</published>
    <updated>2008-05-06T14:47:32.833392-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="Real World" label="Real World" scheme="http://www.julmar.com/blog/mark/CategoryView,category,RealWorld.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">
&lt;!--[if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin-top:0in;
	mso-para-margin-right:0in;
	mso-para-margin-bottom:10.0pt;
	mso-para-margin-left:0in;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-ascii-font-family:Cambria;
	mso-ascii-theme-font:minor-latin;
	mso-hansi-font-family:Cambria;
	mso-hansi-theme-font:minor-latin;}
&lt;/style&gt;
&lt;![endif]--&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;o:shapedefaults v:ext="edit" spidmax="2050"/&gt;
&lt;/xml&gt;&lt;![endif]--&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;o:shapelayout v:ext="edit"&gt;
  &lt;o:idmap v:ext="edit" data="1"/&gt;
 &lt;/o:shapelayout&gt;&lt;/xml&gt;&lt;![endif]--&gt;
&lt;div class="Section1"&gt;
&lt;h1&gt;
&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
Last month, my colleague, &lt;a href="http://www.develop.com/us/technology/bio.aspx?id=87"&gt;Pinku
Surana&lt;/a&gt;, wrote an article about .NET AppDomains and how they can be used to provide
component isolation and make your applications more reliable.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;If
you missed it, you can read the &lt;a href="http://www.develop.com/us/technology/technology.aspx?tech=all"&gt;Developments
archives&lt;/a&gt; on Developmentor’s website.&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;This month,
I’d like to continue exploring reliability and extensibility by introducing you to
a new framework included with .NET 3.5: The Managed Add-in Framework (MAF), sometimes
referred to as System.AddIn.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Developers (and managers) have long desired a way to easily create extensible applications
that allow new features to be added without jeopardizing the stability of the existing
code base.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The .NET framework has provided the underlying
support to accomplish this from the very beginning through the reflection API and
AppDomain support Pinku examined last month.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;MAF builds
on that fundamental support to provide a higher-level service that allow you to dynamically
discover, load, secure and interact with external assemblies used to provide features
for your application.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Several common architectural requirements
are made trivial with MAF:
&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="text-indent: -0.25in;"&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;1)&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!--[endif]--&gt;Isolate aspects of your code for security reasons or partial-trust scenarios.
&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in;"&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;2)&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!--[endif]--&gt;Allow business partners to extend your application safely without access
to the source code; Adobe Illustrator is a great example of this style of application.
&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in;"&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;3)&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!--[endif]--&gt;Separate volatile sections of your application out – where depending
on the customer the application needs to execute different sets of code.
&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in;"&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;4)&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!--[endif]--&gt;Add or change code without unloading the application – for example pay-to-play
scenarios, or where you need to update an assembly but the application must continue
to run.
&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="text-indent: -0.25in;"&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;5)&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!--[endif]--&gt;Develop and evolve different sections of the application in parallel
without any fear of destabilizing one based on the other.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
If any of these scenarios sound like something you could utilize in your application
then you should know about MAF!
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
At the center of the MAF-based application is the pipeline.
&lt;/p&gt;
&lt;h2&gt;The Pipeline
&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;
Communication between add-ins and the host application is strictly regulated by the
pipeline.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The pipeline is dynamically created by MAF through
a set of loosely-coupled components which are used to version, marshal and transform
the data as it passes back and forth between the host and each loaded add-in.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style=""&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shapetype
 id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
 path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;
 &lt;v:stroke joinstyle="miter"/&gt;
 &lt;v:formulas&gt;
  &lt;v:f eqn="if lineDrawn pixelLineWidth 0"/&gt;
  &lt;v:f eqn="sum @0 1 0"/&gt;
  &lt;v:f eqn="sum 0 0 @1"/&gt;
  &lt;v:f eqn="prod @2 1 2"/&gt;
  &lt;v:f eqn="prod @3 21600 pixelWidth"/&gt;
  &lt;v:f eqn="prod @3 21600 pixelHeight"/&gt;
  &lt;v:f eqn="sum @0 0 1"/&gt;
  &lt;v:f eqn="prod @6 1 2"/&gt;
  &lt;v:f eqn="prod @7 21600 pixelWidth"/&gt;
  &lt;v:f eqn="sum @8 21600 0"/&gt;
  &lt;v:f eqn="prod @7 21600 pixelHeight"/&gt;
  &lt;v:f eqn="sum @10 21600 0"/&gt;
 &lt;/v:formulas&gt;
 &lt;v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/&gt;
 &lt;o:lock v:ext="edit" aspectratio="t"/&gt;
&lt;/v:shapetype&gt;&lt;v:shape id="O_x0020_2" o:spid="_x0000_i1028" type="#_x0000_t75"
 style='width:6in;height:81pt;visibility:visible' o:gfxdata="UEsDBBQABgAIAAAAIQCxpCU+/wAAAOEBAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbJSRwU7DMAyG

70i8Q5QralJ2QAi13YGOIyA0HsBK3DZa60RxKNvbk27sgISGOCb2//n372q9n0YxY2TnqZa3qpQC

yXjrqK/l+/apuJeCE5CF0RPW8oAs1831VbU9BGSR1cS1HFIKD1qzGXACVj4g5Urn4wQpP2OvA5gd

9KhXZXmnjaeElIq0MGRTtdjBx5jEZp+/T06yXIrHU98yqpYQwugMpGxUL1XdVC/ZeHQWxSvE9AxT

7tI2ssaVb71RlxkzWTVx4bvOGVRt5M1RdfMH2/pPijj/F95m2RvOZ/ovG0cc+cLKi92fuRbfmaqs

PMbCgwt8nqCPB2q+AAAA//8DAFBLAwQUAAYACAAAACEAOP0h/9YAAACUAQAACwAAAF9yZWxzLy5y

ZWxzpJDBasMwDIbvg72D0X1xmsMYo04vo9Br6R7A2IpjGltGMtn69jODwTJ621G/0PeJf3/4TIta

kSVSNrDrelCYHfmYg4H3y/HpBZRUm71dKKOBGwocxseH/RkXW9uRzLGIapQsBuZay6vW4mZMVjoq

mNtmIk62tpGDLtZdbUA99P2z5t8MGDdMdfIG+OQHUJdbaeY/7BQdk9BUO0dJ0zRFd4+qPX3kM66N

YjlgNeBZvkPGtWvPgb7v3f3TG9iWOboj24Rv5LZ+HKhlP3q96XL8AgAA//8DAFBLAwQUAAYACAAA

ACEAf8D54GENAABZlQAADgAAAGRycy9lMm9Eb2MueG1s7J1bc+I4Fsfft2q+g8uvU5lgDIZQTU+l

05Oeqcr0pkJm91nYArzxbWWR26efc45kYxNIEweHTVZ5IAJfJP91LOn8fCR/+vU+jqxbLvIwTca2

80vHtnjip0GYzMf2X9fnR0PbyiVLAhalCR/bDzy3f/380z8+3WUj3k0XaRRwYcFJknx0l43thZTZ

6Pg49xc8ZvkvacYT2DhLRcwkfBXz40CwOzh7HB13Ox3v+C4VQSZSn+c5/PpVbbQ/0/lnM+7Lf85m

OZdWNLahbJI+BX1O8fP48yc2mguWLUJfF4M1KEXMwgQyLU/1lUlmLUXY4FRR6t/w4IwltyyHU0b+

qPqLLmPkv/7MbJTcfhPZJLsUWHL/++2lsMKAtElYDJWl1IENejcQ63jtqPnqBPczEeOJ0tnMuqez

PJQK83tp+fDj0HM6XgcqwodtjtcZuL2ezmUBFYXHdbtD2gN26HVcSlMl+YvffnASKJsqAyQq5aIk

FmzL5Tqubanr/SbSZWY53Vdd97by/y9LsK7A8A0VcAfDwRMjcDu9IZoJGkHvpI/pZ41gdZItRpBn

ygKeWrvjFNV/Ba0FS+YRt5wiu++3eEBh98XBOfxmTe/+TAO4SdhSpnTrr9n/tkso7ODE6fXKO8Ed

wM1AmZblZ6NM5PIbT2MLE2NbQPEoI3Z7kUtVpmIXvLg8jcLgPIwi+iLm07NIWLcMGr7zc2919tpu

UfL8kR36Q+2hXLUjF5wFvyWBJR8yECGBxt227sZ2zAPbijj0BZiiOpMsjHbZE3LA4mBGukmS9xOq

Nnn/JQ0esKRT+A/aQ4cDgixS8QiZQuM9tvP/LpmAIkR/JPnYJm2htacvvf6gC6Ykqlum1S3JMj5L

QSYwBCEjSsL+LPEhg7HtS1F8OZOq5/DTOGPyIplk0Aw7VCdYEdf3/2Yi07UloZ6/p5MFy/imSlP7

4iUl6SlY0CzUNaquEDdEuZzIh4hjOuCzS9VMQ+oKFIjAUMc2T47+mujaWe0S3UYOWiiL5lAPEV0V

tcezNJGn9OOU5apYeeZ/4TPMAlKXvlQGU1hibevpTD6zn96qi5c/QkNO5g29LOga0ucNFzhIgH6b

JKnZE/X4vDTZ4MbZZHURk2FCNjdjPtjdz3FyFEllZ5ytbeBMbfDztQ1+vtIMxCSb06KR8LdRF/WL

mbiA9gfNB+3BqEm3865qooRaTXelZtHqGTVfZpsooVazt1LT0f2GMc4X3uqooZazX5Fz2B3SsMNY

58usEzXUcnorOdVIuNp0Qu9wzaYT6ByKdgA6XOqaOLtIvogb6iaokddf4egFdHXg2l0uEx86fdXd

vuduBhXSYg0qYg16br2fMWJBn4wKabGGK7FQKRpdlDeqEQvEQoW0WCcVsbz+gDxqIxYOnYvRHiqk

0pVxNrkbK+mg9YFB4BW1UGES8AQaoLI9I8dgB7uDA9YG3jB6h2HsthZODY4j9C6wMqvjcqfqjlX3

2OsYfrqEYfj1PY32psvJY5k8B/+h/PIdXD7t301X/qgyQLJCAUPom2Ucxul/YPgPKlR9FmuDhwC7

LAtXMpcivCHHckIpIEbo5ik/M0EcGIWP/Hc6LzozUYh0Ec4QhEICNYBUHsuziDPwOApFUc4kRRcZ

Cq7dzTW3ds0Nmc43uiGcyKK6anDU1pySUxEy8Lr8BRNAHjF7lR0IgiWQn39Pc4n5gz8Fn8oKwfLw

l9LTXeZ8kiGRUMcWrnBeeIRRcsVngOuAmKkuca3kzPfBXAll0ZXC3pj5DC6+PLBrk4Eha115XvUD

9f64n7ro8uAdci2PoJzBeMqD4xDqcFPuK78P7xkqNBRfXzWm6A59huZ0N9AcqkMinBO4t5WgCZEd

un68339Ec5yuc0Ld8zqROgDO6XRgkFoYVc2JjhJkMCf9bl/fLzOwTUjGWQCIJJkXXiw2XXTpNWRU

twN5v9H0EXR8ZflCgQLKXY0VgZ0mAWjLRq2hocIGy+bGgCLUO6p0YNAfXapmBlLQ29UaXWX5q10+

AijaYqY7tclgT4YZrZDxTvf/Wwn7cfHRgS32A5OkAyv7gaHSgZV9t3zpwLq9W9R0YN3eLXU6sG7v

FkAdWDfDop48d9bPk/+vWVQ9huMc/jRJqjn9+4ZRRKTg463w3WuJ3ZuoZP0r5Hc1ZgfOYxJcMsHQ

y35/nLNN1VbCENTcCW3uwvZ6Bdu7hpgf/piGgQXBe8ScIEjxZWzPEimg2T48RUKWhhhFxy123f7Q

60LYKpK+7qAzGOh4wIL0wUN3ilhTMYz6kbFCK0UIWBGWVcQCFcWlfHYK36r74gWTJdqzjCHwTLWX

fSq8yrvkv6R5rYUwWHBj/BhGkUEFmxCyjxlCduAxHYbg0f364aLJDiysIYObni/ugWUbMrjxye0e

lDVksC1lDRlUQdAvjXU2ZLCZboYMNtPNkMFmuhkyaMjgD+ZoIRdsjQxapwHLJBc19AWsZm9Mx9vA

dPqvYjqOB4Faa1Cn73YG/T5Mc0So43onw95A5bEZ6nhux+udaNhqoM57ivVCqNM+0YEs1PzAMzMl

sB6iXMYlZv6epwQeGDsYntMSdjA8pyVhDc9pizoYntOWsobnNPMTDc9pppvhOc10MzynmW6v5jkw

sczMORxJtn3OYW2aYfiDSYG1OIl8l6AYgB/lRL7TIDiC9Ug2MRITHmRvHCOAfG2FBw0KlFRZyMlr

iJIqAUEw2Q7n3T5djKpgR8VaBrSm2eFWcjJT/8waUWbq347TsffwUN8AoZa4hQFCLQlrgNDGIcke

2gIDhNpS1gChZo6mAULNdDNAqJluBgg10+3VQAjXcjFICJZOegYJmelZG9ehUviqtdAemEOl1lWv

8BgddvPi6VoVHuMNhg6t0rltKaZyraY3ADJmLaZiKfJcz3cpVipbLWVmFu02azFVF+1uy1UwQKYl

bmCATEvCGiDTVltggExbyhog08zRM0CmmW4GyDTTzQCZZroZIGNmXB1qxpWOJ3qy1tA+J1zB0tBP

qEzxDr6XLqJToTLuwHVLKgMJ/cIxeLam39rn9PGFUBBGg1RmQHO0np9g1fx9Z67reZtnxJmVcDau

hGPepPZx36Rmpk2pBbE+2nw0A2UMlKHXZb3grYoHbgsMlDFQplymUHkZB7ZIA2WaOckGyjTTzUCZ

ZroZKGOgzKGgzBm8iEwwv9kb24Dc4MvK4N9cZOpt5ttfXtYFOqLYzAWfyaOrcL6Q1qkQ6Z3l0Go0

r3uH2dAdFq8w63dcz+1p7FMQmkHPUy+KRELjdU5W74zfsgTO3wAAAP//7JdRb+M2DMe/iqHX4dDF

TZpccC6Q5tZtQHcLmg73zMhy7EWWPUlu0376kZQSO8Vu6Lo9DelDQ0m0Rf1EmfprVfj7alv6hbXN

k7j+BHN4vHP+4vrTBcxb6/yPqqmp2zW6ym8rrbkhS1WrpbbJI+hMgJTK+JQf1139S5OH/vR7/BP4

Lphj969FEbpnfTfotoTQOx5HZ5zYHd7PYZxMrU3ylImPk3QiEgltJgoNHs26zTPhzFYkoLcmE9Jb

jufk4eN7w5R+P6LoaMLh6mjZn8GVwYmHwiJs05mcl1MqyH8weeKfW5UJ0xglKKxa5SLRCqcniz09

VPotnhiENkRKFYWS/rgHrl1Z6vb7dRt+b5r8mawN/q5wB5T1mSgb+4IhWCLi/ujAYkD6Z+MQ1QjJ

isRzYzyZptiww5HNcMR09bLBLR2hk9dsoj8YiRNkAkEHc+mxhQOyqVvwd2bdSnqGwiJ6D/uvYNuE

THxI7f2XZl1Cq9jhVYIFX3rStYvON7dVzL6wPhrQzq/9s1Zk56pYBSJo3eP6NZhtJpT58Ns6bmbv

oh/1CPnFlNC8Jo67aIxfcJ5swIWwXCtvVBHikCvpw+5z+lKCDEcXhf8bvzgaw3MvmUgxtUWyYaoV

/98pi0kywgPy3iTFrK8M518BEnNwYSvABcoSrFNIPZ47BQOf72rzQUHIS+leDUjX40OufCwiP96D

R50SyhrsXSY4jygxmOEZ7DvAEs0I9rIHy6f1DLZVIavfk7FEM4Id92BHl9PRFR3Dc8ry9+I9ZAln

JDsZkJ2lMyzpZ7L/ImcJZyR71ZNN0xmm7JAsFpUH2Kyxphw+FFiluaIpuDM3dsfVhWtDbOLTJVbI

ymxXnZFYGEKV/p9UJ4IVuU0H3KbjSyqt/Vk/cwsbfqjqBCtym/XcCBpfVY7fyDO3U24EK3L7OOB2

NZme1pYzt1NuBCvk3uAqz3qmp4jnFS+X9/w1q0yOipLNf5KL+IpXN3uUB3hP/ta3MNy+NckX2lW8

5B8v/iMSqYfb/9DjPxUJmw5F9MOeleKmW78czVsUKMfGF9SXUUxujsIwZqIy+QoskBLadXVVN7+j

wkAOQ1mU/IUIQZfuoFydt9WOdeyaraisg6w1ja1BVy/qJ34v6SVdGfTGN+SV9c9sudovtQIUNQem

BNSgmtMaQz+q2xOh/TY5PhTEqAXfontwup4Lz465hp1+fxDPnVPr9h6FdgguqGvWeey4tS3J7Qst

57qRO5UvwTyCi2PQlpX8DB6GbbSf2rlKm7LRubLXfwIAAP//AwBQSwMEFAAGAAgAAAAhAIbR737X

AAAABQEAAA8AAABkcnMvZG93bnJldi54bWxMj81qwzAQhO+FvIPYQm+NnFBMcCyHNMX4XLfkLFsb

28RaGUv+6dt320t7WRhmmP0mPa22FzOOvnOkYLeNQCDVznTUKPj8yJ8PIHzQZHTvCBV8oYdTtnlI

dWLcQu84l6ERXEI+0QraEIZESl+3aLXfugGJvZsbrQ4sx0aaUS9cbnu5j6JYWt0Rf2j1gJcW63s5

WQV+KXGY451bw1R119e8eCvyQqmnx/V8BBFwDX9h+MFndMiYqXITGS96BTwk/F72DvELy4pD8T4C

maXyP332DQAA//8DAFBLAQItABQABgAIAAAAIQCxpCU+/wAAAOEBAAATAAAAAAAAAAAAAAAAAAAA

AABbQ29udGVudF9UeXBlc10ueG1sUEsBAi0AFAAGAAgAAAAhADj9If/WAAAAlAEAAAsAAAAAAAAA

AAAAAAAAMAEAAF9yZWxzLy5yZWxzUEsBAi0AFAAGAAgAAAAhAH/A+eBhDQAAWZUAAA4AAAAAAAAA

AAAAAAAALwIAAGRycy9lMm9Eb2MueG1sUEsBAi0AFAAGAAgAAAAhAIbR737XAAAABQEAAA8AAAAA

AAAAAAAAAAAAvA8AAGRycy9kb3ducmV2LnhtbFBLBQYAAAAABAAEAPMAAADAEAAAAAA=

"&gt;
 &lt;v:imagedata src="Creating%20Extensible%20Applications%20with%20MAF_files/image001.png"
  o:title="" croptop="-786f" cropbottom="-414f"/&gt;
 &lt;o:lock v:ext="edit" aspectratio="f"/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;
&lt;!--[if !vml]--&gt;&lt;img src="http://www.julmar.com/blog/mark/content/binary/image001.png" alt="image001.png" border="0" height="102" width="557"&gt;
&lt;br&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Each section of the pipeline is contained in a separate assembly, loaded as necessary
to manage the specific add-in.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;MAF discovers each component
and then loads them on request using reflection.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
For reliability, MAF allows optional isolation boundaries to be created between the
add-in and host – everything to the left of the contract is loaded into the main (host)
AppDomain and everything to the right loaded into a newly created AppDomain which
has its own security permission set.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The isolation can
also be done through cross-process calls if true process-level isolation is necessary.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Under
the covers, the system uses traditional remoting calls to do the work of marshaling
calls back and forth.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Breaking down the pipeline, there are three main parts starting in the center with
the contract.
&lt;/p&gt;
&lt;h2&gt;Contract
&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;
As you might expect, MAF is based on interface contracts.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Interfaces
allow classes in an application to be loosely coupled, reducing the risk when changes
are made between dependent sections of the code.&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;The
interface contract is shared between the host and add-in and once it has been established,
it should never be changed.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Consider the simple example of a translator program.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The
host will expect to load one or more translator add-ins that will do some work on
an inbound string and return the results.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;To accomplish
this, I might create an &lt;b style=""&gt;ITranslator&lt;/b&gt; interface that looks like:
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;[AddInContract]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;public interface ITranslator
: IContract&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;string
Translate(string input);&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;br&gt;
}&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
Notice that the interface derives from &lt;b style=""&gt;IContract&lt;/b&gt;. &lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;This
is a requirement for add-in contracts and is what will be used to provide marshalling
support when the pipeline is established.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;We also need
to decorate the interface with the &lt;b style=""&gt;[AddInContract]&lt;/b&gt; attribute – this
is the marker used by MAF to identify the contract when it is dynamically constructing
the pipeline.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Both of these types come from the &lt;b style=""&gt;System.AddIn.Pipeline&lt;/b&gt; namespace
in &lt;b style=""&gt;System.AddIn.Contract.dll&lt;/b&gt;.
&lt;/p&gt;
&lt;h2&gt;Views
&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;
Moving to the edges, we find the views.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This is the code
that the add-in and host directly interact with.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It represents
a host or add-in specific “view” of the contract and, like the contract, is contained
in a separate assembly.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Both of the view classes will echo the structure of the contract, but not actually
be dependent upon the contract. &lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;For example, our host
side view might look like this:
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;public abstract class
TranslatorHostView&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
abstract string Translate(string input);&lt;br&gt;
}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
The view is commonly exposed as an abstract class to make it look more natural when
used by the host, but an interface will work just as well.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The
host uses the view directly when communicating with any add-in based on the contract.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
On the add-in side, we have an almost identical class – except we decorate this type
with the &lt;b style=""&gt;[AddInBase]&lt;/b&gt; attribute so MAF knows which side of the pipeline
this view is for (the add-in).&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;This is located in
the &lt;b style=""&gt;System.AddIn.Pipeline&lt;/b&gt; namespace in the &lt;b style=""&gt;System.AddIn&lt;/b&gt; assembly.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
When we create each add-in, the implementation will use this type as the base class.
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;[AddInBase]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;public abstract class
TranslatorAddInView&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
abstract string Translate(stringinp);&lt;br&gt;
}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;h2&gt;Adapters
&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;
The last piece of the pipeline is the adapters.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The adapters
play a very special role in the pipeline – they are the glue that binds the contract
to the view: implementing lifetime management and any necessary data conversion between
the two ends.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
It may seem redundant to have this class, but by separating the view from the contract
we introduce version tolerance into our architecture – the host can version independently
of the add-in and vice-versa.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Depending on the situation,
the adapters can be as simple as a pass-through class, or can provide higher-level
services to allow non-serializable types to be marshaled across the isolation boundaries.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
On the host side, the adapter will implement the view (remember it is either an interface
or abstract class).&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It will be passed a reference to the
contract in the constructor and it is responsible for connecting the two together.
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;[HostAdapter]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;public class TranslatorHostViewToContract
: &lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;TranslatorHostView&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ITranslator
_contract;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ContractHandle
_lifetime;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;i&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
TranslatorHostViewToContract(&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ITranslator
contract)&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;_contract
= contract;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;_lifetime
= new ContractHandle(contract);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;i&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
override string Translate(string inp)&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;return
_contract.Translate(inp);&lt;br&gt;
&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
In this simple example, the code caches off the contract interface.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This
is a remoting proxy to the actual loaded add-in.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The adapter
then implements the &lt;b style=""&gt;Translate&lt;/b&gt; method and passes it forward to the
contract for implementation.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;If we had non-serializable
types, then the adapter would be responsible for converting them into something that &lt;i style=""&gt;was&lt;/i&gt; serializable.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
It also provides some lifetime management for the contract.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Because
the contract is a remoting proxy and is likely running in a separate AppDomain (or
even process) we have to be concerned with how long it lives.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;MAF
provides all the support for this through the &lt;b style=""&gt;ContractHandle&lt;/b&gt; class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Most
of the time, all you will need to do is store a &lt;b style=""&gt;ContractHandle&lt;/b&gt; in
your host adapter and then pass it the inbound contract to wrap in your constructor.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Finally, in order for MAF to identify this class, it must be decorated with the &lt;b style=""&gt;[HostAdapter]&lt;/b&gt; attribute
from the &lt;b style=""&gt;System.AddIn.Pipeline&lt;/b&gt; namespace out of the &lt;b style=""&gt;System.AddIn.dll&lt;/b&gt;. 
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
The add-in side looks very similar, but does the opposite: it makes the add-in view
look like the contract.
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;[AddInAdapter]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;public class TranslatorAddInViewToContract
: 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ContractBase,
ITranslator&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;TranslatorAddInView
_view;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
TranslatorAddInViewToContract(&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;TranslatorView
view)&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;_view
= view;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;i&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
string Translate(string inp)&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;{&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
_view.Translate(inp);&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;} 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;
&lt;br&gt;
MAF passes the view to the constructor and the class caches the reference off in a
field.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It implements the contract (&lt;b style=""&gt;ITranslator&lt;/b&gt;)
and &lt;b style=""&gt;ContractBase&lt;/b&gt; which provides the implementation of the &lt;b style=""&gt;IContract&lt;/b&gt; interface
for us (remember this was a required interface on our contract).&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;As
the host makes calls to the contract interface, this class will translate those calls
to the add-in view, which as you will see is the implementation provided by the add-in
itself.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Note how the &lt;b style=""&gt;[AddInAdapter]&lt;/b&gt; attribute
is used to mark this class so MAF can discover it.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
If it seems like all the above is a lot of repetitious, boilerplate code well.. you’re
right!&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;To make it easier on the developer to create the
pipeline components, the MAF team has created a &lt;a href="http://www.codeplex.com/clraddins"&gt;pipeline
builder&lt;/a&gt; available at http://www.codeplex.com/clraddins.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It
takes the contract assembly and then generates the views and adapters from it: 
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style=""&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape
 id="P_x0020_3" o:spid="_x0000_i1027" type="#_x0000_t75" alt="image1.jpg"
 style='width:6in;height:284pt;visibility:visible;mso-wrap-style:square'&gt;
 &lt;v:imagedata src="Creating%20Extensible%20Applications%20with%20MAF_files/image003.jpg"
  o:title="image1.jpg"/&gt;
 &lt;v:textbox style='mso-rotate-with-shape:t'/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;
&lt;!--[if !vml]--&gt;&lt;img src="http://www.julmar.com/blog/mark/content/binary/image003.jpg" alt="image003.jpg" border="0" height="623" width="947"&gt;
&lt;br&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;h2&gt;Creating an add-in
&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;
Once the pipeline pieces are built you can create add-ins.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Each
add-in provides an implementation of the abstract add-in view.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;For
example, we might provide a BabelFish add-in for universalized translation:
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;[AddIn(“BabelFishTranslator”, 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Description=“Universal
translator”, 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;Version=“1.0.0.0”,
Publisher=“Zaphod Beeblebrox”]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;public class BabelFishAddIn
: TranslatorAddInView&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
string Translate(string input) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;...&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
The add-in implements the &lt;b style=""&gt;AddInView&lt;/b&gt;, providing a concrete implementation
of the &lt;b style=""&gt;Translate&lt;/b&gt; method.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It is decorated
with the &lt;b style=""&gt;[AddIn]&lt;/b&gt; attribute that allows it to provide a name, version,
description and other data the host can use to decide whether it is a useful translator.
&lt;/p&gt;
&lt;h2&gt;Putting the pieces together – the directory structure
&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;
To properly identify each of the components necessary, MAF enforces a particular directory
structure you need to follow for deployment.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Each piece
is stored in a sub-directory off the root of the pipeline directory (this is typically
the APPBASE where the host executable is stored).&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style=""&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape
 id="O_x0020_4" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:6in;
 height:182pt;visibility:visible' o:gfxdata="UEsDBBQABgAIAAAAIQAK4ErHDgEAABMCAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbJSRwU7DMAyG

70i8Q5QralN2QAi13YGOIyA0HiBK3DaicaI4lO3tSTomwTSBOMb29+f/7Xq9sxObIZBx2PDrsuIM

UDltcGj46/ahuOWMokQtJ4fQ8D0QX7eXF/V274FYopEaPsbo74QgNYKVVDoPmDq9C1bG9AyD8FK9

yQHEqqpuhHIYAWMRswZv6w56+T5Fttml8sFJwjm7P8zlrxouvZ+MkjEZFbkr2vopGQ9GA3uWIT5K

m6aEDiRg5Tqnyt81ZtSlpcL1vVFQdoE2C3X1h7Z2Hxhg/q94l7AXmI/qZxJ7HE4SG5s3lusp6xki

wEQnyPcl5YA/L1F8XaFM5LJIGo2noyexnLT9BAAA//8DAFBLAwQUAAYACAAAACEAOP0h/9YAAACU

AQAACwAAAF9yZWxzLy5yZWxzpJDBasMwDIbvg72D0X1xmsMYo04vo9Br6R7A2IpjGltGMtn69jOD

wTJ621G/0PeJf3/4TItakSVSNrDrelCYHfmYg4H3y/HpBZRUm71dKKOBGwocxseH/RkXW9uRzLGI

apQsBuZay6vW4mZMVjoqmNtmIk62tpGDLtZdbUA99P2z5t8MGDdMdfIG+OQHUJdbaeY/7BQdk9BU

O0dJ0zRFd4+qPX3kM66NYjlgNeBZvkPGtWvPgb7v3f3TG9iWOboj24Rv5LZ+HKhlP3q96XL8AgAA

//8DAFBLAwQUAAYACAAAACEA0sCGr/EJAACNcQAADgAAAGRycy9lMm9Eb2MueG1s7F3dctu4Fb7v

TN8Bw6vsdLw2/yTKE2VHcXa3mUm3nlW29zAISZxQIAtAP+5V36Fv2CfpOQD4I7mON4wVJ17cSBQJ

AQcfDgF8PMDHlz/s1yXZcqmKSkyD8PuLgHDBqrwQy2nw2/ufzrKAKE1FTstK8Glwy1Xww6s//+nl

rr7kUbWqypxLApkIdbmrp8FK6/ry/FyxFV9T9X1VcwEXF5VcUw0/5fI8l3QHua/L8+jiYnS+q2Re

y4pxpeDsG3sxeGXyXyw4039fLBTXpJwGYJs2n9J83uDn+auX9HIpab0qmDODDrBiTQsBhbZZvaGa

ko0sBmRVVuwDz6+o2FIFWZbssn/G2Viyz8+ZXortz7Ke19cSLWe/bK8lKXKDjaBraCyLDlxwyQCs

86N/LbsM9gu5xoyqxYLsTS63LcJ8rwmDk1mYxskFNASDa3ESTS7gh2kDtoKGwv9lcQYNGxBIEEUX

k6xL8OMDmYBt1gY46NmlarRKbO9WdBQQW9H3YN/rak/StsaYmOg9nASvxrOm4k0WymF2VOUwjaBy

zvZ4BOa7yjXVH4Vjc9JWP87SNHF5NznVUumfebUmeDANJDiw8Su6fae0NaNJYmpV/VSUpT3fGKX3

c1NjtD6/xVQ38A3V2YGbTwP1zw2VPCBSl1eVuSswiapnGw2ZuTLsP/BCqfRc35Ycj3O+uLbOAke/

Qo4lxduci7Pf5q4eXZJyW4YIIi2X0DOUpkDjFYtK6Jk5eUMVN7VTNXvNF9YOds002VJjWVOx3tXZ

Qn8knbvqzFP/Ah8y7gb3ehgQuB3h8wOX2FVh45icqrLIEUXzA/sdflVKa4HeN22v+qlKqgtB9G3N

F5TBfTKTBYUKshWV0NV0Tk97af6yFmecOv9SRxeY6uADXI23OfzQKjiMEMo1le+mQZKOzQ3igTXg

DwEW0XTAxh2wkzAxzuKBHQwsoumATTpgw3gcjrBf9MgORhbhdMimPWSzKMMR0iNre+IhnQHC6ZAd

dchGUQYu20cWBpX39GYOY0rTUcAQakY0Tt+J1/KDGV3M2OB+wr9XMELCvPR6IxgMDGGABT2T0QnB

criNe7iNk/hwePK42QZvRnUEy+GWdbghaIejj8ftEDcEy+E26eE2SseHY4vH7RA3BMv6Xm8qbxiC

gVMezeMJzprtcG0YMs6aoSPLC6mBksGRWuurklOYQzt2o1/VRc3LQnAiq0pjUqAtlbwlL2qqFM+J

rohecbigWAUPC27J7PrtdwQ5FUzm4dMYwkV+TSU95hUP2eNIkcmnozwbxef1r2CGvWw5EZRkyeD9

lBAeVxxSwrGbsv9i+OMnU8LI0UBDZ7NJiq4KJtHLlhLGUWL81zBiTwk9JZwGOIvxlNAy8i/FtT0l

PNFDDE8JT/V4yFPCUyHrKaEdhD71gaWnhMNw85RwGG6eEg7DbTgl/B1kcJbnb8W8yPksp7WG0PAR

z3s01vmCQSQJAq+K0Dw/g4iMgkLh2JRKkHmub8qCq++ODHiYaB7V8nEpZggc+pBjTh6PYx7EVFuO

OYom5tmS55gYi/RhR4hZeo7ZRX09x/zGA+WeY56KCXmOeSpkPcccNnf1HHMYbp5jDsPNc8xhuJ2e

Y/6j4LsvTC63UORXzCyjY2YZmvWLZnHvHGPmn7qitR++jCcjs5jyMHyZpna5h6eWnlq65bCeWnpq

+WxWuXlqeSoC5KnlqZD11HLYlNVTy2G4eWo5DDdPLYfhdlJqeQVBRUmZPhmzJF3cEgOYWNZXTCmT

O5QyfrxoZZJM0naDZxutTMZjs/PCU0pPKT2lxMULT7L71K+I9StizZa2b2fDtKeUnlIa6ZCvZgu/

p5TDpvieUg7DzVPKYbidlFL+tYKdl70FseTF0YrUR1sS266IXUGRZ9/Ietg7MjzhZ+rw9KOW6UU0

wf3oh1FLv+kyIF6Hh3kdnqcVOPIU01NMTzG92pmROPNRy2FTV08xh+HmKeYw3DzFHIbbSSmm2XT5

JUKWjbgP7Ksk//33fwinbEVA2pfsCr0iFPZgimWJuzBxR+aT7Lxke2EFUMX2Cg+talQnbxu2Gj9z

CL4Wy5UmEPMVRrKIhJ3ej/uz3fx5kJfCpbQ3u79VOWyko6CbGqCiD0q4ggASyLylsNkSI5h41qnh

nsVZiGpyIKGEF9NjRhqlYScDFKZZhoQVIj/36MKi2JLJ/h5d2IOA0dETUcoYF/r/C5sKsgPJ1Cwd

pyBnimqxC9gbB4frOgflWLFshAaZlqb4j5Vzs7Ryd+VmDUjZSQ7U29Ycg1qN1qqp6EFOKHH7hqqV

/ZO6VfjDUnhZbURuyPyK0/xHAeJSoMM6DQT4YIDWr3kekJLDPk88Milhk3D5e1KCUaUw4kxGObpV

3MX2Nka2rtUeHPhF52NRu8e39bGZlNWu72ndrt8hntbzrTAKzSMOdK44jJI7jzuSLGolph72LeXu

ivamsM3oPe3r9LRJs0DjXk+LTGdiNgF8tqddjLDrMp7mhPfMHdas3UjjTt7be9rz6tPih/u06BH7

tM7TkjCbJGF0+AjXe5pTKn+Go2cMKu1WIePePg2c0XQ8MOQ+Yp+WjOM09Z4GM9g/yDwtbnfM3e9p

3Ra6R/S0NBplE+9pz8fT6oLhlFxsrwt2zDjjlnHCRb2RnMQdzWzTQw7v4N0viojqCmXD+UzVQErx

+Th0dcBNkF7YzOFHryAQOaqbF1jgsXtHDLzl5uG36QA9LRh/U7HNGkihfaWO5CiIUgm1KmoF7+24

BB0lDvxPvs3dvQAUgWu2wgov4M0Znc5uewEs7JtlGVRHZx0rvu9dL810cpSZ5cHmdSnu2EJxDy3+

+OtSwKaWyQHYaL376oHZcbikne8A6rbVuumNawiTwx+t1VAc2ki8A9+MnNz7AQt42mZrJw9Ns0FD

NnMF32yOvMVpdHfh/ZPebe1I3DZbN/D6ZnPNlmWjO093nvZui5upettsjqh1o9VTdpL/AwAA///M

UVtuwjAQvIrlA9QBAoKoQapArSqhCvUGxtkQC7+0Nml6+64JqDlB1a+d9Yx3xmvYe3W14JKYF8VK

IBiZtHex0yFyhhXYEzQ1x/dmxsX2WVYxISTVZdhqYz5BJToXE4LwyejwSuztQjhirkOLNlfftmyo

+WxVFGTJ2XfNy3K2oXY0gCExRYLVernOvCLBHY9Gj0EBY3oDb1kGFJGS8Gwg+0O8Z3pIxoC3IJQu

aJV19+L6o1ZjRPXRH5Fpem9ZcuakhZoTma4IrFyM8bLmoacJB68ukTm/66Q7w0sMlIIel7Xk9Cum

ZmI03U/GbLDGxQpr3qUUKiGi6sDK+OQDOOJaj1YmavEsaH9a/Y9v2ywXxR9/mzCqMrRzaHbS9TLe

1nxGGTqt9jLJaU/4K1Qw9503DeD2BwAA//8DAFBLAwQUAAYACAAAACEAqiYOvrwAAAAhAQAAGQAA

AGRycy9fcmVscy9lMm9Eb2MueG1sLnJlbHOEj0FqwzAQRfeF3EHMPpadRSjFsjeh4G1IDjBIY1nE

GglJLfXtI8gmgUCX8z//PaYf//wqfillF1hB17QgiHUwjq2C6+V7/wkiF2SDa2BSsFGGcdh99Gda

sdRRXlzMolI4K1hKiV9SZr2Qx9yESFybOSSPpZ7Jyoj6hpbkoW2PMj0zYHhhiskoSJPpQFy2WM3/

s8M8O02noH88cXmjkM5XdwVislQUeDIOH2HXRLYgh16+PDbcAQAA//8DAFBLAwQUAAYACAAAACEA

YqF+rNkAAAAFAQAADwAAAGRycy9kb3ducmV2LnhtbEyPQUvEMBCF74L/IYzgRdxULWWpTRcRingS

Wy/e0mZsi82kJOlu+++d9aKXYR5vePO94rDaSRzRh9GRgrtdAgKpc2akXsFHU93uQYSoyejJESrY

MMChvLwodG7cid7xWMdecAiFXCsYYpxzKUM3oNVh52Yk9r6ctzqy9L00Xp843E7yPkkyafVI/GHQ

Mz4P2H3Xi1VQp9nblrqb9vOlanys2m1pXjelrq/Wp0cQEdf4dwxnfEaHkplat5AJYlLAReLvZG+f

pSxbBQ/nRZaF/E9f/gAAAP//AwBQSwMECgAAAAAAAAAhAE0YY5B4IQAAeCEAABQAAABkcnMvbWVk

aWEvaW1hZ2UxLnBuZ4lQTkcNChoKAAAADUlIRFIAAACQAAAAkAgGAAAA50biuAAAAAlwSFlzAAAL

EwAACxMBAJqcGAAAAARnQU1BAACxjnz7UZMAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADq

YAAAOpgAABdvkl/FRgAAIO5JREFUeNpi/P//P8MoGAXkAoAAYhxNQKOAEgAQQKMJaBRQBAACaDQB

jQKKAEAAjSagUUARAAig0QQ0CigCAAE0moBGAUUAIIBGE9AooAgABNBoAhoFFAGAABpNQKOAIgAQ

QKMJaBRQBAACaDQB0Qmc3V0nAKQKgNgfiA0GsVM/APEGIG40dm16QEgxQACNJiD6JB5QwqkHYoEh

5vREYCJagE8BQACNJiDaJ575QCphCHvBEZiIDuCSBAggltEopm/iEZbSZRAQVWPg4hVnYOMYXAXS

t88vGT6+vsXw7N5hZOF8IMaZgAACaDQB0bbagiceZhZ2BmX9IAZeQTkkVX8HlZu5eEXAmIHhHzAR

HYUJB+DTAxBAowmINokH1EjuR048asbhwMgRG3SJBhvgEZQhWi1AAI0mINqA+cgcZX1fYOIRHhKJ

BwL+Ea0SIIBGExD1S58G5G66lJI5A6+AFAPD/79DxxMkuBUggEYTEHUTjwO0uw5vU0gqmgyhkof0

EggggEYTEPUSjwB61SWv6TAEEw9pCQgggEYTEHXbPQrwqkvRiIGLB5im/v8Zgl4hPtEDBNBoAqJO

6TMfubvLKygBrLr0h2jpQ1oJBBBAowmI8jZPP3KjmY2Dh0FZ12EIJx7SSiCAAGKhIPBAxbUDtNi2

H8oJ4fsfboY//1gYvvziZ/gGZP/9RzhYWJl/KbAyKSmgi7P95mZ4dfThkPG7s70Sll4Y8SUQQACx

kJlw+hkIjFAOJcDJ8hVS9bB9BNNffvExfPnNx/DppyBOPb//soExOvj2G0h8/jLEu+zEJyCAAGIh

MfEkoPc0hiPgYfsExsKcrxhef5MEJ6jhC/5QVIUBBBALpYmHV1CRgZNXgoGFlYPaWYMIsf9YlBGp

Dwl8fv+I4e+fnwzfPr9CraaYfjFI8TwEJyB+aUegHzmHfHL58vUrw/37DwgkFuJLIIAAYiEy8Rig

Jx4pZUcGMTlLBmYWDionmP/Eif3HJYdPP3Y9kgyWYPrXj4/AxPSY4dnd40D2J5QSif3HSQZ55SAG

LmBmGcrg1avXqAkIWxVGwkg0QAAxEamuH5mjoB3IIKnkSGHi+Y+E/6HR2MT+QRp3MIyh5h8W/n8C

NCqbjZ2XQVhCk0HXOolBQcsNPAkKb9t8fsFw68w8MD28wF8smPgSCCCAmIgofRygvS14ySMsZUil

BIMv8cASy38ETWECwVCDnCDRzBeW1AAmpHhgFS2NCOo/P4ZhIqIsAQEEEDFVWDy8i8opAC556F8t

Ea6GiNbzH59eVHFmFjYGNaMAhgfX9jK8fX4DJRGpGCWA235DDfz794+qjWiAACImAcEHyQRENUlo

+BKZGP4zUDeBYE2UpOjFpBW0HMH02+c34YnozrkFDEoGcQycPOJDKwGhj/FQ2AYCCCDSEpCY5qBq

/BJXyhCbMPGbraBlD01Et+CJ6PaZWQzS6r7AcNEbOgno7z8iShviqzCAACJxIPE/BaUMFRMIxeaT

SEMTvYKmHTQR3Ybb9PTmZoY/v74zCEqZDM0SCGsVRnwCAgggMhMQtaolMquu/5QmDHQx9ASDSy+w

JNK0ZeAVkGB4cB2x8Pzl/T0Mn9/eYhBX9mRgZecfWm0grNUV8VUYQACRkYD+DfrGLyWlDDHqhSWV

weHw4PpRRDf/0yOGh5cWMPCJ6jDwixsxsLDzDdIE9J+qVRhAAJFfAg2Bxi/+BIMrERLXVhKWVAL2

wgQY7l46yPDrxxdo++Inw4cXZ8GYjUuUgYNXhoGdU2xQJaZf3z4zcLF+RRJhI9AZwg8AAoi0BAQb

kxlCjV/C1RKp/kCoAy0Y0zL1ZHh8+yzD2xf30CLqNRgPRiDDizTOdwjkDy4GHn4eBnFp0F41NpLM

AgggCttAtGz80rdaItdcZhYWYLvIjEFKUZvh2f3LwIT0YMiNDX378g2MXz19xSAmLQZs4/ESrRcg

gEhMQP+Q6kcyGqwD2PglqbQi6HZMvWwcnMCEZMogq2rA8OHNU4Zvnz8wfP/yARgxH4Bd/t9DJjGB

EtHbl2+JVg8QQBQ0oode45f65mK6n5mFmUFYQg6IZbH79z8N3Ao2l3Q9f//8Yfj84QPDh7dvgYn+

HZgPGeMivhcGEEBUqsKGTuMXpzq6JERqJhhiEzdumpmFiUFARBCMf8n/YHhw8w4wQX0iKUUABBAV

SqCh1/jFX8qQWX1SFLlEqicrkROXwNnYWRnU9DQZbl26BkxEn4lOEQABRF4baBg0fqlvLi2qJdJL

FUoTobKWCsPlU5eIrsYAAoiMbjw5HiEQAP+pXQqQW4WQEFH/Sc3xRKj7T6VShYJqFFytCQsQ3ZAG

CCAyqzAKSx9aNSQpaPwSjKhB1PglnCFJDQNUICBCfAICCCA6dONHG7+UlVy0SIT4AagnSSwACCDq

zIWNNn4JjE9RsdFLlJkI9u+fvxh+/YSMQ/349p3h39+/8K76j28/wGwOLg4GCXkpssaNAAKIuiPR

Q6rxS8tqiT6NX1CCAI3dwBLGL2BiASUYSOL4Do81RkZGvLFKQBovAAggytpANG/80jMhDs7G749v

38AJ4tvnz9AE8hOeUPAlDpA4I5Epg5GCFAQQQKS3gf7/G4BShsxxkyHU+P3x9Rs4cYBKju9IbFwR

jC+B4EwQjMhMRqoUQQABRJ2BRHK69CO48fv102dg4vgKTDTfwQkFxMcW8bgSCYYYI7ZEQXxpQ0kJ

BBBAFPTCRhu/xLgPklC+gasicMIBstEjjaiEgpxIGEmrhgi3gchPQAABROXlHMOl8Uu+GV8/fWL4

Bkwo34EJ5huQDWq/EEos6AmFEZFaCEYyJQmHGgkIIIAoHEgcyMYvFcaTqDAhCUswIBpbVcTExEQ4

sTCSV8UQ09bBJYGilYIEBBBAlA8k/qdB1UFWz4Y+jV9IVQRJLJ/fvUeJSPTShdTEQnTiYcQugKqU

kYjGM+UlEEAAUbCkdWQ0fv/+/QOuij4BEwso0YAaveQkGEKJhXBCQU4kjLgb0IwkFEhUGAcCCCAa

9MKGfuMXlEg+vX8PLmHQqyXkKonYBEMwsRBKKIy4EwgjnhTBSGQqYWRiIjsBAQQQGVXYf4bh2PgF

VU2gBANKOKCeEsFShtwEg5ZYiEkojPgSCNZqj7SGMwUFEANAAFGpET30Gr+wLvaH12+A1dMHnFUT

9RIMI1LEMmJNLNgSCiOWVMFIwhgPzhIJWZyJ/CQEEEAUVmH0aPxSdzUeKKGAEs3712+plmjwJxgc

ZpGZUDCrP7TEga1EomE3HiCAqNQLo8eEJPnVFKghDEo0H4CJBlf1hC3RkJ1gsPW48FQ/BBMKniqL

Km0gChIQQACRVwJRvBqPdiO/yPRnYNX0/s0bME27REOghIGVLnhKFoQZ2BMKyW0gIrpbjFRKQAAB

RGI3nsqTqVRo/KKLgaqlt89fMnx48xY+CkxxoiGilMGVYChKLLiqNlJLHGxzZVQaBwIIICp24+nX

+MVWcoGqJ1CiAXW7cXa5CSQaoqomLG0OYhMMzsRCZGLC2tahyjgQ+QkIIIBoP5lKw60o4AYxMNG8

ffEKb2kDSzy4Egv2kgaLXiISDa4Eg7VkIVTyYEsktBgHoiABAQQQ9SdT6bAaD1TKgHZSgkodvKUN

toREKNHgq5qolGAIJRacDfBB2AYCCCDKx4HoshUFQoMSzNsXr8ELrcgpbfC1abCVNBAxAokGR5XE

iKPaISmxkNsGIjAeRM25DIAAonBjIRVX5f3HPRf14fU7cMIBLePEmnBIKm3wt2nwJhoiEwaxCYbU

ag1vIsFbRdGuDQQQQFSaTKX+jk5Qwnn34g044cAOhoRVUyg9KRwJB28VhS2iyUk0WKok5ARIUtee

iJKHuGkLbMMF+BtOlIxEAwQQlfeFUb7uGVTKgNo3b4GJB5ZwcFVTeHtSjASqKKRIJDbRoJRO2BID

OQkGixzhhEL+zDy120AAAUSjNdGk98BACefV05fA6uo9/lKFkbLSBlsVhWo+kYmGlF4a3kYzI96E

glGKkDkzj7ftREECAggg6icgEvei//37F1pVQUocfA1jQgkHwsdR2uBINNiqIrwJidgBRJITDOHJ

VnIb0ITbQGSnHwaAAKLxikRcA46YCYf8EgezmiJY2iBXX3jaNIQSDcEqDe8UBpZRbdSChqhuOzlt

IMzVA+SvBwIIIPLGgUiaQMUEoETzGlhdUZ5wsFRTWNo2OKsofAkJW6IhokGNO9EQP9lKeGYeexuI

qFWOWNvm5BdBAAFE5sZCQqsGsQNQ+wbUzkHujlM14RBZ2uBNSIzElTSovS3SEgzB7jsj7oSCfx0S

mW0gCnphAAFExV0ZuMHXT1/BJc7XT19QxnFonnAIlDYoVRQp7SAcEQ5rg5GSYHAlFtwTvLRoA5Gf

gAACiMLTOfADUDvnxcNn8J4VeqKhRsIh2CjGl5DQ2kyEGtSYiYaS2XlGrCULzsRC7KIzPJO1OEsu

CkoggAAiIwERB5DbObhKG2omHJTqCgufgZFw1x5rm4ZQoiF6dp4Rb+mCNbEw4t/HxUigO07spkNK

SiCAACL73nh81RWo1EGer0IJKCbMRIPZHWeiWsJBqc5wde0xBgQJVE8kJRpcY1rEJxZGHImE5H1l

GONGhAccCQGAAKJaAgJVV6+fvASXPCRXV+jjOEy42zjkJhxSSht8bRpsiQZfKUMowRCTWIhKNPiW

fDASGpImPwUBBBBVEtDn958YngNLnT+/fpNVXaEPAOJrHFMr4SAa0NiqKMoTDbbpEXwJhlBiQS1B

cW9YxNebo7S0wQYAAoiF0lLn6d3H4ASEdc0xweoKtWTCTASYiQJvgmAivgGNt7QhOP2BmmiILmXw

JBhsiQVnQsHWg6NywiAWAAQQ2QkI1NZ5fOsB+AIzkkodPF1tfAkHQw2+EgdPTwxfQsDZI8MyVcKI

N3GQkGCwLLNFTyzIjfbBBgACiIWcUge5rYOv1MHXu8JXXSHMYsJsRFMt4RA3io2ZYBgpSzT4Egya

OUMBAAQQSQnox9cfDK8evcDewyKq1GEiqrrCGEHGWkqhtXGwJDaSEg6xVRQRiYbYEfbBXroQAwAC

iKQEBOqeMzMzYfayCJQ6+BrJRLdzGAm0l4hIOIQnW7GNkuNQS06iYURtaw0HABBAJCUgzFKCzFIH

vrIQR7ccPSExYY4LYbSFYIvqSUg4BNs2BKZJsPkbY7EbzB7GYZJi0ABAAJHYBmLEm3iIbevgLXWQ

qiJ87Rxc3XFGUnt3KKUOntIGh19HYqJBBgABRHYvDNeEKMGEgaORTFR1hUU9MW0cUhMOodIGWwYa

SYkGGQAEEAuJBRD2IXGUMQwm6pQ6TIz4ExdaQ5boYQH0hIOjkcyItIAfua2HUeWOwESDDAACiIWc

kgdX4oKXQoyYEUhsqUNqdUV0A52YhENkaQNO3CM40SADgAAiqwpjZMB1SjpShONIPMilDrZRZPw9

MAINZKzjSeQnHJSR9NHSBisACCDSemE42kHYZDHmg7AlHiylDnHVFaHxJEa0hWuY7TD0hINeTY2W

NsQBgAAirxHNiK36YsB5gjpKGwk98SC3dQg0krHN1hOVcNBKkNGEQz0AEEBUXA+EqIKwzRAzMmA5

3h8t8aCO+xBXXaGOTTFhVmGkJJzRaopkABBALDQxFantgzIyjNTDQekt4Uk8xA0JMCJteyY34Qyf

0WF6AoAAYqFW6YMz8JFKH0YGLD015GNZMBIPE/b2Ea7qCluphJxYoaXeaMKhHgAIIKqVQIwMWKov

bLsxGTGrOkYSEw9ydYWtgQxTi3wYw2jCoQ0ACCAWcgoblDEhRiyr7JCqL1jbmhFLgxpl0A5f4gGX

IqgDlYzIQwR4qivkxIMo5UYjnloAIIAomsogqgpDL4kYUds96NtYcCceSCJAaeugsbElHnh3f7RX

RRMAEEAslCceLAkFiY1cXTFi2zeOUjURTjwYbR1G9ISFWl2NJhzaAoAAInk2Hp8wI1IbBHtiYcBI

VCij1WiNa2ztHYy2EHrJw8SIMZ82CmgHAAKI9LkwbKOIDASaFVgSDwN6FYg8joQr8eCpspiQ1gyN

tnPoBwACiCq9MMQGNUbs1ReWhINZkhBOPOhVFnqpM1pd0R8ABBDFCQjbFAZciBEzYWHvkiO3k2Bt

HszEg1FlMSHTo6XOQACAAGKhsOjB2mgmNO7DgDwBC2/7ICbUULrpsMSDlHDApc9oqTMoAEAAUaEK

w7+nmxE5gRBR+iD3tpATD0aVNVrqDAoAEEAUDSRiFUZq92D00NBKH8xGMxP+xMMEayyP9rAGCwAI

IJISEAePOAMbOxfGlADKuAuOUWD0GW94bwlpjAg+lsOEW/9oD4sOgIQzEwECiKQExM4tzsDJLYRU

FSGtTkRffYi2QRD9NDD0LTEoh4gz4liLPNrWoQ9g+ku0UoAAorwNRNwNrzja3bg342GyRxPPYAQA

AUS1qQy8N9jAFOC4exR9Fyss8TAxMqHoGwWDDwAEEEkJ6OWjM6MhNgpQAEAAMY0GwSigBAAE0GgC

GgUUAYAAlF3RDsIgDCyrsBc+mo/mBWqHV1N06qLzoblrIWvYLRmwrIQxzlVexbwklFIeWzq1Vs45

c4yRRSSqamLmZIs1dF2BCdde3TceLeavTeMXxIwz2tnQH+iJi+fi3TbS3hZ622Ki439nPz622BwL

ucPJcdMf92gc9N1XYyf6fszRRq/HQk5TetZY3ty/I/IZV+S+As3EsSMmaO/gDbxZDL5hg14denXo

B/lEoadCz5lnuNbj19hvAjB2BikMg0AUjaZtBFeC4P0PlUO4EgShCBk7k46JDGmJMPBhvmh+nguz

yeNuiDTWdVXOOWWt1SEEnXOeGYYdFABYcFMGFzWoDV7NF4boxfXkNfcawJnRp9X3pw0jPEpoxU9F

PA/fJk8guPcXFhlK919B9StAgkX2r7wSKtJ9ruiRbr0nAAKhAa2AXqqNgdoYnAMkgoeKDjAdcHwf

b8oc9ZExwjPVWifvfYsxtlIKpJRuwUPjIwDl5ZICMAgD0cYWpWfx/sdyL5TWTqSBUexvMSAY/GQe

g359RFv6TCklAbUu5zx77xeDQ8EBNCvGVTjsyml0wWMAzaR6GYJHHtQDIp1x0v8QbW70cyTofkd3

DxsZ3+w9qGNgmnJLuxuIGik8lEgHQbRTEm2o0wRSeDz13sEvsbXgY4GfBb6WEEKJMapqM98oOgUQ

Sb2wZ8+eMWpoaDACSx4mUNUFTDAswNTMCk0oHNBEww20kxPIB7E5sJQ+zGjVFBOukgZblYSeQvCV

HqQOR5BiBpYEw0i69SilGCOSm4ip8pBLJmwJCZaIWJGaDOCMCp0aAqUNsB5gYvoLFPvHxcX1T0JC

4t+NGzcYpaSkiMpVAAE4u2McgEEYBoCA6FD+/9lIlDZGjpQtoRMLC/gUvJEGhOcLKoFI8VjgGxC6

D5+qG3h0HZxE1oEu6zuGBwdhYC2BJgw42vNnypxMoEM5b4DO46oJTMuDICBUhO7uvbnOu9id5oO/

RbmKSEW+imfnXRJfE3wC8HYGKwCDMAw1mzD6/x+8JdJADzI3GPOoFzGvSW6+ciDFV0SANjecg0sX

63SiCpFj67ADZYF2WRY4hgelo2BVcGeQfA3GH2sxCHdwOVVQYu/M96zRpk6pgr2XAW15NsBRtGWR

7tKRGm7SlXuQzu3hvxaXAGIi0sMMoNJHWFiYAVjMgUogmAeZYA1haEpnQeploTeYWaDqkNs9jNBi

FV51wdo4jIibSMBiyHg4d4ux+BWe0dAyGyNa+DFBMyczNLMixwdGnKD1gMGJDBSvoPgFxTMovonJ

nAABRNY4ELDlzghqhIHOiAZZAmUj95rgDWNGKEBvEMMCA73EoaRNM9wTFnq7DTn8kDMccgKDAib0

NicovkDxBoo/UDyC2KB4JdVdAAFEVgICtdaBRd1/2DodKPs/eoMOVCf/hwL0XgSst4HW60DuNf0f

TTb4hw2Qww8qjh7GMIDeYwPHFyjeYMtoQGxQvJLqLoAA3J07DgAgCEON9z8vk/gpoaYxDs4OLoYB

aYn4Futj8hiqMAMVMxtgBzTLBWTtJ6RyiRXXMs7FYHFnq8FYDC0I9nT9bpTjrLvhpNmGcCPWr+cw

7QkY28mFVJPUiyAyTAVdoS90ht4v30BNAagxoxSAQRiG3v/GQ9i6vGGkFAr6OaHgl6gvxJojB9Lb

GLK7ULf+bVbjpnuXglfiSTntVF0lBaWcT1hYT3Gt6BLZKqy/iqsTSXfG/NvKYrHLJ0HAwSzGvPfF

IXFhPuAGPziyFlzhC+fds7wCkGJGKQDCMAz1/ge24pzYJ90o3ZSiH6H7Gm2SDpa0gQiX9Iu3kA8Q

NulzR35wKIprVrSK1tVwn7VZaUMYdhuyhM2oPqb3pnozVoL4wWgz/DHBw32fep3MfAZeanhVumkc

x5vx3nUApo+0pUY/dERPdEVfdEbvDA+XACKpGw8y/P79+/+BXXnQoBOyJ8Bdc2jDjAFplPQPtDv/

m9BINJYpDKJGopGnAkgdzMPSUP9Pgl5CA4tEGPEfw25iR6LR2jQ4R6KRExUs8QDj6TtoWgMqDi6F

QFUJsPr6B6y+/hM7iAgCAAFE1GQqrIUfGhqKPBfG/OnTJxY2NjbwSDTQfvD4D7a5MNBcDLa5MOSE

RM+5MFIHIYlt1BIzwUrtuTAsCQe5zQObCwPVTT+hc2E/gHEFKp1+AuMKnLB+/fr1m4+P78/Lly//

QufC/q9evfo/MZNhAAEYNZsUAEIQCiPM3vvf0RME0+QTBZGmXLRoEZQ/j3pfT7fbEOQka1NECPQW

3kFcqmGH+8FeSKNvfnRofPIjrjQ++R7RBFRIBxWVOdL4U5z+aHwHnCaZ+TZKVV9OodwtGh/Fc6Px

oUBeLEbjNU9G4zEHjcd6zedkZgxTIC2g1k+EJQClVrsDIAgCt5q8//OWH90x3DCy7IfT+IMbF+Ad

fzKQF1XJVipzyZEOIFiFVVwy4SyJBbVW4aINPoRyBoFjQBoILYLH9s3sHUB7J8sWMtNMDhnA5XWn

mZZ141rC90fJa87P08jGW3kKmca9sooDULYflXt4ARtwtKE2xvkEaNg0H5zdQKzUhlhlnHWUgw00

mmf1zxi3RYr/EoBSM0oBGAZh6NZ2N+j97+j3NphKBCt2pb9+beURicm5GwX4XpBB1HsvRFT5A5uE

rAIIMjKNOXh+Ie5oM4D8SpNrKmCqyMwGVcKsxItsWG0pRElMsNUV+un8rPKqI9jv7IRhrmqw5Zi9

pu5+Zc0AMnfM736b24Lh0f4Pzx9WG1WeCI//nxUfnwCUmkEKwCAMBKX2/y9utZmwhaA2VEEaPHkY

Nhu3uwo0KRHb4CGdP8xYo0Z4GYfitGUXd1CAR7mZf4FNYV/VWRVgdQXSwmy/4WB8yk8NeFKXwU/9

bWkjOD2pP6et0LrayhyP4FArBCVFvwQZ47hDxFkMSpmyWMrHUJ1mhvk2kLxtlfATWd9UlEcAxq0g

B0AQhgX4/5MdtriRoszgzUkMYbUrdB5roA1NE0TjAYUX6yaosKOkMZFGIHHymGwDwtnENFnGwdQU

POKThUFb3eRr9flp7AMkEd5FAFUktvhrP2L8+IPagScTv++DP4+ZxKaLnvT38FyGC0HGGC0XwToB

Jo8HmK7YUcU4VAjejnEEDt+JPBnyZNiud2oeZZ6snyq7bgE4NaMUAGEYhjK/dv/7zrqEtLRlH6og

bipu2NcaXD45EvND9dIIERxsAGhPyjRBaCOYzpbWw6CRGPSdCITEV4BxlAbieQFDaORdCWgaTG4J

KRClT9jVRPdowJR20jrjXU7F/ZY8PJaBOvwLKvAkoAo8Dg3agAYVRvDcAoa7Ks8SPLyGPgq/kpiV

BmPMOc3BUZwibn8qj2+PAJyaQQqAMAwEaf7/396CmbKRNFgoHgQPgtqOazabvwpUv7wV/ZPe0v7G

qSVI8dBr4+acvJAFRIOCO6Rzs+yca0DNBMiCRqOXL0ANnvx9sXKmYNAKLHZwb6M1UUeZk7iBaIOn

qZEXp3WaInwjCGWIvVh2wbCpUV5XwaKWqZ18ZY9OYRzrTNbl9Ozy/glO7hNOi+NLeW4V6BGAdTPc

ARAEgfDy/Z/Z4jsPh6xfrf4gMFvpCRrX5wjUv4a9ASnJSX4JwKPkHfpIncgEoFzNBwiD9IeMlSSf

6ZcCFPYKnkZK2xvpBAv8lvT79+mrgKVK+fsGGtuay8NWi5h56tqScXAfASKe+ahftRPXkcZoMPHR

R6BwkXO6bgQ45spIuuQj0kBL5X6xWKXTjnGWLSsIHTj3D2SqRwDWzeYGQBCGwuAI3NiBHQk7sgM3

RrD2lZYowYvRS4OpXvjoj336vwVZlhbw3lLKVDLGGH2tVbQmbvzVgQ3zIQTPqW5GC8ADTQqnOlmz

RacHEETsBIAUjEOVkauUZFtEm48qCHYAOfVBkbbtxOA2yosB0QqOWYPnplB4bdnNhw8KKTQGkKy5

fiQ+SHKfLWHYqbWMPMdR/uy9y4zSIgyGoSklaq1NaHLODz321y/u63UJQNsZrAAMgzB06///8+Yr

iQTZZYP1onjUENompZ9OYW+eAhFtyE9bLMyE820CCvDk4KtZHuZKM5VzbJiuVYM7F9ssDfMU+Bj8

9jE5us4i52LUQHoUD2vgXJyKVfY36ORiqo6uCySH9i+9V+JQ5BwNynpdandmJ15NJPgA0QQMAuhk

muz99ZN18xaAlzPIARCEgeCS+P+/8gLdqYsxEaNePNWEKqGMWwjV9ldJ6AymHNJegOq9N+8OBFQO

Eimw+S2rctpAI1QpiiXWVto/USkAAMkTpCgYYOlsfW/Bgk+gU/w12u7GART0X/l/2VcAwMD1aEMp

8uzDRkHKFwBTewMcKErNMWpD/0lFq9W5rOMgYHFcxK5pBsw48H4DTfvwo4onPjYBaDVjG4BBGAh+

j8QGTMH+IzAFG3iB5N8xSChBqaAyLpBljjcCH1WgP5h2QGkIqlorKMMLWKUUmNmEi6fRVYuJdtBY

DpVkSJm0Mbpnab1hC7iUEkb3nXya43lhe8UaUF4fTXWIJwzE/cOhiLn7QjmmLaURBCw7EBiM1/tv

GP+EJOeM3vsCCss/WmsYn5w7YE4qzW7cAohxMCxKR9+qgxwg2BIWiEZOXNC1SmB59EQGMweU2EAA

lOBgaoGRCJcHJUAQEBQUJOhe6MY7UIKFi0EbrOBFd6AEAWKDEgWS/SiJA6YWts4Klkhgqx6wJRT0

sCE3wVCzBAIIMADgTncj6jKEKwAAAABJRU5ErkJgglBLAQItABQABgAIAAAAIQAK4ErHDgEAABMC

AAATAAAAAAAAAAAAAAAAAAAAAABbQ29udGVudF9UeXBlc10ueG1sUEsBAi0AFAAGAAgAAAAhADj9

If/WAAAAlAEAAAsAAAAAAAAAAAAAAAAAPwEAAF9yZWxzLy5yZWxzUEsBAi0AFAAGAAgAAAAhANLA

hq/xCQAAjXEAAA4AAAAAAAAAAAAAAAAAPgIAAGRycy9lMm9Eb2MueG1sUEsBAi0AFAAGAAgAAAAh

AKomDr68AAAAIQEAABkAAAAAAAAAAAAAAAAAWwwAAGRycy9fcmVscy9lMm9Eb2MueG1sLnJlbHNQ

SwECLQAUAAYACAAAACEAYqF+rNkAAAAFAQAADwAAAAAAAAAAAAAAAABODQAAZHJzL2Rvd25yZXYu

eG1sUEsBAi0ACgAAAAAAAAAhAE0YY5B4IQAAeCEAABQAAAAAAAAAAAAAAAAAVA4AAGRycy9tZWRp

YS9pbWFnZTEucG5nUEsFBgAAAAAGAAYAfAEAAP4vAAAAAA==

"&gt;
 &lt;v:imagedata src="Creating%20Extensible%20Applications%20with%20MAF_files/image005.png"
  o:title="" croptop="-1068f" cropbottom="-276f" cropleft="-247f" cropright="-7858f"/&gt;
 &lt;o:lock v:ext="edit" aspectratio="f"/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;
&lt;!--[if !vml]--&gt;&lt;img src="http://www.julmar.com/blog/mark/content/binary/image006.png" alt="image006.png" border="0" height="184" width="434"&gt;
&lt;br&gt;
&lt;!--[endif]--&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape id="O_x0020_5" o:spid="_x0000_s1026"
 type="#_x0000_t75" style='position:absolute;margin-left:251.55pt;margin-top:36.6pt;
 width:196.3pt;height:156.5pt;z-index:1;visibility:visible;
 mso-wrap-distance-left:9pt;mso-wrap-distance-top:.48pt;
 mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:1.04pt;
 mso-position-horizontal:absolute;mso-position-horizontal-relative:text;
 mso-position-vertical:absolute;mso-position-vertical-relative:text'
 wrapcoords="-221 0 -221 21327 21186 21327 21628 16132 21628 15311 21186 0 -221 0"
 o:gfxdata="UEsDBBQABgAIAAAAIQCkzN3HDQEAABUCAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbJSRwU7DMAyG

70i8Q5QralJ2QAi13YGOIyA0HiBK3DbQOFEcyvb2pN2QYEKTOCb2//uz/2q9cyObIJL1WPNrUXIG

qL2x2Nf8dftQ3HJGSaFRo0eo+R6Ir5vLi2q7D0Asq5FqPqQU7qQkPYBTJHwAzJXOR6dSfsZeBqXf

VQ9yVZY3UntMgKlIswdvqhY69TEmttnl7wNJlnN2f+ibR9VchTBarVIGlXNVNtVTBo/WAHtWMT0q

l7ukiSRh5VuvxXmPCY1wVPiusxpEG2mzqK6O3n8wvQXoT6Csm5daCmd4jP/ECNN/gdose4HpDFGE

kU6Ifp5pXvF3FsUxB5GVyylpsIG+J8gl1OYLAAD//wMAUEsDBBQABgAIAAAAIQA4/SH/1gAAAJQB

AAALAAAAX3JlbHMvLnJlbHOkkMFqwzAMhu+DvYPRfXGawxijTi+j0GvpHsDYimMaW0Yy2fr2M4PB

MnrbUb/Q94l/f/hMi1qRJVI2sOt6UJgd+ZiDgffL8ekFlFSbvV0oo4EbChzGx4f9GRdb25HMsYhq

lCwG5lrLq9biZkxWOiqY22YiTra2kYMu1l1tQD30/bPm3wwYN0x18gb45AdQl1tp5j/sFB2T0FQ7

R0nTNEV3j6o9feQzro1iOWA14Fm+Q8a1a8+Bvu/d/dMb2JY5uiPbhG/ktn4cqGU/er3pcvwCAAD/

/wMAUEsDBBQABgAIAAAAIQCMFrdAswUAABcXAAAOAAAAZHJzL2Uyb0RvYy54bWzsWNFu2zYUfR+w

fxD0OqS2HMWxjTpFmjRZh6w16hR7pinK0kJRGkk7Tr5+55K0rGTJ0qUDBgx+sSnx6vLy3ENeHr59

t6lktBbalLWaxsmbfhwJxeusVMtp/PX64mAUR8YylTFZKzGN74SJ3538+MPb22YiBnVRy0zoCE6U

mdw207iwtpn0eoYXomLmTd0Ihc681hWzeNTLXqbZLbxXsjfo94e921pnja65MAZvz31nfOL857ng

9nOeG2EjOY2H/fEwjuw0PvAtjYCT9DCOFniVHA76o7h38pZNlpo1RclDVOwVQVWsVIihdXXOLItW

unyFK1nzG5GdMbVmBi4ln3TfhBgl/37PbKLWl7qZNzNNkfNP65mOymwaI6WKVcidRwcdwQxg9R59

tdw52OS6Ikd1nkcb5+WOfh3CYmMjjpeHySBFFuOIo28wPkqH4zSMUiBv9F06TEfOhCxG46MhzJ0P

Xnx4wQuC80Gg0QnMNSmyZ+Y73s73UterJgqkeOW0nw3/P4WgKbkHYFbyx+nGEvHpRp9daREdxVEm

DMdqKSu2FMmbX2aXLRVaB3B5BaqaSNVnBVNLcWoarD4sMbJFBohQfjRHmvbDhSybi1JKCojagdIY

7uW9ANwquTiv+aoSyvoNQQvJLHYjU5SNiSM9EdVCgMb6Y+ZCYRNjtbC8oAFzDPwFYfoQ2w5E2A3L

hDXxiNIv57afjvpP0Bvut64abeylqKuIGggSsbiNg62vTIhqa+JQ9KHAAfCmCZjGJ/Kvy/Z4m8fP

ayajYZsxsvTTVevtV+Q1Wtz+WmdY5mxlaxfDNsawgrvTTYejdJQMvNMnqTxMx8nIrZ3nZysk8m3E

8xPGGq2JG27BSxXdYssYJQ5RhmKRI9PYO6oG6TVqGUdMLlGFuNXOpallmW2pZfRycSZ1BDCm8cUF

0uL2EQT3wIzAPmem8Hauy08Se4HKXByFYNkHlUX2rgFaCmUtpsAqkcWRFBifWs7SslJ+iyWCkIry

KFzFajNPaaHXdjN3abab93V2R28W+EfKUHhBmqLW9wgBVQsw/LFiGgHJj8pM43GSpthdrXtIj44H

eNDdnkW3R62qsxroJDCy0jVhzxTHANMYSPvmmcUT7dl11TB7peYNqk/iECf0rje/Md0EPltw41M9

L1jzZJa9LU3INKeg3UUZOO/nRx3S2Lm9k4LamchnHhG0vmD+EhvNNBbq4OucEAeOOxO5lgnR2nNC

ujm5uPNa2VNHlAUL5DMNfy9yHwefceuz3xKk23ua27+xC70hPHOPmpUSXRcOVdR/YHsjNB2VqKg5

Tw9YSuce0fLUbra75wOS0ganHP9yxsHBU10yTJAXTOOos6uyrGPzU6UOBPO85OZRBzc7+ICrQzLg

RyGiOSAoK6avUJGJR0QMh+Ee2FcAS2gGYA93wLrVuge2EZ7Vr2EsoRmATXfAJofHCZ0b95R9PbIE

Z0D2qIPsaDDCEWeP7HdwluAMyA53yA4GI1C2iyyKyjVbzFFTthsFqrSraIJdqff6xlUXVxvCI76m

ozh08Wyl/FmcBvqfVCcCK+B23MHtOIWS3+OGqvRMVSewAm6jHW4EmjuqtGV9zze/ULanIQIr4Dbu

4DY8On5YW/a4PcSNwPIYdo7yTs/sUMR6xeHyi9vNSpVBzLvmP+EiXDw62UMe4Jz83F7oT9+S5Atl

FRKgPfhDYe7kYdfiXxUJixXO+dcbpxQXq/l927yAQGkfPkFfBjG5aIVhYKJQ2YxpRkroZlWVVf07

FAZw6Mqi6AkRApPVVrnizqO8cTp27lqQEaQjvaxVdO8qy3vxs/NLekmWdI0LD1mpLe7k0DKVPZOC

QdRsMSVAW+XeqtsHGsbd8L6odLqCGDrkW3QPhtvh4ngHruHlTjyvjJg3u1sfr65hQXcp+Av3g71H

V62hz10N031u9xnt7n32yZ8AAAD//wMAUEsDBBQABgAIAAAAIQBYYLMbugAAACIBAAAZAAAAZHJz

L19yZWxzL2Uyb0RvYy54bWwucmVsc4SPywrCMBBF94L/EGZv07oQkaZuRHAr9QOGZJpGmwdJFPv3

BtwoCC7nXu45TLt/2ok9KCbjnYCmqoGRk14ZpwVc+uNqCyxldAon70jATAn23XLRnmnCXEZpNCGx

QnFJwJhz2HGe5EgWU+UDudIMPlrM5YyaB5Q31MTXdb3h8ZMB3ReTnZSAeFINsH4Oxfyf7YfBSDp4

ebfk8g8FN7a4CxCjpizAkjL4DpvqGkgD71r+9Vn3AgAA//8DAFBLAwQUAAYACAAAACEAKpBimeEA

AAAKAQAADwAAAGRycy9kb3ducmV2LnhtbEyPQU+DQBCF7yb+h82YeLNLwQIiQ9OYaIy9tLWp1wGm

QGR3kd22+O9dT3qcvC/vfZMvJ9WLM4+2MxphPgtAsK5M3ekGYf/+fJeCsI50Tb3RjPDNFpbF9VVO

WW0uesvnnWuEL9E2I4TWuSGT0lYtK7IzM7D22dGMipw/x0bWI118ueplGASxVNRpv9DSwE8tV5+7

k0Kw68SuaFPGr1v6erl/Sw6bj6NCvL2ZVo8gHE/uD4Zffa8OhXcqzUnXVvQIiyCaexQhiUIQHkgf

FgmIEiFK4xBkkcv/LxQ/AAAA//8DAFBLAwQKAAAAAAAAACEAexEA6hEiAAARIgAAFQAAAGRycy9t

ZWRpYS9pbWFnZTEuanBlZ//Y/+AAEEpGSUYAAQEBAGAAYAAA/9sAQwAIBgYHBgUIBwcHCQkICgwU

DQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkM

CwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy

MjIy/8AAEQgAvgDEAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//E

ALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJ

ChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeI

iYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq

8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQH

BQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJico

KSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZ

mqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/a

AAwDAQACEQMRAD8A9isZ0t9DsXfOPIjHH+6Kf/atv/t/lVMf8i3Y/wDXKP8A9BrjtUW7n1mWG2F2

ZBaxmJorjZHE5ZxuZdw3DgcYbp0rRRTZEpNHe/2rb/7f5Uf2rb/7f5VxK6lfPESDbq0l41tExjYh

Apb5m+YZyFxgY5NMGq30zW0MbWscjicPJIjFSYmAyo3Dg89+PU45ORC52dz/AGrb/wC3+VH9q2/+

3+VcKutX9zLYpa2YbzII55gccKxwcEsuMYJzhu3Apkl5qVzcWjpcQRR/2hJCFEbEsqhx8x3DP3em

OuD7U+RBzv8Ar7zvf7Vt/R/yo/tW39H/ACrgpNWvlRIbK2EtxJPcAA/MNqORj5nXrkd+OwrTiu7g

6s1vOqxRmPdEuwkv03HeDgYJxjHoc0KCYc7Oq/tW39H/ACo/tW3/ANv8qxKKORBzs2/7Vt/9v8qP

7Vt/R/yrEoo5EHOzb/tW29H/ACo/tW29H/KsSijkQc7Nv+1bb0f8qP7VtvR/yrEoo5EHOzb/ALVt

vR/yo/tW29H/ACrEoo5EHOzb/tW29H/Kj+1bb0f8qwJpGihZ0heZgOEjxuP0yQP1qjpWrjVQ7JYX

luiEqXuEVcsDggDcT+nY0ciDnZ1v9q23o/5Uf2rbej/lXJazt+yoZbBryBWLyoAhAAB5IcjNGgQz

W2i29vPbtBJGCpRip79tpIxRyIOdnW/2rbej/lR/att6P+VcT4guLiBrQ6fJKdQLN5Vuo3JKO+8Z

AAHHzZ4qXw/M09lI8080l15pE6zDaYn/ALoXJAGMYx1zmhQTBzZMkiz65rcig7Wu0xn/AK94aKjs

v+QlrH/X2n/pPDRUg9zpoImn0DT41IBMUfX/AHKhGjSCUyDyfMIClu5A6DOPc/nV3Tf+QVpn/XJP

/QKde61pOm3UNtfanZWtxPxDFPOiPJzj5QTk88cUuZp2LcUzMfw+ssDwSRWrwuSzRsuVYk5yRjnn

moJ/CcFw8Hmw2zRwIyJCVBjAOP4cdtoxXU4HpUMlxbxTxQSTRJNNnyo2YBnwMnaOpwOuKOdi5UYc

vh5J3ieaG1keI5jZ1yUPtkcdBQ/h5ZI/LeG1ZN/mbWXI3ZzuxjrnnNdFgelGB6Uc7DkRzcvhuK4i

8qa3s5I95fY6AjcepwR15PNPXQAlw9wkVss7gBpAuGYehOMmti81Cx05Ymvbu3thLIIozPIqb3PR

Rk8k+lPubi3s7aS5upooII13PLKwVVHqSeAKOdhyIyf7Kn/vx/mf8KP7Kn/vx/mf8K1Z7u0tYklu

LiGGN2VFeRwoZmOFAJ6kk4A71Hp+p6dq0LTabfWt7EjlGe2lWRVYc4JUnnkce9PnYciM7+yp/wC/

H+Z/wo/sqf8Avx/mf8K28D0FUNO1zR9Ykkj0zVbC9eLBkW2uEkKZ6Z2k4pc7DkRT/sqf+/H+Z/wo

/sqf+/H+Z/wrUu72z0+JZb25gto2cIHmkCAseAMnufSrGB6Uc7DkRh/2VP8A34/zP+FH9lT/AN+P

8z/hW5gelGB6U+dhyIw/7Kn/AL8f5n/Cj+yp/wC/H+Z/wrcwPSq95eWenWj3d9cwWttHjfNPIERc

nAyx4HJFLnYciMv+yp/78f5n/Cj+yp/78f5n/CtOxvrLU7Rbqwure7tnyFmgkWRGwcHBHHWrOB6U

+dhyowm0iV1KsYmUjBByQR+VL/ZU/wDfj/M/4VuYHpSYHoKXOw5EYn9lT/34/wAz/hR/ZU/9+P8A

M/4VrRzRTwxzQSJJDIodHQhlZTyCCOoIp9PnYciOGtEMera0hxlbxQcf9cIaKlgGdb17/r+H/oiK

ihEvc6bTf+QVpn/XJP8A0CuO8UxX9n4wj1HQkv5dQmWC2ubOTT2ltLqHcefOxtiK72J+bsOPXsdN

/wCQVpn/AFyT/wBArQ3D1qX8VzTo0eVwxeIp9Z1/SG1nULe10aOcw3cXmXMjm4w0QKglnMalgBye

VI7VSsrPWLq88Lale6Xq8U1tJeW5kFxeSBnIXypGEhMkcbMDneMYHzcYr1mzsrLTomisbSC1jZzI

yQRBAWPViAOp9asbh61KVkvQbet/M8WgtvF7eH55X1TxA+pSm1W6tVs7qIxv9oHmMkjOykbSwPlA

JtAOBWzp9r4g0zxBayK2vTWya3cwMs808yfY/KLJkMSCN3Rzk5wM9q9Q3D1o3D1p3/r7v8rejJt/

X3/5/geUeLrDWfiDeRx2eizw2lvphmjGpl7Ux3Up+UjCMGdAvTIxvPIqh4mk13xFoV02oaf4hje4

0WL7JZ2sM6r9q3N5wlVBg9FwJOCp+Xk17NuHrRuHrR/X5/5/gh31v/XT/L8WeRa9ZateauY7q31y

aeLV7F7OOFJjarar5ZYsF/d5Dbs7vmGB2FGiafqt7c2tsYtds7FrnVZZhGLi0yWkDwkkbTyDkfiP

UV67uHrRuHrR0+/8bf5X9QWlv67/AOZieEJNQm8GaQ+qrMuoG0T7QJ1Kyb8c7gec+ua5LQtP1+w0

jTpZYC9+miSwadstTGIJCFby5wxJ3EomG+VeGBAJGfSNw9aNw9aJatvv/wAH/MI+6kjzTTdGvL2H

QZbq71e88nVvMbzIb21aAfZ2zuEsjMy7gvzZ2/MVHBIMk0fiFr3xTK17qK3Itbtba1is7kIVx+5a

OXeYt+McIobJOc4r0fcPWjcPWh6sadreX+bf6nBanZ6vF4g0a3i1DUbexSKNlkFvdXRkmMmZFlZH

AUEbR+9DKATjGKlsbPVodTs79ptWeWTWbuGaOWWQxLa/vin7s/KFyEIbGeQM4wK7jcPWjcPWnf8A

r1F0t/WzX/B9TzeYaufCqqkusxai14n9rySQ3kpQfNnyFRlJTdtH7hsbeuea29ZtNQn8AWlvBNLd

3wezInktXDMRNGS7xE7xgDJBIPByRXW7h60bh60lp96f3Dvqmcdb6Df2nimyknvLiYXJubu9ktFe

3gaUeQsYKhjxtTozHOG7EisQzaxb6Pq0/mavFdR6RdvqMlw06xrdDmM25f5QB+8x5Xy4255xXpm4

etMmjhuIJIJ40likUo8bruVlPBBB6g0f1/X9dEOLs02eeg6ydH1uTR31gwtb24DXyTtL524/aGiV

iHI8sjAjIXI+TFWtP02+u5NEtrjUdXuLLyLxpZVW6siTvj8tX3uZQQN20s2SAeoruhtVQBgAcAAd

KXcPWh2bZK0SOd03Tb//AIQDTdNgvJtM1BNOgiWcRrI0Mioo5VwQ3IwQe2cEHkWfDVlrFhosMWva

r/aepH5ppliSNFJH3ECqvyj1PJ5PHAGucE9aPxoG3d3OMg/5Devf9fw/9ERUUQf8hvXv+v4f+iIq

KpGb3Ol03/kFaZ/1yT/0Cm3Wox2m0P5jMQm7DRqAXbagy5AyzcADJz9Rl2m/8grTP+uSf+gVjeJN

D03W0hhv0SdQIpDC9o1wAUJKNhfu9WHPDDI6ZBqK1YTNgarYBoo5b+KCaVtiQyyIrltxXAHc7gRx

nJHGauspUA7yeR1A9fpWGpS3eyjjui4Z9zEvsLMZCW+XzFPUkYKsexz0q5pUnmWch8zfiYDPmb/7

vfe/8x9O5TWouhPe6paafc2cFw217uXyouOM4zz+OB9SKdqF/Dptsk8yuyPcQW4CAE7pZUiU89tz

gn2z16VzXi+2QpeXNzPPGPIjitniiJ8pzJn5R5i73LKvGONq/jd8UTrFoNit1NGkz6jpxIJC7iLy

AsQMngZ9Tj1oly2Vnr1LSlu9jo8D0pjuqRNIRlVBJwPShHWSNZEZXR1DKynIIPIINRz/APHjL/uP

/M1Ayo2s2yjlJP8Ax3/Go49fs5Z44lSXLsFB+XGScetMJYmRi8oIJwVDMOpGMAeg+vP0zDMzD7MN

7MrzxkblZSMOvZue/wClAG/gelGB6UlFAC4HpRgelJRQAuB6UYHpSUUALgelGB6UlFAC4HpRgelJ

RQAuB6UYHpSUUALgelGB6UlFAHFw/wDIc17/AK/h/wCiIqKSH/kOa9/1/D/0RFRVIh7nTad/yCdM

/wCuSf8AoFY3iPw+dehij+0FI90EjCO6eBg0Tl1+ZOSCT+GARggEa9gCdH03BIPlJyP9yrW1v+er

/kP8KTmotpjcb6ozI7S+iNts1DaocyTIjoFYs5ZhzGxPXHBXOO1aKSyPH++ESvvGBHJvyOPUD3p2

1v8Anq/5D/Cja3/PV/yH+FL2ivcOV2sZmqaNc6hqtpeJexLHaAtFBLbl1808eYcOucDgDt1zUPiL

wlYeLdDttM1vdcLDNFOZF+Qs6fe4B4DKWX23ZHIFbO1v+er/AJD/AAo2t/z1f8h/hUcyNHJtJMmp

kkfmW7RbsblYZ9Mk/wCNM2t/z1f8h/hRtb/nq/5D/CnzIVii2mXDkkz2uSc5+y//AGVNGkTeZGzX

MOEdXIS32k4IOM7vatDa3/PV/wAh/hRtb/nq/wCQ/wAKOZBYmoqHa3/PV/yH+FG1v+er/kP8KOZB

YmoqHa3/AD1f8h/hRtb/AJ6v+Q/wo5kFiaiodrf89X/If4UbW/56v+Q/wo5kFiaiodrf89X/ACH+

FG1v+er/AJD/AAo5kFiaiodrf89X/If4UbW/56v+Q/wo5kFiaiodrf8APV/yH+FG1v8Anq/5D/Cj

mQWJqKh2vvI81+Mdh6fSnCNv+er/AJD/AAqhHHQ/8hzXv+v4f+iIqKIRjW9eGc/6cOf+2EVFUiHu

dNp//II03/rkn/oFcD4V8LWlx4b8PyHwZ4XuLaWwtXlu5yPPbdEhdinkEFsk9X57kZ477T/+QRpv

/XJP/QKzf+EI8J/9Cvov/gvi/wDiaznuaIPBH/Ig+HP+wXbf+ilrR+ZXk25/eMV+hzVq3t4re3jt

7eJIoYlCRxxqFVFAwAAOAAO1S7G9KhXAoxkqqBSo4bBbtzTkmZtoZyq85Y45PpnpVzY3pRsb0p69

gG0U7Y3pRsb0pWYxtFO2N6UbG9KLMBtFO2N6UbG9KLMBtFLtPpS7G9KVmA2inbG9KNjelOzAbRTt

jelGxvSizAbRTtjelGxvSizAbRTtjelGxvSizAo6naT31pPbW949o0gCtNGMuq452nPB9+1Jo2mH

SNPisVuHmhhAWLzPvIoHC57j/P0kaW5e4nW3hhZY2CMZJSvO0HjCnsRVafVJ7QM00EG1QSdk7E4H

XHyCtUSc/Ef+J5r3/X8P/REVFEf/ACHde/6/h/6IioqkZvc6bT/+QRpv/XJP/QKuVT0//kEab/1y

T/0CrlZVPiNUPj71hvqV4LyGRX3QF52eLaOURlXjvkct79K3EIGcmq0FjDDMZchmDyMh6bQ5BYe/

IpxBmY2uyW9k85CXGJpuAW3eWrEAgKp4xjk4HTJ5qxLrMwvGghs1dfMESu023LFN4yNpwMZ/T8Jm

0TTWhEPklYwGG1JWUEMckHB5Ht0qf7DaCXzPLG/zBJncfvBdoPX04piKH9v72s1htJJDPEkrhQx8

tWOOykevUjpV/T5nmtm81izpI8ZYgDdtYgHj2Api6ZZoYCishgUIhSVl+UcgHB+YexzUtnbraW/l

7wzFmdmxjLMSTx9TTugLFFJkeooyPUUXAWikyPUUZHqKLgUtSa6W2jNsZAoYGUxKrSBMH7obIJzj

sTjOOagi1UF4oEBnL+X5cjMAZFYEliABgja3GPyq9Pbx3MSpI8igHP7uZoz+akGq8WmxxX0c4dBH

DF5UMSrjaD1JOeT+XU9c0kDKTarezfYmhhhTzLkxSRtKdwG0naw2fKe/4Dkg5p7a6RJe7bORorZJ

CJMMAzJ1BO3aMnOME9OlXBplmEC4kOJBLuMzl9wGM7s56cdaU6dZlrg7WxcAiVBK21s9TtzgE+oG

aBlSDWJpLtIJbNYw0vlMwm3YYpvHG3njr6H1pNX1dLC6hQ3MUW0ebIrsAXXIGBn/AIEeP7vvV77D

aCXzPLG/zBJncfvBdoPX04pYbK1giaOOMBGQRkFicqBgDn2p3QihqGp3KNIlrGoSGWGOSUvyCzLw

FxgjBHOR1pJtSupbqBIUEVu100BlDAsxVWz8pXAGRwcnp71afSbCSRXaNsrs4ErAHb90kZwSMdTz

StpVi1wZ9jCTcX4lYAMRgkDOAcHqBSAzLbWruPT43aEXLJaLdTSPIEJBLZAAXGeOOn19egVgyhh0

IyKpR6XYxQNCkZ8tofIIMjHKc8ZJz/EauLtVQoIwBgc020Bj398+m2mq3cccMjJcxgLPcCBDlIl5

cggdfx6d6wnvpNRtLx5Y7RCkbEfZ70T9u+FGK6C5s2v4NUtkmEJa5jIcxLJjCRN91gQen4de1Y93

bmzs7uNrhpi0bgZiRAOP9kCgCrH/AMh3Xv8Ar+H/AKIiopE/5Duvf9fw/wDREVFWiHudRp//ACCN

N/65J/6BVyqen/8AII03/rkn/oFXKxqfEaIfH3rNi1pZPEE+meTtWNMpNv8AvuApdMY7K6HOecn0

rSj71zlv4Mt7a8gv1vbs38d09y8jXErROX3bwIS+xcqxAIHGB17ivYGS6X4sgv7CO7lgePdYQ3rQ

wJJPKokLDG1U+b7vbJ65AABNtPEmmSJZNHLO5vHZIkS1lLgq21t6hcoFYgMWACk84rDHgSSPTFtI

9SjJWxtbM+dal45BC7Md6BxuVwxUrkcdz0p9l4JksLDTrSC9tIltLyS6MkNkY3UPJv8ALiKyARrj

KkEMCvGK10uErX0/rT/M228R6Ul5dWz3JR7WN5JWeJ1jCqAXw5G1iuRkAkjvVyxvYtQtEuoFnWN8

4E8Dwvwcco4DD8RXO2XgyLT9U1W8hTSX+3ecyvNpgadWkOWDyhx5kec/JgcYGeK2dD02TSNJispb

n7Q6FjvCsqgFiQqqzMVUA4ALHAAFSttdxPfQ0aKKKACiiigCnqGpWulWYubt3CblRRHE0jsx4AVE

BZj7AGs2DxXYXd9aRWrrJazxXLtcsSgjMDIrAhgO7HnjG3vR4os7u4061uNOilkv7O4WeBY40fLY

KncryRgja7fxg9/asjSfB9xc6bE2tSlJpor9biBFGcXUgcjcCQCoGOMjJ6nGSls/66f5laXV/wCt

/wDgGjc+NdMj0ebUbbzJEglgSRJ4pLdlWWRUD4dQSuCSCBg7SAfS5H4n0yXT5L2L7bJHHL5MkaWE

7TRvjOGiCb14IPK9CD3FZUnhC+u7S5N7q8T30otUSeGzKIiQS+YoKF2yxJbJyByMAY5bdeDLm9tJ

Bd39ncXNxefaroTWBe2mAj8tU8kyfwgKQSzfMucelPrb+tv+CT0Nqy1yHUNXezt1DwfYobyO4VuH

WRnAGMeiZznv7Vq1z3h3wv8A2A0BF554i06Cw/1WzPlFzu6nrv6dsda6Gh2voD3/AK7f5hRRRSAK

KKKAM51u4rq58iOGRZXDkvKUIOxVxwp/u1n3WmX12HVkt0DgjImY4yMdNlbZ/wBc/wCH8qcKAOJX

/kO67/1+j/0RFRSL/wAh3Xf+v0f+iIqKpGb3Op0//kEab/1yT/0CrlU9P/5BGm/9ck/9Aq5WVT4j

VD0Gc1nnXdP/ALVOmo1zLcqwRzDayyRxsRna8iqUQ4IOGIOCPUVoR96wdLOo6XdS6dLpVxPBJdSz

JfwyReWFkcv84Zw+4ZxwpHAPfAcdgZ0GPr+dGPr+deXz6De6foOszS6Z9jePRryO/u90f/EzmYZW

X5GLHGHOXAI34A60+WxXRtPvNYGmDSUQ2jWloZIy93dIzFnUKxy0its5O9sfMKqytcGrfj+n+Z6L

e3ttp9v9oupDHFvSPdgn5nYKo49WYD8asY+v51yupaNeQ+B4LG1tmuryKa3nkjjZVMjrOkkhBYhc

khjyRWf4l0nUNbmF0dBmmkmsjDZiZ4N+mXG4/vid5xnKHMZZh5fTmi2tvP8AQFqrndY+v51Xub22

s5baOeQo91L5MIwTufazY46cKx59K5W90m/j1nWLv+xYtSvJrXbY3soiZIlEW0wkMwYbm3HgbTv5

IxxneHvDOqWD2qfYZoLOHWRdRxzfZkaOI2rITtgxGP3h6KO+eeTQkm/67i/r8D0PH1/OjH1/Oloo

sBn6prFlo0EEt604E0gijWCCSZ3fBbAWNWPRSenarVrcR3dtHcRLMqSDIEsbxMPqrAMPoQKxfE2j

Sa02ixKs3kw3wmnaC4aF0TypFyGVlb7zKODnn0zWB4k8O6lca7prWFhNIlibY295ugdwolBlWSWY

mb7g42EZywYnOKIq9r9xvTbt+p21ne21/E8ltIZEjleFjgjDoxVhz6EEVYx9fzrhG8P3yy2EjaUb

ieLV7q4XzRDJBHHJPuEjBmDB9vKMgLKcgjBINjQPD93Z+NdT1O9jvjLK8uy5H2byJImZSiEqPOJU

AABsqNpx1FCSf9egS0vbv+rOzx9fzox9fzpaKLCEx9fzox9fzpaKLAJj6/nRj6/nS0UWAhP+uf8A

D+VOFNP+uf8AD+VOFAHED/kO67/1+j/0TFRSf8x7Xf8Ar9H/AKJioq1sZvc6rT/+QRpv/XJP/QKu

VT0//kEab/1yT/0CrlY1PiNUPTPOKdz6j8qbH3rItTp5vpDefZ/7T85tnnY8zGTt2Z5xtx09++ac

dgZs8+o/Kjn1H5Vy82qvdaYIDcrJKdPnNygxlXAA5x0PJ4p6TSWT6nIt228SwuUYJ8sZCbm6ZwBk

Z9vXmqsI6Xn1H5Uc+o/KsE6lNd3ZS1vB5LXqxLJGFb5PK3HBIIPPepdPvbu41q5ilngEcbOv2cyD

zAARtbbtBwRzksRz2osBs8+o/Kjn1H5UtFACc+o/Kjn1H5UtFACDOByPyo59R+VA+6PpS0kAnPqP

yo59R+VLRTATn1H5Uc+o/KlooATn1H5Uc+o/KlooATn1H5Uc+o/KlooAhP8Arn/D+VOFNP8Arn/D

+VOFAHD/APMe13/r9H/omKilH/Id13/r9H/omKirWxm9zqdP/wCQRpv/AFyT/wBAq5VPT/8AkEab

/wBck/8AQKuVjU+I1Q9O/FOz7Gmx96xFubxIZL03juq3jQ/Z2RNpXzNgAIAbPTuelOOwM3c+xoz7

GspNZeW6uY47KZ44Q+11VvmZOCv3dvJzjBPTtT01SWVLRYYYJJ7jccCY7FVevzbc55Axjrn0qhGl

n2NGfY1lrqksksWYfLjN29uCJAS20PkkbeB8o6HP9akuuXb6Y8yWqQvLaPPA3m7sbQM5G3g85HXP

fFIdtbG/n2NGfY1ktqktuX86PMi28ThFfKl3YqBnaD1xk/p6q2rTriL7IhuvtAgZBN8oJTeDu29M

Y7ev4uwjVz7GjPsar2F2by28xo/LdXaN0DbgGViDg8ZHFWaAEB4HBoz7GqWpNdLbRm2MgUMDKYlV

pAmD90NkE5x2JxnHNQRaqC8UCAzl/L8uRmAMisCSxAAwRtbjH5UkBqZ9jRn2NYjarezfYmhhhTzL

kxSRtKdwG0naw2fKe/4Dkg5p7a6RJe7bORorZJCJMMAzJ1BO3aMnOME9OlAzYz7GjPsayYNYmku0

gls1jDS+UzCbdhim8cbeeOvofWk1fV0sLqFDcxRbR5siuwBdcgYGf+BHj+7707CNfPsaM+xrI1DU

7lGkS1jUJDLDHJKX5BZl4C4wRgjnI60k2pXUt1AkKCK3a6aAyhgWYqrZ+UrgDI4OT096QGxn2NGf

Y1z9trV3Hp8btCLlktFuppHkCEglsgALjPHHT6+utd3hgihMUYklncJGrNtBJBPJwccA9qdgJT/r

n/D+VOFZeraq2kafJfy2F1c7AplitArMgxyfmK5A7/njGcS6RqZ1W1Fx9hurRT91bkICf++WNAHL

j/kO67/1+j/0TFRQP+Q7rv8A1+j/ANExUVa2M3udRYELo+mliAPKTk/7lWvOi/56J/30Kq2Gf7I0

3aQD5SdRn+CrmJf76f8AfB/xrOUbs0FSaIZzKn/fQqrHY6bHcecpBbeZAGnZlDHqwUnAPJ5A71Zx

L/fT/vg/40Yl/vp/3wf8aErAQLbWKSzSJIUabO8LcMFyepABwD7jmmmy07yoo92PLYsrCdg+T1+b

OTnvk81ZxL/fT/vg/wCNGJf76f8AfB/xpgRCCwATBQbJWmX950c5yev+0aq2Ol6fZ2ohaRZWMPku

zSHBXuACTtB9BV/Ev99P++D/AI0Yl/vp/wB8H/GgCv8AZNO2MhKsGjETFpixKgkjknPBJ560sdrp

8SxhWUlJPNDNKWbfgjJJOTwcc1PiX++n/fB/xoxL/fT/AL4P+NACQ/ZbdWWJ0UM7OfnzyTkn8zUn

nw/89U/76FMxL/fT/vg/40Yl/vp/3wf8aAGTrbXMSpJOygHP7udoz+akGq0VnbRX0c4niEcMXlQx

LxtB6knPJ/LqeuauYl/vp/3wf8aMS/30/wC+D/jQBWFlpwQLvJxIJdxuGL7gMZ3Zz0460ps9PLXB

3cXAIlQTttbPU7c4BPqBmrGJf76f98H/ABoxL/fT/vg/40AQ/ZtPEvmfJv8AMEmfM/iC7QevpxSw

wWEETRx+WEZBGQXzlQMAcn0qXEv99P8Avg/40Yl/vp/3wf8AGgCo+naZJIrtjK7OBOwB2/dJGcEj

HU80rWGmtcGfIEm4vxOwAYjBIGcA4PUCrWJf76f98H/GjEv99P8Avg/40AVY7DTIoGhTb5bQ+QQZ

icpzxknP8Rp8lpp8qOrFcO4kJWUqQwAAIIORwAOKnxL/AH0/74P+NGJf76f98H/GgCNXhjYosi7V

AAy+eAPU9aekkCKFV41UDAAIAApcS/30/wC+D/jRiX++n/fB/wAaAOLXDa5rhByDejH/AH4iooTP

9t65nr9tH/oiKiqRm9z/2VBLAQItABQABgAIAAAAIQCkzN3HDQEAABUCAAATAAAAAAAAAAAAAAAA

AAAAAABbQ29udGVudF9UeXBlc10ueG1sUEsBAi0AFAAGAAgAAAAhADj9If/WAAAAlAEAAAsAAAAA

AAAAAAAAAAAAPgEAAF9yZWxzLy5yZWxzUEsBAi0AFAAGAAgAAAAhAIwWt0CzBQAAFxcAAA4AAAAA

AAAAAAAAAAAAPQIAAGRycy9lMm9Eb2MueG1sUEsBAi0AFAAGAAgAAAAhAFhgsxu6AAAAIgEAABkA

AAAAAAAAAAAAAAAAHAgAAGRycy9fcmVscy9lMm9Eb2MueG1sLnJlbHNQSwECLQAUAAYACAAAACEA

KpBimeEAAAAKAQAADwAAAAAAAAAAAAAAAAANCQAAZHJzL2Rvd25yZXYueG1sUEsBAi0ACgAAAAAA

AAAhAHsRAOoRIgAAESIAABUAAAAAAAAAAAAAAAAAGwoAAGRycy9tZWRpYS9pbWFnZTEuanBlZ1BL

BQYAAAAABgAGAH0BAABfLAAAAAA=

"&gt;
 &lt;v:imagedata src="Creating%20Extensible%20Applications%20with%20MAF_files/image007.png"
  o:title=""/&gt;
 &lt;o:lock v:ext="edit" aspectratio="f"/&gt;
 &lt;w:wrap type="tight"/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;
&lt;!--[if !vml]--&gt;
&lt;!--[endif]--&gt;The directory names are required, but not case sensitive – each directory
holding a single piece of the pipeline that MAF will load dynamically when it is loading
the add-in.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The host-side view is always located in the
same directory as the host executable itself so it does not need a dedicated directory.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;When
creating your Visual Studio project, it is important to set the output directories
appropriately so that you create the above directory structure.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;In
addition, all references between the components should be marked as CopyLocal = “false”
in Visual Studio to ensure a local copy of the assembly isn’t placed into the sub-directory:&amp;nbsp; &lt;span style=""&gt;
&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;span style=""&gt;&lt;img src="http://www.julmar.com/blog/mark/content/binary/image008.png" alt="image008.png" border="0" height="159" width="198"&gt;
&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;h2&gt;Discovering and loading add-ins from the host
&lt;/h2&gt;
&lt;p class="MsoNormal"&gt;
The last piece of the puzzle is the actual loading of add-ins from the host.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This
is done in three basic steps:
&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpFirst" style="text-indent: -0.25in;"&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;1.&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!--[endif]--&gt;Identify and catalog the add-ins
&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in;"&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;2.&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!--[endif]--&gt;Retrieve the list of specific add-ins based on view or name
&lt;/p&gt;
&lt;p class="MsoListParagraphCxSpLast" style="text-indent: -0.25in;"&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;&lt;span style=""&gt;3.&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;!--[endif]--&gt;Activate and use the add-in
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
The first step is to identify the available add-ins for the host.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This
is done through the &lt;b style=""&gt;System.AddIn.AddInStore&lt;/b&gt; class:
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;string[] errorList
= AddInStore.Rebuild(&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;PipelineStoreLocation.ApplicationBase);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Calling &lt;b style=""&gt;Rebuild&lt;/b&gt; forces MAF to walk the directory structure and create
the pipeline database.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It stores this information in the
pipeline root directory and returns a list of errors, if any occur.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The
most common errors are missing pipeline components – where MAF is unable to locate
some required portion of the pipeline such as a View or Adapter.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Next, the host will retrieve a list of add-ins based on the host view through the &lt;b style=""&gt;FindAddIns&lt;/b&gt; method
– these will be the add-ins conforming to a specific contract (whatever the view/adapter
is bound to):
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;Collection&amp;lt;AddInToken&amp;gt;
addinTokens = AddInStore.FindAddIns(&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;typeof(TranslatorHostView),&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;PipelineStoreLocation.ApplicationBase);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
The first parameter is the host view type – so MAF knows what add-ins we are looking
for, the second is the pipeline root directory, which is the same directory passed
to the &lt;b style=""&gt;Rebuild&lt;/b&gt; method and indicates where the pipeline database is
stored.
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
The returning collection represents a series of &lt;i style=""&gt;tokens &lt;/i&gt;that are used
to identify and control the add-ins.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This is how the host
can examine, activate and unload the add-in.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;To activate
a specific add-in, you can take the token and call &lt;b style=""&gt;Activate&lt;/b&gt;:
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;Collection&amp;lt;AddInToken&amp;gt;
addinTokens;&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;...&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;foreach (AddInToken token in
addinTokens)&lt;br&gt;
{&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;TranslatorHostView
view =&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;token.Activate&amp;lt;TranslatorHostView&amp;gt;(&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;AddInSecurityLevel.Internet);&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;string
hello = view.Translate(“Bonjour”);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;...&lt;br&gt;
}&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
The &lt;b style=""&gt;Activate&lt;/b&gt; call loads all the required components, instantiates
the add-in type and returns the host view used to interact with the add-in.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Calls
made to this object will be marshaled back and forth to the add-in using the pipeline.
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
Notice that the parameter passed to &lt;b style=""&gt;Activate&lt;/b&gt; indicates the security
level required.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;There are several overrides that allow
you to dictate exactly how the add-in is loaded.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;You can
load the add-in into a specific AppDomain – the current one for best performance:
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;token.Activate&amp;lt;TranslatorHostView&amp;gt;(AppDomain.CurrentDomain)&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
You can specify a specific permission set to restrict the things the add-in can do
on your behalf:
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;PermissionSet pset = ...;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;token.Activate&amp;lt;TranslatorHostView&amp;gt;(pset);&lt;/span&gt;&lt;/b&gt;&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
Or you can specify a known permission set based on the CAS zones:
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;img src="http://www.julmar.com/blog/mark/content/binary/image010.png" alt="image010.png" border="0" height="102" width="244"&gt;
&lt;br&gt;
&lt;span style=""&gt;
&lt;!--[if gte vml 1]&gt;&lt;v:shape id="P_x0020_11" o:spid="_x0000_i1025"
 type="#_x0000_t75" alt="image1.JPG" style='width:242pt;height:100pt;
 visibility:visible;mso-wrap-style:square'&gt;
 &lt;v:imagedata src="Creating%20Extensible%20Applications%20with%20MAF_files/image009.png"
  o:title="image1.JPG" chromakey="#f4f4f4"/&gt;
 &lt;v:textbox style='mso-rotate-with-shape:t'/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;
&lt;!--[if !vml]--&gt;
&lt;!--[endif]--&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Once the add-in is activated, the host can call it just like any other object – but
never forget that you are likely crossing an isolation barrier!&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Make
sure to design your contracts so that you minimize the number of calls between the
host and add-ins to ensure your performance doesn’t suffer.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
When you are finished with the add-in, you can tell MAF to unload it through the &lt;b style=""&gt;AddInController&lt;/b&gt; associated
with the view:
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;AddInController ctrl
= &lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;&lt;span style=""&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;AddInController.GetAddInController(view);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNoSpacing"&gt;
&lt;b style=""&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;;"&gt;ctrl.Shutdown();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
This will unload the add-in side pipeline and then destroy the containing AppDomain
so you release the resources associated with it.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
There are many other capabilities MAF provides such as versioning, passing collections
and WPF visuals, passing non-serializable types, etc.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;You
can get a pretty decent overview of the features from &lt;a href="http://msdn.microsoft.com/en-us/library/bb384241.aspx"&gt;MSDN&lt;/a&gt; and
the MAF team has a blog at &lt;a href="http://blogs.msdn.com/clraddins/"&gt;&lt;span style="font-family: &amp;quot;Lucida Grande&amp;quot;;"&gt;http://blogs.msdn.com/clraddins/&lt;/span&gt;&lt;/a&gt; that
has some great, practical information on using this new framework.&lt;span style="font-family: &amp;quot;Lucida Grande&amp;quot;; color: black;"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Creating popup windows in XBAP applications</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/04/03/CreatingPopupWindowsInXBAPApplications.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,725cf1d9-3dc7-48f1-89f0-da8e3f3cfccb.aspx</id>
    <published>2008-04-03T07:47:05.896-07:00</published>
    <updated>2008-04-03T07:51:52.8830437-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">A colleague at <a href="http://www.develop.com">DevelopMentor</a> recently
asked me about creating popup windows in XAML browser applications (XBAP). Normally
this is not allowed - if you try to create a top-level window you will get a <strong>SecurityException</strong> because
WPF asks for <strong>UIPermission</strong> which is strictly prohibited when hosted
in the browser. It turns out, however, that you <em>can</em> get a popup window -
there's a hidden little gem in the <strong>System.Windows.Controls.Primitive</strong> namespace
that is your friend: <strong>Popup</strong>. It's the same underlying class that ToolTip,
Menu, and ComboBox use to display drop-down menus and overlays and it is browser-hosting
aware! It's pretty limited in functionality - I'm not sure you can get it to move
around with the mouse for example, but for simple cases it works great. Here's a code
snippet - wire this up to a button in an XBAP:<br />
  <style type="text/css">

.csharpcode, .csharpcode pre

{

	font-size: small;

	color: black;

	font-family: Consolas, "Courier New", Courier, Monospace;

	background-color: #ffffff;

	/*white-space: pre;*/

}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 

{

	background-color: #f4f4f4;

	width: 100%;

	margin: 0em;

}

.csharpcode .lnum { color: #606060; }

</style><div class="csharpcode"><pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">void</span> OnClick(<span class="kwrd">object</span> sender,
EventArgs e)</pre><pre><span class="lnum"> 2: </span>{</pre><pre class="alt"><span class="lnum"> 3: </span> Popup window = <span class="kwrd">new</span> Popup();</pre><pre><span class="lnum"> 4: </span> </pre><pre class="alt"><span class="lnum"> 5: </span> StackPanel sp = <span class="kwrd">new</span> StackPanel
{ Margin = <span class="kwrd">new</span> Thickness(5) };</pre><pre><span class="lnum"> 6: </span> sp.Children.Add(<span class="kwrd">new</span> TextBlock
{ Text = <span class="str">"Hi from a popup"</span> });</pre><pre class="alt"><span class="lnum"> 7: </span> Button newButton = <span class="kwrd">new</span> Button
{ Content = <span class="str">"Another button"</span> };</pre><pre><span class="lnum"> 8: </span> newButton.Click += <span class="kwrd">delegate</span> {
window.IsOpen = <span class="kwrd">false</span>; };</pre><pre class="alt"><span class="lnum"> 9: </span> sp.Children.Add(newButton);</pre><pre><span class="lnum"> 10: </span> sp.Children.Add(<span class="kwrd">new</span> Slider
{ Minimum = 0, Maximum = 50, Value = 25, Width = 100 });</pre><pre class="alt"><span class="lnum"> 11: </span> </pre><pre><span class="lnum"> 12: </span> window.Child = <span class="kwrd">new</span> Border
{ Background = Brushes.White, BorderBrush = Brushes.Black, 
<br />
BorderThickness = <span class="kwrd">new</span> Thickness(2), Child = sp };</pre><pre class="alt"><span class="lnum"> 13: </span><b>window.PlacementTarget = <span class="kwrd">this</span></b>;</pre><pre><span class="lnum"> 14: </span> window.Placement = PlacementMode.Center;</pre><pre class="alt"><span class="lnum"> 15: </span> </pre><pre><span class="lnum"> 16: </span> window.IsOpen = <span class="kwrd">true</span>;</pre><pre class="alt"><span class="lnum"> 17: </span>}</pre></div><br />
The key thing you need to do is set the <strong>PlacementTarget</strong>. That associates
a "parent" window and without it, the <strong>Popup</strong> class asserts <strong>UIPermission</strong> which
will fail in the browser environment.
</div>
    </content>
  </entry>
  <entry>
    <title>When .NET 1.1 threads are faster than .NET 3.5!</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/02/07/WhenNET11ThreadsAreFasterThanNET35.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,bec3e025-9602-4276-8d08-e0ad4ee5ca04.aspx</id>
    <published>2008-02-06T21:35:52.022-08:00</published>
    <updated>2008-02-06T21:40:16.0709727-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Today at the GNET <a href="http://www.develop.com/us/technology/bio.aspx?id=107">Michael
Kennedy</a>, <a href="http://www.develop.com/us/technology/bio.aspx?id=52">Jason Whittington</a> and
I discovered a pretty interesting change in .NET 2.0 SP1 (included in .NET 3.5). 
<br /><br />
We knew they increased the thread pool limit from 25 threads/cpu to 250 threads/cpu,
but we also found they changed the heuristics for creating threads to avoid creating
a bunch of threads in a short period of time. In previous versions of .NET, threads
were allocated at a rate of 1 every 500ms assuming there were queued items. This is
documented behavior <a href="http://msdn2.microsoft.com/en-us/library/0ka9477y.aspx">in
MSDN</a>. 
<br /><br />
In .NET 3.5, it appears to have been changed to a sliding scale where they slow down
thread creation as more demand is placed on the pool. This is a change even from the
beta and must have been slipped in at the last minute. 
<br /><br /><a href="http://www.michaelckennedy.net/blog/PermaLink,guid,55a9b21e-ae85-4c24-a0b6-63dff4a6b491.aspx">Michael
documented the whole change on his blog here</a>.. recommended reading. 
</div>
    </content>
  </entry>
  <entry>
    <title>Demos from the Boston WPF class</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/02/05/DemosFromTheBostonWPFClass.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,e6ee10cb-b142-4f82-9fdc-6a099cee06d1.aspx</id>
    <published>2008-02-05T07:41:26.1419384-08:00</published>
    <updated>2008-02-05T07:41:26.1419384-08:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Thanks to all of you who attended the Boston
WPF class last week. You can get the demos we built in class here -- <a href="http://www.julmar.com/DMStuff/Class.zip">Class.zip</a>. 
</div>
    </content>
  </entry>
  <entry>
    <title>.NET Framework source debugging</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2008/01/18/NETFrameworkSourceDebugging.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,fcc4b6f4-11fd-4ee6-bf7a-6f1071817f0f.aspx</id>
    <published>2008-01-18T07:36:33.5818198-08:00</published>
    <updated>2008-01-18T07:36:33.5818198-08:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">It's finally here! Shawn Burke gives details
on how to debug into the .NET framework source code! <a href="http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx">Here's
the post</a>!
</div>
    </content>
  </entry>
  <entry>
    <title>Christmas comes early: Microsoft releases Visual Studio .NET 2008</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/12/19/ChristmasComesEarlyMicrosoftReleasesVisualStudioNET2008.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,60915760-aaa4-4438-bcd4-e0d29cb4b156.aspx</id>
    <published>2007-12-19T08:56:11.093-08:00</published>
    <updated>2007-12-19T08:56:11.0937809-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
After a long beta period Microsoft pushed Visual Studio .NET 2008 (code named “Orcas”)
out to MSDN in November - keeping their promise to deliver it by the end of the year.
We’ve been using Orcas in many of our .NET classes for a while now and I for one,
am pretty excited that it’s finally here. There’s a ton of new features and enhancements
in this release that makes it almost a no-brainer to upgrade - I thought I’d take
a moment and list my top ten favorites in no particular order: 
</p>
        <strong>#10: WPF designer (“Cider”)</strong>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/vs2008_10.jpg" border="0" />
        </p>
I spend a lot of time on rich-client island and compared to the embarrassing support
for WPF provided for VS2005 (through an add-on) VS2008 just plain rocks. Not only
does the designer just work, the XAML intellisense is full featured and driven through
a real XAML parser and not an XSD file. That means custom types and namespace completion
actually functions how you would expect them to! The visual designer and XAML views
stay synchronized and “mini” thumbnails and scaling bars are used to help you see
what you are building. You can also see how the new Cider environment has borrowed
from Blend - a Search box is present to filter properties down and the selection in
the XAML pane is synchronized with the visual designer so if you highlight a tag,
it selects the appropriate object in the visual pane. <strong><br /><br />
#9: WPF and Windows Forms integration (“Crossbow”)</strong><p><img src="http://www.julmar.com/blog/mark/content/binary/vs2008_09.jpg" border="0" /></p>
Hand in hand with the designer view, VS2008 improves the designer experience for Windows
Forms to WPF integration. Specifically, ElementHost is now present in the toolbox
and you can drag and drop WPF user controls right onto your Form! You get a live preview
of the control and can edit the content right in the designer. <strong><br /><br />
#8: ClickOnce improvements</strong> Microsoft introduced a simplified way to deploy
Windows Forms clients from the web with Visual Studio 2005 called ClickOnce. With
2008, they’ve improved the experience by allowing deployment through FireFox (previously
only IE was supported), file associations so your application can be launched by activating
a data file, better support for certificate expiration and changing the deployment
location without resigning the application and support for Office add-in and WPF XAML
Browser application deployment. 
<br /><br /><strong>#7: Multi-framework targeting</strong><p><img src="http://www.julmar.com/blog/mark/content/binary/vs2008_07.jpg" border="0" /></p>
This release of Visual Studio has a much-needed feature that I wish had been there
before - the ability to target multiple versions of .NET. Specifically, you can select
your target framework (2.0 SP1, 3.0 or 3.5) and the project types, toolbox, references,
intellisense and features will be appropriately set to that version. This selection
can occur during project creation - in the project templates dialog or on the project
properties dialog. Be aware that selecting .NET Framework 2.0 actually means 2.0 SP1
and not the original .NET 2.0 framework released with Visual Studio 2005. <strong><br /><br />
#6: Better intellisense support</strong><p><img src="http://www.julmar.com/blog/mark/content/binary/vs2008_06.jpg" border="0" /></p>
Web developers benefit from this release too - Visual Studio now has intellisense
and code completion support for JavaScript! It’s smart enough to look at the underlying
type currently assigned and correctly infer the methods which are available. So, for
example if you assign a numeric type, the dropdown will be populated with the proper
methods available for the type. Visual Studio will also look at the comments applied
to your methods - just like in C# and VB.NET, it will pull descriptions out of XML
based comments on your JavaScript methods and display descriptions as tooltips when
you are navigating the intellisense dropdown. Another cool feature added to Intellisense
is the filtering applied - now if you press a letter and start typing, it will begin
to restrict your choices displayed, not just scroll to that section. This filters
the output and makes it easier to find what you are looking for. 
<br /><br /><strong>#5: Organize your using statements</strong><p><img src="http://www.julmar.com/blog/mark/content/binary/vs2008_05.jpg" border="0" /></p>
Visual Studio now has the ability to organize your using statements. As a project
evolves, you often end up with a ton of using statements at the top of each file which
are not really being used - either because the project template added it, or because
you originally did use something from that namespace which was then removed later.
Now you can right click on your using statements and sort and/or remove unused namespaces. <strong><br /><br />
#4: Refactoring enhancements</strong> The refactoring support was a welcome addition
to VS 2005 - and Microsoft has enhanced the support in 2008 to support C# 3.0 features
and allow you to refactor anonymous types, extension methods and lambda expressions. <strong><br /><br />
#3: C# 3.0 support</strong> Speaking of C# 3.0, that has got to be one of the coolest
features - functional programming seems to be all the rage these days and introducing
these features into C# 3.0 will allow you to be the coolest programmer on your floor.
Things like automatic properties, lambda expressions (which reduce your typing for
anonymous delegates), partial methods, anonymous types and extension methods will
radically change how you can build applications. They can seem weird at first for
some people, but don’t be afraid of them! They will cut down your typing and provide
for some really cool ways to enhance and evolve your projects. <strong><br /><br />
#2: Visual Studio Split View</strong><p><img src="http://www.julmar.com/blog/mark/content/binary/vs2008_02.jpg" border="0" /></p>
It is becoming increasingly more common to have multiple monitors on developers desks.
Building on the “split” window feature of VS 2005, Visual Studio 2008 now allows you
to tile the window horizontally or vertically so you can split your design and code
view across monitors! This works in any of the designers (ASP.NET, WinForms, WPF,
etc.) <strong><br /><br />
#1: Debugging the .NET source code</strong> There are actually several debugging enhancements
(try debugging JavaScript on the client-side for example - it works great!) but I
think the coolest feature by far has got to be the debugging enhancements which will
allow you to actually debug into the source code of the .NET framework. Scott Guthrie
announced a few weeks ago on his <a href="http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx">blog</a> that
they intend to release the source code under the Microsoft Reference License. As part
of that release, VS2008 will have integrated debugging support so that you can step
into the framework libraries (ever want to know why your DataBind isn’t working??).
Visual Studio will automatically download the source file from Microsoft’s server
and you will get full watch and breakpoint support. This isn’t quite ready yet, but
it’s coming soon and promises to be one of the biggest timesavers added to Visual
Studio! 
<br /><br /><br />
There’s a ton of other features that make VS 2008 a worthwhile upgrade - you can experience
it yourself by downloading a free copy today (Express editions have been released)
or upgrading from MSDN. VS 2008 co-exists just fine with 2005 and 2003 but be aware
that the project format has changed and it’s not backward compatible so sharing projects
with your coworkers may be slightly painful for you until everyone moves to the new
release as you will have to maintain two project and solution files.
</div>
    </content>
  </entry>
  <entry>
    <title>Guerrilla .NET Tampa samples</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/11/19/GuerrillaNETTampaSamples.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,ad823418-2717-4002-8d26-bd634139edec.aspx</id>
    <published>2007-11-19T15:01:13.0320569-08:00</published>
    <updated>2007-11-19T15:01:13.0320569-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">Thanks to all those who attended the GNET
in Tampa last week. We had a blast with all of you and wish you the best of luck going
back and using all the cool tricks and technologies we showed you! As promised, here
are the demos we build during the week - <a href="http://www.julmar.com/DMStuff/gnet-demos.zip">Demos</a>.
Enjoy! 
</div>
    </content>
  </entry>
  <entry>
    <title>Organizing your using statements</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/09/06/OrganizingYourUsingStatements.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,afc742d5-26ab-4b7b-af4b-a2d9580e59e8.aspx</id>
    <published>2007-09-06T07:47:15.906-07:00</published>
    <updated>2007-09-06T07:47:15.9060068-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Another interesting feature I hadn't noticed about VS.NET 2008 is the "Organize Using"
command.  It allows you to sort and filter your using blocks on a file-by-file
basis.  For large projects that have changed over time I could see how it could
be very useful.<br /></p>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/vs2k8_using.jpg" border="1" />
        </p>
        <p>
 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Creating a legacy web service proxy in Visual Studio 2008</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/08/13/CreatingALegacyWebServiceProxyInVisualStudio2008.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,daadebd8-7fc8-42ce-b4dc-4d401ea85eea.aspx</id>
    <published>2007-08-13T12:58:09.4110817-07:00</published>
    <updated>2007-08-13T12:58:09.4110817-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you right click on "References" in a VS2008 project you will find only two options
now - "Add Reference" and "Add Service Reference".  The first is for local assemblies,
and the second generates WCF-compatible proxies through SVCUTIL.EXE.  This happens
to be one of the most obviously changed things in Orcas - the dialog presented is
a more professional version than what was supplied with the original WCF CTP for VS.2005:
</p>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/ScreenShot001.bmp" border="0" />
        </p>
        <p>
The "Discover" button above can locate IIS-hosted web services (not Self Hosted however)
and it now shows operations directly which is pretty cool.  The best part is
the "Advanced" button though.  Clicking that gives you:
</p>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/ScreenShot001.jpg" border="0" />
        </p>
        <p>
Here you can control all the details of SVCUTIL.EXE -- how to reuse types, whether
to generate public/private types, whether to genrate lower-level message contracts
(giving complete control over the SOAP structure), and whether to generate asynchronous
methods (ala the original web services references in .NET 2.0).
</p>
        <p>
The bottom section - "Compatibility" allows you to generate a web service proxy using
that original WS technology.  Clicking this will yield the traditional dialog
you are probably used to:
</p>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/ScreenShot002.jpg" border="0" />
        </p>
        <p>
So, if you were confused by the lack of a "Add Web Reference" in Orcas, fear no more
- it's still there just a little harder to get to!
</p>
        <p>
You might be asking - "Why would I want to generate one of those?  Why not just
use WCF?"  Well, we have to keep in mind that not all our clients want to move
to WCF just yet (as much as we want them to, there is a cost in deployment), and second,
WCF isn't supported on pre-XP platforms.  There are still a lot of Windows 2000
systems out there!  For those clients, we have no choice but to use legacy web
service proxies.
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Fixing SVCUTIL.EXE for Orcas Beta 2</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/07/30/FixingSVCUTILEXEForOrcasBeta2.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,19b2283e-5117-4833-9ba3-7c8b8b1b5fa6.aspx</id>
    <published>2007-07-30T15:20:15.2069224-07:00</published>
    <updated>2007-07-30T15:20:15.2069224-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <div>Microsoft apparently didn't resign all the tools in the SDK supplied with Beta
2 of Visual Studio 2008.  This is actually documented in the readme that
UISpy has this issue, which of course, I didn't read..
</div>
        <div> 
</div>
        <div>SVCUtil.exe also has this problem and it causes any proxy-generation
from VS.NET 2008 to fail (as well as killing the client tester process which is spawned
for WCF testing).  You'll know you've hit this error when the program crashes
with a "System.IO.FileException" and indicates that it has failed strong-name validation.
</div>
        <div> 
</div>
        <div>It's easy enough to fix .. 
</div>
        <div> 
</div>
        <div>1) Open a command prompt with full admin rights
</div>
        <div>2) CD to the C:\Program Files\Microsoft SDKs\Windows\V6.0a\bin directory
</div>
        <div>3) execute "SN -Vr svcutil.exe"
</div>
        <div> 
</div>
        <div>This turns off strong-name validation for svcutil.exe.
</div>
        <div> 
</div>
      </div>
    </content>
  </entry>
  <entry>
    <title>Playing with VS.NET 2008 .. </title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/07/16/PlayingWithVSNET2008.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,a7d85c0f-d41d-4702-b57f-efecc1ac30e9.aspx</id>
    <published>2007-07-16T11:26:30.155-07:00</published>
    <updated>2007-07-16T11:26:30.1555242-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been playing a bit with VS.NET '08 June CTP lately and noticing several nice
improvements - the Cider WPF add-in especially seems to have better integration with
the code window. For example, double clicking on an element now creates the code-behind
handler (finally!).
</p>
        <p>
The layout support is much better as well - you finally get the drag handles and positioning
lines.
</p>
        <img border="0" src="http://www.julmar.com/blog/mark/content/binary/vsnet2008_1.jpg" />
        <p>
        </p>
        <p>
The property sheet seems a bit sketchy right now - I see how Blend has certainly influenced
it (as the code apparently is coming from that product), but I find Blend to be easier
to work with there. No support for Data Providers either which is a bummer.
</p>
        <p>
Bindings are still not as nice as Blend; manual addition seems to be the only way
to do them at this point, however Intellisense is *much* better now. There's also
a nice zoom bar present which allows fine-detail work to be done when drawing graphical
elements (such as Control Templates or even just 2D/3D shapes).
</p>
        <p>
Overall, I'm seeing some good progress - here's hoping for more as the product matures!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>TSP++ 3.0 is now free!</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/07/13/TSP30IsNowFree.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,61b8e49c-f652-4897-a4cf-087b3ac6bb2e.aspx</id>
    <published>2007-07-13T14:46:33.631-07:00</published>
    <updated>2007-07-13T14:50:24.7235391-07:00</updated>
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="Tapi" label="Tapi" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Tapi.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sales of the TSP++ products have steadily fallen over the past 5 years, so much so
that I decided two years ago to release the 2.x product into the open-source community,
and now I am doing the same for the server edition. 
</p>
        <p>
The download is available <a href="http://www.julmar.com/_Media/tspv3053.exe">here</a> and
requires a key to install it - use <span style="font-family: 'Lucida Grande'; font-size: 14px;"></span></p>
        <p>
          <span style="font-family: 'Lucida Grande'; font-size: 14px;">J35M-3KXo-q60T</span>
        </p>
        <p>
          <span style="font-family: 'Lucida Grande'; font-size: 14px;">
            <span style="font-family: Times; font-size: 16px;">
            </span>
          </span>
        </p>
        <p style="font-family: Verdana; font-size: 12px;">
which will let you install the full product. Documentation and samples are all part
of the image so have fun!
</p>
        <p>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Adding Pause/Resume into SynchronizationContext based components</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/01/17/AddingPauseResumeIntoSynchronizationContextBasedComponents.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,b862bda0-ca95-42b9-b557-0f16f15628d6.aspx</id>
    <published>2007-01-17T08:11:04.998-08:00</published>
    <updated>2007-01-17T08:24:36.3167367-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="Real World" label="Real World" scheme="http://www.julmar.com/blog/mark/CategoryView,category,RealWorld.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
About a year ago, I blogged on using the .NET 2.0 facility <b>SynchronizationContext</b> to
create thread-aware components which could be hosted and would "do the right thing"
for callbacks. Here's the <a href="http://www.julmar.com/blog/mark/PermaLink,guid,78805871-cb7b-4ea4-9be8-a8a1d61a15d8.aspx">Link</a> to
that post. 
</p>
        <p>
Recently, I got an email from a reader who wanted to use that paradigm, but wanted
to be able to suspend the operation for some period of time and then resume it later
on. He asked if there was an easy way to modify the sample I presented, and it turns
out that there is. 
</p>
        <p>
It essentially involves three steps: 
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
            <b>1.</b> In the AsyncStateData structure, add a <b>ManualResetEvent</b> object. This
will be used to trigger the pause/resume behavior. It must be initially set as signaled. 
<br /><b><br />
2.</b> In the actual asynchronous operation loop, add the event into the loop condition
by calling <b>event.WaitOne()</b>. Make sure you have released any locks and the code
can safely be halted at that point in the logic otherwise you may create deadlock
scenarios and other difficult debugging issues. 
<br /><b><br />
3.</b> Add a <b>Pause</b> and <b>Continue</b> method into the class which signals
and resets the event. 
</p>
        </blockquote> Modifying my previous code example, here's what I come up with: 
<h4>Step 1: Add the event to AsyncStateDate
</h4><div class="csharpcode"><pre><span class="lnum"> 1: </span><span class="kwrd">class</span> AsyncStateData</pre><pre><span class="lnum"> 2: </span>{</pre><pre><span class="lnum"> 3: </span><span class="kwrd">private</span> ManualResetEvent
pauseEvent = <span class="kwrd">new</span> ManualResetEvent(<span class="kwrd">true</span>);</pre><pre><span class="lnum"> 4: </span> ...</pre><pre><span class="lnum"> 5: </span>}</pre></div><h4>Step 2: Add event into the loop at a safe point
</h4><div class="csharpcode"><pre><span class="lnum"> 1: </span><span class="kwrd">public
partial</span><span class="kwrd">class</span> Calculator</pre><pre><span class="lnum"> 2: </span>{</pre><pre><span class="lnum"> 3: </span><span class="kwrd">private</span><span class="kwrd">void</span> InternalCalculatePi(<span class="kwrd">int</span> digits,
AsyncStateData</pre><pre><span class="lnum"> 4: </span>asyncData)</pre><pre><span class="lnum"> 5: </span> {</pre><pre><span class="lnum"> 6: </span><span class="kwrd">int</span> completedDigits
= 0;</pre><pre><span class="lnum"> 7: </span><span class="kwrd">for</span> (; !asyncData.canceled
&amp;&amp; pauseEvent.WaitOne(-1, <span class="kwrd">true</span>) &amp;&amp;</pre><pre><span class="lnum"> 8: </span>completedDigits
&lt; digits; completedDigits++)</pre><pre><span class="lnum"> 9: </span> { ... }</pre><pre><span class="lnum"> 10: </span> }</pre><pre><span class="lnum"> 11: </span> </pre><pre><span class="lnum"> 12: </span>...</pre><pre><span class="lnum"> 13: </span>}</pre></div><h4>Step 3: Add a Pause and Continue API
</h4><!-- code formatted by http://manoli.net/csharpformat/ --><div class="csharpcode"><pre><span class="lnum"> 1: </span><span class="kwrd">public
partial</span><span class="kwrd">class</span> Calculator</pre><pre><span class="lnum"> 2: </span>{</pre><pre><span class="lnum"> 3: </span><span class="kwrd">public</span><span class="kwrd">void</span> PauseAsync(<span class="kwrd">object</span> asyncTask)</pre><pre><span class="lnum"> 4: </span> {</pre><pre><span class="lnum"> 5: </span> AsyncStateData
asyncData = asyncTask <span class="kwrd">as</span> AsyncStateData;</pre><pre><span class="lnum"> 6: </span><span class="kwrd">if</span> (asyncData
!= <span class="kwrd">null</span> &amp;&amp; asyncData.running == <span class="kwrd">true</span>)</pre><pre><span class="lnum"> 7: </span> asyncData.pauseEvent.Reset();</pre><pre><span class="lnum"> 8: </span> }</pre><pre><span class="lnum"> 9: </span> </pre><pre><span class="lnum"> 10: </span><span class="kwrd">public</span><span class="kwrd">void</span> ContinueAsync(<span class="kwrd">object</span> asyncTask)</pre><pre><span class="lnum"> 11: </span> {</pre><pre><span class="lnum"> 12: </span> AsyncStateData
asyncData = asyncTask <span class="kwrd">as</span> AsyncStateData;</pre><pre><span class="lnum"> 13: </span><span class="kwrd">if</span> (asyncData
!= <span class="kwrd">null</span> &amp;&amp; asyncData.running == <span class="kwrd">true</span>)</pre><pre><span class="lnum"> 14: </span> asyncData.pauseEvent.Set();</pre><pre><span class="lnum"> 15: </span> }</pre><pre><span class="lnum"> 16: </span>...</pre><pre><span class="lnum"> 17: </span>}</pre></div><br /><br />
There are certainly other ways to do this as well, for example, create a dedicated
Thread object instead of using an Async delegate and then call <b>Suspend</b> on the
thread (and <b>Resume</b> to continue). That can be dangerous if you take locks while
running your async operation so the <b>ManualResetEvent</b> is probably a better solution
from that perspective (since you are blocking in a known location vs. just suspending
the thread arbitrarily and potentially holding onto shared resources. 
</div>
    </content>
  </entry>
  <entry>
    <title>It appears I am bent on world domination.. who would have thought?</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/01/17/ItAppearsIAmBentOnWorldDominationWhoWouldHaveThought.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,2931da3e-6352-42b4-ac57-9f09747030a7.aspx</id>
    <published>2007-01-17T06:02:01.0911015-08:00</published>
    <updated>2007-01-17T06:02:01.0911015-08:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">According to the super villain quiz I am 
<br /><br /><b><font size="6">Lex Luthor</font></b><table><tr><td width="250">
A brilliant businessman on a quest for world domination and the self-proclaimed greatest
criminal mind of our time!<br /><img src="http://www.thesuperheroquiz.com/villain/pics/lex2.jpg" /></td></tr></table><a href="http://www.thesuperheroquiz.com/villain"> Click here to take the Super Villain
Personality Test</a><br /></div>
    </content>
  </entry>
  <entry>
    <title>WPF Data Providers</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2007/01/17/WPFDataProviders.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,5716861f-5560-40c7-b700-483e0cd80116.aspx</id>
    <published>2007-01-17T02:57:58.48-08:00</published>
    <updated>2007-01-17T03:00:41.8389687-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="WPF" label="WPF" scheme="http://www.julmar.com/blog/mark/CategoryView,category,WPF.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">&lt;p&gt;
One of the nifty new features of the WPF platform is the pluggable data providers.&amp;nbsp;
It ships with two out of the box:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;ObjectDataProvider:&lt;/strong&gt;&amp;nbsp;allows you to execute binding expressions
against an object and it's methods&lt;br&gt;
&lt;strong&gt;XmlDataProvider:&lt;/strong&gt; loads an XML data source and makes it available
as a binding source
&lt;/p&gt;
&lt;p&gt;
Both of these derive from the abstract class&amp;nbsp;&lt;strong&gt;System.Data.DataSourceProvider&lt;/strong&gt; which
implements the binding glue (&lt;strong&gt;INotifyPropertyChanged&lt;/strong&gt;) needed for data
binding.&amp;nbsp; A side note here is that you could write your own custom data provider
if you needed to, although if the data is exposed through a .NET object, then the
ObjectDataProvider is probably sufficient.
&lt;/p&gt;
&lt;p&gt;
Using the providers is fairly easy -- let's say we have some XML data that looks like
this:
&lt;/p&gt;
&lt;p&gt;
&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;&lt;font color=blue size=+1&gt;?&lt;/font&gt;xml version&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"1.0"&lt;/font&gt; encoding&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"utf-8"&lt;/font&gt;&lt;font color=blue size=+1&gt;?&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;taxrecords&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;entry name&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"Opal
Harrison"&lt;/font&gt; state&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"AL"&lt;/font&gt; income&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"$51,466.81"&lt;/font&gt; age&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"27"&lt;/font&gt; &lt;font color=blue size=+1&gt;/&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;entry name&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"Eugene
Black"&lt;/font&gt; state&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"FL"&lt;/font&gt; income&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"$13,314.89"&lt;/font&gt; age&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"71"&lt;/font&gt; &lt;font color=blue size=+1&gt;/&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;entry name&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"Opal
Chang"&lt;/font&gt; state&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"NC"&lt;/font&gt; income&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"$225,115.15"&lt;/font&gt; age&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"41"&lt;/font&gt; &lt;font color=blue size=+1&gt;/&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;entry name&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"Gary
Waters"&lt;/font&gt; state&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"WI"&lt;/font&gt; income&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"$151,788.49"&lt;/font&gt; age&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"39"&lt;/font&gt; &lt;font color=blue size=+1&gt;/&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;entry name&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"Xavier
Davis"&lt;/font&gt; state&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"AK"&lt;/font&gt; income&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"$136,344.97"&lt;/font&gt; age&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"66"&lt;/font&gt; &lt;font color=blue size=+1&gt;/&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;entry name&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"Stacy
Harrison"&lt;/font&gt; state&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"TX"&lt;/font&gt; income&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"$122,432.82"&lt;/font&gt; age&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"32"&lt;/font&gt; &lt;font color=blue size=+1&gt;/&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;/taxrecords&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The goal is to put this data into a ListBox - displaying the fields in the following
format:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Name&lt;br&gt;
&lt;/strong&gt;State, Age, Income
&lt;/p&gt;
&lt;p&gt;
We could clearly do all of this from procedural code -- create an XmlReader object,
load the data and render each XmlNode into the listbox.&amp;nbsp; However, this is the
21st century and so we want to avoid coding as much as we can and utilize the underlying
framework support instead!
&lt;/p&gt;
&lt;p&gt;
We can get the data loaded into a collection source through the XmlDataProvider.&amp;nbsp;
This is easily done in XAML:
&lt;/p&gt;
&lt;font color=#0000ff size=5&gt; 
&lt;p&gt;
&lt;font size=3&gt;&amp;lt;&lt;/font&gt;
&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;XmlDataProvider&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Source&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;largeXmlFile.xml&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#ff0000&gt;x:Key&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;xmlData&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;XPath&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;/taxrecords&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=5&gt;&lt;font size=3&gt; /&amp;gt;&lt;/font&gt;&lt;/font&gt;&gt;
&lt;p&gt;
&lt;font color=#0000ff size=5&gt;&lt;font color=#000000 size=2&gt;This will look for the file
"largeXmlFile.xml", create&amp;nbsp;an XmlDocument and load the file into memory.&amp;nbsp;
Notice we supply an XPath expression as part of this to indicate what we'd like the
data provider to hand us as the collection itself.&amp;nbsp; In this case, we want to
see everything under the node "taxrecords" which is the root of the document.&amp;nbsp;
An interesting facet of this provider is that it performs it's work asynchronously
-- you can see this behavior when you load very large XML files.&amp;nbsp; The UI will
come up first, completely empty and then suddenly be populated with data.&amp;nbsp; The
behavior can be adjusted through the &lt;strong&gt;IsAsynchronous&lt;/strong&gt; property of the
data provider.&amp;nbsp; Setting this to &lt;strong&gt;false&lt;/strong&gt; will delay the display
of the UI until the data is fully available.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;Another interesting thing about this class is that we can define
the XML data inline within the XAML document.&amp;nbsp; You do this with the &lt;strong&gt;x:XData&lt;/strong&gt; tag:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;&lt;font color=#0000ff size=3&gt;&amp;lt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;XmlDataProvider&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#ff0000&gt;x:Key&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;xmlData&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;XPath&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;/taxrecords&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=5&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;x:Data&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;taxrecords&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;entry
name&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"Opal Harrison"&lt;/font&gt; state&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"AL"&lt;/font&gt; income&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"$51,466.81"&lt;/font&gt; age&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"27"&lt;/font&gt; &lt;font color=blue size=+1&gt;/&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;/font&gt;&lt;span class=cch1&gt;&lt;font color=gray&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;font color=blue size=+1&gt;&amp;lt;&lt;/font&gt;entry
name&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"Eugene Black"&lt;/font&gt; state&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"FL"&lt;/font&gt; income&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"$13,314.89"&lt;/font&gt; age&lt;font color=blue size=+1&gt;=&lt;/font&gt;&lt;font color=purple&gt;"71"&lt;/font&gt; &lt;font color=blue size=+1&gt;/&lt;/font&gt;&lt;font color=blue size=+1&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt;&lt;font color=#0000ff size=5&gt;&lt;font size=3&gt;&lt;span class=cch1&gt;
&lt;br&gt;
&lt;/span&gt;&lt;font color=blue size=+1&gt;&lt;font color=#808080 size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&amp;lt;&lt;/font&gt;/taxrecords&lt;font color=blue size=+1&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=3&gt;&amp;lt;/x:Data&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font color=#000000&gt;&lt;font color=#0000ff size=3&gt;&lt;font color=#000000&gt;&lt;font color=#0000ff size=3&gt;&amp;lt;/&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;XmlDataProvider&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=5&gt;&lt;font size=3&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&gt;&gt; 
&lt;p&gt;
&lt;font color=#0000ff size=5&gt;&lt;font color=#000000 size=2&gt;The next step is to bind this
data to a ListBox control - this is a normal Data Binding expression:&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;font color=#0000ff size=5&gt;&lt;font color=#0000ff size=5&gt; 
&lt;p&gt;
&lt;font size=3&gt;&amp;lt;&lt;/font&gt;
&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;ListBox&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Name&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;lb1&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Margin&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;10&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;IsSynchronizedWithCurrentItem&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;True&lt;/font&gt;&lt;font color=#000000&gt;" &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#ff0000&gt;ItemsSource&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
Source={StaticResource xmlData, XPath=entry}}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&gt;
&lt;p&gt;
&lt;font color=#0000ff size=5&gt;&lt;font color=#000000 size=2&gt;Notice how we use a new property
of the BindingExpression called &lt;strong&gt;XPath&lt;/strong&gt;.&amp;nbsp; This property allows
you to identify which element(s) you want to load from the XML data source.&amp;nbsp;
It is specific to this data provider and allows for any XPath expression to be supplied.&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=5&gt;&lt;font color=#000000 size=2&gt;This
will succesfully load each of the "/taxrecord/entry" nodes into the ListBox, but the
data itself&amp;nbsp;will show&amp;nbsp;up as a blank line.&amp;nbsp; This, of course, is because
the data is really an XmlNode object which the ListBox has no idea how to display.&amp;nbsp;
To fix this, we supply a DataTemplate to render our data:&amp;nbsp;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;font color=#0000ff size=5&gt;&lt;font color=#0000ff size=5&gt; 
&lt;p dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;font size=3&gt;&amp;lt;&lt;/font&gt;
&lt;/font&gt;&lt;font color=#800000 size=3&gt;ListBox.ItemTemplate&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;DataTemplate&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;FontWeight&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;Bold&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
XPath=@name}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Orientation&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;Horizontal&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
XPath=@state}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;, &lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
XPath=@age}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;, &lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
XPath=@income}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;DataTemplate&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;ListBox.ItemTemplate&lt;/font&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&gt;
&lt;p&gt;
&lt;font color=#0000ff size=5&gt;&lt;font color=#000000 size=2&gt;Again, we use the XPath property
to define what piece of information we are binding to -- attributes of our entry in
this case.&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=5&gt;&lt;font color=#000000 size=2&gt;This
template will give us the format we are looking for:&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;br&gt;
&lt;img src="http://www.julmar.com/blog/mark/content/binary/AsyncDataBind.jpg" border=0&gt;&gt;
&lt;p&gt;
We can add sorting, filtering and grouping using the normal &lt;strong&gt;CollectionViewSource&lt;/strong&gt; support.&amp;nbsp;
Here is a XAML file which will present the above UI complete with sorting by the age
element.&amp;nbsp; Notice how the XPath expression now moves to the CollectionView.&amp;nbsp;
This is because the CollectionViewSource creates a &lt;strong&gt;ListCollectionView &lt;/strong&gt;to
manage the XML nodes because the data provider supports the &lt;strong&gt;IList&lt;/strong&gt; interface.&amp;nbsp;
The binding expression on the listbox is now simply a binding to the collection view.
&lt;/p&gt;
&lt;font color=#0000ff size=5&gt; 
&lt;p&gt;
&lt;font size=3&gt;&amp;lt;&lt;/font&gt;
&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;Window&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Title&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;AsyncDataBind&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Height&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;300&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Width&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;300&lt;/font&gt;&lt;font color=#000000&gt;"&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#ff0000&gt;xmlns&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/font&gt;&lt;font color=#000000&gt;"&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#ff0000&gt;xmlns:cm&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;clr-namespace:System.ComponentModel;assembly=WindowsBase&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; 
&lt;br&gt;
&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#ff0000&gt;xmlns:x&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;/font&gt;&gt;
&lt;p&gt;
&lt;font size=3&gt;&amp;lt;&lt;/font&gt;
&lt;/font&gt;&lt;font color=#800000 size=3&gt;Window.Resources&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;XmlDataProvider&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Source&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;largeXmlFile.xml&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;IsAsynchronous&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;True&lt;/font&gt;&lt;font color=#000000&gt;"&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#ff0000&gt;x:Key&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;xmlData&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;XPath&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;/taxrecords&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;CollectionViewSource&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;x:Key&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;collView&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Source&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
Source={StaticResource xmlData},XPath=entry}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;CollectionViewSource.SortDescriptions&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;cm:SortDescription&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;PropertyName&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;@age&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Direction&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;Ascending&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;CollectionViewSource.SortDescriptions&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;CollectionViewSource&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;
&lt;br&gt;
&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;Window.Resources&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;Grid&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;Grid.RowDefinitions&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;RowDefinition&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Height&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;*&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;RowDefinition&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Height&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;Auto&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;Grid.RowDefinitions&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;/font&gt;&gt;
&lt;p&gt;
&lt;font size=3&gt;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/font&gt;
&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;ListBox&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Name&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;lb1&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Margin&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;10&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;IsSynchronizedWithCurrentItem&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;True&lt;/font&gt;&lt;font color=#000000&gt;"&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#ff0000&gt;ItemsSource&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
Source={StaticResource collView}}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;ListBox.ItemTemplate&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;DataTemplate&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;FontWeight&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;Bold&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
XPath=@name}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Orientation&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;Horizontal&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
XPath=@state}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;, &lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
XPath=@age}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;, &lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
XPath=@income}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;DataTemplate&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;ListBox.ItemTemplate&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;ListBox&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;Button&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Grid.Row&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;1&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Orientation&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;Horizontal&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt;{Binding
ElementName=lb1, Path=Items.Count}&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;TextBlock&lt;/font&gt;&lt;font color=#0000ff&gt; &lt;/font&gt;&lt;font color=#ff0000&gt;Text&lt;/font&gt;&lt;font color=#0000ff&gt;=&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;font color=#0000ff&gt; Items&lt;/font&gt;&lt;font color=#000000&gt;"&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;StackPanel&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;Button&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;
&lt;br&gt;
&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#800000 size=3&gt;Grid&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font size=3&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font color=#800000&gt;Window&lt;/font&gt;&lt;font color=#0000ff&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;
Data binding in WPF is extremely powerful -- I am constantly amazed at how much procedural
code you can dump in favor of markup with creative bindings.&amp;nbsp; In the next post
I'll talk a bit more about asynchronouus bindings outside of the two data providers.
&lt;/p&gt;
&lt;p&gt;
Until then.. 
&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>The Mystery of Concurrent GC</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/12/08/TheMysteryOfConcurrentGC.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,3670d081-0276-48e6-b97d-1b644093b52e.aspx</id>
    <published>2006-12-08T11:25:29.158-08:00</published>
    <updated>2006-12-08T11:57:33.0989253-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Debugging" label="Debugging" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Debugging.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">&lt;p&gt;
&lt;style type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: large;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
There's been a discussion going on within DevelopMentor for a couple weeks regarding
concurrent GC and when it really applies. 
&lt;/p&gt;
&lt;p&gt;
The idea behind the concurrent collector is to do as much of the GC while the UI thread
continues to process UI stuff and then only interrupt the application threads when
memory is being shuffled around and fixups are occurring. This provides for more responsive
UI applications at the expense of slower collections and a higher memory utilization. 
&lt;/p&gt;
&lt;p&gt;
The instructors who are involved with .NET were discussing this because of a discrepancy
in various reliable sources - First, Maoni Stephens, the ultimate authority on all
things .NET GC, stated in her blog entries that concurrent GC was the default behavior
for the workstation version of GC (see &lt;a href="http://blogs.msdn.com/maoni/"&gt;http://blogs.msdn.com/maoni&lt;/a&gt; for
more information on this). 
&lt;/p&gt;
&lt;p&gt;
This is well known, and now well documented in various places. However, Jeff Richter
seems to say in his book "&lt;i&gt;CLR via C#&lt;/i&gt;" that concurrent collections occur &lt;u&gt;only&lt;/u&gt; on
multiprocessor machines. Several other authors back this up (notably Stephen Pratschner
in "&lt;i&gt;Customizing the .NET Framework Common Language Runtime&lt;/i&gt;" and Joe Duffy in
his "&lt;i&gt;Professional .NET Framework 2.0&lt;/i&gt;" book; both are excellent btw). 
&lt;/p&gt;
&lt;p&gt;
So, we had some differing opinions from people in the "know". Our &lt;a href="http://www.develop.com/training/course.aspx?id=344"&gt;Effective
.NET&lt;/a&gt; and &lt;a href="http://www.develop.com/training/course.aspx?id=267"&gt;Essential
.NET&lt;/a&gt; courses were written around Maoni's blogs and so the diagram we presented
showed concurrent collections even on single-processor machines since she didn't explicitly
say it required multiple processors to turn it on. One of the guys noticed this and
said &lt;i&gt;"Wait! That's wrong!"&lt;/i&gt; 
&lt;/p&gt;
&lt;p&gt;
We tried to actually see the concurrent collection in action but it turns out that
it's actually quite difficult to get this to happen because concurrent collections
only occur on &lt;strong&gt;Gen2&lt;/strong&gt;, which for a well-written application shouldn't
occur that often. To add to the complexity, the CLR attempts to optimize this behavior
- just because it &lt;em&gt;can&amp;nbsp;&lt;/em&gt;do the GC&amp;nbsp;concurrently, it might not.&amp;nbsp;
Finally,&amp;nbsp;the thread which is used for this collection is actually created and
destroy as necessary so it doesn't exist most of the time. 
&lt;/p&gt;
&lt;p&gt;
So, to settle the argument, Jason Whittington and I spent some time spelunking into
the CLR this past week to see if we could spot the concurrent collection in action.
With a little WinDBG and some symbols, I think we've put the question to rest once
and for all (at least for us) :-).&amp;nbsp; If you scan the GC symbols in &lt;b&gt;mscorwks.dll&lt;/b&gt;,
you'll find a treasure trove of information; one of the things that caught my eye
was this: 
&lt;/p&gt;
&lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; x mscorwks!WKS::gcheap::*
79f8c5dd mscorwks!WKS::GCHeap::Relocate = &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;no&lt;/span&gt; &lt;span class=attr&gt;type&lt;/span&gt; &lt;span class=attr&gt;information&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; 7a0d09d9
mscorwks!WKS::GCHeap::ValidateObjectMember = &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;no&lt;/span&gt; &lt;span class=attr&gt;type&lt;/span&gt; &lt;span class=attr&gt;information&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; 7a088e2a &lt;b&gt;mscorwks!WKS::GCHeap::IsConcurrentGCInProgress&lt;/b&gt; = &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;no&lt;/span&gt; &lt;span class=attr&gt;type&lt;/span&gt; &lt;span class=attr&gt;information&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt; &lt;/pre&gt;Disassembling
that method showed me that it checks a flag in memory -- &lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; u
mscorwks!WKS::GCHeap::IsConcurrentGCInProgress mscorwks!WKS::GCHeap::IsConcurrentGCInProgress:
7a088e2a a1701b387a mov eax,dword ptr [&lt;b&gt;mscorwks!WKS::gc_heap::settings+0x10&lt;/b&gt; (7a381b70)]
7a088e2f c3 ret &lt;/font&gt;&lt;/pre&gt;I tried putting a breakpoint at the end of the GC process
and dumping that flag out when it was a Gen2 collection (the breakpoint itself stolen
shamelessly from &lt;a href="http://msdn.microsoft.com/msdnmag/issues/06/11/CLRInsideOut/default.aspx"&gt;Maoni's
MSDN article in November 2006&lt;/a&gt;): &lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; bp
mscorwks!WKS::GCHeap::RestartEE "j 
&lt;br&gt;
&lt;/font&gt;&lt;font size=3&gt;(dwo(mscorwks!WKS::GCHeap::GcCondemnedGeneration)==2) 
&lt;br&gt;
'dd mscorwks!WKS::gc_heap::settings+0x10 L1';'g'"&lt;/font&gt;&lt;/pre&gt;But I didn't get much
success seeing it set to "1" - I suspect that it requires a more complex application
than I was using to cause the CLR to decide a concurrent collection is worth the effort.
So I decided this was a dead end and started looking to see where the GC process determines
that concurrent collections are allowed at all. I figured &lt;b&gt;GCHeap::Initialize&lt;/b&gt; sounded
like a good spot -- &lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; u
mscorwks!WKS::GCHeap::Initialize mscorwks!WKS::GCHeap::Initialize: 79ed6924 a14412387a
mov eax,dword ptr [mscorwks!g_pConfig (7a381244)] 79ed6929 8b4058 mov eax,dword ptr
[eax+58h] ..... 79ed697b 51 push ecx 79ed697c e823040000 call mscorwks!WKS::gc_heap::initialize_gc
(79ed6da4) 79ed6981 85c0 test eax,eax &lt;/font&gt;&lt;/pre&gt;Going into that function yielded
what I was looking for -- &lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; u
mscorwks!WKS::gc_heap::initialize_gc mscorwks!WKS::gc_heap::initialize_gc: 79ed6da4
56 push esi 79ed6da5 e80cf1ffff call mscorwks!WKS::write_watch_api_supported (79ed5eb6)
79ed6daa 33f6 xor esi,esi ... 79ed6dc6 c70564ce387a01000000 mov dword ptr [&lt;b&gt;mscorwks!WKS::gc_heap::gc_can_use_concurrent&lt;/b&gt; (7a38ce64)],1 &lt;/font&gt;&lt;/pre&gt;Looking
at that particular memory location, I tried various configurations to make sure I
had the right spot. First, I did a simple console app with no config file and dumped
out the location on a multi-processor box: &lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; dd
mscorwks!WKS::gc_heap::gc_can_use_concurrent L1 7a38ce64 &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;b&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt;00000001&lt;/font&gt;&lt;span class=kwrd&gt;&lt; span&gt;&lt;font size=3&gt;&lt;span class=html&gt;b&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;/font&gt;
&lt;/pre&gt;Next, I set the application up in server mode (also on a multi-processor box): &lt;pre class=csharpcode&gt;&lt;span class=kwrd&gt;&lt;?&lt;/span&gt;&lt;font size=3&gt;&lt;span class=html&gt;&lt;font color=#0000ff&gt;&amp;lt;&lt;/font&gt;xml&lt;/span&gt; &lt;span class=attr&gt;version&lt;/span&gt;&lt;span class=kwrd&gt;="1.0"&lt;/span&gt; &lt;span class=attr&gt;encoding&lt;/span&gt;&lt;span class=kwrd&gt;="utf-8"&lt;/span&gt; ?&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;configuration&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;runtime&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;gcServer&lt;/span&gt; &lt;span class=attr&gt;enabled&lt;/span&gt;&lt;span class=kwrd&gt;="true"&lt;/span&gt; &lt;span class=kwrd&gt;/&amp;gt;&lt;/span&gt; &amp;lt;/&lt;/font&gt;&lt;span class=kwrd&gt;&lt; span&gt;&lt;font size=3&gt;&lt;span class=html&gt;runtime&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;/font&gt;&lt;span class=kwrd&gt;&lt; span&gt;&lt;font size=3&gt;&lt;span class=html&gt;&lt;span class=kwrd&gt;&amp;lt;/&lt;/span&gt;configuration&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; dd mscorwks!WKS::gc_heap::gc_can_use_concurrent
L1 7a38ce64 &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;b&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt;00000000&lt;/font&gt;&lt;span class=kwrd&gt;&lt; span&gt;&lt;font size=3&gt;&lt;span class=html&gt;b&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;/font&gt;
&lt;/pre&gt;Showing that it was now off.. next I tried a VM session which emulates a single
processor: &lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; dd
mscorwks!WKS::gc_heap::gc_can_use_concurrent L1 7a38ce64 &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;b&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt;00000001&lt;/font&gt;&lt;span class=kwrd&gt;&lt; span&gt;&lt;font size=3&gt;&lt;span class=html&gt;b&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
It appears that the CLR &lt;b&gt;is&lt;/b&gt; capable of doing concurrent collections on a single
processor! My final test was to try turning it off altogether via a configuration
switch: 
&lt;/p&gt;
&lt;pre class=csharpcode&gt;&lt;span class=kwrd&gt;&lt;?&lt;/span&gt;&lt;font size=3&gt;&lt;span class=html&gt;&lt;font color=#0000ff&gt;&amp;lt;&lt;/font&gt;xml&lt;/span&gt; &lt;span class=attr&gt;version&lt;/span&gt;&lt;span class=kwrd&gt;="1.0"&lt;/span&gt; &lt;span class=attr&gt;encoding&lt;/span&gt;&lt;span class=kwrd&gt;="utf-8"&lt;/span&gt; ?&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;configuration&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;runtime&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;gcConcurrent&lt;/span&gt; &lt;span class=attr&gt;enabled&lt;/span&gt;&lt;span class=kwrd&gt;="false"&lt;/span&gt; &lt;span class=kwrd&gt;/&amp;gt;&lt;/span&gt; &amp;lt;/&lt;/font&gt;&lt;span class=kwrd&gt;&lt; span&gt;&lt;font size=3&gt;&lt;span class=html&gt;runtime&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;/font&gt;&lt;span class=kwrd&gt;&lt; span&gt;&lt;font size=3&gt;&lt;span class=html&gt;&lt;span class=kwrd&gt;&amp;lt;/&lt;/span&gt;configuration&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;pre class=csharpcode&gt;&lt;font size=3&gt;0:000&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; dd mscorwks!WKS::gc_heap::gc_can_use_concurrent
L1 7a38ce64 &lt;span class=kwrd&gt;&amp;lt;&lt;/span&gt;&lt;span class=html&gt;b&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt;00000000&lt;/font&gt;&lt;span class=kwrd&gt;&lt; span&gt;&lt;font size=3&gt;&lt;span class=html&gt;b&lt;/span&gt;&lt;span class=kwrd&gt;&amp;gt;&lt;/span&gt; &lt;/font&gt;
&lt;/pre&gt;
&lt;br&gt;
As a final note on this, Jason asked Maoni directly and her response was that concurrent
GC does &lt;strong&gt;not&lt;/strong&gt; depend on the number of processors - just as we are seeing
above. So, apparently several primary sources are actually incorrect on this behavior.
It just goes to show how complex the overall GC process really is -- simple in concept,
but boy there are a lot of moving parts! &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;</content>
  </entry>
  <entry>
    <title>New Version of ATAPI.NET available</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/12/08/NewVersionOfATAPINETAvailable.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,7bf0a572-660a-4134-95ba-bee2ae82988e.aspx</id>
    <published>2006-12-08T10:11:22.514-08:00</published>
    <updated>2006-12-08T11:27:59.6884002-08:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Tapi" label="Tapi" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Tapi.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">I've updated ATAPI.NET in the samples page <a href="http://www.julmar.com/samples/atapinet.zip">http://www.julmar.com/samples/atapinet.zip</a> with
several fixes and support for conferences, full transfers and phone support. I think
almost everything is now wrapped - if you find any missing functions that you want/need
ping me and I'll see what I can do.
</div>
    </content>
  </entry>
  <entry>
    <title>Utilizing TAPI from an ASP.NET application</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/11/14/UtilizingTAPIFromAnASPNETApplication.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,0535ed97-f590-438e-9b99-1ddee1e8237a.aspx</id>
    <published>2006-11-14T08:01:25.0273367-08:00</published>
    <updated>2006-11-14T08:01:25.0273367-08:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: large;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
I've gotten several email requests about using ATAPI from ASP.NET -- people have had
trouble getting it to function properly so I figured I'd post an example of how it
works. First, I'd recommend using ATAPI and <b>not</b> ITAPI3 - only because the latter
pulls in COM objects which always makes things <i>much</i> more complex. The key thing
to remember is where to hook up your events. Don't hook events inside your ASP.NET
page-derived classes - that will keep the pages alive and cause memory leaks. Instead,
use static methods (as presented here) or hook the events in <b>global.asax</b> or
some other global shared class. I created a simple dialer in ASP.NET 2.0 through the
following steps: 
<ol><li>
Create an ASP.NET website 
</li><li>
Add a reference to ATAPI.DLL 
</li><li>
Add a Global Application Class (global.asax) 
</li><li>
Create the <b>TapiManager</b> class in your global application class 
</li><li>
Utilize the TapiManager from your pages 
</li></ol>
As an example, here is my <b>global.asax</b> class - I chose to store the <b>TapiManager</b> class
into the Application property bag, but you could just make it a global as well if
you prefer that approach. <pre class="csharpcode"><span class="kwrd">void</span> Application_Start(<span class="kwrd">object</span> sender,
EventArgs e) { <span class="rem">// Code that runs on application startup</span> JulMar.Atapi.TapiManager
tapiManager = <span class="kwrd">new</span> JulMar.Atapi.TapiManager(<span class="str">"TestWebApp"</span>); <span class="kwrd">if</span> (!tapiManager.Initialize())
System.Diagnostics.EventLog.WriteEntry(<span class="str">"Application"</span>, <span class="str">"TapiManager
failed to initialize"</span>); <span class="kwrd">else</span> { Application[<span class="str">"tapi"</span>]
= tapiManager; } } <span class="kwrd">void</span> Application_End(<span class="kwrd">object</span> sender,
EventArgs e) { <span class="rem">// Code that runs on application shutdown</span> JulMar.Atapi.TapiManager
tapiManager = (JulMar.Atapi.TapiManager)Application[<span class="str">"tapi"</span>]; <span class="kwrd">if</span> (tapiManager
!= <span class="kwrd">null</span>) tapiManager.Shutdown(); } </pre>
Next, I added some markup to my <b>default.aspx</b> file to give me some server-side
controls to manipulate TAPI with: <pre class="csharpcode"><span class="asp">&lt;%@
Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
%&gt;</span><span class="kwrd">&lt;</span><span class="html">html</span><span class="attr">xmlns</span><span class="kwrd">="http://www.w3.org/1999/xhtml"</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">head</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>Untitled
Page<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">form</span><span class="attr">id</span><span class="kwrd">="form1"</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">h1</span><span class="kwrd">&gt;</span>Sample
TAPI Dialer<span class="kwrd">&lt;/</span><span class="html">h1</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">asp:Label</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="attr">Text</span><span class="kwrd">="Select
Line:"</span><span class="kwrd">/&gt;</span><span class="attr">&amp;nbsp;</span><span class="attr">&amp;nbsp;</span><span class="kwrd">&lt;</span><span class="html">asp:DropDownList</span><span class="attr">ID</span><span class="kwrd">="lineList"</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;</span><span class="html">br</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;</span><span class="html">asp:Label</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="attr">Text</span><span class="kwrd">="Number
to dial:"</span><span class="kwrd">/&gt;</span><span class="attr">&amp;nbsp;</span><span class="attr">&amp;nbsp;</span><span class="kwrd">&lt;</span><span class="html">asp:TextBox</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="attr">Width</span><span class="kwrd">="100"</span><span class="attr">ID</span><span class="kwrd">="number"</span><span class="kwrd">/&gt;</span><span class="attr">&amp;nbsp;</span><span class="attr">&amp;nbsp;</span><span class="kwrd">&lt;</span><span class="html">asp:Button</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="attr">ID</span><span class="kwrd">="dial"</span><span class="attr">OnClick</span><span class="kwrd">="DialNumber"</span><span class="attr">Text</span><span class="kwrd">="
Dial "</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;</span><span class="html">asp:Button</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="attr">ID</span><span class="kwrd">="refresh"</span><span class="attr">Text</span><span class="kwrd">="
Refresh "</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;</span><span class="html">br</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;</span><span class="html">br</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;</span><span class="html">asp:ListBox</span><span class="attr">runat</span><span class="kwrd">="server"</span><span class="attr">ID</span><span class="kwrd">="events"</span><span class="attr">Width</span><span class="kwrd">="400"</span><span class="attr">Height</span><span class="kwrd">="300"</span><span class="attr">EnableViewState</span><span class="kwrd">="false"</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
Finally, I added the code-behind to actually do the dialing. As part of this, I hook
the appropriate events using static methods - not instance methods so I don't keep
the page alive longer than a single request. I also store all my TAPI events in a
global string collection so that when the page is refreshed, I can display the current
set of events. <pre class="csharpcode"><span class="kwrd">using</span> System; <span class="kwrd">using</span> System.Configuration; <span class="kwrd">using</span> System.Web; <span class="kwrd">using</span> System.Web.Security; <span class="kwrd">using</span> System.Web.UI; <span class="kwrd">using</span> System.Web.UI.WebControls; <span class="kwrd">using</span> System.Collections.Specialized; <span class="kwrd">using</span> JulMar.Atapi; 
<br /><span class="kwrd">public</span><span class="kwrd">partial</span><span class="kwrd">class</span> _Default
: System.Web.UI.Page { <span class="kwrd">static</span> StringCollection data = <span class="kwrd">new</span> StringCollection(); 
<br /><span class="kwrd">protected</span><span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender,
EventArgs e) { TapiManager tapiManager = (TapiManager)Application[<span class="str">"tapi"</span>]; <span class="kwrd">if</span> (!Page.IsPostBack)
{ <span class="kwrd">if</span> (tapiManager != <span class="kwrd">null</span>) lineList.DataSource
= tapiManager.Lines; } 
<br />
events.DataSource = data; DataBind(); } 
<br /><span class="kwrd">protected</span><span class="kwrd">void</span> DialNumber(<span class="kwrd">object</span> sender,
EventArgs e) { TapiManager tapiManager = (TapiManager)Application[<span class="str">"tapi"</span>]; <span class="kwrd">string</span> lineName
= lineList.SelectedValue; 
<br />
TapiLine line = tapiManager.GetLineByName(lineName, <span class="kwrd">true</span>); <span class="kwrd">if</span> (line
!= <span class="kwrd">null</span>) { <span class="kwrd">if</span> (!line.IsOpen) { <span class="kwrd">try</span> {
line.Open(MediaModes.InteractiveVoice); } <span class="kwrd">catch</span> { line.Open(MediaModes.DataModem);
} 
<br />
line.NewCall += <span class="kwrd">new</span> EventHandler&lt;NewCallEventArgs&gt;(line_NewCall);
line.CallInfoChanged += <span class="kwrd">new</span> EventHandler&lt;CallInfoChangeEventArgs&gt;(line_CallInfoChanged);
line.CallStateChanged += <span class="kwrd">new</span> EventHandler&lt;CallStateEventArgs&gt;(line_CallStateChanged);
} 
<br /><span class="kwrd">if</span> (number.Text.Length &gt; 0) { TapiCall call = line.MakeCall(number.Text);
data.Add(<span class="kwrd">string</span>.Format(<span class="str">"Created call:
{0}"</span>, call)); } } } 
<br /><span class="kwrd">static</span><span class="kwrd">void</span> line_NewCall(<span class="kwrd">object</span> sender,
NewCallEventArgs e) { data.Add(<span class="kwrd">string</span>.Format(<span class="str">"New
call: {0}, {1}"</span>, e.Call, e.Privilege)); } 
<br /><span class="kwrd">static</span><span class="kwrd">void</span> line_CallStateChanged(<span class="kwrd">object</span> sender,
CallStateEventArgs e) { data.Add(<span class="kwrd">string</span>.Format(<span class="str">"CallState:
{0} is now {1}"</span>, e.Call.ToString(), e.CallState)); } 
<br /><span class="kwrd">static</span><span class="kwrd">void</span> line_CallInfoChanged(<span class="kwrd">object</span> sender,
CallInfoChangeEventArgs e) { data.Add(<span class="kwrd">string</span>.Format(<span class="str">"CallInfo:
{0} {1}"</span>, e.Call.ToString(), e.Change)); } } </pre>
This deploys and executes properly on Windows 2003 Server and IIS6. I did not try
it under XP or IIS5, although I see no reason why it would not work as shown. Hopefully
this will help someone out there trying to use TAPI from within a website!
</div>
    </content>
  </entry>
  <entry>
    <title>SOS: finding the method bound to an EventHandler&lt;T&gt; with WinDbg.</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/09/01/SOSFindingTheMethodBoundToAnEventHandlerWithWinDbg.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,643649fc-0467-4f0d-9a95-323ed7ce4298.aspx</id>
    <published>2006-09-01T11:18:41.341-07:00</published>
    <updated>2006-09-01T11:20:15.3422461-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="Debugging" label="Debugging" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Debugging.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="html">I was preparing a sample memory leak application for an Advanced C# class at Microsoft this past week and debugging through it with SOS.DLL ("Son of Strike").  My prepared application was an ASP.NET application that would leak memory by holding references to the page objects after they had completed their work.  I did this by having the page hook up an event handler to a global event and then never remove the handler.
&lt;br /&gt;
&lt;br /&gt;
This, of course, is bad form because the System.Web.UI.Page object is intended to
be a transient object - it goes away at the end of the request - in production code,
I would really bind the event to a handler in &lt;b&gt;global.asax&lt;/b&gt; instead. But as I
said, this was a sample. 
&lt;br /&gt;
&lt;br /&gt;
So, I was debugging through it prior to the class just to make sure it exhibited the
behavior I was looking for. I run the web page a few times, noted my working set going
up and never coming back down. Next, I used &lt;b&gt;ADPLUS.VBS&lt;/b&gt; to take a hang dump
of the process. I then loaded this dump up into WinDBG and started poking around.
First, I looked at the heap and sure enough I saw a bunch of page objects: 
&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: medium;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;
0:000&gt; .load sos
0:000&gt; !DumpHeap -stat
total 36955 objects
Statistics:
      MT    Count    TotalSize Class Name
7b4ecd7c        1           12 System.Windows.Forms.ButtonInternal.ButtonPopupAdapter
7b481f00        1           12 System.Windows.Forms.LinkLabel+LinkComparer
7b475ca8        1           12 System.Windows.Forms.FormCollection
7b474f8c        1           12 System.Windows.Forms.Layout.DefaultLayout
7b4749e0        1           12 System.Windows.Forms.ClientUtils+WeakRefCollection
7b473ca8        1           12 System.Windows.Forms.Layout.ArrangedElementCollection
7a755834        1           12 System.Diagnostics.PerformanceCounterCategoryType
7a753394        1           12 System.Diagnostics.TraceOptions
7a71a710        1           12 System.Net.TimeoutValidator
.......
00166030      891       169744      Free
054d24d4     3128       187680 System.Web.UI.LiteralControl
&lt;b&gt;0548cbd4
519 197220 ASP.default_aspx &lt;/b&gt;791242ec 1545 297960 System.Collections.Hashtable+bucket[]
79124670 1185 1090500 System.Char[] 79124228 11961 1279380 System.Object[] 790fa3e0
19149 1561392 System.String Total 110069 objects &lt;/pre&gt;
So, next I used &lt;b&gt;DumpHeap&lt;/b&gt; to just look at this specific type by giving it a
metadata token: &lt;pre class="csharpcode"&gt;
0:000&gt; !DumpHeap -mt 0548cbd4        
 Address       MT     Size
.....     
01854ff0 0548cbd4      380     
01860130 0548cbd4      380     
0186b2b4 0548cbd4      380     
018773f8 0548cbd4      380     
01882538 0548cbd4      380     
0188d6bc 0548cbd4      380     
01898840 0548cbd4      380     
018a39c4 0548cbd4      380     
018aeb48 0548cbd4      380     
total 519 objects
Statistics:
      MT    Count    TotalSize Class Name
0548cbd4      519       197220 ASP.default_aspx
Total 519 objects
&lt;/pre&gt;
I then used the &lt;i&gt;very&lt;/i&gt; cool &lt;b&gt;GCRoot&lt;/b&gt; command to determine why a page instance
was still rooted and therefore not collectable. 
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="border:thin solid;border-color:black;background-color:lightgrey;padding-top:10px;padding-left:10px;padding-right:10px;padding-bottom:10px;"&gt;
&lt;b&gt;Note: &lt;/b&gt;it appears that GCRoot doesn't work well inside VS.NET 2005 - apparently
the SOS debugging extension is using some debugger API which isn't fully supported
in VS.NET, so you need to familiarize yourself with WinDBG to do this. 
&lt;/div&gt;
 /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;
0:000&gt; !gcroot 018aeb48 
Note: Roots found on stacks may be false positives. Run "!help gcroot" for
more info.
Scan Thread 0 OSTHread 3a8
Scan Thread 2 OSTHread e8
Scan Thread 3 OSTHread 1a8
Scan Thread 6 OSTHread 7d4
Scan Thread 7 OSTHread 2b4
Scan Thread 8 OSTHread fdc
Scan Thread 9 OSTHread eac
DOMAIN(001E5E08):HANDLE(Pinned):12312f0:Root:0226c498(System.Object[])-&gt;
018af940(System.EventHandler)-&gt;
0186c0ac(System.Object[])-&gt;
018af920(System.EventHandler)-&gt;
018aeb48(ASP.default_aspx)
&lt;/pre&gt;
With this output, I can tell that my default_aspx object is being kept alive through
an EventHandler as I expected. The interesting thing about this output is I cannot
tell which event handler is keeping it alive - i.e. there is nothing in this root
list that points to a specific object holding it other than a object[]. That essentially
means this is a static event and there isn't an actual object around on the heap for
it. This just makes the debugging exercise more interesting - after all if it were
an instance event then I would see the class name at the top of the root list and
we could stop right here. 
&lt;br /&gt;
&lt;br /&gt;
So, my next step is to dump the event handler to try to identify what method it is
wrapping - I could then search the code for this method and find out where it is being
bound. I dump out the &lt;b&gt;EventHandler&lt;/b&gt; object: &lt;pre class="csharpcode"&gt;
0:000&gt; !do 018af920
Name: System.EventHandler
MethodTable: 7910d61c
EEClass: 790c3a7c
Size: 32(0x20) bytes
 (C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
Fields:
      MT    Field   Offset                 Type VT     Attr    Value Name
790f9c18  40000f9        4        System.Object  0 instance 018aeb48 _target
79109208  40000fa        8 ...ection.MethodBase  0 instance 00000000 _methodBase
790fe160  40000fb        c        System.IntPtr  0 instance 88962888 _methodPtr
790fe160  40000fc       10        System.IntPtr  0 instance        0 _methodPtrAux
790f9c18  4000106       14        System.Object  0 instance 00000000 _invocationList
790fe160  4000107       18        System.IntPtr  0 instance        0 _invocationCount
&lt;/pre&gt;
From this I get the internals of the EventHandler object. It gives me some specific
information: 
&lt;ul&gt;
&lt;li&gt;
&lt;b&gt;_target&lt;/b&gt; is the object the delegate is holding onto - my default_aspx in this
case. The value &lt;i&gt;better&lt;/i&gt; match up with my original object! 
&lt;li&gt;
&lt;b&gt;_methodBase&lt;/b&gt; is used for dynamic code and is null here. 
&lt;li&gt;
&lt;b&gt;_methodPtr&lt;/b&gt; is the method associated with the instance, or possibly a dynamically
generated thunk for static methods. This is what I'm interested in. 
&lt;li&gt;
&lt;b&gt;_methodPtrAux&lt;/b&gt; is used for static methods; this holds the method descriptor
and the &lt;b&gt;_methodPtr&lt;/b&gt; is a dynamically generated block of code to remove the &lt;b&gt;this&lt;/b&gt; reference.
Noting that this is null, I can infer that this is an instance method bound to the
delegate. 
&lt;li&gt;
&lt;b&gt;_invocationList&lt;/b&gt; and &lt;b&gt;_invocationCount&lt;/b&gt; are used for Multicast Delegates
-- these are both zero indicating that this is a single delegate and there is no chain
to follow. 
&lt;/ul&gt;
&lt;br /&gt;
My next step is to try to get a valid method name from the &lt;b&gt;_methodPtr&lt;/b&gt; so I
convert that to hex and pass it into IP2MD. &lt;pre class="csharpcode"&gt;
0:000&gt; !ip2md 0n88962888 
Failed to request MethodData, not in JIT code range
&lt;/pre&gt;
This is a pretty common error and simply means that the method may not have been JITted
yet, or may be a dynamic block of code which never went through the JIT compiler.
In .NET 1.1 we could start dumping method descriptors and trying to match up the address
(DumpClass -md) for this class and it's base class. 
&lt;br /&gt;
&lt;br /&gt;
However, under .NET 2.0 this rarely works anymore - the address doesn't appear to
ever match up to a valid descriptor. However, it clearly is part of the managed heap
due to it's address. So, failing to locate this address, I tried disassembling the
code: &lt;pre class="csharpcode"&gt;
0:000&gt; !u 0n88962888 
Unmanaged code
054d7748 e862289b74      call    mscorwks!LogHelp_TerminateOnAssert+0x3f5f (79e89faf)
054d774d 5e              pop     esi
054d774e cc              int     3
054d774f cc              int     3
054d7750 38c8            cmp     al,cl
054d7752 48              dec     eax
054d7753 05a0774d05      add     eax,54D77A0h
054d7758 0100            add     dword ptr [eax],eax
054d775a 0011            add     byte ptr [ecx],dl
054d775c 0000            add     byte ptr [eax],al
&lt;/pre&gt;
Humph. This doesn't even look like valid code to me.. this looks like random data,
so I dumped it out: &lt;pre class="csharpcode"&gt;
0:000&gt; dd 0n88962888 
054d7748  9b2862e8 cccc5e74&lt;b&gt; 0548c838
054d77a0&lt;/b&gt; 054d7758 11000001 90000000 054d77a0 11000002 054d7768 90000004 00000000
054d77a0 00000000 &lt;/pre&gt;
The third and fourth DWORD look interesting because they appear to fall in the managed
heap as well -- so I began to dump them out trying to figure out what they were. I
found that the first value is a method descriptor: &lt;pre class="csharpcode"&gt;
0:000&gt; !dumpmd 0548c838 
Method Name: _Default.OnDatabaseHasChanged(System.Object, System.EventArgs)
Class: 054ab574
MethodTable: 0548c86c
mdToken: 06000004
Module: 0548c35c
IsJitted: no
m_CodeOrIL: ffffffff
&lt;/pre&gt;
It is the real method bound to the delegate instance. The other DWORD appears to be
an metadata reference to the event owner itself: &lt;pre class="csharpcode"&gt;
0:000&gt; !dumpmt 054d77a0
EEClass: 0551940c
Module: 048ac9ec
Name: DatabaseMonitor
mdToken: 02000002  (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\leakypage\2a399ab5\b1e04c63\App_Code.onwg1zqj.dll)
BaseSize: 0xc
ComponentSize: 0x0
Number of IFaces in IFaceMap: 0
Slots in VTable: 8
&lt;/pre&gt;
From here I can see the module that this code is defined in (the dynamically generated
App_Code directory) and the name (&lt;b&gt;DatabaseMonitor&lt;/b&gt;). This gives me enough information
to stop here and begin looking at the code itself - specifically where default.aspx
binds it's OnDatabaseHasChanged method to the DatabaseMonitor static class defined
somewhere in the App_Code directory. If I didn't have the source code available, I
could locate the module and then save it out to a file through the &lt;b&gt;savemodule&lt;/b&gt; command: &lt;pre class="csharpcode"&gt;
0:000&gt; lm m App_Code_onwg1zqj
start    end        module name
04de0000 04de8000   App_Code_onwg1zqj C (no symbols)           
0:000&gt; !savemodule 04de0000 c:\appcode.dll
3 sections in file
section 0 - VA=2000, VASize=504, FileAddr=200, FileSize=600
section 1 - VA=4000, VASize=2c8, FileAddr=800, FileSize=400
section 2 - VA=6000, VASize=c, FileAddr=c00, FileSize=200
&lt;/pre&gt;
I could then ILDasm or Reflector the generated assembly and look for my bug from that. 
&lt;br /&gt;
&lt;br /&gt;
I love SOS and WinDBG.. if only they could match up managed source code to the image I'd abandon VS.NET as a debugger altogether..
</content>
  </entry>
  <entry>
    <title>Living in an OS X world</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/09/01/LivingInAnOSXWorld.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,8cacb269-767b-4e53-8564-70e6b2dd1c40.aspx</id>
    <published>2006-09-01T09:15:50.148-07:00</published>
    <updated>2006-09-01T09:19:35.5571773-07:00</updated>
    <category term="Real World" label="Real World" scheme="http://www.julmar.com/blog/mark/CategoryView,category,RealWorld.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">A DM colleague of mine, <a href="http://nielsb.wordpress.com/2006/08/29/apps-for-a-windows-user-on-osx/">Neils
Berglund</a> noted his required applications under OS X and asked for feedback on
what everyone else is using (assuming you are on OS X anyway). 
<br /><br />
The original question was what RSS reader are you using.. my preference is <a href="http://www.newsgator.com/NetNewsWire.aspx">NetNewsWire</a> as
I was used to the Newsgator line of products when using Windows all the time so it
made an easy transition for me. I also use <b>MarsEdit</b> to update posts on this
blog -- it's not WYSIWYG but it keeps my HTML skills (if I ever had any) from drying
up. 
<br /><br />
So, adding to Neils list, I also use -- 
<ul><li><u>Final Cut Express</u> - for editing movies, I found iMovie to be too limiting. 
</li><li><u>CHMOX</u> - to open and read .CHM (Windows Help) files. 
</li><li><u>DivX codecs</u> - to play my 300+ .divx movies. 
</li><li><u>Smultron</u> - a decent, quick color-coded text editor 
</li><li><u>Virtue Desktops</u> - an awesome window manager. 
</li><li><u>Remote Buddy</u> - allows the Apple Remote to be used to control other applications
such as Power Point. 
</li><li><u>Microsoft Office</u> - I just can't live without Word/Excel/Power Point. I know
Apple has iWork, but it just isn't quite the same. 
</li><li><u>Flip4Mac</u> - Codecs for .WMV (Windows Media), essential in a 99.999% Windows
dominated world. 
</li><li><u>Coverflow</u> - this isn't critical, but it's a fun app to show off - it let's
you view your music through the album covers in a cool, flip-3d style fashion. 
</li></ul><br />
I'm also trying out a .mac membership for backup purposes. Not sure I'll stay with
that, but it is automatic and seems to work even when I travel. 
<br /><br />
So, what things do <b>you</b> think are necessary applications under OS X? 
</div>
    </content>
  </entry>
  <entry>
    <title>Creating TFS Work Items programatically</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/08/28/CreatingTFSWorkItemsProgramatically.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,ede5f8e9-7d52-413b-8553-99faa147e2bd.aspx</id>
    <published>2006-08-28T04:45:13.106-07:00</published>
    <updated>2006-09-01T09:20:02.9012773-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Enterprise" label="Enterprise" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Enterprise.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">One question I get a lot when teaching the
VSTS course is "How can I move tasks or bugs from our existing system into TFS?" 
<br /><br />
The answer is quite simple: write a program that utilizes the Team Systems Object
Model. 
<br /><br />
The Object Model is documented partially in the VSIP SDK -- if you intend to work
with it, I highly recommend you go and grab that SDK from Microsoft, but here is a
simple example of creating a bug in the first Team Project available on the server
named <b>TFSServer</b> (you can imagine the rest which uses ADO.NET to pull your existing
tracking tickets from whatever system you have): 
<br /><br /><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: large;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><div class="csharpcode"><pre><span class="lnum"> 1: </span><span class="kwrd">using</span> System;</pre><pre><span class="lnum"> 2: </span><span class="kwrd">using</span> System.Collections;</pre><pre><span class="lnum"> 3: </span><span class="kwrd">using</span> System.Collections.Generic;</pre><pre><span class="lnum"> 4: </span><span class="kwrd">using</span> System.Text;</pre><pre><span class="lnum"> 5: </span><span class="kwrd">using</span> Microsoft.TeamFoundation.Client;</pre><pre><span class="lnum"> 6: </span><span class="kwrd">using</span> Microsoft.TeamFoundation.WorkItemTracking.Client;</pre><pre><span class="lnum"> 7: </span></pre><pre><span class="lnum"> 8: </span><span class="kwrd">namespace</span> EnterWorkItems</pre><pre><span class="lnum"> 9: </span>{</pre><pre><span class="lnum"> 10: </span><span class="kwrd">class</span> Program</pre><pre><span class="lnum"> 11: </span> {</pre><pre><span class="lnum"> 12: </span><span class="kwrd">static</span><span class="kwrd">void</span> Main(<span class="kwrd">string</span>[]
args)</pre><pre><span class="lnum"> 13: </span> {</pre><pre><span class="lnum"> 14: </span> TeamFoundationServer tfs = <span class="kwrd">new</span> TeamFoundationServer(<span class="str">"TFSServer"</span>);</pre><pre><span class="lnum"> 15: </span> WorkItemStore wis = (WorkItemStore) tfs.GetService(<span class="kwrd">typeof</span>(WorkItemStore));</pre><pre><span class="lnum"> 16: </span></pre><pre><span class="lnum"> 17: </span> Project teamProject = wis.Projects[0];</pre><pre><span class="lnum"> 18: </span><span class="kwrd">foreach</span> (WorkItemType
wit <span class="kwrd">in</span> teamProject.WorkItemTypes)</pre><pre><span class="lnum"> 19: </span> Console.WriteLine(wit.Name);</pre><pre><span class="lnum"> 20: </span></pre><pre><span class="lnum"> 21: </span> WorkItemCollection wic = wis.Query(<span class="str">"Project='Test'
AND Type='Bug'"</span>);</pre><pre><span class="lnum"> 22: </span><span class="kwrd">foreach</span> (WorkItem wiEntry <span class="kwrd">in</span> wic)</pre><pre><span class="lnum"> 23: </span> {</pre><pre><span class="lnum"> 24: </span> }</pre><pre><span class="lnum"> 25: </span></pre><pre><span class="lnum"> 26: </span> WorkItemType witBug = teamProject.WorkItemTypes[<span class="str">"Bug"</span>];</pre><pre><span class="lnum"> 27: </span><span class="kwrd">if</span> (witBug != <span class="kwrd">null</span>)</pre><pre><span class="lnum"> 28: </span> {</pre><pre><span class="lnum"> 29: </span> Console.WriteLine(<span class="str">"Adding new
bug to Team Project {0}"</span>, teamProject.Name);</pre><pre><span class="lnum"> 30: </span></pre><pre><span class="lnum"> 31: </span> WorkItem wi = <span class="kwrd">new</span> WorkItem(witBug);</pre><pre><span class="lnum"> 32: </span> wi.Description = <span class="str">"This is a
sample bug which was added through the object model"</span>;</pre><pre><span class="lnum"> 33: </span> wi.Reason = <span class="str">"New"</span>;</pre><pre><span class="lnum"> 34: </span> wi.Title = <span class="str">"You have Bugs!
[Ding]"</span>;</pre><pre><span class="lnum"> 35: </span></pre><pre><span class="lnum"> 36: </span> wi.Save();</pre><pre><span class="lnum"> 37: </span> Console.WriteLine(<span class="str">"Added Work
Item # {0} created by {1}"</span>, wi.Id, wi.CreatedBy);</pre><pre><span class="lnum"> 38: </span> }</pre><pre><span class="lnum"> 39: </span> }</pre><pre><span class="lnum"> 40: </span> }</pre><pre><span class="lnum"> 41: </span>}</pre></div><br /><br />
Breaking this down a bit, the first main piece of code is the connection to the Team
Server itself. This is accomplished on line 14 by creating a new <b>TeamFoundationServer</b> object.
An optional constructor allows for credentials to be provided, otherwise it logs on
as the current principle. 
<br /><br />
Next, we retrieve the <b>WorkItemStore</b>. Almost everything in the object model
is accessed through the <b>IServiceProvider</b> interface which provides a <b>GetService</b> method
where you pass in the <b>System.Type</b> object you want to work with. This is a nice
versioning technique that is utilized in many other Microsoft technologies as well. 
<br /><br />
With the WorkItemStore, you can then query work item type definitions, one of which
is necessary to create a <b>WorkItem</b>. You fill in the details for the Work Item
you want to create and call the <b>Save</b> method (line 36) to commit the changes
to the TFS store. The WorkItem id will then be valid and could be added to the existing
bug tracking system as a forward link to the new information if you wanted.
</div>
    </content>
  </entry>
  <entry>
    <title>Moving Work Items from one Team Project to another</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/07/17/MovingWorkItemsFromOneTeamProjectToAnother.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,b883c0c6-1c9e-4d9e-95a0-82c7465b979a.aspx</id>
    <published>2006-07-17T11:05:53.208-07:00</published>
    <updated>2006-07-17T11:07:58.3964588-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Enterprise" label="Enterprise" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Enterprise.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">I was having lunch with an associate a while
back and he mentioned a need to move a work item from one team project to another.
While there isn't any direct support for this from the Team Explorer interface, I
figured it couldn't be too hard to manipulate the underlying database and achieve
the results - it's just SQL Server right? I hadn't actually <b>looked</b> at the schema
mind you, I'm an optimist.<br /><br />
It wasn't quite as simple as I thought - it felt like the database had been designed
by the security group and intentionally obscured for privacy. The TFS database is
fairly generic (so that it can add arbitrary items into the schema for custom project
types) and has been somewhat secured to protect the code itself - the stored procedures
are encrypted and SQL Profiler doesn't give much information on what's happening.<br /><br />
So, I spent a week or so looking at the schema for the Work Item system and a lot
of trial and error. End result is that I got a simple application to move work items
around. This application does a couple of other things as well - lists projects, active
web services, etc. I was mostly playing with the schema and trying to figure things
out. It's just a console application but it does the job.<br /><br /><a href="http://www.julmar.com/samples/TfsCmd.zip">Here's</a> the code, <b><u>use
at your own risk (a.k.a. if it screws up your system, I can't help you)</u></b>. The
source for the simple test project is included so you can see what was done and incorporate
it into your own code base if you like.<br /><br />
The program is fairly easy to use - a binary is included with the release. Issuing
the command with no parameters generates a simple "Help" page --<br /><br /><font face="Courier New"> C:\Work\TfsCmd&gt;<b>tfscmd</b><br />
TfsCmd [command] [/t tfsserver] [/u user] [/p password] [params]<br />
ListProjects - Lists the active projects on the TF server.<br />
TfsCmd ListProjects<br />
ListServices - Displays the web services exposed by the TF server.<br />
TfsCmd ListWebServices<br />
WQL - Execute a WorkItem Query.<br />
TfsCmd Wql [query]<br />
MoveWorkItem - Moves a work item from one Team Project to another<br />
TfsCmd MoveWorkItem [id] [ProjectName]<br /></font><br />
Executing a command will use your logged on user/password (domain credentials) unless
you supply a <b>/u</b> and <b>/p</b> parameter. For example, running the <b>ListProjects</b> command
generates something like:<br /><br /><font face="Courier New"> C:\Work\TfsCmd&gt;<b>tfscmd ListProjects</b><br />
Project Name: Test<br />
Status: WellFormed<br />
Guid: 8c5b175b-b0ef-46bb-9a9e-dde05bb145ac<br />
Process Template: MSF for Agile Software Development - v4.0<br />
Defined Properties: MSPROJ<br /></font><br />
Listing the web services just hits the underlying database to get the information: 
<br /><br /><font face="Courier New"> C:\Work\TfsCmd&gt;<b>tfscmd ListServices</b><br />
BuildStoreService = http://(local):8080/Build/v1.0/BuildStore.asmx<br />
BuildControllerService = http://(local):8080/Build/v1.0/BuildController.<br />
IBISEnablement = http://(local):8080/Build/v1.0/Integration.asmx<br />
LinkingProviderService = http://(local):8080/Build/v1.0/Integration.asmx<br />
IProjectMaintenance = http://(local):8080/Build/v1.0/Integration.asmx<br />
PublishTestResultsBuildService = http://(local):8080/Build/v1.0/PublishT tsBuildService.asmx<br /><br /></font> Moving work items is fairly easy - just provide the work item id (the numeric
identifier) and the new project name - this must match an existing project in your
TFS system. The tool will attempt to match up the iteration to a value in the new
project - if it cannot, it will default to the first iteration available.<br /><br /><br /><font face="Courier New"> C:\Work\TfsCmd&gt;<b>tfscmd MoveWorkItem 1 "Mark's New Project"</b><br />
Work Item #1: "Create Project Definition" is currently located in project "Test Project
(Iteration 0)"<br />
Moving work item to "Mark's New Project (Iteration 0)"<br /><br /></font> If you have the TFS client open, then you should shut it down and reopen it
before modifying the moved work item - the client appears to cache bits of information
and I had some issues with moved items if I didn't clear the cache by closing the
work item window and reopening it.<br /><br />
Have fun! 
</div>
    </content>
  </entry>
  <entry>
    <title>You can be just like the government and record telephone conversations.. with TAPI 3.1</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/06/19/YouCanBeJustLikeTheGovernmentAndRecordTelephoneConversationsWithTAPI31.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,a080551e-30d1-47d5-b8a4-1007481b9528.aspx</id>
    <published>2006-06-19T08:41:45.901-07:00</published>
    <updated>2006-06-19T08:41:45.9014691-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="Tapi" label="Tapi" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Tapi.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font face="Times New Roman" size="3">I've gotten several questions on this topic
so I thought it might be a good thing to show in a blog.  Recording with TAPI
3.1 is actually pretty easy if you are running on Windows XP or better.  TAPI
3.1 provides some simple filename-based methods to dump the conversation into a .WAV
file.  If you want to control the file, or stream it somewhere else, it's a bit
more difficult and Microsoft provides a decent sample with the platform SDK that does
it.</font>
        </p>
        <p>
          <font face="Times New Roman" size="3">Here's a simple example -- in this scenerio
we will create a new outgoing call, connect it and then setup an outgoing stream to
play a welcome message:</font>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font size="3">
              <font color="#0000ff">TapiCall</font> currCall <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> selectedAddress.CreateCall(numberToDial,
LINEADDRESSTYPES.PhoneNumber, TAPIMEDIATYPES.AUDIO);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (currCall
!<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
{<br />
   currCall.Connect(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">false</span>);<br /></font>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font size="3">  
playbackTerminal <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> currCall.RequestTerminal(TTerminal.FilePlaybackTerminal,
TAPIMEDIATYPES.AUDIO, TERMINAL_DIRECTION.TD_CAPTURE);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
if</span> (playbackTerminal !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
   {<br />
      playbackTerminal.MediaPlayList <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>[]
{ MESSAGE_PROMPT };<br />
      currCall.SelectTerminalOnCall(playbackTerminal);<br />
   }<br />
}</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">When
the call is actually connected, then we will start the playbackTerminal stream and
begin recording the conversation - this would typically be done in the TE_CALLSTATE
handler:</font>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font size="3">
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (e.State
== CALL_STATE.CS_CONNECTED &amp;&amp; playbackTerminal !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
// Start the playback message..</span><br />
   playbackTerminal.Start();<br />
   </font>
              <font size="3">
                <font color="#008000">// Begin recording the
conversation - may be half-duplex..<br /></font>   RecordConversation("RecordedMessage.wav");<br /></font>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font size="3">}<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">else</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (e.State
== CALL_STATE.CS_DISCONNECTED)<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
// Stop recording when the call terminates.</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
if</span> (recordTerminal !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
      recordTerminal.Stop();<br /><br />
   recordTerminal <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br />
   playbackTerminal <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br />
}<br /></font>
            </span>
          </span>
        </p>
        <p>
          <font face="Times New Roman" size="3">The code for recording the conversation is pretty
simple as well, given a filename, just get a recording terminal and assign it. 
TAPI will take care of creating the file and writing contents into it.</font>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font size="3">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> RecordConversation(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> fileName)<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
// This code only works on XP or better (TAPI 3.1).</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
if</span> (currCall !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
   {<br />
      recordTerminal <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> currCall.RequestTerminal(TTerminal.FileRecordingTerminal,
TAPIMEDIATYPES.MULTITRACK, TERMINAL_DIRECTION.TD_RENDER);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
if</span> (recordTerminal !<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br />
      {<br />
         recordTerminal.RecordFileName <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> fileName;<br />
         currCall.SelectTerminalOnCall(recordTerminal);<br />
         recordTerminal.Start();<br />
      }<br /><font color="#0000ff">   </font>}<br />
}<br /></font>
          </span>
        </p>
        <p>
          <font face="Times New Roman" size="3">Finis.<br /></font>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Using Excel for VSTS Data Driven Testing</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/05/01/UsingExcelForVSTSDataDrivenTesting.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,e47f09cc-e893-46a6-aa13-7202d4e50986.aspx</id>
    <published>2006-05-01T09:55:40.0864411-07:00</published>
    <updated>2006-05-01T09:55:40.0864411-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Code" label="Code" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Code.aspx" />
    <category term="Enterprise" label="Enterprise" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Enterprise.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A colleague of mine, <a href="http://blogs.advantaje.com/blog/kevin/Net/2006/04/15/Using-Config-Files-to-Manage-DataDrivenTesting-in-VSTS.html">Kev
Jones</a>, has posted some information on using a detached SQL Server database
for driving VSTS unit tests which works great if you need a full blown SQL implementation. 
However, if all you want is a simple data feed, you can also use an Excel file, and
as it turns out, it's pretty easy to do.
</p>
        <p>
Let's start by stealing Kev's sample, hopefully he won't mind -- say I have a starship
class with a <strong>FirePhotonTorpedo</strong> method:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Enterprise<br />
{<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> torpedosLeft
= 10;<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> FirePhotonTorpedo(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> count)<br />
   {<br /></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
if</span> (torpedosLeft &lt; count)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">        
throw</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> ArgumentException(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"count"</span>);<br /><br />
      torpedosLeft -= count;<br /><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      //
Instruct bridge officer to "Fire!"</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
return</span> torpedosLeft;<br />
   }<br />
}</span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">The
equivalent unit test might look something like:</font>
            </span>
          </span>
        </p>
        <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <font face="Verdana" color="#003300" size="2">
              <p>
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                    <font color="#000000">[TestMethod]</font>
                    <br />
public</span>
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> TestFirePhotonTorpedo()<br />
{<br />
   Enterprise target <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Enterprise();<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
int</span> torpedoCount <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 5;<br />
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> expected <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> 5;<br /></span>
              </p>
              <p>
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
int</span> actual <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> target.FirePhotonTorpedo(torpedoCount);<br />
   Assert.AreEqual(expected, actual, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"FirePhotonTorpedo
did not return the expected value."</span>);<br />
}<br /></span>
              </p>
            </font>
          </span>
        </span>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">This
code just tests a specific case -- I would also need to write other unit tests for
edge cases and exceptional cases.  I can do this several different ways I could
do this:</font>
            </span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">1)
Write a unit test for each specific case passing each value and testing the expected
result.<br />
2) Put all the tests into this one unit test function -- asserting each validation
as we go.<br />
3) Pull the input and expected out of a database and run them through
the function.</font>
            </span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">This
last step, as Kev details can be done from a SQL database - either one reachable by
all the people who might run the unit tests, or as his blog shows from a .MDF file
you check in with the project and then locally attach prior to running the unit tests. 
Hit the link above for the details on that. </font>
            </span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">So,
to make an Excel data-driven test, the first step is to create an Excel document with
columns for each of our pieces of data.  My sample Excel document has the following
columns:</font>
            </span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <table width="100%" border="0">
                <tbody>
                  <tr>
                  </tr>
                  <font face="Verdana" color="#003300" size="2">
                    <td width="20%">
                      <strong>ID</strong>
                    </td>
                    <td width="80%">
A unique number identifying the row so we can use the Random data driven test</td>
                    <tr>
                      <td>
                        <strong>torpedoCount</strong>
                      </td>
                      <td>
The input for our unit test</td>
                    </tr>
                    <tr>
                      <td>
                        <strong>expected</strong>
                      </td>
                      <td>
The expected result coming out of the function</td>
                    </tr>
                    <tr>
                      <td>
                        <strong>shouldFail</strong>
                      </td>
                      <td>
Whether the function will throw an exception.</td>
                    </tr>
                  </font>
                </tbody>
              </table>
            </span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">I
can then enter a single test on each row of the given worksheet.  Here's
a screen shot --</font>
            </span>
          </span>
        </p>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/datadriven-excel1.JPG" border="0" />
        </p>
        <p>
You can create multiple "tables" by adding additional sheets to the worksheet. 
Each sheet can be named as appropriate; I'm naming this one "TorpedoData".
</p>
        <p>
Now, I need to add the appropriate attribute to my test case to indicate that it should
pull the data from a data source and run the method once per row found.  The
key is that <em>any</em> ADO.NET data source can be used.  Here I will specify
my Excel file which is named "UnitTests.xls" and indicate that the table itself is
a particular sheet within the Excel document "TorpedoData":
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                    <font color="#000000">[TestMethod]<br /></font>
                  </span>
                </span>
              </font>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                    <font color="#000000">
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                          <font face="Verdana" color="#003300" size="2">
                            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                                <font color="#000000">[DeploymentItem(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Tests.xls"</span>)] <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
Copies the file to the deployment directory</span></font>
                              </span>
                            </span>
                          </font>
                        </span>
                      </span>
                    </font>
                  </span>
                </span>
              </font>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                    <font color="#000000">
                      <br />
                    </font>
                    <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">[DataSource(<br /><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"System.Data.OleDb"</span>, <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
The provider</span><br /><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=<strong>'Tests.xls'</strong>;Persist Security Info=False;Extended Properties='Excel
8.0'"</span>,<br /><span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"TorpedoData$"</span>,      <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//
The table name, in this case, the sheet name with a '$' appended.</span><br />
DataAccessMethod.Sequential)]  </span>
                    <br />
public</span>
                  <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> TestFirePhotonTorpedo()<br />
{</span>
              </font>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300" size="2">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <br />
                </span>
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">}<br /></span>
              </font>
            </span>
          </span>
        </p>
        <p>
I also need to update the test case itself to use the data -- we do that through the
TestContext.DataRow property that gives us access to the current row of data from
our data source:
</p>
        <p>
          <font face="Courier New">
            <font color="#0000ff">public</font>
            <font color="#000000">
            </font>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font size="2">void</font>
            </span>
          </font>
          <font face="Courier New" color="#000000"> TestFirePhotonTorpedo()<br />
{</font>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <br />
                  <font size="2">   Enterprise target <font color="#000000"><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> Enterprise();<br />
   </font></font>
                </span>
              </font>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font size="2">
                    <font color="#000000">
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> torpedoCount <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Convert.ToInt32(TestContext.DataRow[<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"torpedoCount"</span>]);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   int</span> expected <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Convert.ToInt32(TestContext.DataRow[<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"expected"</span>]);<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
bool</span> shouldFail <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bool</span>)TestContext.DataRow[<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"shouldFail"</span>];<br /><br />
   TestContext.WriteLine(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Running
test with TorpedoCount={0}, ExpectedCount={1}, ShouldFail={2}"</span>,<br />
            torpedoCount, expected,
shouldFail);<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
try</span><br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
int</span> actual <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> target.FireTorpedos(torpedoCount);<br />
      Assert.AreEqual(expected, actual, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"FireTorpedos
did not return the expected value."</span>);<br />
   }<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">  
catch</span> (Exception ex)<br />
   {<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">     
if</span> (!shouldFail)<br />
         Assert.Fail(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span>.Format(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"FireTorpedo
threw exception {0}"</span>, ex.Message));<br />
   }<br /></span>
                    </font>
                  </font>
                </span>
              </font>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font size="2">
                    <font color="#000000">
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">}</span>
                    </font>
                  </font>
                </span>
              </font>
            </span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font>
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font size="2">
                    <font size="2">
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                      </span>
                    </font>
                  </font>
                </span>
              </font>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font size="2">
                    <font color="#000000">
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                        <font face="Verdana" color="#003300" size="2">So,
here we will grab the data from the current row, converting it as necessary to the
appropriate types, output a test line just to prove that we executed the method more
than once and then run the test.  The test will compare the result with the expected
database result and output a failure if they aren't the same.  If an exception
is thrown, then the <strong>shouldFail </strong>must be true or that will be considered
a failure.</font>
                      </span>
                    </font>
                  </font>
                </span>
              </font>
            </span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font size="2">
                    <font color="#000000">
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                        <font face="Verdana" color="#003300" size="2">This
approach allows me to run through different scenarios very easily and I can just store
the Excel worksheet right with my unit tests - make sure it's deployed to the target
deployment directory (either through a <strong>DeploymentItem</strong> attribute,
or through the test run configuration).  The size of my table here is about 14K,
compared to the equivalent .MDF file which is over 2M for the same data.  If
I didn't want to hardcode the filenames and such, I can also use an <strong>app.config</strong> file
for the unit test and put the information there - just as Kev details.</font>
                      </span>
                    </font>
                  </font>
                </span>
              </font>
            </span>
          </span>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <font face="Verdana" color="#003300">
                <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                  <font size="2">
                    <font color="#000000">
                      <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                        <font face="Verdana" color="#003300" size="2">Cool
stuff indeed.</font>
                      </span>
                    </font>
                  </font>
                </span>
              </font>
            </span>
          </span>
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>ATAPI.NET updated for VB.NET</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/04/20/ATAPINETUpdatedForVBNET.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,79d8f859-419f-429f-a500-4cf8bbe2d928.aspx</id>
    <published>2006-04-20T07:01:49.5208011-07:00</published>
    <updated>2006-04-20T07:01:49.5208011-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <category term="Tapi" label="Tapi" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Tapi.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Minor, but breaking update for ATAPI.NET (version number has changed).  It was
pointed out to me that the assembly wasn't very VB.NET friendly in that it didn't
show any events at the TapiManager level and you couldn't use the UI to hook it all
up.  That's fixed and all the line-level events are also exposed at the TapiManager
level for those who want to use VB.NET with the 2.0 wrapper.
</p>
        <p>
 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Platform type observations..</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/04/04/PlatformTypeObservations.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,28d0a66c-1741-42a0-8ad0-1e2734c0e9f9.aspx</id>
    <published>2006-04-04T08:39:12.169-07:00</published>
    <updated>2006-04-04T09:06:01.4035949-07:00</updated>
    <category term=".NET" label=".NET" scheme="http://www.julmar.com/blog/mark/CategoryView,category,NET.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently someone informed me that the TAPI wrappers (ITAPI3 and ATAPI) do not appear
to function properly on the Win64 platform.  It throws an exception that says:
</p>
        <p>
          <font face="Arial">"Could not load file or assembly 'ITapi3, Version=1.0.0.3, Culture=neutral,
PublicKeyToken=36377d9f6f1f4883' or one of its dependencies. An attempt was made to
load a program with an incorrect format."</font>
        </p>
        <p>
Now, as most know, .NET code compiles to an Intermediate Language (IL) which
is a bytecode that is translated to the appropriate processor-specific instructions
at runtime by the just-in-time (JIT) compiler.  The type of code that is generated
is determined by the version of the CLR that is loaded.
</p>
        <p>
When a .NET application starts, mscoree.dll is responsible for determining the proper
version of the CLR to start for the process.  This is done by looking at the
application manifest to see which version of .NET the application was compiled for
(1.0, 1.1, or 2.0) and mscoree will suck in the appropriate assemblies and DLLs for
that specific version, or in some cases, upgrade it silently to a newer version.
</p>
        <p>
On Win64, the picture is a little more complex because we have to consider the platform
as well.  There are actually two 2.x versions of .NET on Win64 - a 32-bit version
(which is the same as the one running on Win32) and a 64-bit version which has been
optimized for the 64-bit platform and generates 64-bit JITted code.  When an
assembly starts on a Win64 platform, the mscoree.dll will look at not just the version,
but also the platform flag which is coded into the manifest.  We can see this
flag using ILDASM:
</p>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/ildasm1.JPG" border="1" />
        </p>
        <p>
The <strong>.corflags</strong> above tells the loader that this particular assembly <strong>requires</strong> the
32-bit CLR, in other words, that we have a dependency on a 32-bit resource such as
a COM object or platform DLL.  By default, the flag will be set to 0x0000001
(ILONLY) indicating no dependency (VS.NET refers to this as "AnyCpu" in the platform
flag settings) and, on a Win64 machine, the assembly will be loaded under the
64-bit CLR.  With it set as above, on a Win64 machine it would be loaded into
the 32-bit CLR.  For those who are interested in this aspect, there is a tool
in the SDK (CORFLAGS.EXE) that will let you manipulate this flag and force an ILONLY
assembly to be loaded as 32-bit.
</p>
        <p>
VS.NET allows you to change the platform type on an assembly-by-assembly basis through
the project settings, Build Tab:
</p>
        <p>
          <img src="http://www.julmar.com/blog/mark/content/binary/platformtype.JPG" border="1" />
        </p>
        <p>
When loading, this platform CLR determination appears to be, as with the CLR versioning,
based solely on the assembly that starts the process.  The loader doesn't scan
the dependencies and determine that one of the required assemblies is marked as '"x86"
and will simply fail the process when that assembly eventually gets loaded.
</p>
        <p>
So, if I have an assembly that requires 32-bit execution (such as ATAPI.NET or ITAPI3
that depend on the 32-bit TAPI subsystem and COM objects), but my starting assembly
is marked as "AnyCpu", then the loader will start it under Win64 as a 64-bit process
and when it tries to initialize ATAPI.NET or ITAPI3, it will fail the AppDomain with
an exception.  Marking ATAPI.NET and ITAPI3 as "x86" (which they are by the way)
won't help in this case -- you <strong>must</strong> mark your application as 32-bit.
</p>
        <p>
This really is a bummer and, while I'm not surprise the CLR loader doesn't do it,
I am surprised that VS.NET doesn't force the .EXE to be "x86" when it sees a dependency
that requires it.
</p>
        <p>
The wrappers <em>do</em> function under Win64, but <em>only</em> if the starting application
has the platform target marked as "x86".
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>ITAPI3 update posted</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/03/30/ITAPI3UpdatePosted.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,8edc8427-e71b-4d90-b526-1431890ca7ca.aspx</id>
    <published>2006-03-30T16:16:09.8397199-07:00</published>
    <updated>2006-03-30T16:16:09.8397199-07:00</updated>
    <category term="Tapi" label="Tapi" scheme="http://www.julmar.com/blog/mark/CategoryView,category,Tapi.aspx" />
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have updated ITAPI3 to fix a couple of reported bugs -- the TE_FILETERMINAL event
wasn't always being raised and the TCall.GenerateCustomTone didn't work properly. 
Both of these issues are fixed in the latest drop.  Enjoy!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Rotor (SSCLI) Version 2.0 is now out!</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/03/24/RotorSSCLIVersion20IsNowOut.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,guid,fdc00f8d-a25f-429d-aef0-ff7d5721b8e9.aspx</id>
    <published>2006-03-24T07:38:31.6260353-07:00</published>
    <updated>2006-03-24T07:38:31.6260353-07:00</updated>
    <author>
      <name>Mark</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Great news!  Rotor is an incredible tool for learning about how and why the CLR
works the way it does.
</p>
        <p>
For more info -- <a href="http://blogs.msdn.com/jasonz/archive/2006/03/23/559581.aspx">http://blogs.msdn.com/jasonz/archive/2006/03/23/559581.aspx</a></p>
        <p>
 
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Implementing disposable components</title>
    <link rel="alternate" type="text/html" href="http://www.julmar.com/blog/mark/2006/03/22/ImplementingDisposableComponents.aspx" />
    <id>http://www.julmar.com/blog/mark/PermaLink,gu