<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Wandering through the Wilderness - WPF</title>
    <link>http://www.julmar.com/blog/mark/</link>
    <description>... a journey through WPF, MVVM and .NET4</description>
    <language>en-us</language>
    <copyright>Mark Smith</copyright>
    <lastBuildDate>Tue, 13 Apr 2010 15:34:06 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>mark@julmar.com</managingEditor>
    <webMaster>mark@julmar.com</webMaster>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=9bfff0e8-8b0f-4e29-bb74-69402c3636f9</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,9bfff0e8-8b0f-4e29-bb74-69402c3636f9.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,9bfff0e8-8b0f-4e29-bb74-69402c3636f9.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=9bfff0e8-8b0f-4e29-bb74-69402c3636f9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have updated MVVM Helpers against the RTM of Visual Studio 2010.  I will be
updating the codeplex site (<a href="http://mvvmhelpers.codeplex.com">http://mvvmhelpers.codeplex.com</a>)
shortly, but in the meantime, here’s the project template for Visual Studio 2010. 
Copy the .zip into your templates directory, mine is located at:
</p>
        <p>
          <strong>C:\Users\Mark\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual
C#</strong>
        </p>
        <p>
          <a href="http://www.julmar.com/samples/WpfMvvmApplication.zip" target="_blank">Here’s
the file.</a>
        </p>
      </body>
      <title>MVVM Helpers for .NET 4.0</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,9bfff0e8-8b0f-4e29-bb74-69402c3636f9.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/04/13/MVVMHelpersForNET40.aspx</link>
      <pubDate>Tue, 13 Apr 2010 15:34:06 GMT</pubDate>
      <description>&lt;p&gt;
I have updated MVVM Helpers against the RTM of Visual Studio 2010.&amp;nbsp; I will be
updating the codeplex site (&lt;a href="http://mvvmhelpers.codeplex.com"&gt;http://mvvmhelpers.codeplex.com&lt;/a&gt;)
shortly, but in the meantime, here’s the project template for Visual Studio 2010.&amp;nbsp;
Copy the .zip into your templates directory, mine is located at:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;C:\Users\Mark\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual
C#&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/samples/WpfMvvmApplication.zip" target="_blank"&gt;Here’s
the file.&lt;/a&gt;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,9bfff0e8-8b0f-4e29-bb74-69402c3636f9.aspx</comments>
      <category>.NET</category>
      <category>MVVM</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=42b78070-6421-4c78-b4c5-706dcd199bf9</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,42b78070-6421-4c78-b4c5-706dcd199bf9.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,42b78070-6421-4c78-b4c5-706dcd199bf9.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=42b78070-6421-4c78-b4c5-706dcd199bf9</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today I was building a simple simulator to test some events to a new piece of hardware
I’m working on.  Of course, I’m using WPF to show the simulator – and I wanted
to create a topmost window that did not have a Close button on it.  Imagine my
surprise when I realized there was not a set of flags you could supply to the Window
object to actually achieve this result!
</p>
        <p>
However, with a little Win32 mojo we can get the desired effect:
</p>
        <p>
          <font size="2" face="Consolas">public partial class MainWindow<br />
{<br />
    public MainWindow()<br />
    {<br />
        <strong>SourceInitialized += MainWindow_SourceInitialized</strong>;<br />
        InitializeComponent();<br />
    } </font>
        </p>
        <p>
          <font size="2" face="Consolas">    </font>
          <strong>
            <font size="2" face="Consolas">void
MainWindow_SourceInitialized(object sender, EventArgs e)<br />
    {<br />
        WindowInteropHelper wih = new WindowInteropHelper(this);<br />
        int style = GetWindowLong(wih.Handle, GWL_STYLE);<br />
        SetWindowLong(wih.Handle, GWL_STYLE, style
&amp; ~WS_SYSMENU);<br />
    } </font>
          </strong>
        </p>
        <p>
          <font size="2" face="Consolas">    private const int GWL_STYLE = -16;<br />
    private const int WS_SYSMENU = 0x00080000; </font>
        </p>
        <p>
          <font size="2" face="Consolas">    [DllImport("user32.dll")]<br />
    private extern static int SetWindowLong(IntPtr hwnd, int index,
int value);<br />
    [DllImport("user32.dll")]<br />
    private extern static int GetWindowLong(IntPtr hwnd, int index);<br />
}</font>
        </p>
        <p>
The key here is hooking the <strong>SourceInitialized </strong>event and then using
the <strong>SetWindowLong </strong>function to strip off the <strong>WS_SYSMENU </strong>bit. 
You can just cut/paste this code right into your solution.
</p>
      </body>
      <title>Removing the Close Button on a WPF window</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,42b78070-6421-4c78-b4c5-706dcd199bf9.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/03/22/RemovingTheCloseButtonOnAWPFWindow.aspx</link>
      <pubDate>Mon, 22 Mar 2010 20:32:02 GMT</pubDate>
      <description>&lt;p&gt;
Today I was building a simple simulator to test some events to a new piece of hardware
I’m working on.&amp;nbsp; Of course, I’m using WPF to show the simulator – and I wanted
to create a topmost window that did not have a Close button on it.&amp;nbsp; Imagine my
surprise when I realized there was not a set of flags you could supply to the Window
object to actually achieve this result!
&lt;/p&gt;
&lt;p&gt;
However, with a little Win32 mojo we can get the desired effect:
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2" face="Consolas"&gt;public partial class MainWindow&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public MainWindow()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;SourceInitialized += MainWindow_SourceInitialized&lt;/strong&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;strong&gt;&lt;font size="2" face="Consolas"&gt;void
MainWindow_SourceInitialized(object sender, EventArgs e)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WindowInteropHelper wih = new WindowInteropHelper(this);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int style = GetWindowLong(wih.Handle, GWL_STYLE);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SetWindowLong(wih.Handle, GWL_STYLE, style
&amp;amp; ~WS_SYSMENU);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private const int GWL_STYLE = -16;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private const int WS_SYSMENU = 0x00080000; &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2" face="Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DllImport("user32.dll")]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private extern static int SetWindowLong(IntPtr hwnd, int index,
int value);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [DllImport("user32.dll")]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private extern static int GetWindowLong(IntPtr hwnd, int index);&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The key here is hooking the &lt;strong&gt;SourceInitialized &lt;/strong&gt;event and then using
the &lt;strong&gt;SetWindowLong &lt;/strong&gt;function to strip off the &lt;strong&gt;WS_SYSMENU &lt;/strong&gt;bit.&amp;nbsp;
You can just cut/paste this code right into your solution.
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,42b78070-6421-4c78-b4c5-706dcd199bf9.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=f6809b09-7c04-4272-99fd-acfa5fc53ad9</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,f6809b09-7c04-4272-99fd-acfa5fc53ad9.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,f6809b09-7c04-4272-99fd-acfa5fc53ad9.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=f6809b09-7c04-4272-99fd-acfa5fc53ad9</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body 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>
      </body>
      <title>Blend Behaviors in Styles: DragPositionBehavior</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,f6809b09-7c04-4272-99fd-acfa5fc53ad9.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/02/05/BlendBehaviorsInStylesDragPositionBehavior.aspx</link>
      <pubDate>Fri, 05 Feb 2010 23:01:51 GMT</pubDate>
      <description>&lt;p&gt;
In the last post, I referred to the &lt;strong&gt;DragPositionBehavior &lt;/strong&gt;in the JulMar
MVVM library.&amp;nbsp; This behavior allows any &lt;strong&gt;UIElement &lt;/strong&gt;to be dragged
and repositioned using the mouse without requiring any code logic on your part.&amp;nbsp;
It’s easy to apply – using the traditional Blend syntax (easiest done by dragging
the behavior onto an element):
&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;}??\fs28 \cf1     \cf3 &amp;lt;\cf1 Interactivity\cf3 :\cf1 Interaction.Behaviors\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 julmar\cf3 :\cf1 DragPositionBehavior\cf3  /&amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 Interactivity\cf3 :\cf1 Interaction.Behaviors\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;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Behaviors&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;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DragPositionBehavior&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;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Behaviors&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 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 &lt;strong&gt;ListBoxItem&lt;/strong&gt; container, not just the content.&amp;nbsp; So I showed
an alternative syntax to apply the same behavior:
&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 ListBox.ItemContainerStyle\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 Style\cf4  TargetType\cf3 ="ListBoxItem"&amp;gt;\par ??\cf1             \cf3 &amp;lt;\cf1 Setter\cf4  Property\cf3 ="julmar:DragPositionBehavior.IsEnabled"\cf4  Value\cf3 ="True" /&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;ListBox.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: #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;Style&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; &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;="julmar:DragPositionBehavior.IsEnabled"&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;/div&gt;
&lt;p&gt;
&lt;br&gt;
Here, the behavior is being applied by setting the &lt;strong&gt;IsEnabled attached property&lt;/strong&gt; onto
the &lt;strong&gt;ListBoxItem&lt;/strong&gt;.&amp;nbsp; Here’s the implementation for that:
&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  This property allows the behavior to be used as a traditional\par ??\cf1 ///\cf3  attached property behavior.\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;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 &amp;lt;summary&amp;gt;\par ??///\cf3  Returns whether DragPositionBehavior is enabled via attached property\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??///\cf3  \cf1 &amp;lt;param name="uie"&amp;gt;\cf3 Element\cf1 &amp;lt;/param&amp;gt;\par ??///\cf3  \cf1 &amp;lt;returns&amp;gt;\cf3 True/False\cf1 &amp;lt;/returns&amp;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 &amp;lt;summary&amp;gt;\par ??///\cf3  Adds DragPositionBehavior to an element\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??///\cf3  \cf1 &amp;lt;param name="uie"&amp;gt;\cf3 Element to apply\cf1 &amp;lt;/param&amp;gt;\par ??///\cf3  \cf1 &amp;lt;param name="value"&amp;gt;\cf3 True/False\cf1 &amp;lt;/param&amp;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 ??}
--&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;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt; IsEnabledProperty
=
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;DependencyProperty&lt;/span&gt;.RegisterAttached(&lt;span style="color: #a31515"&gt;"IsEnabled"&lt;/span&gt;, &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: blue"&gt;bool&lt;/span&gt;), 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DragPositionBehavior&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;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;FrameworkPropertyMetadata&lt;/span&gt;(&lt;span style="color: blue"&gt;false&lt;/span&gt;,
OnIsEnabledChanged));
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&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;static&lt;/span&gt; &lt;span style="color: blue"&gt;bool&lt;/span&gt; GetIsEnabled(&lt;span style="color: #2b91af"&gt;DependencyObject&lt;/span&gt; uie)
&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;return&lt;/span&gt; (&lt;span style="color: blue"&gt;bool&lt;/span&gt;)uie.GetValue(IsEnabledProperty);
&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: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; SetIsEnabled(&lt;span style="color: #2b91af"&gt;DependencyObject&lt;/span&gt; uie, &lt;span style="color: blue"&gt;bool&lt;/span&gt; value)
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; uie.SetValue(IsEnabledProperty, value);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
This is a boilerplate example of an attached property – nothing to see here.&amp;nbsp;
The magic happens in the &lt;strong&gt;PropertyChange &lt;/strong&gt;callback:
&lt;/p&gt;
&lt;!--
{\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 =&amp;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;&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;&amp;amp; existingBehavior == \cf1 null\cf0 )\par ??        \{\par ??            behColl.Add(\cf1 new\cf0  \cf4 DragPositionBehavior\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: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; OnIsEnabledChanged(&lt;span style="color: #2b91af"&gt;DependencyObject&lt;/span&gt; dpo, 
&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; &lt;span style="color: #2b91af"&gt;DependencyPropertyChangedEventArgs&lt;/span&gt; e)
&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: #2b91af"&gt;UIElement&lt;/span&gt; uie = dpo &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;UIElement&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (uie != &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; {
&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;var&lt;/span&gt; behColl
= &lt;span style="color: #2b91af"&gt;Interaction&lt;/span&gt;.GetBehaviors(uie);
&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;var&lt;/span&gt; existingBehavior
= behColl.FirstOrDefault(b =&amp;gt; b.GetType() == 
&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;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DragPositionBehavior&lt;/span&gt;)) &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DragPositionBehavior&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;if&lt;/span&gt; ((&lt;span style="color: blue"&gt;bool&lt;/span&gt;)e.NewValue
== &lt;span style="color: blue"&gt;false&lt;/span&gt; &amp;amp;&amp;amp; existingBehavior != &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; behColl.Remove(existingBehavior);
&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;span style="color: blue"&gt;else&lt;/span&gt; &lt;span style="color: blue"&gt;if&lt;/span&gt; ((&lt;span style="color: blue"&gt;bool&lt;/span&gt;)e.NewValue
== &lt;span style="color: blue"&gt;true&lt;/span&gt; &amp;amp;&amp;amp; existingBehavior == &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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; behColl.Add(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DragPositionBehavior&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;&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;
Let’s break this down a little.&amp;nbsp; When we have the IsEnabled property set onto
an element, first we verify it’s a &lt;strong&gt;UIElement &lt;/strong&gt;(we cannot drag it on
anything that isn’t because the mouse events are defined at this level).&amp;nbsp; 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.&amp;nbsp; If there is no behavior, and we are setting the property to
“true”, then we add a new &lt;strong&gt;DragPositionBehavior &lt;/strong&gt;instance to the collection
here.&amp;nbsp; 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.
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,f6809b09-7c04-4272-99fd-acfa5fc53ad9.aspx</comments>
      <category>.NET</category>
      <category>MVVM</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=3d40b8c3-fab0-4e64-90a8-59a3582a2e31</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,3d40b8c3-fab0-4e64-90a8-59a3582a2e31.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,3d40b8c3-fab0-4e64-90a8-59a3582a2e31.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=3d40b8c3-fab0-4e64-90a8-59a3582a2e31</wfw:commentRss>
      <body 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>
      </body>
      <title>MVVM: IUIVisualizer and event management with behaviors</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,3d40b8c3-fab0-4e64-90a8-59a3582a2e31.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/02/05/MVVMIUIVisualizerAndEventManagementWithBehaviors.aspx</link>
      <pubDate>Fri, 05 Feb 2010 22:43:16 GMT</pubDate>
      <description>&lt;p&gt;
In this post, we will look at the &lt;strong&gt;IUIVisualizer&lt;/strong&gt;, and bring together
some of the concepts we’ve talked about already through a new sample – a simple picture
viewer:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_2.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/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb.png" width="520" height="393"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The application grabs all the images from the user’s photo folder and then displays
each one onto the surface of a corkboard.&amp;nbsp; You can change the properties of an
image, remove an image or add additional images.&amp;nbsp; 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.&amp;nbsp; Here’s some of the coding examples present in the sample:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
It registers a &lt;strong&gt;ISelectFile&lt;/strong&gt; service and implements it as an OpenFileDialog. 
&lt;li&gt;
It displays a “Picture Properties” dialog using the &lt;strong&gt;IUIVisualizer&lt;/strong&gt; service. 
&lt;li&gt;
It maps mouse DoubleClick on an image into a command in the ViewModel to display the
properties. 
&lt;li&gt;
It provides drag support through a behavior on the style.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Let’s look at this four features in particular.&amp;nbsp; Download the sample from here:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/samples/PictureViewer.zip" target="_blank"&gt;PictureViewer&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Open the project in Visual Studio 2008 SP1, it should build and run without any issues.&amp;nbsp;
The project structure is pretty much like all the other samples I’ve blogged about
– I’m trying to keep to a consistent model:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/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/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb_1.png" width="283" height="595"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h4&gt;Service Registration
&lt;/h4&gt;
&lt;p&gt;
If you look at the &lt;strong&gt;App.xaml.cs&lt;/strong&gt; code behind, you’ll find the registration
work being done in the constructor:
&lt;/p&gt;
&lt;!--
{\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&amp;lt;\cf5 IUIVisualizer\cf0 &amp;gt;();\par ??        uiVisualizer.Register(\cf6 "ShowElementProperties"\cf0 , \cf1 typeof\cf0 (\cf5 PropertyWindow\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: blue"&gt;public&lt;/span&gt; App()
&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: green"&gt;// Register the typical services (UI,
Error, etc.) for this application.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;ViewModel&lt;/span&gt;.RegisterKnownServiceTypes();
&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: green"&gt;// Register the file selector service.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af"&gt;ViewModel&lt;/span&gt;.ServiceProvider.Add(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ISelectFile&lt;/span&gt;), &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;OpenFileDialogSelector&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: green"&gt;// Register the UI dialogs.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;var&lt;/span&gt; uiVisualizer = &lt;span style="color: #2b91af"&gt;ViewModel&lt;/span&gt;.ServiceProvider.Resolve&amp;lt;&lt;span style="color: #2b91af"&gt;IUIVisualizer&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; uiVisualizer.Register(&lt;span style="color: #a31515"&gt;"ShowElementProperties"&lt;/span&gt;, &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;PropertyWindow&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
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 &lt;strong&gt;ServiceProvider.Add &lt;/strong&gt;on
the &lt;strong&gt;ViewModel &lt;/strong&gt;class.&amp;nbsp; The interface is defined as a single method:
&lt;/p&gt;
&lt;!--
{\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 ??}
--&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;namespace&lt;/span&gt; PictureViewer.Interfaces
&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;public&lt;/span&gt; &lt;span style="color: blue"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ISelectFile&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;string&lt;/span&gt; SelectFile(&lt;span style="color: blue"&gt;string&lt;/span&gt; fileFilters);
&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;
The registration ties this interface to an implementation that displays the &lt;strong&gt;OpenFileDialog&lt;/strong&gt;,
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.
&lt;/p&gt;
&lt;p&gt;
The final line in the &lt;strong&gt;app.xaml.cs &lt;/strong&gt;file registers a UI dialog to display
the properties of the image.&amp;nbsp; This is done through the &lt;strong&gt;IUIVisualizer &lt;/strong&gt;interface
which is defined in the helper library:
&lt;/p&gt;
&lt;!--
{\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 &amp;lt;UICompletedEventArgs&amp;gt; completedProc);\par ??        \cf1 bool\cf0 ? ShowDialog(\cf1 string\cf0  key, \cf1 object\cf0  state);\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;namespace&lt;/span&gt; JulMar.Windows.Interfaces
&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;public&lt;/span&gt; &lt;span style="color: blue"&gt;interface&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IUIVisualizer&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;void&lt;/span&gt; Register(&lt;span style="color: blue"&gt;string&lt;/span&gt; key, &lt;span style="color: #2b91af"&gt;Type&lt;/span&gt; winType);
&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;bool&lt;/span&gt; Unregister(&lt;span style="color: blue"&gt;string&lt;/span&gt; key);
&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;bool&lt;/span&gt; Show(&lt;span style="color: blue"&gt;string&lt;/span&gt; key, &lt;span style="color: blue"&gt;object&lt;/span&gt; state, &lt;span style="color: blue"&gt;bool&lt;/span&gt; setOwner,
&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; &lt;span style="color: #2b91af"&gt;EventHandler&lt;/span&gt;&amp;lt;UICompletedEventArgs&amp;gt;
completedProc);
&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;bool&lt;/span&gt;?
ShowDialog(&lt;span style="color: blue"&gt;string&lt;/span&gt; key, &lt;span style="color: blue"&gt;object&lt;/span&gt; state);
&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;
Notice the &lt;strong&gt;Register&lt;/strong&gt; and &lt;strong&gt;Unregister &lt;/strong&gt;methods take
a string defined as a “key”.&amp;nbsp; 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.&amp;nbsp; In this sample,
I’ve used the key &lt;strong&gt;“ShowElementProperties”&lt;/strong&gt; – we’ll see in a moment
how it is displayed.&amp;nbsp; The second parameter for the Register method takes the
Type to display.&amp;nbsp; The type must be a WPF Window-derived type (i.e. &lt;strong&gt;NavigationWindow &lt;/strong&gt;or &lt;strong&gt;Window&lt;/strong&gt;)
and will represent the View in our MVVM pattern.
&lt;/p&gt;
&lt;h4&gt;Displaying a UI with IUIVisualizer
&lt;/h4&gt;
&lt;p&gt;
In the &lt;strong&gt;PictureViewModel&lt;/strong&gt; type, there is an &lt;strong&gt;ICommand &lt;/strong&gt;that
is used to drive the Property window:
&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  Command to show the image properties.\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 public\cf0  \cf6 ICommand\cf0  ShowPropertiesCommand \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 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 to show the
image properties.&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; ShowPropertiesCommand
{ &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;
The default constructor fills that in with a &lt;strong&gt;DelegatingCommand &lt;/strong&gt;to
jump to a method of the ViewModel:
&lt;/p&gt;
&lt;!--
{\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 (() =&amp;gt; SendMessage(\cf4 MainViewModel\cf0 .RemovePictureMessage, \cf1 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: blue"&gt;public&lt;/span&gt; PictureViewModel()
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; _picture = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;PictureInfo&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ShowPropertiesCommand = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegatingCommand&lt;/span&gt;(ShowProperties);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectNewImageFile = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegatingCommand&lt;/span&gt;(OnSelectNewFile);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RemovePicture = &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;nbsp;
() =&amp;gt; SendMessage(&lt;span style="color: #2b91af"&gt;MainViewModel&lt;/span&gt;.RemovePictureMessage, &lt;span style="color: blue"&gt;this&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&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  Display the UI associated with this picture\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 internal\cf0  \cf4 void\cf0  ShowProperties()\par ??\{\par ??    \cf4 var\cf0  uiVisualizer = Resolve&amp;lt;\cf6 IUIVisualizer\cf0 &amp;gt;();\par ??    \cf4 if\cf0  (uiVisualizer != \cf4 null\cf0 )\par ??    \{\par ??        uiVisualizer.ShowDialog(\cf7 "ShowElementProperties"\cf0 , \cf4 this\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;&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; Display the UI associated
with this picture&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;internal&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; ShowProperties()
&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;var&lt;/span&gt; uiVisualizer = Resolve&amp;lt;&lt;span style="color: #2b91af"&gt;IUIVisualizer&lt;/span&gt;&amp;gt;();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue"&gt;if&lt;/span&gt; (uiVisualizer != &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; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uiVisualizer.ShowDialog(&lt;span style="color: #a31515"&gt;"ShowElementProperties"&lt;/span&gt;, &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; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
The handler method is marked as &lt;strong&gt;internal&lt;/strong&gt; because the &lt;strong&gt;MainViewModel &lt;/strong&gt;forwards
it’s own command to this same method handler (from the menu and toolbar).&amp;nbsp; Notice
that the method first gets the &lt;strong&gt;IUIVisualizer&lt;/strong&gt; service; you must use
the same service instance where you registered the UI view.&amp;nbsp; Next, it calls &lt;strong&gt;ShowDialog&lt;/strong&gt; to
display a modal view.&amp;nbsp; It takes two parameters – the view key, and the view model.
&lt;/p&gt;
&lt;p&gt;
A &lt;em&gt;modal view &lt;/em&gt;is one that forces the user to interact and dismiss the dialog
before they can continue working with the other elements in the application.&amp;nbsp;
It is what, as an example, applications often use for Options dialogs.&amp;nbsp; &lt;strong&gt;ShowDialog&lt;/strong&gt; will
display the View associated with the given string key (&lt;strong&gt;“ShowElementProperties”&lt;/strong&gt;).&amp;nbsp;
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.&amp;nbsp; The dialog is then
displayed and allows the user to edit the picture properties:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_6.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/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb_2.png" width="244" height="228"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
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:
&lt;/p&gt;
&lt;p&gt;
1. &lt;strong&gt;Watermarked Text display&lt;/strong&gt;: if you remove the title, it will display
some grayed out text in it’s place “Enter the Title Here”:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_8.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/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb_3.png" width="244" height="228"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
2. &lt;strong&gt;Numeric TextBox&lt;/strong&gt;:&amp;nbsp; 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.&amp;nbsp; You can also double-click to change the values and
it enforces numeric text box behavior.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_10.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/MVVMIUIVisualizerandeventmanagementwithb_DE92/image_thumb_4.png" width="244" height="228"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
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:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;System.Windows.Interactivity.dll&lt;/strong&gt; 
&lt;li&gt;
&lt;strong&gt;JulMar.Wpf.Behaviors.dll&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Both of these are included in the Dependencies folder.&amp;nbsp; The first comes from
the Blend SDK and is freely redistributable with your project.&amp;nbsp; To use them,
you add the behavior to the visual element in question, for example, the watermarked
textbox behavior gets applied like 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;}??\fs28 \cf1 &amp;lt;\cf3 TextBox\cf4  Text\cf1 ="\{\cf3 Binding\cf4  Title\cf1 \}"&amp;gt;\par ??\cf3 \tab \cf1 &amp;lt;\cf3 Interactivity\cf1 :\cf3 Interaction.Behaviors\cf1 &amp;gt;\par ??\cf3 \tab \tab \cf1 &amp;lt;\cf3 julmar\cf1 :\cf3 WatermarkTextBoxBehavior\cf4  Text\cf1 ="Enter the Title Here"/&amp;gt;\par ??\cf3 \tab \cf1 &amp;lt;/\cf3 Interactivity\cf1 :\cf3 Interaction.Behaviors\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 TextBox.Style\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="TextBox"\cf4  BasedOn\cf1 ="\{\cf3 StaticResource\cf1  \{\cf3 x\cf1 :\cf3 Type\cf4  TextBox\cf1 \}\}"&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="FontStyle"\cf4  Value\cf1 ="Normal" /&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 Style.Triggers\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 Trigger\cf4  Property\cf1 ="julmar:WatermarkTextBoxBehavior.IsWatermarked"\cf4  Value\cf1 ="True"&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="FontStyle"\cf4  Value\cf1 ="Italic" /&amp;gt;\par ??\cf3                     \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Foreground"\cf4  Value\cf1 ="LightGray" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 Trigger\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 Style.Triggers\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Style\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 TextBox.Style\cf1 &amp;gt;\par ??&amp;lt;/\cf3 TextBox\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;TextBox&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; Title&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: #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;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Behaviors&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: #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;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;WatermarkTextBoxBehavior&lt;/span&gt;&lt;span style="color: red"&gt; Text&lt;/span&gt;&lt;span style="color: blue"&gt;="Enter
the Title Here"/&amp;gt;&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;strong&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;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Behaviors&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: #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;TextBox.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;Style&lt;/span&gt;&lt;span style="color: red"&gt; TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;="TextBox"&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; TextBox&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;Setter&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="FontStyle"&lt;/span&gt;&lt;span style="color: red"&gt; Value&lt;/span&gt;&lt;span style="color: blue"&gt;="Normal"
/&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.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: #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;Trigger&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="julmar:WatermarkTextBoxBehavior.IsWatermarked"&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;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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: #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;Setter&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="FontStyle"&lt;/span&gt;&lt;span style="color: red"&gt; Value&lt;/span&gt;&lt;span style="color: blue"&gt;="Italic"
/&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;Setter&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="Foreground"&lt;/span&gt;&lt;span style="color: red"&gt; Value&lt;/span&gt;&lt;span style="color: blue"&gt;="LightGray"
/&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;Trigger&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.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: #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;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; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox.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;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;
I’ve also applied a Trigger to change the font/colors when the TextBox is watermarked.
&lt;/p&gt;
&lt;p&gt;
The numeric behavior looks like 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;}??\fs28 \cf1 &amp;lt;\cf3 TextBox\cf4  Grid.Row\cf1 ="5"\cf4  Text\cf1 ="\{\cf3 Binding\cf4  Width\cf1 ,\cf4  UpdateSourceTrigger\cf1 =PropertyChanged\}"&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Interactivity\cf1 :\cf3 Interaction.Behaviors\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 julmar\cf1 :\cf3 NumericTextBoxBehavior\cf4  AllowMouseDrag\cf1 ="True" /&amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 Interactivity\cf1 :\cf3 Interaction.Behaviors\cf1 &amp;gt;\par ??&amp;lt;/\cf3 TextBox\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;TextBox&lt;/span&gt;&lt;span style="color: red"&gt; Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;="5"&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; Width&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;=PropertyChanged}"&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;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Behaviors&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;julmar&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;NumericTextBoxBehavior&lt;/span&gt;&lt;span style="color: red"&gt; AllowMouseDrag&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: #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;Interactivity&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Interaction.Behaviors&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;
Notice that I’ve changed the &lt;strong&gt;Binding.UpdateSourceTrigger &lt;/strong&gt;to be &lt;strong&gt;PropertyChanged&lt;/strong&gt; –
this is so the dragging effect works properly and updates the value in the underlying
view model.
&lt;/p&gt;
&lt;h4&gt;Ways to invoke commands in the view
&lt;/h4&gt;
&lt;p&gt;
So let’s look now at how we get the command executed.&amp;nbsp; Switching to the &lt;strong&gt;MainWindow.xaml &lt;/strong&gt;you
will find three places where the Show Properties command is wired up.
&lt;/p&gt;
&lt;p&gt;
First, it can be invoked using a keyboard accelerator. This requires using a &lt;strong&gt;BindableCommand &lt;/strong&gt;from
the library, placing it into resources and then binding against that.&amp;nbsp; The command
we will be executing is the one on the &lt;strong&gt;MainViewModel &lt;/strong&gt;so it requires
the actual picture element as a parameter:
&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.Resources\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;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 \}" /&amp;gt;\par ??&amp;lt;/\cf3 Window.Resources\cf1 &amp;gt;\par ??\par ??&amp;lt;\cf3 Window.InputBindings\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 KeyBinding\cf4  Key\cf1 ="r"\cf4  Modifiers\cf1 ="Ctrl+Alt"\cf4  Command\cf1 ="\{\cf3 StaticResource\cf4  propsCommand\cf1 \}" /&amp;gt;\par ??&amp;lt;/\cf3 Window.InputBindings\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.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; &lt;/span&gt;&lt;span style="color: blue"&gt;&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;="propsCommand"&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; ShowPropertiesCommand&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;&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;CommandParameter&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; SelectedPicture&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.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: 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; &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;="r"&lt;/span&gt;&lt;span style="color: red"&gt; Modifiers&lt;/span&gt;&lt;span style="color: blue"&gt;="Ctrl+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; propsCommand&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.InputBindings&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;
The MainViewModel simply forwards this command onto the PictureViewModel using a typed &lt;strong&gt;DelegatingCommand&lt;/strong&gt;:
&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;}??\fs28 ShowPropertiesCommand = \cf3 new\cf0  \cf4 DelegatingCommand\cf0 &amp;lt;\cf4 PictureViewModel\cf0 &amp;gt;(p =&amp;gt; p.ShowProperties(), p =&amp;gt; p != \cf3 null\cf0 );\par ??}
--&gt;
&lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;
&lt;p style="margin: 0px"&gt;
ShowPropertiesCommand = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegatingCommand&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;PictureViewModel&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
p =&amp;gt; p.ShowProperties(), p =&amp;gt; p != &lt;span style="color: blue"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Next, we can invoke the command using the menu and toolbar:
&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 MenuItem\cf4  Header\cf3 ="_Edit"&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 MenuItem\cf4  Header\cf3 ="Add _New Picture"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  AddNewCommand\cf3 \}" /&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 MenuItem\cf4  Header\cf3 ="_Remove Picture"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  RemoveCommand\cf3 \}"\cf4  CommandParameter\cf3 ="\{\cf1 Binding\cf4  SelectedPicture\cf3 \}" /&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 Separator\cf3  /&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 MenuItem\cf4  Header\cf3 ="P_roperties"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  ShowPropertiesCommand\cf3 \}"\cf4  CommandParameter\cf3 ="\{\cf1 Binding\cf4  SelectedPicture\cf3 \}" /&amp;gt;\par ??\cf1     \cf3 &amp;lt;/\cf1 MenuItem\cf3 &amp;gt;\par ??\cf1         \cf3 &amp;lt;/\cf1 Menu\cf3 &amp;gt;\par ??\cf1         \par ??    \cf3 &amp;lt;\cf1 ToolBar\cf4  DockPanel.Dock\cf3 ="Top"&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 Button\cf4  ToolTip\cf3 ="Add New Picture"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  AddNewCommand\cf3 \}"\cf4  Content\cf3 ="+"\cf4  FontWeight\cf3 ="Bold" /&amp;gt;\par ??\cf1         \cf3 &amp;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" /&amp;gt;\par ??\cf1         \cf3 &amp;lt;\cf1 Button\cf4  ToolTip\cf3 ="Properties"\cf4  Command\cf3 ="\{\cf1 Binding\cf4  ShowPropertiesCommand\cf3 \}"\cf4  CommandParameter\cf3 ="\{\cf1 Binding\cf4  SelectedPicture\cf3 \}"&amp;gt;\par ??\cf1             \cf3 &amp;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" /&amp;gt;\par ??\cf1         \cf3 &amp;lt;/\cf1 Button\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;MenuItem&lt;/span&gt;&lt;span style="color: red"&gt; Header&lt;/span&gt;&lt;span style="color: blue"&gt;="_Edit"&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;MenuItem&lt;/span&gt;&lt;span style="color: red"&gt; Header&lt;/span&gt;&lt;span style="color: blue"&gt;="Add
_New Picture"&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; AddNewCommand&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;MenuItem&lt;/span&gt;&lt;span style="color: red"&gt; Header&lt;/span&gt;&lt;span style="color: blue"&gt;="_Remove
Picture"&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; RemoveCommand&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
CommandParameter&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; SelectedPicture&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;Separator&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;MenuItem&lt;/span&gt;&lt;span style="color: red"&gt; Header&lt;/span&gt;&lt;span style="color: blue"&gt;="P_roperties"&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; ShowPropertiesCommand&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
CommandParameter&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; SelectedPicture&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;MenuItem&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;
&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;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ToolBar&lt;/span&gt;&lt;span style="color: red"&gt; DockPanel.Dock&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; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button&lt;/span&gt;&lt;span style="color: red"&gt; ToolTip&lt;/span&gt;&lt;span style="color: blue"&gt;="Add
New Picture"&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; AddNewCommand&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Content&lt;/span&gt;&lt;span style="color: blue"&gt;="+"&lt;/span&gt;&lt;span style="color: red"&gt; FontWeight&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; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button&lt;/span&gt;&lt;span style="color: red"&gt; ToolTip&lt;/span&gt;&lt;span style="color: blue"&gt;="Remove
Picture"&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; RemoveCommand&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;
CommandParameter&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; SelectedPicture&lt;/span&gt;&lt;span style="color: blue"&gt;}"&lt;/span&gt;&lt;span style="color: red"&gt; Content&lt;/span&gt;&lt;span style="color: blue"&gt;="-"&lt;/span&gt;&lt;span style="color: red"&gt; FontWeight&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; &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button&lt;/span&gt;&lt;span style="color: red"&gt; ToolTip&lt;/span&gt;&lt;span style="color: blue"&gt;="Properties"&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; ShowPropertiesCommand&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;
CommandParameter&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; SelectedPicture&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;&amp;nbsp; ...
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
Note that here we are also binding to the &lt;strong&gt;MainViewModel &lt;/strong&gt;command –
so we must supply the parameter using the &lt;strong&gt;CommandParameter&lt;/strong&gt;.&amp;nbsp;
The final invocation place is when you double-click on the picture itself.&amp;nbsp; This
is done a little differently if you’ve not done much WPF work.&amp;nbsp; 
&lt;/p&gt;
&lt;h4&gt;A quick segway – View code behind vs. View Models
&lt;/h4&gt;
&lt;p&gt;
First, the display of images is actually housed in a &lt;strong&gt;ListBox&lt;/strong&gt;.&amp;nbsp;
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.&amp;nbsp; WPF allows us to customize the visuals however we like, so here the
panel has been replaced with a &lt;strong&gt;Canvas &lt;/strong&gt;(allowing pixel positioning),
and each item is drawn as a &lt;strong&gt;DataTemplate&lt;/strong&gt;.&amp;nbsp; The template decides
how to render each item in the ListBox – the PictureViewModel in this case.&amp;nbsp;
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).&amp;nbsp; I encourage
you to look at the code to see how all that is done.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
One of the core things necessary in MVVM is the ability to interact with visuals and
then &lt;em&gt;sometimes&lt;/em&gt; push notifications of that interaction back to the view model.&amp;nbsp;
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.&amp;nbsp; If it’s not view
specific OR you want to test it, then move it into the view model.&amp;nbsp; 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.&amp;nbsp; 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.
&lt;/p&gt;
&lt;p&gt;
Ok, so back to the double-click implementation.&amp;nbsp; In the &lt;strong&gt;DataTemplate&lt;/strong&gt; assigned
to the &lt;strong&gt;ListBox.ItemTemplate &lt;/strong&gt;property you will find the definition
for the image itself:
&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 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"&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Interactivity\cf1 :\cf3 Interaction.Triggers\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 julmar\cf1 :\cf3 DoubleClickTrigger\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 julmar\cf1 :\cf3 InvokeCommand\cf4  Command\cf1 ="\{\cf3 Binding\cf4  ShowPropertiesCommand\cf1 \}" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 julmar\cf1 :\cf3 DoubleClickTrigger\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;/\cf3 Interactivity\cf1 :\cf3 Interaction.Triggers\cf1 &amp;gt;\par ??&amp;lt;/\cf3 Image\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;Image&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;="imageHolder"&lt;/span&gt;&lt;span style="color: red"&gt; Width&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; Width&lt;/span&gt;&lt;span style="color: blue"&gt;}"&lt;/span&gt;&lt;span style="color: red"&gt; Height&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; Height&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; &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; Image&lt;/span&gt;&lt;span style="color: blue"&gt;}"&lt;/span&gt;&lt;span style="color: red"&gt; Stretch&lt;/span&gt;&lt;span style="color: blue"&gt;="Fill"&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;span style="color: red"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;="Center"&lt;/span&gt;&lt;span style="color: red"&gt; VerticalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;="Center"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;strong&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;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;strong&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;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: #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;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; ShowPropertiesCommand&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: #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;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: #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;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;Image&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;
Note the use of the Interaction.Triggers tag – this is also part of the Blend behavior
implementation.&amp;nbsp; In this case, we are &lt;em&gt;triggering&lt;/em&gt; off something (property
change, event, etc.) and then performance some &lt;em&gt;action&lt;/em&gt;.&amp;nbsp; In the &lt;strong&gt;JulMar.Wpf.Behaviors &lt;/strong&gt;assembly
you will find a whole bunch of triggers, behaviors and actions.&amp;nbsp; In this case,
I am using the &lt;strong&gt;DoubleClickTrigger&lt;/strong&gt; which monitors for a quick double
tap of the left mouse button.&amp;nbsp; When that happens, it runs the list of actions
associated with it – in this case, it invokes the ShowPropertiesCommand.&amp;nbsp; Now,
here we are defining the trigger behavior on the UI that is bound to an actual &lt;strong&gt;PictureViewModel &lt;/strong&gt;(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.
&lt;/p&gt;
&lt;h4&gt;Drag/Position Behavior
&lt;/h4&gt;
&lt;p&gt;
The last thing I want to point out is the dragging behavior.&amp;nbsp; This is also done
through a Blend behavior, but it is being applied in a slightly different way: through
a Style.&amp;nbsp; 
&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 ListBox.ItemContainerStyle\cf1 &amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Style\cf4  TargetType\cf1 ="ListBoxItem"&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="julmar:DragPositionBehavior.IsEnabled"\cf4  Value\cf1 ="True" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Canvas.Left"\cf4  Value\cf1 ="\{\cf3 Binding\cf4  X\cf1 ,\cf4  Mode\cf1 =TwoWay\}" /&amp;gt;\par ??\cf3         \cf1 &amp;lt;\cf3 Setter\cf4  Property\cf1 ="Canvas.Top"\cf4  Value\cf1 ="\{\cf3 Binding\cf4  Y\cf1 ,\cf4  Mode\cf1 =TwoWay\}" /&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 ??}
--&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.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: #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;Style&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;strong&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&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="julmar:DragPositionBehavior.IsEnabled"&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;/strong&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&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="Canvas.Left"&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; X&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: #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&lt;/span&gt;&lt;span style="color: red"&gt; Property&lt;/span&gt;&lt;span style="color: blue"&gt;="Canvas.Top"&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; Y&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: #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&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;/div&gt;
&lt;p&gt;
...
&lt;/p&gt;
&lt;p&gt;
Now, for those who have used Blend behaviors a lot, you may now that it is currently
not possible to apply behaviors through Styles.&amp;nbsp; This is a restriction of the
Attached Property definition being used – the collection cannot be associated on a
style.&amp;nbsp; 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.&amp;nbsp; If
I put the behavior onto the DataTemplate then I move the &lt;em&gt;content&lt;/em&gt; but not
the item container itself (the thing that provides selection and focus rendering)&amp;nbsp;
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!
&lt;/p&gt;
&lt;p&gt;
So, in my set of behaviors, many of them allow you to setup the behavior &lt;em&gt;both
through Blend&lt;/em&gt; and through Style setters (or directly on an element without the
full Blend syntax).&amp;nbsp; 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.&amp;nbsp; 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.
&lt;/p&gt;
&lt;p&gt;
Another question I’ve fielded is why did I even create this behavior at all when the
Blend sample already exists to do this?&amp;nbsp; Well, the short answer is because I
had a specific goal in mind here – this behavior knows about Canvas panels.&amp;nbsp;
If the behavior is attached to an element in a Canvas, it changes the position by
changing the &lt;strong&gt;Canvas.Left &lt;/strong&gt;and &lt;strong&gt;Canvas.Top &lt;/strong&gt;properties.&amp;nbsp;
If not, it uses a &lt;strong&gt;RenderTransform&lt;/strong&gt;.&amp;nbsp; The supplied blend sample
only uses RenderTransform&lt;strong&gt; &lt;/strong&gt;(at least when I last looked at it).
&lt;/p&gt;
&lt;p&gt;
That about covers it, if you have any questions or comments, then contact me!
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,3d40b8c3-fab0-4e64-90a8-59a3582a2e31.aspx</comments>
      <category>.NET</category>
      <category>MVVM</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=88843fe1-6503-46de-9be7-51f507dd068e</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,88843fe1-6503-46de-9be7-51f507dd068e.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,88843fe1-6503-46de-9be7-51f507dd068e.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=88843fe1-6503-46de-9be7-51f507dd068e</wfw:commentRss>
      <body 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>
      </body>
      <title>MVVM: Introducing the message visualizers</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,88843fe1-6503-46de-9be7-51f507dd068e.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/02/01/MVVMIntroducingTheMessageVisualizers.aspx</link>
      <pubDate>Mon, 01 Feb 2010 15:59:35 GMT</pubDate>
      <description>&lt;p&gt;
In this post, I will go over the simple message visualizers available in the MVVM
Helpers toolkit.&amp;nbsp; Essentially the idea is that it is fairly common to want to
display a simple message from the ViewModel to the user.&amp;nbsp; Since the VM is supposed
to be testable, we encapsulate this ability into four services, three of which I’ll
focus on here:
&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="2" width="622"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;strong&gt;IMessageVisualizer&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="420"&gt;
Displays a title + message to the user and allows them to dismiss it through a set
of user-defined buttons.&amp;nbsp; The button used to dismiss the dialog is returned as
the result.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;strong&gt;IErrorVisualizer&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="420"&gt;
Displays a title + message to the user to report an error.&amp;nbsp; The only button displayed
is OK, and the visualizer returns true/false.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;strong&gt;INotificationVisualizer&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="420"&gt;
Used to manage some short operation that will halt the UI briefly.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;strong&gt;IUIVisualizer&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="420"&gt;
Displays a custom modal or modaless UI to the user with an associated ViewModel to
drive it.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&lt;br&gt;
To demonstrate the first three visualizer types, we’ll build a very simple MVVM application
to display messages.&amp;nbsp; I start with the project template and remove all the ViewModel
and View code to have a blank solution.&amp;nbsp; Each of the three visualizers we are
going to look at take a &lt;strong&gt;string&lt;/strong&gt; Title and Message as their parameters
– we’ll drive it from a unique command for each.&amp;nbsp; To start with, let’s define
a simple data structure that wraps an &lt;strong&gt;ICommand&lt;/strong&gt; and a textual title:
&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  Simple command + title text\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf4 public\cf0  \cf4 class\cf0  \cf6 TitledCommand\par ??\cf0 \{\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Title to display\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf4 string\cf0  Title \{ \cf4 get\cf0 ; \cf4 private\cf0  \cf4 set\cf0 ; \}\par ??\par ??    \cf1 ///\cf3  \cf1 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Command to execute\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf6 ICommand\cf0  Command \{ \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="title"&amp;gt;&amp;lt;/param&amp;gt;\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;param name="cmd"&amp;gt;&amp;lt;/param&amp;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 ??}
--&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; Simple command + title
text&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;TitledCommand&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: 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; Title
to display&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; Title
{ &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; Command
to execute&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;ICommand&lt;/span&gt; Command
{ &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="title"&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="cmd"&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; TitledCommand(&lt;span style="color: blue"&gt;string&lt;/span&gt; title, &lt;span style="color: #2b91af"&gt;ICommand&lt;/span&gt; cmd)
&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; Title = title;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Command = cmd;
&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;
Next, in the &lt;strong&gt;MainViewModel.cs &lt;/strong&gt;file, we need a &lt;strong&gt;Title&lt;/strong&gt; string
property – this will be the title for each of the visualziations.&amp;nbsp; It’s just
a simple field-backed INPC property, we’ll bind it to something in the view:
&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  Main View Model\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;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 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Title for visualizations\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;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 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Result\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;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 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Visualization Command list\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf6 IList\cf0 &amp;lt;\cf6 TitledCommand\cf0 &amp;gt; VisualizationCommands \{ \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     \cf4 public\cf0  MainViewModel()\par ??    \{\par ??        VisualizationCommands = \cf4 new\cf0  \cf6 List\cf0 &amp;lt;\cf6 TitledCommand\cf0 &amp;gt;\par ??        \{\par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Message"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &amp;lt;\cf4 string\cf0 &amp;gt;(OnShowMessage, \par ??                s =&amp;gt; !\cf4 string\cf0 .IsNullOrEmpty(Title) &amp;amp;&amp;amp; !\cf4 string\cf0 .IsNullOrEmpty(s))),\par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Error"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &amp;lt;\cf4 string\cf0 &amp;gt;(OnShowError,\par ??                s =&amp;gt; !\cf4 string\cf0 .IsNullOrEmpty(Title) &amp;amp;&amp;amp; !\cf4 string\cf0 .IsNullOrEmpty(s))),        \par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Notification"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &amp;lt;\cf4 string\cf0 &amp;gt;(OnShowNotification, \par ??                s =&amp;gt; !\cf4 string\cf0 .IsNullOrEmpty(Title))),\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; Main View Model&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;ViewModel&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; _title;
&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; Title
for visualizations&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; Title
&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; _title;
}
&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; {
_title = &lt;span style="color: blue"&gt;value&lt;/span&gt;; OnPropertyChanged(&lt;span style="color: #a31515"&gt;"Title"&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;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Now we can create a collection of the &lt;strong&gt;TitledCommand &lt;/strong&gt;objects and display
them to the user for execution.&amp;nbsp; We will place this collection into the &lt;strong&gt;MainViewModel.cs&lt;/strong&gt;.&amp;nbsp;
Let’s populate it with a set of delegating commands for each type of visualization
we want to create.&amp;nbsp; We will use the &lt;strong&gt;DelegatingCommand&amp;lt;T&amp;gt;&lt;/strong&gt; version
which allows us to type the parameter being passed.&amp;nbsp; We will assume the inbound
parameter is always the message to display and there a string:
&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  Main View Model\par ??\cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;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 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Title for visualizations\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;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 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Result\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;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 &amp;lt;summary&amp;gt;\par ??\cf0     \cf1 ///\cf3  Visualization Command list\par ??\cf0     \cf1 ///\cf3  \cf1 &amp;lt;/summary&amp;gt;\par ??\cf0     \cf4 public\cf0  \cf6 IList\cf0 &amp;lt;\cf6 TitledCommand\cf0 &amp;gt; VisualizationCommands \{ \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     \cf4 public\cf0  MainViewModel()\par ??    \{\par ??        VisualizationCommands = \cf4 new\cf0  \cf6 List\cf0 &amp;lt;\cf6 TitledCommand\cf0 &amp;gt;\par ??        \{\par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Message"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &amp;lt;\cf4 string\cf0 &amp;gt;(OnShowMessage, \par ??                s =&amp;gt; !\cf4 string\cf0 .IsNullOrEmpty(Title) &amp;amp;&amp;amp; !\cf4 string\cf0 .IsNullOrEmpty(s))),\par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Error"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &amp;lt;\cf4 string\cf0 &amp;gt;(OnShowError,\par ??                s =&amp;gt; !\cf4 string\cf0 .IsNullOrEmpty(Title) &amp;amp;&amp;amp; !\cf4 string\cf0 .IsNullOrEmpty(s))),        \par ??            \cf4 new\cf0  \cf6 TitledCommand\cf0 (\cf7 "Show Notification"\cf0 , \cf4 new\cf0  \cf6 DelegatingCommand\cf0 &amp;lt;\cf4 string\cf0 &amp;gt;(OnShowNotification, \par ??                s =&amp;gt; !\cf4 string\cf0 .IsNullOrEmpty(Title))),\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; Main View Model&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;ViewModel&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;/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; Visualization
Command list&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;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;TitledCommand&lt;/span&gt;&amp;gt;
VisualizationCommands { &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: blue"&gt;public&lt;/span&gt; MainViewModel()
&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; VisualizationCommands = &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;TitledCommand&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; {
&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;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;TitledCommand&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Show
Message"&lt;/span&gt;, &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegatingCommand&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;(OnShowMessage, 
&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;
s =&amp;gt; !&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(Title) &amp;amp;&amp;amp; !&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(s))),
&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;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;TitledCommand&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Show
Error"&lt;/span&gt;, &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegatingCommand&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;(OnShowError,
&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;
s =&amp;gt; !&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(Title) &amp;amp;&amp;amp; !&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(s))),&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;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;TitledCommand&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Show
Notification"&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;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DelegatingCommand&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;(OnShowNotification, 
&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;
s =&amp;gt; !&lt;span style="color: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(Title))),
&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;p style="margin: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
The &lt;strong&gt;CanExecute&lt;/strong&gt; handler for each of them will test the &lt;strong&gt;Title&lt;/strong&gt; property
– ensure there is a value there, and the inbound parameter (the Message) and make
sure there is a value there as well.
&lt;/p&gt;
&lt;h4&gt;IMessageVisualizer
&lt;/h4&gt;
&lt;p&gt;
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.&amp;nbsp; The default implementation
of the service displays a &lt;strong&gt;MessageBox&lt;/strong&gt;.&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/image_2.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/MVVMIntroducingthemessagevisualizers_8347/image_thumb.png" width="402" height="185"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The buttons you can display include:
&lt;/p&gt;
&lt;!--
{\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 ??}
--&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;enum&lt;/span&gt; &lt;span style="color: #2b91af"&gt;MessageButtons&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; OK = 0,
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OKCancel = 1,
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YesNoCancel = 3,
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YesNo = 4
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
The result from the service is which button was used to dismiss the dialog:
&lt;/p&gt;
&lt;!--
{\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 ??}
--&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;enum&lt;/span&gt; &lt;span style="color: #2b91af"&gt;MessageResult&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; None = 0,
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OK = 1,
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cancel = 2,
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Yes = 6,
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; No = 7
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
Using the visualizer is very easy – request the service from the service locator using
the &lt;strong&gt;Resolve&lt;/strong&gt; method (this requires you derive from the &lt;strong&gt;JulMar.Windows.Mvvm.ViewModel&lt;/strong&gt; base
class, or hit the service locator using the static property):
&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;}??\fs28     \cf3 private\cf0  \cf3 void\cf0  OnShowMessage(\cf3 string\cf0  message)\par ??    \{\par ??        \cf3 var\cf0  messageVisualizer = Resolve&amp;lt;\cf4 IMessageVisualizer\cf0 &amp;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 ??}
--&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;private&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; OnShowMessage(&lt;span style="color: blue"&gt;string&lt;/span&gt; message)
&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;var&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; &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; {
&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; Result = &lt;span style="color: #2b91af"&gt;Enum&lt;/span&gt;.GetName(&lt;span style="color: blue"&gt;typeof&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;MessageResult&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;
messageVisualizer.Show(Title, message, &lt;span style="color: #2b91af"&gt;MessageButtons&lt;/span&gt;.YesNoCancel));
&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;
&lt;br&gt;
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).
&lt;/p&gt;
&lt;p&gt;
We want to see the result, so I take the resulting enum and convert it to a string
and assign it to a new &lt;strong&gt;Result&lt;/strong&gt; property on the ViewModel.&amp;nbsp; This,
like &lt;strong&gt;Title&lt;/strong&gt;, is just a field-backed string that does a property change
notification.
&lt;/p&gt;
&lt;h4&gt;IErrorVisualizer
&lt;/h4&gt;
&lt;p&gt;
The error visualizer is for cases where you want to display an error dialog to the
user with a title and message.&amp;nbsp; The default implementation displays a &lt;strong&gt;MessageBox &lt;/strong&gt;with
an OK button
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/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/MVVMIntroducingthemessagevisualizers_8347/image_thumb_1.png" width="391" height="183"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
It returns a boolean response indicating that the user clicked the OK button (versus
dismissing using the Close “X” button).&amp;nbsp;&amp;nbsp; It has a similar interface to
the message visualizer:
&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;}??\fs28     \cf3 private\cf0  \cf3 void\cf0  OnShowError(\cf3 string\cf0  errorMessage)\par ??    \{\par ??        \cf3 var\cf0  errorVisualizer = Resolve&amp;lt;\cf4 IErrorVisualizer\cf0 &amp;gt;();\par ??        \cf3 if\cf0  (errorVisualizer != \cf3 null\cf0 )\par ??        \{\par ??            Result = errorVisualizer.Show(Title, errorMessage).ToString();\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;private&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; OnShowError(&lt;span style="color: blue"&gt;string&lt;/span&gt; errorMessage)
&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;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; &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; {
&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; Result = errorVisualizer.Show(Title,
errorMessage).ToString();
&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;
&lt;br&gt;
We will assign the boolean result to the string Result property as well.
&lt;/p&gt;
&lt;h4&gt;INotificationVisualizer
&lt;/h4&gt;
&lt;p&gt;
This visualizer is for cases where you are doing something in the ViewModel logic,
on the UI thread that takes a moment to process.&amp;nbsp; Sorting a list, or searching
an in-memory list might be an example.&amp;nbsp; True long-running operations should always
be on a separate thread and use properties or the message mediator to coordinate with
the UI thread.&amp;nbsp; 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.&amp;nbsp;
Enter the &lt;strong&gt;INotificationVisualizer&lt;/strong&gt;.&amp;nbsp; 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”).&amp;nbsp; 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.&amp;nbsp; Invoking it is simple:
&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;\red0\green128\blue0;}??\fs28     \cf3 private\cf0  \cf3 void\cf0  OnShowNotification(\cf3 string\cf0  message)\par ??    \{\par ??        \cf3 var\cf0  notifyVisual = Resolve&amp;lt;\cf4 INotificationVisualizer\cf0 &amp;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 ??}
--&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;private&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; OnShowNotification(&lt;span style="color: blue"&gt;string&lt;/span&gt; message)
&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;var&lt;/span&gt; notifyVisual
= Resolve&amp;lt;&lt;span style="color: #2b91af"&gt;INotificationVisualizer&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; &lt;span style="color: blue"&gt;if&lt;/span&gt; (notifyVisual
!= &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;&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;using&lt;/span&gt; (notifyVisual.BeginWait(Title,
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; {
&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;//
Sleep for 2sec, pretending to work&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: #2b91af"&gt;Thread&lt;/span&gt;.Sleep(2000);
&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;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br&gt;
The &lt;strong&gt;BeginWait&lt;/strong&gt;() method kicks off the notification visual (hourglass
cursor in this case).&amp;nbsp; It returns a disposable object that you invoke Dispose
on to return to the normal cursor.&amp;nbsp; 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.
&lt;/p&gt;
&lt;h4&gt;Creating the View
&lt;/h4&gt;
&lt;p&gt;
The View for this application will be simple – let’s use an &lt;strong&gt;ItemsControl&lt;/strong&gt; to
generate a button for each of the exposed commands, two &lt;strong&gt;TextBoxes&lt;/strong&gt; to
hold the Title and Message, and then a &lt;strong&gt;TextBlock&lt;/strong&gt; for the result,
here’s what I want it to look like:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/MVVMIntroducingthemessagevisualizers_8347/image_6.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/MVVMIntroducingthemessagevisualizers_8347/image_thumb_2.png" width="426" height="320"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
I’ll let you go through the XAML – it’s straightforward and should be pretty easy
to follow.&amp;nbsp; The only new thing might be that we’ll set focus to the first focusable
element using the &lt;strong&gt;FirstFocusedElement&lt;/strong&gt; markup extension:
&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 ="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 \}\}"&amp;gt;\par ??\cf3     \cf1 &amp;lt;\cf3 Grid\cf4  Margin\cf1 ="5"&amp;gt;\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\cf1  /&amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 Grid.RowDefinitions\cf1 &amp;gt;\par ??\cf3         \par ??        \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 ??\cf3         \par ??        \cf1 &amp;lt;\cf3 Label\cf4  Grid.Column\cf1 ="0"\cf4  Grid.Row\cf1 ="0"\cf4  Content\cf1 ="Title:" /&amp;gt;\par ??\cf3         \cf1 &amp;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 \}" /&amp;gt;\par ??\par ??\cf3         \cf1 &amp;lt;\cf3 Label\cf4  Grid.Column\cf1 ="0"\cf4  Grid.Row\cf1 ="1"\cf4  Content\cf1 ="Message:" /&amp;gt;\par ??\cf3         \cf1 &amp;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" /&amp;gt;\par ??\par ??\cf3         \cf1 &amp;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 \}"&amp;gt;\par ??\cf3             \cf1 &amp;lt;\cf3 ItemsControl.ItemTemplate\cf1 &amp;gt;\par ??\cf3                 \cf1 &amp;lt;\cf3 DataTemplate\cf1 &amp;gt;\par ??\cf3                     \cf1 &amp;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\}" /&amp;gt;\par ??\cf3                 \cf1 &amp;lt;/\cf3 DataTemplate\cf1 &amp;gt;\par ??\cf3             \cf1 &amp;lt;/\cf3 ItemsControl.ItemTemplate\cf1 &amp;gt;\par ??\cf3         \cf1 &amp;lt;/\cf3 ItemsControl\cf1 &amp;gt;\par ??\cf3         \par ??        \cf1 &amp;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\}" /&amp;gt;\par ??\cf3         \par ??    \cf1 &amp;lt;/\cf3 Grid\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;="ServicesTest.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:ServicesTest.ViewModels"&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;="Notification
Visualizer Test"&lt;/span&gt;&lt;span style="color: red"&gt; Height&lt;/span&gt;&lt;span style="color: blue"&gt;="300"&lt;/span&gt;&lt;span style="color: red"&gt; Width&lt;/span&gt;&lt;span style="color: blue"&gt;="400"&lt;/span&gt;&lt;span style="color: red"&gt; Background&lt;/span&gt;&lt;span style="color: blue"&gt;="LightYellow"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="color: red"&gt;WindowStartupLocation&lt;/span&gt;&lt;span style="color: blue"&gt;="CenterScreen"&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; FocusManager.FocusedElement&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;FirstFocusedElement&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;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;}}"&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: red"&gt; Margin&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; &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: 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.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;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;Label&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; 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;="Title:"
/&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.Column&lt;/span&gt;&lt;span style="color: blue"&gt;="1"&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; Margin&lt;/span&gt;&lt;span style="color: blue"&gt;="5,2"&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; Title&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.Column&lt;/span&gt;&lt;span style="color: blue"&gt;="0"&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;="Message:"
/&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; 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;="tbMessage"&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; Grid.Row&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"
/&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;ItemsControl&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.ColumnSpan&lt;/span&gt;&lt;span style="color: blue"&gt;="2"&lt;/span&gt;&lt;span style="color: red"&gt; Margin&lt;/span&gt;&lt;span style="color: blue"&gt;="10"&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: 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; VisualizationCommands&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;ItemsControl.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;&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;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;&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;Button&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; Content&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; Title&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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; Command&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
CommandParameter&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;=tbMessage,&lt;/span&gt;&lt;span style="color: red"&gt; Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Text}"
/&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;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;ItemsControl.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;ItemsControl&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;TextBlock&lt;/span&gt;&lt;span style="color: red"&gt; FontSize&lt;/span&gt;&lt;span style="color: blue"&gt;="24pt"&lt;/span&gt;&lt;span style="color: red"&gt; Grid.ColumnSpan&lt;/span&gt;&lt;span style="color: blue"&gt;="2"&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; &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;
HorizontalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;="Center" &lt;/span&gt;&lt;span style="color: red"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;="Center"&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;
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; Result&lt;/span&gt;&lt;span style="color: blue"&gt;,&lt;/span&gt;&lt;span style="color: red"&gt; FallbackValue&lt;/span&gt;&lt;span style="color: blue"&gt;=None}"
/&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;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;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;
That should do it – if you’d like to just download the project and play with it, it’s
available here: &lt;a href="http://www.julmar.com/samples/VisulizerTest.zip" target="_blank"&gt;VisualizerTest.zip&lt;/a&gt;.&amp;nbsp;
In the next post we’ll take a look at the grand-daddy of the message visualizers in
the MVVM Helper toolkit: the &lt;strong&gt;IUIVisualizer&lt;/strong&gt;!
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,88843fe1-6503-46de-9be7-51f507dd068e.aspx</comments>
      <category>.NET</category>
      <category>MVVM</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=99559ede-2613-43f4-89a5-124081f24baa</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,99559ede-2613-43f4-89a5-124081f24baa.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,99559ede-2613-43f4-89a5-124081f24baa.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=99559ede-2613-43f4-89a5-124081f24baa</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>MVVM: Binding RadioButton groups</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,99559ede-2613-43f4-89a5-124081f24baa.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/01/29/MVVMBindingRadioButtonGroups.aspx</link>
      <pubDate>Fri, 29 Jan 2010 18:41:42 GMT</pubDate>
      <description>&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;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,99559ede-2613-43f4-89a5-124081f24baa.aspx</comments>
      <category>.NET</category>
      <category>MVVM</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=9250b94b-00c5-4e83-86ea-31359f1e4170</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,9250b94b-00c5-4e83-86ea-31359f1e4170.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,9250b94b-00c5-4e83-86ea-31359f1e4170.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=9250b94b-00c5-4e83-86ea-31359f1e4170</wfw:commentRss>
      <body 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>
      </body>
      <title>rCAT 2.0 is online, 3.0 is coming</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,9250b94b-00c5-4e83-86ea-31359f1e4170.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/01/28/rCAT20IsOnline30IsComing.aspx</link>
      <pubDate>Thu, 28 Jan 2010 20:58:46 GMT</pubDate>
      <description>&lt;p&gt;
The main project I’ve been working on the past few months has been a rRNA sequencing
application.&amp;nbsp; It’s a joint project involving Microsoft Research and the University
of Texas in Austin.&amp;nbsp; The goal being to produce lightning fast visualizations
(nucleotide, 2D and 3D) with very large (100,000 sequence) data sets on WPF.&amp;nbsp;
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.&amp;nbsp; 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.&amp;nbsp; rCAT 4.0 (coming in March) is even more
ambitious with editing support for the sequences!
&lt;/p&gt;
&lt;p&gt;
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 &lt;a href="http://rcat.codeplex.com/" target="_blank"&gt;http://rcat.codeplex.com/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
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.&amp;nbsp;
And it, of course, is all MVVM.&amp;nbsp; Fun stuff!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/WindowsLiveWriter/rCAT2.0isonline3.0iscoming_D2A1/CATUI.Overview.Shrink_2.png"&gt;&lt;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"&gt;&lt;/a&gt;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,9250b94b-00c5-4e83-86ea-31359f1e4170.aspx</comments>
      <category>.NET</category>
      <category>MVVM</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=276acdbc-7308-416c-a4ca-b75e43ac54bd</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,276acdbc-7308-416c-a4ca-b75e43ac54bd.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,276acdbc-7308-416c-a4ca-b75e43ac54bd.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=276acdbc-7308-416c-a4ca-b75e43ac54bd</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>MVVM: Rename TreeView nodes</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,276acdbc-7308-416c-a4ca-b75e43ac54bd.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/01/28/MVVMRenameTreeViewNodes.aspx</link>
      <pubDate>Thu, 28 Jan 2010 17:13:52 GMT</pubDate>
      <description>&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;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,276acdbc-7308-416c-a4ca-b75e43ac54bd.aspx</comments>
      <category>.NET</category>
      <category>MVVM</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=513ec8da-076b-4f88-91be-2151f0010610</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,513ec8da-076b-4f88-91be-2151f0010610.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,513ec8da-076b-4f88-91be-2151f0010610.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=513ec8da-076b-4f88-91be-2151f0010610</wfw:commentRss>
      <title>MVVM: Views and ViewModels</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,513ec8da-076b-4f88-91be-2151f0010610.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/01/22/MVVMViewsAndViewModels.aspx</link>
      <pubDate>Fri, 22 Jan 2010 22:35:37 GMT</pubDate>
      <description>&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;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,513ec8da-076b-4f88-91be-2151f0010610.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>MVVM</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=f4fd7f33-fba2-472e-8491-8b5a7ee06000</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,f4fd7f33-fba2-472e-8491-8b5a7ee06000.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,f4fd7f33-fba2-472e-8491-8b5a7ee06000.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=f4fd7f33-fba2-472e-8491-8b5a7ee06000</wfw:commentRss>
      <body 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></body>
      <title>MVVM Helpers Project Template</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,f4fd7f33-fba2-472e-8491-8b5a7ee06000.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/01/20/MVVMHelpersProjectTemplate.aspx</link>
      <pubDate>Wed, 20 Jan 2010 23:35:13 GMT</pubDate>
      <description>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. &lt;br&gt;
&lt;br&gt;
Download it from &lt;a href="http://www.julmar.com/samples/WpfMvvmApplication.zip"&gt;here&lt;/a&gt; and
copy the zip file into your template directory. 
&lt;br&gt;
&lt;br&gt;
As an example, if your user name was "Mark", like me and you are running Windows 7
it would be: 
&lt;div&gt;&lt;strong&gt;"C:\Users\Mark\Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual
C#\Windows"&lt;/strong&gt;
&lt;/div&gt;
&lt;br&gt;
Here's what my directory looks like: 
&lt;br&gt;
&lt;br&gt;
&lt;img border=0 alt=templatedir.jpg align=center src="http://www.julmar.com/blog/mark/content/binary/images/templatedir.jpg" width=500&gt; 
&lt;p&gt;
With that in place you should be able to fire up Visual Studio 2008 and create a sample
MVVM project: 
&lt;/p&gt;
&lt;p&gt;
&lt;img border=0 alt=project_screen.jpg align=center src="http://www.julmar.com/blog/mark/content/binary/images/project_screen.jpg" width=500&gt; 
&lt;/p&gt;
&lt;p&gt;
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:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&lt;img border=0 alt=sample-run1.jpg align=center src="http://www.julmar.com/blog/mark/content/binary/images/sample-run1.jpg" width=700&gt;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
In tomorrow's post, we'll break the sample down and see how I built it. See you then! 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,f4fd7f33-fba2-472e-8491-8b5a7ee06000.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=8913b470-bc63-4c27-b8c0-48af7ef1093e</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,8913b470-bc63-4c27-b8c0-48af7ef1093e.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,8913b470-bc63-4c27-b8c0-48af7ef1093e.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=8913b470-bc63-4c27-b8c0-48af7ef1093e</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body 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 />
      </body>
      <title>MVVM Helpers 1.05</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,8913b470-bc63-4c27-b8c0-48af7ef1093e.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2010/01/20/MVVMHelpers105.aspx</link>
      <pubDate>Wed, 20 Jan 2010 20:22:12 GMT</pubDate>
      <description>&lt;p&gt;
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 &lt;strong&gt;lot&lt;/strong&gt; of changes. So, without further ado, here's the code for
you to download and play with, this compiles with &lt;strong&gt;Visual Studio 2008 SP1&lt;/strong&gt;,
or with &lt;strong&gt;Visual Studio 2010 Beta 2&lt;/strong&gt;. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/samples/mvvmhelpers.zip"&gt;mvvmhelpers.zip&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Read on for the basics of the project structure and files. 
&lt;/p&gt;
&lt;h2&gt;Project Structure
&lt;/h2&gt;
&lt;div&gt;The code is broken into two assemblies: &lt;strong&gt;Julmar.Wpf.Helpers&lt;/strong&gt; and &lt;strong&gt;Julmar.Wpf.Behaviors&lt;/strong&gt;.
The helpers assembly contains core WPF helper classes and MVVM support and the behaviors
assembly depends on the &lt;strong&gt;System.Windows.Interactivity&lt;/strong&gt; support and
provides Blend-based behaviors for a variety of situations. 
&lt;/div&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign=top width=400&gt;
&lt;h3&gt;Building and Usage
&lt;/h3&gt;
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. 
&lt;h3&gt;Credits
&lt;/h3&gt;
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. 
&lt;h3&gt;Documentation
&lt;/h3&gt;
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. 
&lt;/td&gt;
&lt;td valign=top&gt;
&lt;img border=0 alt=Solution.jpg align=center src="http://www.julmar.com/blog/mark/content/binary/images/Solution.jpg" width=322 height=543&gt; 
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,8913b470-bc63-4c27-b8c0-48af7ef1093e.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=a5520286-2d34-4cde-9a37-fa4dca818cdd</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,a5520286-2d34-4cde-9a37-fa4dca818cdd.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,a5520286-2d34-4cde-9a37-fa4dca818cdd.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=a5520286-2d34-4cde-9a37-fa4dca818cdd</wfw:commentRss>
      <body 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>
      </body>
      <title>Deferred bindings in WPF (ala Deferred Scrolling)</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,a5520286-2d34-4cde-9a37-fa4dca818cdd.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/08/11/DeferredBindingsInWPFAlaDeferredScrolling.aspx</link>
      <pubDate>Tue, 11 Aug 2009 22:54:00 GMT</pubDate>
      <description>&lt;p&gt;
One of the new features added to WPF 3.5 SP1 was the &lt;strong&gt;ScrollViewer.IsDeferredScrollingEnabled&lt;/strong&gt; 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.&amp;nbsp; This is essential
when you have complex visualizations, or if the data itself is virtualized and the
load time is expensive.&amp;nbsp; You can get information on this feature here:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.isdeferredscrollingenabled.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.isdeferredscrollingenabled.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Recently, I was working on a project where I have a Slider that is controlling a grouping
option.&amp;nbsp; When the user changes the slider value, the visuals are regrouped based
on the position of the slider itself.&amp;nbsp; 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.&amp;nbsp;
They are expensive enough that the actual drag of the slider was impacted by it -
not to mention the CPU and rendering!&amp;nbsp; So, my initial response in these situations
is to turn on asynchronous data binding - that's as simple as throwing the &lt;strong&gt;Binding.IsAsync &lt;/strong&gt;flag.&amp;nbsp;
This essentially causes the binding transfer to occur on a background thread and will
often improve responsiveness in situations like this.
&lt;/p&gt;
&lt;p&gt;
&lt;img border=0 src="http://www.julmar.com/blog/mark/content/binary/TaxViewer1.jpg"&gt;
&lt;/p&gt;
&lt;p&gt;
In this case, however, it didn't really help because I was still doing all the intermediate
calculations.&amp;nbsp; What I really need is some way to &lt;em&gt;defer&lt;/em&gt; the binding transfer
until the slider stops.&amp;nbsp;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 &lt;strong&gt;Source&lt;/strong&gt; to
the &lt;strong&gt;Target&lt;/strong&gt;.&amp;nbsp; I could have done it in the code - it's just a
timer solution after all, but I wanted something reuseable.
&lt;/p&gt;
&lt;p&gt;
Here's an example usage:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;lt;StackPanel&amp;gt;
&amp;lt;StackPanel.Resources&amp;gt; &amp;lt;DeferredBinder:DeferredBinding x:&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Key&lt;/span&gt;="dbTest"
Timeout="1" /&amp;gt; &amp;lt;/StackPanel.Resources&amp;gt; &amp;lt;TextBlock x:Name="tb" &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Text&lt;/span&gt;="{Binding
Source={StaticResource dbTest}, Path=Target}" FontSize="48pt" HorizontalAlignment="Center"
/&amp;gt; &amp;lt;Slider x:Name="slider" Margin="10" HorizontalAlignment="Center" Width="200"
Minimum="0" Maximum="100" Value="{Binding Source={StaticResource dbTest}, Path=Source,
Mode=OneWayToSource}" /&amp;gt; &amp;lt;/StackPanel&amp;gt; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
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).
&lt;/p&gt;
&lt;p&gt;
Here's a sample project to try out:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/samples/DeferredBindingSample.zip"&gt;DeferredBindingSample.zip&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,a5520286-2d34-4cde-9a37-fa4dca818cdd.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=695a9497-12aa-48d8-881f-ac40bce1827f</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,695a9497-12aa-48d8-881f-ac40bce1827f.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,695a9497-12aa-48d8-881f-ac40bce1827f.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=695a9497-12aa-48d8-881f-ac40bce1827f</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body 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>
      </body>
      <title>Correcting the WPF Themes</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,695a9497-12aa-48d8-881f-ac40bce1827f.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/08/11/CorrectingTheWPFThemes.aspx</link>
      <pubDate>Tue, 11 Aug 2009 16:30:13 GMT</pubDate>
      <description>&lt;p&gt;
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 &lt;a href="http://www.codeplex.com/wpf"&gt;www.codeplex.com/wpf&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
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.&amp;nbsp;
Looking at the template, it turns out to be an easy fix.&amp;nbsp; 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.&amp;nbsp; Unfortunately, it looks like the
animation is switched - it applies when the checkbox is UNCHECKED vs. CHECKED.&amp;nbsp;
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:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;lt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Trigger&lt;/span&gt; Property="IsChecked"
Value="false" /&amp;gt; &amp;lt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Trigger&lt;/span&gt; Property="IsChecked"
Value="True"&amp;gt; &amp;lt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Trigger&lt;/span&gt;.EnterActions&amp;gt;
&amp;lt;BeginStoryboard x:Name="CheckedOn_BeginStoryboard" Storyboard="{StaticResource
CheckedOn}"/&amp;gt; &amp;lt;/&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Trigger&lt;/span&gt;.EnterActions&amp;gt;
&amp;lt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Trigger&lt;/span&gt;.ExitActions&amp;gt;
&amp;lt;BeginStoryboard x:Name="CheckedOff_BeginStoryboard" Storyboard="{StaticResource
CheckedOff}"/&amp;gt; &amp;lt;/&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Trigger&lt;/span&gt;.ExitActions&amp;gt;&lt;br&gt;
&lt;/span&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;lt;/&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Trigger&lt;/span&gt;&amp;gt; &lt;/span&gt;&lt;/pre&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,695a9497-12aa-48d8-881f-ac40bce1827f.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=27a95721-cf5e-4f75-9d90-d8ced629ae78</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,27a95721-cf5e-4f75-9d90-d8ced629ae78.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,27a95721-cf5e-4f75-9d90-d8ced629ae78.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=27a95721-cf5e-4f75-9d90-d8ced629ae78</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body 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>
      </body>
      <title>MVVM Helpers v1.03</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,27a95721-cf5e-4f75-9d90-d8ced629ae78.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/08/04/MVVMHelpersV103.aspx</link>
      <pubDate>Tue, 04 Aug 2009 18:14:38 GMT</pubDate>
      <description>&lt;p&gt;
I just put the latest version of the MVVM helpers online - &lt;a href="http://www.julmar.com/samples/mvvmhelpers.zip"&gt;mvvmhelpers.zip&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
There's a bunch of new stuff in it - check the release notes for the highlights.&amp;nbsp;
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.&amp;nbsp; Originally in my local version
I did it to the JulMar.Wpf.Helpers.dll and got a dependency against System.Windows.Interactivity.dll.
&lt;/p&gt;
&lt;p&gt;
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.&amp;nbsp;
The breaking change is I removed the original attached behaviors from the library
(DoubleClickBehavior, NumericTextBehavior, MouseDragBehavior) in favor of using these
new versions.&amp;nbsp; I did update the sample to show how they get used.
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;p&gt;
Again, please check the readme included in the .zip file -- as always you are free
to do whatever you like with this code.&amp;nbsp; If you do anything interesting or fun,
let me know!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,27a95721-cf5e-4f75-9d90-d8ced629ae78.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
      <category>MVVM</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=43b8da4d-a392-46f9-9e03-939950798b41</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,43b8da4d-a392-46f9-9e03-939950798b41.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,43b8da4d-a392-46f9-9e03-939950798b41.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=43b8da4d-a392-46f9-9e03-939950798b41</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body 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>
      </body>
      <title>Using Rx (Linq to Events) with WPF</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,43b8da4d-a392-46f9-9e03-939950798b41.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/08/03/UsingRxLinqToEventsWithWPF.aspx</link>
      <pubDate>Mon, 03 Aug 2009 15:56:03 GMT</pubDate>
      <description>&lt;p&gt;
A recent series of blog entries at &lt;a href="http://themechanicalbride.blogspot.com/"&gt;http://themechanicalbride.blogspot.com/&lt;/a&gt;&amp;nbsp;introduced
the Rx framework (System.Reactive.dll) which is an assembly used in the Silverlight
toolkit for UI testing purposes.&amp;nbsp; It essentially provides a mechanism to do event
driven programming through LINQ.&amp;nbsp; 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!
&lt;/p&gt;
&lt;p&gt;
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!&amp;nbsp; My original approach
was to take my favorite exploration tool, reflector (available for free from &lt;a href="http://www.redgate.com"&gt;www.redgate.com&lt;/a&gt;),
and disassemble all the classes into C#, placing them into a project file.&amp;nbsp; 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.&amp;nbsp; I realized while I was doing this
that there was a much easier way to convert a Silverlight assembly to a WPF assembly.
&lt;/p&gt;
&lt;p&gt;
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.&amp;nbsp;
The difference is in the dependency on mscorlib and other references.&amp;nbsp; Specifically,
when you add an assembly via VS2008, it looks at the &lt;strong&gt;version&lt;/strong&gt; of the
referenced&amp;nbsp;mscorlib to determine whether it's a desktop CLR assembly or Silverlight
assembly.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Here's the header of a Silverlight assembly examined through ILDASM:
&lt;/p&gt;
&lt;font size=3&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;&lt;strong&gt;// Metadata version: v2.0.50727&lt;br&gt;
.assembly extern mscorlib&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; .publickeytoken = (7C EC 85 D7 BE A7 79 8E ) // |.....y.&lt;br&gt;
&amp;nbsp;&amp;nbsp; .ver 2:0:5:0&lt;br&gt;
}&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2&gt;Here is a desktop assembly:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;&lt;strong&gt;// Metadata version: v2.0.50727&lt;br&gt;
.assembly extern mscorlib&lt;br&gt;
{&lt;br&gt;
&amp;nbsp; .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
// .z\V.4..&lt;br&gt;
&amp;nbsp; .ver 2:0:0:0&lt;br&gt;
}&lt;br&gt;
&lt;/strong&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=2 face=Verdana&gt;
&lt;br&gt;
Notice the version difference .. Silverlight uses 2.0.5.0 of mscorlib and the desktop
CLR uses 2.0.0.0.&amp;nbsp; The public key is also different, but this is really just
used for loading purposes.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2&gt;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.&amp;nbsp; &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2&gt;Here's how I did it for System.Reactive.dll:&lt;/font&gt;
&lt;/p&gt;
&lt;font face="Courier New"&gt; 
&lt;p&gt;
&lt;font size=2&gt;&lt;strong&gt;ILDASM System.Reactive.dll /out:SR.il&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2 face=Verdana&gt;change the assembly references in the resulting IL text
file (for mscorlib, system and system.core)&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2&gt;&lt;strong&gt;ILASM SR.il /resource=sr.res /output=WPF/System.Reactive.dll&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2 face=Verdana&gt;That gave me a desktop version of the assembly without modifying
anything in the code itself - much easier than my original reflector route!&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2 face=Verdana&gt;Next, I took a couple of the samples from the blog and ported
them to WPF - specifically, I took the events sample listed here &lt;a href="http://themechanicalbride.blogspot.com/2009/07/developing-with-rx-part-1-extension.html"&gt;http://themechanicalbride.blogspot.com/2009/07/developing-with-rx-part-1-extension.html&lt;/a&gt;&amp;nbsp;and
ported it to WPF to test it.&amp;nbsp; I made very few changes, primarily just switching
Application.Current.MainWindow for Application.Current.RootVisual.&amp;nbsp; Here is the
resulting project and switched assembly for anyone who is interested in it. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.julmar.com/blog/mark/content/binary/ExtensionEvents.zip"&gt;ExtensionEvents.zip
(44.62 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=2 face=Verdana&gt;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.&amp;nbsp; I'm looking
forward to building more with this using WPF now that's for sure!&lt;/font&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,43b8da4d-a392-46f9-9e03-939950798b41.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=7953f9ef-2003-444e-8f8a-f9a138bb030f</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,7953f9ef-2003-444e-8f8a-f9a138bb030f.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,7953f9ef-2003-444e-8f8a-f9a138bb030f.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=7953f9ef-2003-444e-8f8a-f9a138bb030f</wfw:commentRss>
      <body 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>
      </body>
      <title>Playing with WPF Behaviors - a WatermarkText behavior</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,7953f9ef-2003-444e-8f8a-f9a138bb030f.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/07/24/PlayingWithWPFBehaviorsAWatermarkTextBehavior.aspx</link>
      <pubDate>Fri, 24 Jul 2009 19:14:52 GMT</pubDate>
      <description>&lt;p&gt;
One of the coolest new features of Blend 3 is the inclusion of behaviors.&amp;nbsp;This
new feature formalizes the "attached behavior" model that has become so prevelant
in WPF (and Silverlight) development.&amp;nbsp; I won't go into details on the architecture
- instead I'll refer you to a nice reference:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.msdn.com/expression/archive/2009/05/19/link-round-up-behaviors-related-posts.aspx"&gt;http://blogs.msdn.com/expression/archive/2009/05/19/link-round-up-behaviors-related-posts.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
To play with this new support, I built a WatermarkTextBehavior which places a watermark
into a TextBox when it has no entered data.&amp;nbsp; 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:
&lt;/p&gt;
&lt;p&gt;
First, we derive from &lt;strong&gt;System.Windows.Interactivity.Behavior&amp;lt;T&amp;gt;&lt;/strong&gt; -
the placeholder parameter is the Visual type you want the behavior to act on.&amp;nbsp;
This can be &lt;strong&gt;UIElement&lt;/strong&gt; for anything WPF, or more restrictive if necessary
based on the events you intend to hook up.&amp;nbsp; For our purposes here, we will set
the restricted type to &lt;strong&gt;TextBox&lt;/strong&gt;.
&lt;/p&gt;
&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt; 
&lt;p&gt;
&lt;font size=3 face="Courier New"&gt;public&lt;/font&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#000000&gt; &lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;class&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt; &lt;/font&gt;&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;WatermarkTextBehavior&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt; : &lt;/font&gt;&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;Behavior&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt;&amp;lt;&lt;/font&gt;&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;TextBox&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=4&gt;&gt;
&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;
Next, you override the&lt;strong&gt; OnAttached()&lt;/strong&gt; and&lt;strong&gt; OnDetaching()&lt;/strong&gt; methods
to hook up your event behaviors you desire.&amp;nbsp; Call the base implementation first,
and then the &lt;strong&gt;AssociatedObject&lt;/strong&gt; property will be the element you've
been attached to (the &lt;strong&gt;TextBox&lt;/strong&gt; in this case).&amp;nbsp; In our case we
want to hook the &lt;strong&gt;GotFocus&lt;/strong&gt; and &lt;strong&gt;LostFocus&lt;/strong&gt; events -
this is where we trigger our behavior.
&lt;/p&gt;
&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt; 
&lt;p&gt;
&lt;font size=3 face="Courier New"&gt;protected&lt;/font&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt; &lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;override&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt; &lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;void&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000 face="Courier New"&gt; OnAttached()&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size=3 face="Courier New"&gt;{&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff face="Courier New"&gt;base&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;.OnAttached();&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font size=3 face="Courier New"&gt;AssociatedObject.GotFocus
+= OnGotFocus;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3 face="Courier New"&gt;AssociatedObject.LostFocus +=
OnLostFocus;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font size=3&gt;&lt;font face="Courier New"&gt;...&lt;/font&gt;&lt;font face="Courier New"&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font size=3 face="Courier New"&gt;}&lt;/font&gt;&gt;
&lt;font size=3 face="Courier New"&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt; 
&lt;p&gt;
&lt;font size=3&gt;protected&lt;/font&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt; &lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;override&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt; &lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;void&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt; OnDetaching()&lt;br&gt;
&lt;/font&gt;{&lt;br&gt;
&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp; base&lt;/font&gt;&lt;/font&gt;.OnDetaching();&lt;br&gt;
&amp;nbsp;&amp;nbsp; AssociatedObject.GotFocus -= OnGotFocus;&lt;br&gt;
&amp;nbsp;&amp;nbsp; AssociatedObject.LostFocus -= OnLostFocus;&lt;br&gt;
}&gt;
&lt;/font&gt; 
&lt;p&gt;
Finally, we can provide any properties necessary to drive our behavior.&amp;nbsp; These
should be done in the form of Dependency Properties so they are bindable and interact
nicely with WPF.&amp;nbsp; The base&lt;strong&gt; Behavior&amp;lt;T&amp;gt;&lt;/strong&gt; derives from &lt;strong&gt;Freezable&lt;/strong&gt; and
inherits the DataContext automatically to enable this support.&amp;nbsp; 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.
&lt;/p&gt;
&lt;font size=4&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font size=3&gt;&lt;font face="Courier New"&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;public&lt;/font&gt;&lt;/font&gt; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;static&lt;/font&gt;&lt;/font&gt; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;readonly&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;DependencyProperty&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt; TextProperty
=&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;font size=3&gt;&lt;font face="Courier New"&gt;&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;DependencyProperty&lt;/font&gt;&lt;/font&gt;.Register(&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;"Text"&lt;/font&gt;&lt;/font&gt;, &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;typeof&lt;/font&gt;&lt;/font&gt; (&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;string&lt;/font&gt;&lt;/font&gt;), &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;typeof&lt;/font&gt;&lt;/font&gt; (&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;WatermarkTextBehavior&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&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; &lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;FrameworkPropertyMetadata&lt;/font&gt;&lt;/font&gt;(&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;string&lt;/font&gt;&lt;/font&gt;.Empty));&lt;/font&gt;&gt;
&lt;/font&gt; 
&lt;p&gt;
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).&amp;nbsp; Drag
our &lt;strong&gt;WatermarkTextBehavior&lt;/strong&gt; onto any &lt;strong&gt;TextBox&lt;/strong&gt; and set
the &lt;strong&gt;Text&lt;/strong&gt; property and it will generate the following XAML:
&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 face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;TextBox&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;TextBox.Style&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;Style&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; TargetType&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="TextBox"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; BasedOn&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="{&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;StaticResource&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt; {&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;x&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;Type&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; TextBox&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;}}"&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&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&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;Style.Triggers&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&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 color=#a31515&gt;&lt;font color=#a31515&gt;Trigger&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; Property&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="julmar:WatermarkTextBehavior.IsWatermarked"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; Value&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="True"&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&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;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;Setter&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; Property&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="Foreground"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; Value&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="Gray"
/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;&lt;font size=3 face="Courier New"&gt;&amp;nbsp;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&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;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;Setter&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; Property&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="FontStyle"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; Value&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="Italic"
/&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&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 color=#a31515&gt;&lt;font color=#a31515&gt;Trigger&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&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=#a31515&gt;&lt;font color=#a31515&gt;Style.Triggers&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;Style&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;TextBox.Style&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;i&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;Interaction.Behaviors&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;julmar&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;WatermarkTextBehavior&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000&gt;&lt;font color=#ff0000&gt; Text&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;="Enter
a name here" /&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;
&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;i&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;:&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;Interaction.Behaviors&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font size=3&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;TextBox&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;
Here is the complete source code to the behavior:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Windows; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Windows.Controls; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.Windows.Interactivity; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;namespace&lt;/span&gt; JulMar.Windows.Interactivity
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
This behavior associates a watermark onto a TextBox indicating what the user should&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
provide as input.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; WatermarkTextBehavior
: Behavior&amp;lt;TextBox&amp;gt; { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
The watermark text&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;static&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;readonly&lt;/span&gt; DependencyProperty
TextProperty &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; DependencyProperty.Register(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Text"&lt;/span&gt;, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;), &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt; (WatermarkTextBehavior), &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; FrameworkPropertyMetadata(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Empty)); &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;static&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;readonly&lt;/span&gt; DependencyPropertyKey
IsWatermarkedPropertyKey &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; DependencyProperty.RegisterAttachedReadOnly(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"IsWatermarked"&lt;/span&gt;, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;bool&lt;/span&gt;), &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(WatermarkTextBehavior), &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; FrameworkPropertyMetadata(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;false&lt;/span&gt;)); &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
This readonly property is applied to the TextBox and indicates whether the watermark&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
is currently being displayed. It allows a style to change the visual appearanve of
the&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
TextBox.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;static&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;readonly&lt;/span&gt; DependencyProperty
IsWatermarkedProperty &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; IsWatermarkedPropertyKey.DependencyProperty; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
Retrieves the current watermarked state of the TextBox.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;param name="tb"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;static&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;bool&lt;/span&gt; GetIsWatermarked(TextBox
tb) { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;bool&lt;/span&gt;)
tb.GetValue(IsWatermarkedProperty); } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
Retrieves the current watermarked state of the TextBox.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;bool&lt;/span&gt; IsWatermarked
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; GetIsWatermarked(AssociatedObject);
} &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; set
{ AssociatedObject.SetValue(IsWatermarkedPropertyKey, value);} } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
The watermark text&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; Text
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;base&lt;/span&gt;.GetValue(TextProperty);
} set { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;base&lt;/span&gt;.SetValue(TextProperty,
value); } } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
Called after the behavior is attached to an AssociatedObject.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;remarks&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
Override this to hook up functionality to the AssociatedObject.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/remarks&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;protected&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;override&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; OnAttached()
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;base&lt;/span&gt;.OnAttached();
AssociatedObject.GotFocus += OnGotFocus; AssociatedObject.LostFocus += OnLostFocus;
OnLostFocus(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;null&lt;/span&gt;, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;null&lt;/span&gt;);
} &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
Called when the behavior is being detached from its AssociatedObject, but before it
has actually occurred.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;remarks&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
Override this to unhook functionality from the AssociatedObject.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/remarks&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;protected&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;override&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; OnDetaching()
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;base&lt;/span&gt;.OnDetaching();
AssociatedObject.GotFocus -= OnGotFocus; AssociatedObject.LostFocus -= OnLostFocus;
} &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
This method is called when the textbox gains focus. It removes the watermark.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;param name="sender"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;param name="e"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; OnGotFocus(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/span&gt; sender,
RoutedEventArgs e) { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Compare(AssociatedObject.Text, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;this&lt;/span&gt;.Text,
StringComparison.OrdinalIgnoreCase) == 0) { AssociatedObject.Text &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Empty;
IsWatermarked &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;false&lt;/span&gt;;
} } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
This method is called when focus is lost from the TextBox. It puts the watermark&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
into place if no text is in the textbox.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;param name="sender"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;///
&amp;lt;param name="e"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; OnLostFocus(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/span&gt; sender,
RoutedEventArgs e) { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.IsNullOrEmpty(AssociatedObject.Text))
{ AssociatedObject.Text &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;this&lt;/span&gt;.Text;
IsWatermarked &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;true&lt;/span&gt;;
} } } } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,7953f9ef-2003-444e-8f8a-f9a138bb030f.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=3e5e25ec-d3e6-4a15-9fbb-aeb7e354583e</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,3e5e25ec-d3e6-4a15-9fbb-aeb7e354583e.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,3e5e25ec-d3e6-4a15-9fbb-aeb7e354583e.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=3e5e25ec-d3e6-4a15-9fbb-aeb7e354583e</wfw:commentRss>
      <body 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>
      </body>
      <title>rCAT 1.0 beta is online</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,3e5e25ec-d3e6-4a15-9fbb-aeb7e354583e.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/07/06/rCAT10BetaIsOnline.aspx</link>
      <pubDate>Mon, 06 Jul 2009 18:24:44 GMT</pubDate>
      <description>&lt;p&gt;
A project I've been working on for the last two months is finally online in beta form
- check out
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://rcat.codeplex.com/"&gt;http://rcat.codeplex.com/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
It's essentially a biological alignment viewer for RNA sequences.&amp;nbsp; Here's a couple
of screen shots:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Alignment Viewer&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img style="WIDTH: 648px; HEIGHT: 383px" border=0 src="http://www.julmar.com/blog/mark/content/binary/rCat001.jpg" width=830 height=488&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;2D Structure Viewer&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img style="WIDTH: 720px; HEIGHT: 441px" border=0 src="http://www.julmar.com/blog/mark/content/binary/rCat002.jpg" width=812 height=495&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;2D Circle relationship Viewer&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img style="WIDTH: 767px; HEIGHT: 403px" border=0 src="http://www.julmar.com/blog/mark/content/binary/rCat003.jpg" width=883 height=489&gt;
&lt;/p&gt;
&lt;p&gt;
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.&amp;nbsp;
The next release will include a full read/write implementation so watch the project
if you are interested!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,3e5e25ec-d3e6-4a15-9fbb-aeb7e354583e.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>Real World</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=f096a7d7-fdae-4e7b-ab43-70dadf817800</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,f096a7d7-fdae-4e7b-ab43-70dadf817800.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,f096a7d7-fdae-4e7b-ab43-70dadf817800.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=f096a7d7-fdae-4e7b-ab43-70dadf817800</wfw:commentRss>
      <body 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>
      </body>
      <title>Menus and MVVM (2)</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,f096a7d7-fdae-4e7b-ab43-70dadf817800.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/04/29/MenusAndMVVM2.aspx</link>
      <pubDate>Wed, 29 Apr 2009 13:30:51 GMT</pubDate>
      <description>&lt;p&gt;
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.&amp;nbsp; First, let's start with my list
of options - for simplicity, we'll just make it an enumeration:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;enum&lt;/span&gt; Test&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; A,&lt;br&gt;
&amp;nbsp;&amp;nbsp; B,&lt;br&gt;
&amp;nbsp;&amp;nbsp; C,&lt;br&gt;
&amp;nbsp;&amp;nbsp; D,&lt;br&gt;
&amp;nbsp;&amp;nbsp; E,&lt;br&gt;
&amp;nbsp;&amp;nbsp; F&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Next,
let's&amp;nbsp;define a ViewModel to wrap this - each entry should support a single value
and a&amp;nbsp;boolean binding to determine whether it is checked:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; CheckValues&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; Test Value { get; set; }&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Text
{ get { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; Value.ToString();
} }&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; IsChecked
{ get; set; }&lt;br&gt;
}&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;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.&amp;nbsp;
The next step is&amp;nbsp;to expose this as a bindable collection - since it's not changing
we'll just use a &lt;strong&gt;List&amp;lt;T&amp;gt;&lt;/strong&gt;.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public
List&amp;lt;CheckValues&amp;gt; EnumValues { get; set; }&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;...
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font color=#000000&gt;EnumValues &lt;/font&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; List&amp;lt;CheckValues&amp;gt;();&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;foreach&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; t &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; Enum.GetValues(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;typeof&lt;/span&gt; (Test)))&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; EnumValues.Add(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; CheckValues
{Value &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; (Test)
t});&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&gt;&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;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:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;Menu
DockPanel.Dock="&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Top&lt;/span&gt;"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;MenuItem Header="Enum &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Values&lt;/span&gt;"
ItemsSource="{Binding EnumValues}"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;MenuItem.ItemContainerStyle&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Style TargetType="MenuItem"&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;lt;Setter Property="Header"
Value="{Binding &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Text&lt;/span&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;lt;Setter Property="IsCheckable"
Value="True" /&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;lt;Setter Property="IsChecked"
Value="{Binding IsChecked}" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Style&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/MenuItem.ItemContainerStyle&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/MenuItem&amp;gt;&lt;br&gt;
&amp;lt;/Menu&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;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.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;But
wait!&amp;nbsp; Often with checkboxes you want mutual exclusive choices - like the RadioButton
groups.&amp;nbsp; This was a feature of Windows Forms which unfortunately did not make
it into WPF, but we can make it work that way.&amp;nbsp; 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.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;First,
let's define an exclusive ViewModel object, here we will track the "current" selection:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; ExclusiveCheckValues&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; Test
SelectedValue { get; set; }&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; Test Value { get; set; }&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Text
{ get { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; Value.ToString();
} }&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; IsChecked&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; Value
== SelectedValue; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if&lt;/span&gt; (value)&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; SelectedValue &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Next,
we populate it into a bindable collection just as before and then we create some slightly
more complex XAML for our menu items.&amp;nbsp; The trick here is to put a RadioButton
into the menu item and associate it with a group.&amp;nbsp; 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 (&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/76c14163-9462-44d6-b0eb-6f22a006b423"&gt;http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/76c14163-9462-44d6-b0eb-6f22a006b423&lt;/a&gt;).&amp;nbsp;
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:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;Menu
DockPanel.Dock="&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Top&lt;/span&gt;"&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;Menu.Resources&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RadioButton x:&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Key&lt;/span&gt;="rb"
x:Shared="false" HorizontalAlignment="&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Left&lt;/span&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;
GroupName="MenuGroup" IsChecked="{Binding IsChecked}"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RadioButton.Template&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;lt;ControlTemplate
TargetType="{x:Type RadioButton}"&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;lt;Path x:Name="&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;check&lt;/span&gt;"
Margin="7,0,0,0" Visibility="Collapsed" VerticalAlignment="Center"&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;
Fill="{TemplateBinding MenuItem.Foreground}" FlowDirection="LeftToRight"&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;
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"/&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;lt;ControlTemplate.Triggers&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;
&amp;lt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Trigger&lt;/span&gt; Property="IsChecked"
Value="True"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;Setter TargetName="&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;check&lt;/span&gt;"
Property="Visibility" Value="Visible" /&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;
&amp;lt;/&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Trigger&lt;/span&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;lt;/ControlTemplate.Triggers&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;lt;/ControlTemplate&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;lt;/RadioButton.Template&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/RadioButton&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/Menu.Resources&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;MenuItem Header="Single &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Select&lt;/span&gt; Enum &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Values&lt;/span&gt;"
ItemsSource="{Binding ExclusiveEnumValues}"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;MenuItem.ItemContainerStyle&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Style TargetType="MenuItem"&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;lt;Setter
Property="Header" Value="{Binding &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Text&lt;/span&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;lt;Setter
Property="Icon" Value="{DynamicResource rb}" /&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;lt;EventSetter
Event="Click" Handler="OnMenuItemClick" /&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;lt;/Style&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/MenuItem.ItemContainerStyle&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/MenuItem&amp;gt;&lt;br&gt;
&amp;lt;/Menu&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Here,
we've placed the RadioButton into our resources - but marked it as non-shareable.&amp;nbsp;
The issue is that Styles always share property setters - and if you tried to do this:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&amp;lt;Style
TargetType="MenuItem"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Icon"&lt;/font&gt;&lt;font color=#000000&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter.Value&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RadioButton ...&amp;nbsp;/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Setter.Value&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;/Setter&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;
&lt;br&gt;
&lt;/p&gt;
&gt;&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;You
will get a very strange error message: "Cannot assigned type 'RadioButton' to type
'object'".&amp;nbsp; Which makes absolutely no sense until you realize the XAML parser
is trying to assign the &lt;strong&gt;same&lt;/strong&gt; RadioButton to every MenuItem.Icon.&amp;nbsp;
The non-shareable resource fixes that issue.&amp;nbsp; The last step is to set the check
-- this is done through the EventSetter in the above template.&amp;nbsp; It's wired to
the little bit of code behind:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; OnMenuItemClick(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
RoutedEventArgs e)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; ((RadioButton) ((MenuItem) sender).Icon).IsChecked &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;;&lt;br&gt;
}&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
&lt;font face=Verdana color=#003300 size=2&gt;This then sets the IsChecked property which
will, in turn, select that item.&amp;nbsp; Now you can look at &lt;strong&gt;ExclusiveCheckValue.SelectedValue&lt;/strong&gt; to&amp;nbsp;get
the current item.&amp;nbsp; This isn't the most elegant solution, nor is it the only solution
but it's an interesting one to think on.&amp;nbsp; 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&amp;nbsp;turn them off).&amp;nbsp;
But this does illustrate how powerful WPF is! &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Verdana color=#003300 size=2&gt;&lt;a href="http://www.julmar.com/samples/menucheckbox.zip"&gt;Here's
the example project with both styles.&lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/p&gt;
&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,f096a7d7-fdae-4e7b-ab43-70dadf817800.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=4c8fb326-39fc-4ef2-8872-8128cc329bd9</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,4c8fb326-39fc-4ef2-8872-8128cc329bd9.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,4c8fb326-39fc-4ef2-8872-8128cc329bd9.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=4c8fb326-39fc-4ef2-8872-8128cc329bd9</wfw:commentRss>
      <body 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></body>
      <title>Using MVVM with Menus in WPF</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,4c8fb326-39fc-4ef2-8872-8128cc329bd9.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/04/21/UsingMVVMWithMenusInWPF.aspx</link>
      <pubDate>Tue, 21 Apr 2009 22:35:59 GMT</pubDate>
      <description>&lt;p&gt;
One question I've fielded a couple of times is how to manage menus, primarily context
menus, with the MVVM pattern.&amp;nbsp; It turns out to be pretty easy once you know the
"trick".&amp;nbsp; The key thing to keep in mind is that menus are just &lt;strong&gt;ItemsControls&lt;/strong&gt; -
they support data templating and binding like any other ItemsControl.&amp;nbsp; However,
the part where people get lost is in hooking up the commands.&amp;nbsp; Here's the trick:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Step 1:&lt;/strong&gt; Define some code behind construct to manage each menu item
in a hiearchial fashion.&amp;nbsp; Here's one I've used:
&lt;/p&gt;
&lt;font size=4&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;public&lt;/font&gt;&lt;/font&gt; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;class&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;MenuItem&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;{&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;public&lt;/font&gt;&lt;/font&gt; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;string&lt;/font&gt;&lt;/font&gt; Text
{ &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;get&lt;/font&gt;&lt;/font&gt;; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;set&lt;/font&gt;&lt;/font&gt;;
}&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;public&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;List&lt;/font&gt;&lt;/font&gt;&amp;lt;&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;MenuItem&lt;/font&gt;&lt;/font&gt;&amp;gt;
Children { &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;get&lt;/font&gt;&lt;/font&gt;; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;private&lt;/font&gt;&lt;/font&gt; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;set&lt;/font&gt;&lt;/font&gt;;
}&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;public&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;ICommand&lt;/font&gt;&lt;/font&gt; Command
{ &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;get&lt;/font&gt;&lt;/font&gt;; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;set&lt;/font&gt;&lt;/font&gt;;
}&lt;br&gt;
&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;public&lt;/font&gt;&lt;/font&gt; MenuItem(&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;string&lt;/font&gt;&lt;/font&gt; item) 
&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text = item; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Children = &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;List&lt;/font&gt;&lt;/font&gt;&amp;lt;&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;MenuItem&lt;/font&gt;&lt;/font&gt;&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
}&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana&gt;&lt;font size=2&gt;&lt;strong&gt;Step
2:&lt;/strong&gt; Create your menu structure using the above container.&lt;/font&gt;&lt;/font&gt;&gt;
&lt;p&gt;
&lt;font face=Verdana size=2&gt;This involves just creating a &lt;strong&gt;List&amp;lt;MenuItem&amp;gt;&lt;/strong&gt; which
holds the root nodes and using a &lt;strong&gt;DelegatingCommand&lt;/strong&gt; to wire up some
code behind method.&amp;nbsp; Here's an example:&lt;/font&gt;
&lt;/p&gt;
&lt;font face=Verdana size=2&gt;&lt;font size=4&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;public&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;List&lt;/font&gt;&lt;/font&gt;&amp;lt;&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;MenuItem&lt;/font&gt;&lt;/font&gt;&amp;gt;
MenuOptions&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;get &amp;nbsp;&lt;/font&gt;&lt;/font&gt;{&gt;
&lt;p&gt;
&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var&lt;/font&gt;&lt;/font&gt; menu
= &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;List&lt;/font&gt;&lt;/font&gt;&amp;lt;&lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;MenuItem&lt;/font&gt;&lt;/font&gt;&amp;gt;();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;if&lt;/font&gt;&lt;/font&gt; (SupportedFileFormats.Count
&amp;gt; 0)&lt;br&gt;
&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; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;var&lt;/font&gt;&lt;/font&gt; mi
= &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;MenuItem&lt;/font&gt;&lt;/font&gt;(&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;"O_pen"&lt;/font&gt;&lt;/font&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 color=#0000ff&gt;&lt;font color=#0000ff&gt;foreach&lt;/font&gt;&lt;/font&gt;(&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;var&lt;/font&gt;&lt;/font&gt; fl &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;in&lt;/font&gt;&lt;/font&gt; SupportedFileFormats)&lt;br&gt;
&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;var
sff = fl;&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;
mi.Children.Add(&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;MenuItem&lt;/font&gt;&lt;/font&gt;(fl.Attributes.Description)&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;{
Command = &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;DelegatingCommand&lt;/font&gt;&lt;/font&gt;(()
=&amp;gt; { LoadFromFormat(sff); })});&lt;br&gt;
&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; menu.Add(mi);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; menu.Add(&lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;MenuItem&lt;/font&gt;&lt;/font&gt;(&lt;font color=#a31515&gt;&lt;font color=#a31515&gt;"Close
_All"&lt;/font&gt;&lt;/font&gt;) { Command = &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;new&lt;/font&gt;&lt;/font&gt; &lt;font color=#2b91af&gt;&lt;font color=#2b91af&gt;DelegatingCommand&lt;/font&gt;&lt;/font&gt;(OnCloseAll,
() =&amp;gt; FileList.Count &amp;gt; 0)});&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color=#0000ff&gt;&lt;font color=#0000ff&gt;return&lt;/font&gt;&lt;/font&gt; menu;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
}
&lt;/p&gt;
&lt;/font&gt;&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Note
the use of an anonymous method to suck the correct file format into the command handler.&amp;nbsp;
A nice trick so the command is executed with some contextual information of what you
clicked on.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Finally,
you need to setup the context menu style:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&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;strong&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;Style&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;Key&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;&lt;strong&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="ContextMenuItemStyle"&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;Setter&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Property&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="MenuItem.Header"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Value&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; Text&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;&lt;strong&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"/&amp;gt;&lt;br&gt;
&amp;nbsp;&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;Setter&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Property&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="MenuItem.ItemsSource"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Value&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; Children&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;&lt;strong&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;}"/&amp;gt;&lt;br&gt;
&amp;nbsp;&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;Setter&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Property&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="MenuItem.Command"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Value&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; Command&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;&lt;strong&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;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;Style&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;And
then use the style where you want the menu to appear:&lt;/font&gt;&lt;/span&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;&lt;/font&gt;&lt;/font&gt; 
&lt;p&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;StackPanel&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Orientation&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="Horizontal"&amp;gt;&lt;br&gt;
&amp;nbsp;&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;Image&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Source&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; Image&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; Width&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="16"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Height&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="16"
/&amp;gt;&lt;br&gt;
&amp;nbsp;&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;TextBlock&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Margin&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="5"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; HorizontalAlignment&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="Left"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; VerticalAlignment&lt;/font&gt;&lt;/font&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;="Center"&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; Text&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; Header&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;&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;StackPanel.ContextMenu&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/font&gt;&lt;strong&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;ContextMenu&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; ItemContainerStyle&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;StaticResource&lt;/font&gt;&lt;/font&gt;&lt;font color=#ff0000 size=4&gt;&lt;font color=#ff0000 size=4&gt; ContextMenuItemStyle&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; ItemsSource&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; MenuOptions&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 size=4&gt; &lt;/font&gt;&lt;/strong&gt;&lt;font color=#0000ff size=4&gt;&lt;font color=#0000ff size=4&gt;&lt;strong&gt;/&amp;gt;&lt;br&gt;
&lt;/strong&gt;&amp;nbsp;&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;StackPanel.ContextMenu&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;lt;/&lt;/font&gt;&lt;/font&gt;&lt;font color=#a31515 size=4&gt;&lt;font color=#a31515 size=4&gt;StackPanel&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;
&gt;&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;HierarchicalDataTemplate&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;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Now
the context menu is populated and properly dispatches to your ViewModel commands!&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;Edit:&lt;/strong&gt; added
intermediate object in LINQ query to fix deferred query issue pointed out in comments.&lt;/font&gt;&lt;/span&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;br&gt;
&amp;nbsp;&gt;
&lt;/span&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,4c8fb326-39fc-4ef2-8872-8128cc329bd9.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=a53ec32e-5190-411e-9950-dfc3aedadb7e</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,a53ec32e-5190-411e-9950-dfc3aedadb7e.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,a53ec32e-5190-411e-9950-dfc3aedadb7e.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=a53ec32e-5190-411e-9950-dfc3aedadb7e</wfw:commentRss>
      <body 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>
      </body>
      <title>More MVVM love</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,a53ec32e-5190-411e-9950-dfc3aedadb7e.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/04/21/MoreMVVMLove.aspx</link>
      <pubDate>Tue, 21 Apr 2009 19:29:47 GMT</pubDate>
      <description>&lt;p&gt;
I recently wrote about the mini-library I tend to use, but &lt;b&gt;Bill Kempf&lt;/b&gt; (one
of the WPF disciples) released a MVVM library for WPF called &lt;b&gt;Onyx&lt;/b&gt; which looks
very appealing. I especially like his use of static reflection to implement &lt;b&gt;INotifyPropertyChanged&lt;/b&gt;.
Sweet Bill! Thanks for sharing! 
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
Check it out: &lt;a href="http://www.codeplex.com/wpfonyx"&gt;WPF Onyx&lt;/a&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,a53ec32e-5190-411e-9950-dfc3aedadb7e.aspx</comments>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=8b3e4279-70a5-431e-8fa3-4c1e047df311</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,8b3e4279-70a5-431e-8fa3-4c1e047df311.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,8b3e4279-70a5-431e-8fa3-4c1e047df311.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=8b3e4279-70a5-431e-8fa3-4c1e047df311</wfw:commentRss>
      <title>WPF MVVM Helper Library (WPF + MVVM = testability)</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,8b3e4279-70a5-431e-8fa3-4c1e047df311.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/04/17/WPFMVVMHelperLibraryWPFMVVMTestability.aspx</link>
      <pubDate>Fri, 17 Apr 2009 16:06:09 GMT</pubDate>
      <description>&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;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,8b3e4279-70a5-431e-8fa3-4c1e047df311.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=81cff507-980a-4086-bcd5-ece419ca33d4</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,81cff507-980a-4086-bcd5-ece419ca33d4.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,81cff507-980a-4086-bcd5-ece419ca33d4.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=81cff507-980a-4086-bcd5-ece419ca33d4</wfw:commentRss>
      <body 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>
      </body>
      <title>Adding to an ObservableCollection from a background thread</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,81cff507-980a-4086-bcd5-ece419ca33d4.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/04/01/AddingToAnObservableCollectionFromABackgroundThread.aspx</link>
      <pubDate>Wed, 01 Apr 2009 17:17:37 GMT</pubDate>
      <description>&lt;p&gt;
One annoying thing about &lt;strong&gt;ObservableCollection&amp;lt;T&amp;gt;&lt;/strong&gt; is that it
doesn't support modifications from background threads.&amp;nbsp; That is to say, the &lt;strong&gt;CollectionChanged&lt;/strong&gt; notification
doesn't marshal to the proper thread when it is raised and it causes the exception
"&lt;strong&gt;This type of CollectionView does not support changes to its SourceCollection
from a thread different from the Dispatcher thread&lt;/strong&gt;".&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
I ran into this problem a while back and searched out to see if someone else had solved
it.&amp;nbsp;I found a solution from Tamir Khason (a fellow WPF disciple), he&amp;nbsp;wrote
a thread-safe version (&lt;a href="http://blogs.microsoft.co.il/blogs/tamir/archive/2007/04/22/Thread-safe-observable-collection.aspx"&gt;http://blogs.microsoft.co.il/blogs/tamir/archive/2007/04/22/Thread-safe-observable-collection.aspx&lt;/a&gt;),
but I didn't want to add the locking into the collection itself (I want to manage
it at a higher level myself).&amp;nbsp; Really, all I want is to do the notification on
the proper (Dispatcher) thread.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
It turns out to be pretty easy, here's my solution:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; MTObservableCollection&amp;lt;T&amp;gt;
: ObservableCollection&amp;lt;T&amp;gt;&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;event&lt;/span&gt; NotifyCollectionChangedEventHandler
CollectionChanged;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
protected&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; OnCollectionChanged(NotifyCollectionChangedEventArgs
e)&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var eh &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; CollectionChanged;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if&lt;/span&gt; (eh !&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)&lt;br&gt;
&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; Dispatcher dispatcher &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; (from
NotifyCollectionChangedEventHandler nh &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; eh.GetInvocationList()&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;
let dpo &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; nh.Target &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;as&lt;/span&gt; DispatcherObject&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;
where dpo !&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&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;
select dpo.Dispatcher).FirstOrDefault();&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if&lt;/span&gt; (dispatcher !&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
dispatcher.CheckAccess() == &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;false&lt;/span&gt;)&lt;br&gt;
&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; dispatcher.Invoke(DispatcherPriority.DataBind,
(Action)(() =&amp;gt; OnCollectionChanged(e)));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
foreach&lt;/span&gt; (NotifyCollectionChangedEventHandler nh &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; eh.GetInvocationList())&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; nh.Invoke(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;,
e);&lt;br&gt;
&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; }&lt;br&gt;
&amp;nbsp; }&lt;br&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;}&lt;br&gt;
&lt;/p&gt;
&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,81cff507-980a-4086-bcd5-ece419ca33d4.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=eca611aa-f16c-4db9-b84b-5149984d9f3b</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,eca611aa-f16c-4db9-b84b-5149984d9f3b.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,eca611aa-f16c-4db9-b84b-5149984d9f3b.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=eca611aa-f16c-4db9-b84b-5149984d9f3b</wfw:commentRss>
      <body 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</body>
      <title>It's been such a long time.. [WPF + Windows 7]</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,eca611aa-f16c-4db9-b84b-5149984d9f3b.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2009/01/29/ItsBeenSuchALongTimeWPFWindows7.aspx</link>
      <pubDate>Thu, 29 Jan 2009 18:02:21 GMT</pubDate>
      <description>&lt;b&gt;Update&lt;/b&gt;
&lt;br /&gt;
Microsoft has released the API code pack including Windows 7 support -- get it here: &lt;a href="http://code.msdn.microsoft.com/WindowsAPICodePack"&gt;http://code.msdn.microsoft.com/WindowsAPICodePack&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, it's been a while since I posted anything, I'm sorry! 
&lt;br&gt;
&lt;br&gt;
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). 
&lt;br&gt;
&lt;br&gt;
So I built an interop library to access: &lt;strong&gt; 
&lt;br&gt;
&lt;br&gt;
&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scenic Ribbon (native Win32 ribbon) in Windows Forms&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt; Native WM_TOUCH and WM_GESTURE messages&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt; Sensor API&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt; Shell APIs (jump lists, thumbnail buttons, libraries) &lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;strong&gt;One note:&lt;/strong&gt; 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: 
&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.julmar.com/samples/win7Interop.zip"&gt;Windows 7 Beta 1 Interop Library
for .NET 2.0&lt;/a&gt; 
&lt;br&gt;
&lt;br&gt;
I'll be posting more details and samples a bit later, here's a couple to get you started. 
&lt;br&gt;
&lt;br&gt;
Here's a simple example of using the Scenic Ribbon and native touch support to create
a (very) simple Windows Forms finger&lt;br&gt;
paint program:&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.julmar.com/blog/mark/content/binary/touch_img.jpg" alt="touch_img.jpg" border="0" height="469" width="699"&gt;
&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.julmar.com/samples/touch_sample.zip"&gt;Multi Touch example with
Windows Forms&lt;/a&gt; 
&lt;br&gt;
&lt;br&gt;
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. 
&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.julmar.com/blog/mark/content/binary/gesture_img.jpg" alt="gesture_img.jpg" border="0" height="372" width="498"&gt;
&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.julmar.com/samples/gesture_sample.zip"&gt;Gesture example with WPF&lt;/a&gt; 
&lt;br&gt;
&lt;br&gt;
Both of these samples work with the HP Touchmate (and multi-touch drivers) and Windows 7 Beta 1.

Have fun!

-mark</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,eca611aa-f16c-4db9-b84b-5149984d9f3b.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=f2689d26-2062-4b7b-a077-4912b976d637</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,f2689d26-2062-4b7b-a077-4912b976d637.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,f2689d26-2062-4b7b-a077-4912b976d637.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=f2689d26-2062-4b7b-a077-4912b976d637</wfw:commentRss>
      <body 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" /></body>
      <title>Debugging WPF with VS2010</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,f2689d26-2062-4b7b-a077-4912b976d637.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/11/12/DebuggingWPFWithVS2010.aspx</link>
      <pubDate>Wed, 12 Nov 2008 19:06:04 GMT</pubDate>
      <description>One of the coolest new debugging features included with VS2010 CTP1 is the management of WPF event traces directly in the IDE.&amp;nbsp; With this feature you can turn specific event traces on and off and have them show up in the debug window.&amp;nbsp; The default setting is to just show data binding errors - the existing behavior.&amp;nbsp; But now you can view resource lookups, routed event creation, etc. Here's the dialog:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img src="http://www.julmar.com/blog/mark/content/binary/NewDebugFeatures11.jpg" border="0"&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,f2689d26-2062-4b7b-a077-4912b976d637.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=824270c5-fa20-4e46-a0d6-ae609d875617</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,824270c5-fa20-4e46-a0d6-ae609d875617.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,824270c5-fa20-4e46-a0d6-ae609d875617.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=824270c5-fa20-4e46-a0d6-ae609d875617</wfw:commentRss>
      <title>Outlined Text in WPF</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,824270c5-fa20-4e46-a0d6-ae609d875617.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/09/13/OutlinedTextInWPF.aspx</link>
      <pubDate>Sat, 13 Sep 2008 03:52:21 GMT</pubDate>
      <description>&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;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,824270c5-fa20-4e46-a0d6-ae609d875617.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=03722678-882a-4bb4-928f-4fe0d35f051e</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,03722678-882a-4bb4-928f-4fe0d35f051e.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,03722678-882a-4bb4-928f-4fe0d35f051e.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=03722678-882a-4bb4-928f-4fe0d35f051e</wfw:commentRss>
      <body 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>
      </body>
      <title>Part 3: Shifting focus to the first available element in WPF</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,03722678-882a-4bb4-928f-4fe0d35f051e.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/09/12/Part3ShiftingFocusToTheFirstAvailableElementInWPF.aspx</link>
      <pubDate>Fri, 12 Sep 2008 12:49:20 GMT</pubDate>
      <description>&lt;p&gt;
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.&amp;nbsp; We can use the &lt;strong&gt;FocusManager.FocusedElement&lt;/strong&gt; property
to shift focus in XAML but it only works when the element exists in the main XAML
file.&amp;nbsp; 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.
&lt;/p&gt;
&lt;p&gt;
In my specific case, I have a wizard-style application which utilizes a TabControl
to move between the pages.&amp;nbsp; The first page looks like this:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.julmar.com/blog/mark/content/binary/TabPage_01.jpg" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
The&amp;nbsp;XAML layout&amp;nbsp;for window1.xaml looks something like this:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;TabControl
x:Name="Pages" SelectedIndex="0"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;FocusTest:Page1 /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;FocusTest:Page2 /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;FocusTest:FinalPage /&amp;gt;&lt;br&gt;
&amp;lt;/TabControl&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;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.&amp;nbsp; 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.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;So
it might seem we are stuck with adding code behind logic (blech!) but all is not lost!&amp;nbsp;
When I hit situations like this, I try to think about how to solve the problem generically
so I can reuse my solution.&amp;nbsp; In this case, I decided to build a &lt;strong&gt;MarkupExtension&lt;/strong&gt; to
locate the first focusable element descendent.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;If
you are not familiar with markup extensions, they are a corner piece in the XAML extensibility
story.&amp;nbsp; They allow for dynamic property assignment - where the value is determined
at runtime vs. XAML compile time.&amp;nbsp; 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.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Creating
a markup extension is trivial - you just extend the &lt;strong&gt;MarkupExtension&lt;/strong&gt; base
class and implement the &lt;strong&gt;ProvideValue&lt;/strong&gt; method.&amp;nbsp; In this case,
when provide value is called, I have to do several steps:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;If
the element we are bound to is not loaded yet, we need to wait for it.&amp;nbsp; We won't
be able to find the child in the visual tree if the parent isn't yet loaded.&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Once
it&amp;nbsp;&lt;strong&gt;is&lt;/strong&gt; loaded, search the children and find the first control
we can give focus to.&amp;nbsp; That means, the control is visible, focusable and enabled.&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;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 &lt;strong&gt;FocusManager.FocusedElement&lt;/strong&gt;.&lt;/font&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;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 &lt;strong&gt;FocusManager.FocusedElement&lt;/strong&gt; and
act differently in that specific case - otherwise the extension just returns the value.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;With
this new extension, I can now add a single line of code to each user control:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;UserControl
x:Class="FocusTest.Page2"&lt;br&gt;
&amp;nbsp;&amp;nbsp; xmlns:FocusTest="clr-namespace:FocusTest"&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;&lt;font color=#ff0000&gt;FocusManager.FocusedElement="{FocusTest:FirstFocusedElement}&lt;/font&gt;&lt;/strong&gt;"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Now,
when I run the application, focus is always assigned to the first control it can be
assigned to.&amp;nbsp; It turns out that I can go one step better and &lt;strong&gt;always &lt;/strong&gt;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 &lt;strong&gt;FrameworkElement.Loaded&lt;/strong&gt; event.&amp;nbsp;
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.&amp;nbsp; This might not be the required behavior so I added a simple property
to the markup extension called OneTime to control that behavior.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;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.&amp;nbsp; &lt;a href="http://www.julmar.com/blog/mark/content/binary/FocusTest.zip"&gt;FocusTest.zip
(17.88 KB)&lt;/a&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;Update: &lt;/strong&gt;&lt;a href="http://agsmith.wordpress.com/category/wpf/"&gt;Andrew
Smith&lt;/a&gt;&amp;nbsp;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.&amp;nbsp;
I didn't in the sample (or in my production app) but I could certainly see that being
a common reality.&amp;nbsp; 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.&amp;nbsp;
Thanks Andrew!&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;
&lt;br&gt;
&lt;/p&gt;
&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,03722678-882a-4bb4-928f-4fe0d35f051e.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=6e4769e5-a0b3-47b2-a142-6dfefd0c028e</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=6e4769e5-a0b3-47b2-a142-6dfefd0c028e</wfw:commentRss>
      <body 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>
      </body>
      <title>Part 2: Changing WPF focus in code</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/09/04/Part2ChangingWPFFocusInCode.aspx</link>
      <pubDate>Thu, 04 Sep 2008 20:44:44 GMT</pubDate>
      <description>&lt;p&gt;
In the &lt;a href="http://www.julmar.com/blog/mark/PermaLink,guid,2974164f-97c1-4e20-85f9-416cf6bed219.aspx"&gt;last
post&lt;/a&gt;, 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.
&lt;/p&gt;
&lt;p&gt;
Now, let's talk a little about how you can influence that programatically.&amp;nbsp; First,
you can always determine which element has logical focus in your application through
the &lt;strong&gt;FocusManager.GetFocusedElement&lt;/strong&gt; method -- pass it the window in
question and it will return which element has logical focus in that window.&amp;nbsp;
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.&amp;nbsp; But in general, the following code will tell you which element
WPF thinks has focus in the window:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IInputElement
focusedElement &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; FocusManager.GetFocusedElement(thisWindow);&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;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).&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Keyboard
focus is most often set through runtime activity - the user clicks on an element,
or uses the TAB key to&amp;nbsp;move around the UI.&amp;nbsp; You can also set it programatically
a couple of ways.&amp;nbsp; First,&amp;nbsp;there&amp;nbsp;is a &lt;strong&gt;Keyboard&lt;/strong&gt; class
in WPF which&amp;nbsp;exposes several methods and properties.&amp;nbsp; There is a &lt;strong&gt;Keyboard.FocusedElement&lt;/strong&gt; read-only
property which returns the current keyboard focused element, and there is a &lt;strong&gt;Keyboard.Focus&lt;/strong&gt; method
which attempts to change keyboard focus.&amp;nbsp; It returns the element that now has
focus - so you can check to see if your request was fulfilled or ignored.&amp;nbsp; So,
for example, you can change focus during your application initialization:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; OnLoaded(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
RoutedEventArgs e)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; Keyboard.Focus(firstTextBox);&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Notice
that we uses the &lt;strong&gt;Loaded&lt;/strong&gt; event - this is because no focus requests
will be accepted prior to the element being initialized and loaded.&amp;nbsp; That's the
first place in the application where you can make focus changes.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;When
would setting focus fail?&amp;nbsp; Well, it can fail for a lot of reasons, but the most
common are:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;The
element&amp;nbsp;has Focusable = false&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;The
element has Enabled = false&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;The
element has IsVisible = false&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;The
element has not been loaded yet&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;The
currently focused element will not release focus.&lt;/font&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;That
final one is important, changing focus involves potentially taking it away from an
existing element - they receive a &lt;strong&gt;PreviewLostKeyboardFocus&lt;/strong&gt; and&amp;nbsp;&lt;strong&gt;LostKeyboardFocus&lt;/strong&gt; event.&amp;nbsp;
If they handle the preview event, focus will not change.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;You
can also manipulate focus through programatic keyboard navigation - simulating the
user pressing TAB to cycle through the focusable elements.&amp;nbsp; This is controlled
through the &lt;strong&gt;KeyboardNavigation&lt;/strong&gt; class which is used when the user
presses a key that changes focus (TAB, SHIFT+TAB, Up, Down, etc.).&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Controls&amp;nbsp;can&amp;nbsp;set
a &lt;strong&gt;TabIndex&lt;/strong&gt; property assignment which determines the tabbing order.&amp;nbsp;
The default is to tab through them in order of declaration.&amp;nbsp; You can also use
the &lt;strong&gt;KeyboardNavigation.TabIndex&lt;/strong&gt; attached property which works for
any element - not just controls.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;To
control navigation, the &lt;strong&gt;KeyboardNavigation&lt;/strong&gt; class has an attached
property &lt;strong&gt;TabNavigation&lt;/strong&gt;&amp;nbsp;allowing you to change how navigation
occurs within a container.&amp;nbsp; You can set it to:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;Continue&lt;/strong&gt; -
each focusable element receives focus and the container is exited when the edge is
reached.&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;Cycle&lt;/strong&gt; -
focus does not leave the container but wraps around the edges&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;Once&lt;/strong&gt; -
the container itself is treated as a single focusable element where only the first
child receives focus&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;Local&lt;/strong&gt; -
uses TabIndex locally within the container - independant of any outside elements.&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;Contained&lt;/strong&gt; -
focus statys in the container but does not wrap (stays at edges when top/bottom are
reached)&lt;/font&gt;&lt;/span&gt; 
&lt;li&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;None&lt;/strong&gt; -
no keyboard navigation allowed in the container&lt;/font&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;The
default is &lt;strong&gt;Continue&lt;/strong&gt;, but you can set the attached property on any
element to change it for that element and any children. &lt;/font&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;To
see this in action, paste the following into your XAML editor of choice and change
the ComboBox while tabbing through the TextBlock elements.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns:sys="clr-namespace:System;assembly=mscorlib"&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Title="Simple Focus"&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;Window.Resources&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;Style TargetType="TextBox"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Margin" Value="10" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Width" Value="100" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;/Style&amp;gt;&lt;br&gt;
&amp;lt;/Window.Resources&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;StackPanel&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;ComboBox x:Name="tabStyles" SelectedIndex="0" Focusable="False"&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sys:String&amp;gt;None&amp;lt;/sys:String&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sys:String&amp;gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font color=#000000&gt;Continue&lt;/font&gt;&lt;/span&gt;&amp;lt;/sys:String&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sys:String&amp;gt;Cycle&amp;lt;/sys:String&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sys:String&amp;gt;Once&amp;lt;/sys:String&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sys:String&amp;gt;Local&amp;lt;/sys:String&amp;gt;&lt;br&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;sys:String&amp;gt;Contained&amp;lt;/sys:String&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;/ComboBox&amp;gt;&lt;br&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
&amp;lt;TextBox TabIndex="1"&amp;nbsp;/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;TextBox TabIndex="2" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;StackPanel 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;strong&gt;&lt;font color=#ff0000&gt;KeyboardNavigation.TabNavigation="{Binding
ElementName=tabStyles,Path=SelectedItem}"&lt;/font&gt;&lt;/strong&gt;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TextBox TabIndex="1"&amp;nbsp;/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TextBox TabIndex="2" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;br&gt;
&amp;lt;/StackPanel&amp;gt;&lt;br&gt;
&amp;lt;/Window&amp;gt;&lt;br&gt;
&lt;/p&gt;
&gt;&gt;&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;You
can have the system ignore specific elements (but still allow them to have focus)
by setting the &lt;strong&gt;KeyboardNavigation.IsTabStop="false"&lt;/strong&gt; attached property.&amp;nbsp;
This will cause keyboard navigation to "jump" over the control as if it were not present.&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Three
methods are exposed by&amp;nbsp;UIElement and FrameworkElement&amp;nbsp;to programatically
shift focus: &lt;strong&gt;Focus&lt;/strong&gt;, &lt;strong&gt;MoveFocus&lt;/strong&gt; and &lt;strong&gt;PredictFocus&lt;/strong&gt;.&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;To
force focus to a specific element, you can call &lt;strong&gt;Focus&lt;/strong&gt; on it.&amp;nbsp;
For example, above we set the keyboard focus by calling Keyboard.Focus(), but the
same effect can be achieved like this:&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; OnLoaded(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; sender,
RoutedEventArgs e)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; firstTextBox.Focus();&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;This
method attempts to set focus using Keyboard.Focus().&amp;nbsp; If that fails, but the
element is Focusable and enabled,&amp;nbsp;it finds the focus scope for the element and
sets logical focus there (so that keyboard focus will eventually end up on the control).&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;FrameworkElement.MoveFocus&lt;/strong&gt; is
used to change the keyboard focus in the application using the&amp;nbsp;same algorithm
as the TAB traversal.&amp;nbsp; You pass in the direction (specified through a TraversalRequest
object) and the method returns true/false to indicate success.&amp;nbsp; &amp;nbsp;Under the
covers it actually uses the KeyboardNavigation class, but it's an easy way to push
focus around the window:&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;firstTextBox.MoveFocus(&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;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; TraversalRequest(FocusNavigationDirection.Next));&lt;br&gt;
&lt;/p&gt;
&lt;/span&gt;
&lt;/span&gt;
&lt;/font&gt;&lt;/span&gt;&gt;&gt;&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;strong&gt;PredictFocus&lt;/strong&gt; works
the same way, but instead of actually shifting focus, it returns what &lt;em&gt;would &lt;/em&gt;be
the focused item if you were to execute MoveFocus.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;So,
up to this point, we've seen a lot of code to change focus.&amp;nbsp; However, the most
common request is to set initial focus to a specific control - remember that WPF doesn't
do that by default.&amp;nbsp; You can do it in code, just like the above example where
we use the Loaded event.&amp;nbsp; Or, it turns out you can do it in XAML too.&amp;nbsp; The
key to remember is that the FocusedElement of the main focus scope (the Window) is
the one that will get initial focus.&amp;nbsp; That is (by default) null, but you can
set it in XAML using the attached property syntax.&amp;nbsp; 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:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns:sys="clr-namespace:System;assembly=mscorlib"&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Title="Simple Focus"&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;&lt;font color=#ff0000&gt;FocusManager.FocusedElement="{Binding
ElementName=tb2}"&lt;/font&gt;&lt;/strong&gt;&amp;gt;&lt;br&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;
...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TextBox TabIndex="1" /&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TextBox &lt;font color=#ff0000&gt;x:Name="tb2"&lt;/font&gt; TabIndex="2"
/&amp;gt;&lt;br&gt;
&amp;nbsp; ...&lt;br&gt;
&amp;lt;/Window&amp;gt;&lt;br&gt;
&lt;/p&gt;
&lt;/span&gt;&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;Now
when you run the application, focus is placed into &lt;em&gt;the &lt;/em&gt;second text box in
the window.&amp;nbsp; This technique works great&amp;nbsp;as long as the element you want
to assign focus to is declared here in&amp;nbsp;the same XAML file.&amp;nbsp; However, a popular
way to develop WPF applications is to separate out chunks of UI into separate UserControls.&amp;nbsp;
When you do that, the above trick fails -- even if you put the FocusManager.FocusedElement
binding&amp;nbsp;into the UserControl!&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;How
we solve that is what we'll look at&amp;nbsp;in the next post!&amp;nbsp; Stay tuned...&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;/p&gt;
&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=2974164f-97c1-4e20-85f9-416cf6bed219</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,2974164f-97c1-4e20-85f9-416cf6bed219.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,2974164f-97c1-4e20-85f9-416cf6bed219.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=2974164f-97c1-4e20-85f9-416cf6bed219</wfw:commentRss>
      <title>Part 1: It's Basically Focus</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,2974164f-97c1-4e20-85f9-416cf6bed219.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/09/02/Part1ItsBasicallyFocus.aspx</link>
      <pubDate>Tue, 02 Sep 2008 19:55:39 GMT</pubDate>
      <description>&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;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,2974164f-97c1-4e20-85f9-416cf6bed219.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=507386bd-a72e-455e-b345-315e0dcf35e9</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,507386bd-a72e-455e-b345-315e0dcf35e9.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,507386bd-a72e-455e-b345-315e0dcf35e9.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=507386bd-a72e-455e-b345-315e0dcf35e9</wfw:commentRss>
      <body 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>
      </body>
      <title>Focusing on WPF:  How to deal with Focus() in the WPF world</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,507386bd-a72e-455e-b345-315e0dcf35e9.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/09/01/FocusingOnWPFHowToDealWithFocusInTheWPFWorld.aspx</link>
      <pubDate>Mon, 01 Sep 2008 19:07:39 GMT</pubDate>
      <description>&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;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.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I
looked at the Navigation support in WPF (which is nice) but ultimately decided to
model it around a styled &lt;/font&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;TabControl&lt;/span&gt;&lt;/b&gt;&lt;font face=Calibri&gt; –
each page being a tab and the progress noted through the custom &lt;/font&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;TabItem&lt;/span&gt;&lt;/b&gt;&lt;font face=Calibri&gt; visuals
across the top.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;It all works great and
looks fabulous.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&lt;img height=446 src="http://www.julmar.com/blog/mark/content/binary/navpage_ss.jpg.jpg" width=611 border=0&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;One of the bugs that was logged against the
application and got assigned to me&amp;nbsp;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.&amp;nbsp; &lt;/font&gt;&lt;font face=Calibri color=#000000 size=3&gt;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.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;You
can, of course, also assign focus programmatically but it turns out to not be as easy
as you’d think.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; In fact, I encountered several
nasty gotchas trying to get it to work&amp;nbsp;exactly the way I wanted it to.&amp;nbsp;&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;/span&gt;My
frustrations with focus and how WPF manages it have resulted in this set of blog posts&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&lt;a href="http://www.julmar.com/blog/mark/PermaLink,guid,6e4769e5-a0b3-47b2-a142-6dfefd0c028e.aspx"&gt;Part
1:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Focus Basics&lt;br&gt;
Part 2:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Setting focus in code and XAML&lt;/a&gt;
&lt;br&gt;
&lt;a href="http://www.julmar.com/blog/mark/PermaLink,guid,03722678-882a-4bb4-928f-4fe0d35f051e.aspx"&gt;Part
3:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Getting a little smarter – setting
focus to the first focusable control&lt;br&gt;
&lt;/a&gt;Part 4:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Setting focus to template
items&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,507386bd-a72e-455e-b345-315e0dcf35e9.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=b919500f-b0b7-4abf-8059-be5719e259f8</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,b919500f-b0b7-4abf-8059-be5719e259f8.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,b919500f-b0b7-4abf-8059-be5719e259f8.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=b919500f-b0b7-4abf-8059-be5719e259f8</wfw:commentRss>
      <body 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>
      </body>
      <title>(Possibly) better validations in WPF</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,b919500f-b0b7-4abf-8059-be5719e259f8.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/08/25/PossiblyBetterValidationsInWPF.aspx</link>
      <pubDate>Mon, 25 Aug 2008 14:45:20 GMT</pubDate>
      <description>&lt;p&gt;
I've never cared much for the built-in validation mechanisms provided by WPF.&amp;nbsp;
I just don't think any of them feel natural to the way we build WPF applications today.&amp;nbsp;
Basically, there are essentially three mechanisms built into WPF for validations:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Validation Rules&lt;/li&gt;
&lt;li&gt;
Exceptions&lt;/li&gt;
&lt;li&gt;
IDataErrorInfo&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Validation rules are checked prior to transferring the value from the bound control
to your source (typically the business object).&amp;nbsp; Exceptions are a form of validation
rule - if the property setter throws an exception, it fails validation.&amp;nbsp; Finally, &lt;strong&gt;IDataErrorInfo&lt;/strong&gt; was
added with WPF 3.5 to support validations inside the business objects directly.&amp;nbsp;
Often, you will use one or several of these validation techniques in your WPF application
to check the input.
&lt;/p&gt;
&lt;p&gt;
It's this last scenario&amp;nbsp;(&lt;strong&gt;IDataErrorInfo&lt;/strong&gt;)&amp;nbsp;I want to focus
on in this post.&amp;nbsp; I actually like having validations in the business object -I
think it makes the most sense in&amp;nbsp;most scenarios.&amp;nbsp; However, the interface
itself feels clunky to me - it looks like this:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;interface&lt;/span&gt; IDataErrorInfo&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
string&lt;/span&gt; Error { get; }&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
string&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;[&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; columnName];&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
It's a weird one for sure.&amp;nbsp; 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.&amp;nbsp; 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.
&lt;/p&gt;
&lt;p&gt;
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:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Something must be there&lt;/li&gt;
&lt;li&gt;
It's a certain required length&lt;/li&gt;
&lt;li&gt;
It's a certain required pattern&lt;/li&gt;
&lt;li&gt;
It's a certain range (numeric)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
And I thought to myself, "surely there's a better way!"&amp;nbsp; And so I came up with
an attribute-based validation system.&amp;nbsp; It piggy-backs onto the &lt;strong&gt;IDataErrorInfo&lt;/strong&gt; interface,
but delegates off to a helper class which looks for attributes applied to the properties.&amp;nbsp;
The attributes them provide the validation for you.&amp;nbsp; Here's the idea:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;interface&lt;/span&gt; IValidator&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
string&lt;/span&gt; Validate(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; name, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; value);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;abstract&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; ValidatorBase
: Attribute, IValidator&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;abstract&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Validate(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; name, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; value);&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;The &lt;strong&gt;IValidator&lt;/strong&gt; interface
represents the validation to occur.&amp;nbsp; It get's passed the name of the property
and the current value.&amp;nbsp; We wrap that in an abstract class called ValidatorBase
for most attributes to derive from.&amp;nbsp; Here's a couple of examples:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; RequiredAttribute
: ValidatorBase&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Validate(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; name, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; value)&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return&lt;/span&gt; value == &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt; ||
value.ToString().Length == 0 ? name &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;+&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"
must be supplied."&lt;/span&gt; : &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; RequiredLengthAttribute
: ValidatorBase&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; Minimum
{ get; set; }&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; Maximum
{ get; set; }&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;override&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Validate(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; name, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; value)&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if&lt;/span&gt; (value == &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
int&lt;/span&gt; len &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; value.ToString().Length;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return&lt;/span&gt; (len &amp;gt;= Minimum &amp;amp;&amp;amp; len &amp;lt;= Maximum)&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;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&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;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;.Format(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Length
of {0} must be between {1} and {2}."&lt;/span&gt;, name, Minimum, Maximum);&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;You
could get as complicated as you like - I have in my toolbox a bunch more (Regex validator,
range validator, etc.)&amp;nbsp; Next, we use a validation manager class to do the validations
for us, this is what will implement the logic for &lt;strong&gt;IDataErrorInfo&lt;/strong&gt;:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; ValidationManager&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Validate(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; name, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; instance)&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if&lt;/span&gt; (instance == &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
throw&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"instance"&lt;/span&gt;);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Type type &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; instance.GetType();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var errorList &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;&amp;gt;();&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if&lt;/span&gt; (!&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;.IsNullOrEmpty(name))&lt;br&gt;
&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; ValidateProperty(name, instance,
errorList);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
else&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
foreach&lt;/span&gt; (PropertyInfo pi &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; type.GetProperties(BindingFlags.Public &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;|&lt;/span&gt; BindingFlags.Instance))&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; ValidateProperty(pi.Name,
instance, errorList);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;.Join(Environment.NewLine,
errorList.ToArray());&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; ValidateProperty(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; name, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt; instance,
ICollection&amp;lt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;&amp;gt;
errorList)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type type &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; instance.GetType();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PropertyInfo pi &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; type.GetProperty(name,
BindingFlags.Public &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;|&lt;/span&gt; BindingFlags.Instance);&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if&lt;/span&gt; (pi !&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
object&lt;/span&gt; value &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; pi.GetValue(instance, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;);&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
foreach&lt;/span&gt; (Attribute att &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;in&lt;/span&gt; pi.GetCustomAttributes(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;true&lt;/span&gt;))&lt;br&gt;
&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; var iv &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; att &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;as&lt;/span&gt; IValidator;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&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;
if&lt;/span&gt; (iv !&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&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;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&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;
string&lt;/span&gt; err &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; iv.Validate(name,
value);&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&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;if&lt;/span&gt; (!&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;.IsNullOrEmpty(err))&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;
errorList.Add(err);&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;br&gt;
&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;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;}&lt;br&gt;
&lt;/p&gt;
&lt;/span&gt;&gt;&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;It's
pretty simple - it just uses reflection to walk through the properties and look for
the &lt;strong&gt;IValidator&lt;/strong&gt; interface on any attributes.&amp;nbsp; If it finds any,
it executes the Validate logic and returns a string indicating the failure(s).&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;To
use the above code, you add the attributes&amp;nbsp;to your business object properties.&amp;nbsp;
For example, here is a simple Person object which uses the two validators for it's
name property:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Person
: INotifyPropertyChanged, IDataErrorInfo&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; _name;&lt;br&gt;
&lt;strong&gt;&lt;font color=#ff0000&gt;&amp;nbsp;&amp;nbsp; [Required]&lt;br&gt;
&amp;nbsp;&amp;nbsp; [RequiredLength(Minimum=2, Maximum=10)]&lt;br&gt;
&lt;/font&gt;&lt;/strong&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;
public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Name&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; _name;
}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set { _name &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; value;
OnPropertyChanged(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Name"&lt;/span&gt;);
}&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp; ...&lt;br&gt;
}&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&lt;font face=Verdana color=#003300 size=2&gt;Finally,
you implement the IDataErrorInfo by utilizing the ValidationManager class.&amp;nbsp; 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:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;#region&lt;/span&gt; IDataErrorInfo
Members&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; IDataErrorInfo.Error&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; get { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; ValidationManager.Validate(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;);
}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; IDataErrorInfo.&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;[&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; columnName]&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; get&amp;nbsp;{&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; return&lt;/span&gt; ValidationManager.Validate(columnName, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt;);
}&lt;br&gt;
}&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;#endregion&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&gt;&gt;&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;That's
it!&amp;nbsp; Now, you have an extensible validation mechanism which is reusable and easy
to apply.&amp;nbsp; 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.&amp;nbsp; Feel free to use the above code in your own projects, if you create any
really cool validators, please share!&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;font face=Verdana color=#003300 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,b919500f-b0b7-4abf-8059-be5719e259f8.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=adc227ac-2da6-4ad4-8b7e-e7d5aee32fb2</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,adc227ac-2da6-4ad4-8b7e-e7d5aee32fb2.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,adc227ac-2da6-4ad4-8b7e-e7d5aee32fb2.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=adc227ac-2da6-4ad4-8b7e-e7d5aee32fb2</wfw:commentRss>
      <body 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></body>
      <title>Implementing Drag/Drop with TabControl</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,adc227ac-2da6-4ad4-8b7e-e7d5aee32fb2.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/07/25/ImplementingDragDropWithTabControl.aspx</link>
      <pubDate>Fri, 25 Jul 2008 20:09:45 GMT</pubDate>
      <description>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.&amp;nbsp; Recently I was experimenting with dragging tabs around on a TabControl at runtime.&amp;nbsp; 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.&lt;br&gt;
&lt;br&gt;
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 &lt;a href="http://msdn.microsoft.com/en-us/library/ms749011.aspx"&gt;attached
property&lt;/a&gt;.&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp;
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 &lt;i&gt;without changing
the code in TextBox&lt;/i&gt;.&lt;br&gt;
&lt;br&gt;
Back to my drag/drop prototype.&amp;nbsp; So with this code, I can add the property to
any TabControl and get a nice, simple drag/drop experience.&amp;nbsp; 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.&lt;br&gt;
&lt;br&gt;
Here's the code:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt;
&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.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; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Diagnostics; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Controls; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Input; &lt;span class="kwrd"&gt;using&lt;/span&gt; System.Windows.Media; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; WpfApplication1
{ &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DragDropTabManager
{ &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty
ManagerProperty = DependencyProperty.Register(&lt;span class="kwrd"&gt;typeof&lt;/span&gt; (DragDropTabManager).ToString(), &lt;span class="kwrd"&gt;typeof&lt;/span&gt; (DragDropTabManager), &lt;span class="kwrd"&gt;typeof&lt;/span&gt; (DragDropTabManager)); &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty
EnabledProperty = DependencyProperty.RegisterAttached(&lt;span class="str"&gt;"Enabled"&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;bool&lt;/span&gt;), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(DragDropTabManager), &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyMetadata(&lt;span class="kwrd"&gt;false&lt;/span&gt;,
DDTM_EnabledChanged)); &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DDTM_EnabledChanged(DependencyObject
d, DependencyPropertyChangedEventArgs e) { var tc = d &lt;span class="kwrd"&gt;as&lt;/span&gt; TabControl; &lt;span class="kwrd"&gt;if&lt;/span&gt; (tc
!= &lt;span class="kwrd"&gt;null&lt;/span&gt;) { var oldValue = (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)
e.OldValue; var newValue = (&lt;span class="kwrd"&gt;bool&lt;/span&gt;) e.NewValue; &lt;span class="kwrd"&gt;if&lt;/span&gt; (oldValue
== &lt;span class="kwrd"&gt;true&lt;/span&gt; &amp;amp;&amp;amp; newValue == &lt;span class="kwrd"&gt;false&lt;/span&gt;)
{ var ddtm = tc.GetValue(ManagerProperty) &lt;span class="kwrd"&gt;as&lt;/span&gt; DragDropTabManager; &lt;span class="kwrd"&gt;if&lt;/span&gt; (ddtm
!= &lt;span class="kwrd"&gt;null&lt;/span&gt;) { tc.PreviewMouseDown -= ddtm.TabItem_PreviewMouseDown;
tc.SetValue(ManagerProperty, &lt;span class="kwrd"&gt;null&lt;/span&gt;); } } &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (oldValue
== &lt;span class="kwrd"&gt;false&lt;/span&gt; &amp;amp;&amp;amp; newValue == &lt;span class="kwrd"&gt;true&lt;/span&gt;)
{ var ddtm = &lt;span class="kwrd"&gt;new&lt;/span&gt; DragDropTabManager(); tc.SetValue(ManagerProperty,
ddtm); tc.PreviewMouseDown += ddtm.TabItem_PreviewMouseDown; } } } &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; GetEnabled(DependencyObject
obj) { &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)obj.GetValue(EnabledProperty);
} &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetEnabled(DependencyObject
obj, &lt;span class="kwrd"&gt;bool&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;) { obj.SetValue(EnabledProperty, &lt;span class="kwrd"&gt;value&lt;/span&gt;);
} &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; isMoving; &lt;span class="kwrd"&gt;private&lt;/span&gt; TabItem
movingTabItem; &lt;span class="kwrd"&gt;private&lt;/span&gt; TabItem lastTab; &lt;span class="kwrd"&gt;private&lt;/span&gt; Point
ptStart; &lt;span class="kwrd"&gt;void&lt;/span&gt; TabItem_PreviewMouseDown(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
MouseEventArgs e) { var ti = e.Source &lt;span class="kwrd"&gt;as&lt;/span&gt; TabItem; &lt;span class="kwrd"&gt;if&lt;/span&gt; (ti
!= &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; e.LeftButton == MouseButtonState.Pressed)
{ var tc = ti.Parent &lt;span class="kwrd"&gt;as&lt;/span&gt; TabControl; &lt;span class="kwrd"&gt;if&lt;/span&gt; (tc
!= &lt;span class="kwrd"&gt;null&lt;/span&gt;) { tc.MouseMove += tc_MouseMove; tc.MouseLeftButtonUp
+= tc_MouseLeftButtonUp; ptStart = e.GetPosition(tc); movingTabItem = ti; } } } &lt;span class="kwrd"&gt;void&lt;/span&gt; tc_MouseMove(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
MouseEventArgs e) { var tc = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; TabControl; &lt;span class="kwrd"&gt;if&lt;/span&gt; (tc
== &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt;; Point pt = e.GetPosition(tc); &lt;span class="kwrd"&gt;if&lt;/span&gt; (isMoving
== &lt;span class="kwrd"&gt;false&lt;/span&gt;) { &lt;span class="kwrd"&gt;if&lt;/span&gt; (Math.Abs(pt.X
- ptStart.X) &amp;gt; 10) { movingTabItem.IsHitTestVisible = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
movingTabItem.RenderTransformOrigin = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(.5, .5);
movingTabItem.RenderTransform = &lt;span class="kwrd"&gt;new&lt;/span&gt; TranslateTransform(0,
0); tc.Cursor = Cursors.Hand; Panel.SetZIndex(movingTabItem, 1); isMoving = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
tc.CaptureMouse(); } &lt;span class="kwrd"&gt;return&lt;/span&gt;; } TabItem newPos = FindTabItem(tc,
pt); &lt;span class="kwrd"&gt;if&lt;/span&gt; (newPos == &lt;span class="kwrd"&gt;null&lt;/span&gt;) tc.Cursor
= Cursors.No; &lt;span class="kwrd"&gt;else&lt;/span&gt; { lastTab = newPos; var xform = movingTabItem.RenderTransform &lt;span class="kwrd"&gt;as&lt;/span&gt; TranslateTransform; &lt;span class="kwrd"&gt;if&lt;/span&gt; (xform
!= &lt;span class="kwrd"&gt;null&lt;/span&gt;) xform.X = pt.X - ptStart.X; tc.Cursor = Cursors.Hand;
} } &lt;span class="kwrd"&gt;void&lt;/span&gt; tc_MouseLeftButtonUp(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
MouseButtonEventArgs e) { var tc = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; TabControl;
Debug.Assert(tc != &lt;span class="kwrd"&gt;null&lt;/span&gt;); tc.ReleaseMouseCapture(); tc.MouseMove
-= tc_MouseMove; tc.MouseLeftButtonUp -= tc_MouseLeftButtonUp; &lt;span class="kwrd"&gt;if&lt;/span&gt; (isMoving
== &lt;span class="kwrd"&gt;true&lt;/span&gt;) { isMoving = &lt;span class="kwrd"&gt;false&lt;/span&gt;; tc.Cursor
= Cursors.Arrow; movingTabItem.RenderTransform = &lt;span class="kwrd"&gt;null&lt;/span&gt;; movingTabItem.IsHitTestVisible
= &lt;span class="kwrd"&gt;true&lt;/span&gt;; Panel.SetZIndex(movingTabItem, 0); &lt;span class="kwrd"&gt;if&lt;/span&gt; (lastTab
!= &lt;span class="kwrd"&gt;null&lt;/span&gt;) { &lt;span class="kwrd"&gt;if&lt;/span&gt; (lastTab != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
movingTabItem != lastTab) { &lt;span class="kwrd"&gt;int&lt;/span&gt; targetIndex = tc.Items.IndexOf(lastTab);
tc.Items.Remove(movingTabItem); tc.Items.Insert(targetIndex, movingTabItem); movingTabItem.Focus();
} } } movingTabItem = lastTab = &lt;span class="kwrd"&gt;null&lt;/span&gt;; } &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; TabItem
FindTabItem(UIElement parent, Point pt) { var fe = parent.InputHitTest(pt) &lt;span class="kwrd"&gt;as&lt;/span&gt; FrameworkElement; &lt;span class="kwrd"&gt;while&lt;/span&gt; (fe
!= &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; fe.GetType() != &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TabItem))
fe = VisualTreeHelper.GetParent(fe) &lt;span class="kwrd"&gt;as&lt;/span&gt; FrameworkElement; &lt;span class="kwrd"&gt;return&lt;/span&gt; fe &lt;span class="kwrd"&gt;as&lt;/span&gt; TabItem;
} } } &lt;/pre&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,adc227ac-2da6-4ad4-8b7e-e7d5aee32fb2.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=725cf1d9-3dc7-48f1-89f0-da8e3f3cfccb</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,725cf1d9-3dc7-48f1-89f0-da8e3f3cfccb.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,725cf1d9-3dc7-48f1-89f0-da8e3f3cfccb.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=725cf1d9-3dc7-48f1-89f0-da8e3f3cfccb</wfw:commentRss>
      <body 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.</body>
      <title>Creating popup windows in XBAP applications</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,725cf1d9-3dc7-48f1-89f0-da8e3f3cfccb.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2008/04/03/CreatingPopupWindowsInXBAPApplications.aspx</link>
      <pubDate>Thu, 03 Apr 2008 14:47:05 GMT</pubDate>
      <description>A colleague at &lt;a href="http://www.develop.com"&gt;DevelopMentor&lt;/a&gt; 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 &lt;strong&gt;SecurityException&lt;/strong&gt; because
WPF asks for &lt;strong&gt;UIPermission&lt;/strong&gt; which is strictly prohibited when hosted
in the browser. It turns out, however, that you &lt;em&gt;can&lt;/em&gt; get a popup window -
there's a hidden little gem in the &lt;strong&gt;System.Windows.Controls.Primitive&lt;/strong&gt; namespace
that is your friend: &lt;strong&gt;Popup&lt;/strong&gt;. 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:&lt;br&gt;
&amp;nbsp; &lt;style type="text/css"&gt;

.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; }

&lt;/style&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; OnClick(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
EventArgs e)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; Popup window = &lt;span class="kwrd"&gt;new&lt;/span&gt; Popup();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; StackPanel sp = &lt;span class="kwrd"&gt;new&lt;/span&gt; StackPanel
{ Margin = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thickness(5) };&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; sp.Children.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; TextBlock
{ Text = &lt;span class="str"&gt;"Hi from a popup"&lt;/span&gt; });&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; Button newButton = &lt;span class="kwrd"&gt;new&lt;/span&gt; Button
{ Content = &lt;span class="str"&gt;"Another button"&lt;/span&gt; };&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; newButton.Click += &lt;span class="kwrd"&gt;delegate&lt;/span&gt; {
window.IsOpen = &lt;span class="kwrd"&gt;false&lt;/span&gt;; };&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; sp.Children.Add(newButton);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; sp.Children.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Slider
{ Minimum = 0, Maximum = 50, Value = 25, Width = 100 });&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; window.Child = &lt;span class="kwrd"&gt;new&lt;/span&gt; Border
{ Background = Brushes.White, BorderBrush = Brushes.Black, 
&lt;br&gt;
BorderThickness = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thickness(2), Child = sp };&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; &lt;b&gt;window.PlacementTarget = &lt;span class="kwrd"&gt;this&lt;/span&gt;&lt;/b&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; window.Placement = PlacementMode.Center;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; window.IsOpen = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
The key thing you need to do is set the &lt;strong&gt;PlacementTarget&lt;/strong&gt;. That associates
a "parent" window and without it, the &lt;strong&gt;Popup&lt;/strong&gt; class asserts &lt;strong&gt;UIPermission&lt;/strong&gt; which will fail in the browser environment.</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,725cf1d9-3dc7-48f1-89f0-da8e3f3cfccb.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=a7d85c0f-d41d-4702-b57f-efecc1ac30e9</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,a7d85c0f-d41d-4702-b57f-efecc1ac30e9.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:comment>http://www.julmar.com/blog/mark/CommentView,guid,a7d85c0f-d41d-4702-b57f-efecc1ac30e9.aspx</wfw:comment>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=a7d85c0f-d41d-4702-b57f-efecc1ac30e9</wfw:commentRss>
      <body 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>
      </body>
      <title>Playing with VS.NET 2008 .. </title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,a7d85c0f-d41d-4702-b57f-efecc1ac30e9.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2007/07/16/PlayingWithVSNET2008.aspx</link>
      <pubDate>Mon, 16 Jul 2007 18:26:30 GMT</pubDate>
      <description>&lt;p&gt;
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!).
&lt;/p&gt;
&lt;p&gt;
The layout support is much better as well - you finally get the drag handles and positioning
lines.
&lt;/p&gt;
&lt;img border="0" src="http://www.julmar.com/blog/mark/content/binary/vsnet2008_1.jpg"&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;p&gt;
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).
&lt;/p&gt;
&lt;p&gt;
Overall, I'm seeing some good progress - here's hoping for more as the product matures!
&lt;/p&gt;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,a7d85c0f-d41d-4702-b57f-efecc1ac30e9.aspx</comments>
      <category>.NET</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.julmar.com/blog/mark/Trackback.aspx?guid=5716861f-5560-40c7-b700-483e0cd80116</trackback:ping>
      <pingback:server>http://www.julmar.com/blog/mark/pingback.aspx</pingback:server>
      <pingback:target>http://www.julmar.com/blog/mark/PermaLink,guid,5716861f-5560-40c7-b700-483e0cd80116.aspx</pingback:target>
      <dc:creator>Mark</dc:creator>
      <wfw:commentRss>http://www.julmar.com/blog/mark/SyndicationService.asmx/GetEntryCommentsRss?guid=5716861f-5560-40c7-b700-483e0cd80116</wfw:commentRss>
      <title>WPF Data Providers</title>
      <guid isPermaLink="false">http://www.julmar.com/blog/mark/PermaLink,guid,5716861f-5560-40c7-b700-483e0cd80116.aspx</guid>
      <link>http://www.julmar.com/blog/mark/2007/01/17/WPFDataProviders.aspx</link>
      <pubDate>Wed, 17 Jan 2007 10:57:58 GMT</pubDate>
      <description>&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;</description>
      <comments>http://www.julmar.com/blog/mark/CommentView,guid,5716861f-5560-40c7-b700-483e0cd80116.aspx</comments>
      <category>.NET</category>
      <category>Code</category>
      <category>WPF</category>
    </item>
  </channel>
</rss>