<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel xmlns:blog="http://www.dotnetnuke.com/blog/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
    <title>Richard Waddell</title>
    <description>Richard Waddell on Silverlight</description>
    <link>http://www.openlightgroup.net/Blog/tabid/58/BlogId/3/Default.aspx</link>
    <language>en-US</language>
    <webMaster />
    <pubDate>Sat, 04 Feb 2012 11:34:30 GMT</pubDate>
    <lastBuildDate>Sat, 04 Feb 2012 11:34:30 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 4.1.0.0</generator>
    <item>
      <title>LightSwitch Book Inventory Tracker Part 1</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/167/LightSwitch-Book-Inventory-Tracker-Part-1.aspx</link>
      <description>&lt;p&gt;&lt;a href="http://www.openlightgroup.nethttp://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_206.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_102.png" width="1028" height="368" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I’m using &lt;strong&gt;LightSwitch&lt;/strong&gt; as a prototyping tool to get a jump start on a project at work that I took over from a long-exited programmer. The design I inherited has a lot of gaps that need to be filled in. I think the quickest way I can display those to my boss is to create the tables and basic maintenance screens so I can easily point out what’s there and what’s missing. &lt;strong&gt;LightSwitch&lt;/strong&gt; inherently expresses database relationships in the screens it creates, so even if you aren’t going to use &lt;strong&gt;LightSwitch&lt;/strong&gt; in the final application, you can quickly throw together and easily modify the table layout as you create the basic application in &lt;strong&gt;LightSwitch&lt;/strong&gt;. Then you can step through the resulting screens and clearly see the table relationships with errors in design jumping right out at you.&lt;/p&gt;  &lt;h3&gt;The Requirements&lt;/h3&gt;  &lt;p&gt;The client has a need to track books as they move between various locations.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Locations&lt;/strong&gt; contain multiple &lt;strong&gt;Buildings&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Buildings&lt;/strong&gt; contain multiple &lt;strong&gt;Rooms&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Books&lt;/strong&gt; are always assigned to one of:       &lt;ul&gt;       &lt;li&gt;A particular &lt;strong&gt;Room&lt;/strong&gt; &lt;/li&gt;        &lt;li&gt;&lt;strong&gt;OpenInventory&lt;/strong&gt;, which has no specified location &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Books&lt;/strong&gt; can be transferred:       &lt;ul&gt;       &lt;li&gt;From &lt;strong&gt;Room&lt;/strong&gt; to &lt;strong&gt;Room &lt;/strong&gt;across all &lt;strong&gt;Buildings&lt;/strong&gt; at all &lt;strong&gt;Locations&lt;/strong&gt; &lt;/li&gt;        &lt;li&gt;From any &lt;strong&gt;Room&lt;/strong&gt; to &lt;strong&gt;OpenInventory&lt;/strong&gt; &lt;/li&gt;        &lt;li&gt;To&lt;strong&gt; OpenInventory&lt;/strong&gt; from any &lt;strong&gt;Room&lt;/strong&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;An &lt;strong&gt;AssignedInventory&lt;/strong&gt; table row records the quantity and is uniquely identified by       &lt;ul&gt;       &lt;li&gt;&lt;strong&gt;Book&lt;/strong&gt; &lt;/li&gt;        &lt;li&gt;&lt;strong&gt;Room&lt;/strong&gt; &lt;/li&gt;        &lt;li&gt;Condition &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;An &lt;strong&gt;OpenInventory&lt;/strong&gt; table row records quantity and is uniquely identified by       &lt;ul&gt;       &lt;li&gt;&lt;strong&gt;Book&lt;/strong&gt; &lt;/li&gt;        &lt;li&gt;Condition &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;OpenInventoryTransfers&lt;/strong&gt; and &lt;strong&gt;AssignedInventoryTransfers&lt;/strong&gt; include       &lt;ul&gt;       &lt;li&gt;&lt;strong&gt;Book&lt;/strong&gt; &lt;/li&gt;        &lt;li&gt;Condition &lt;/li&gt;        &lt;li&gt;Quantity Sent &lt;/li&gt;        &lt;li&gt;Received &lt;/li&gt;        &lt;li&gt;Quantity Received New &lt;/li&gt;        &lt;li&gt;Quantity Received Used &lt;/li&gt;        &lt;li&gt;Condition Variance &lt;/li&gt;        &lt;li&gt;Quantity Variance &lt;/li&gt;        &lt;li&gt;Source (Open Inventory or Room) &lt;/li&gt;        &lt;li&gt;Destination (Open Inventory or Room) &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The nice thing about &lt;strong&gt;LightSwitch&lt;/strong&gt; is that I can define classes, primarily in the form of table layout, that simultaneously define the underlying tables and the entities that represent them.  For instance, a &lt;strong&gt;Location&lt;/strong&gt; class instance will have a &lt;strong&gt;Buildings&lt;/strong&gt; collection property because I defined the one-to-many relationship between &lt;strong&gt;Location&lt;/strong&gt; and &lt;strong&gt;Building&lt;/strong&gt;. The underlying database will contain a &lt;strong&gt;Buildings&lt;/strong&gt; table where each row holds a foreign key on a &lt;strong&gt;Locations&lt;/strong&gt; table row. But I only see that represented logically, as a collection property in the &lt;strong&gt;Location&lt;/strong&gt; class. And because I defined that relationship, &lt;strong&gt;LightSwitch&lt;/strong&gt; can automatically generate a screen to maintain &lt;strong&gt;Location&lt;/strong&gt; and &lt;strong&gt;Building&lt;/strong&gt; records in a master/detail screen. I don’t have to create &lt;strong&gt;GridViews&lt;/strong&gt; or the &lt;strong&gt;ListBoxes&lt;/strong&gt; that bind to &lt;strong&gt;Linq&lt;/strong&gt; queries written by me, and I don’t have to do it over and over again.&lt;/p&gt;  &lt;p&gt;First, create the project:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb.png" width="644" height="364" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In &lt;strong&gt;Solution&lt;/strong&gt; &lt;strong&gt;Explorer&lt;/strong&gt;, you can right-click / &lt;strong&gt;Open&lt;/strong&gt; &lt;strong&gt;Properties&lt;/strong&gt;, or double-click&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_1.png" width="644" height="344" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Under&lt;strong&gt; Application Type&lt;/strong&gt; select the&lt;strong&gt; Web Radio&lt;/strong&gt; Button:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_2.png" width="644" height="287" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now we start adding tables:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_3.png" width="644" height="392" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Instead of creating all the tables and then the screens, I’m going to create one table at a time, working from the bottom up, and create the requisite screens at that point. This will probably mean deleting and re-creating some screens as the design plays out, but it’s so easy it doesn’t really matter. And I could use the screen designer to make the changes.&lt;/p&gt;  &lt;p&gt;Let’s begin with the &lt;strong&gt;Book&lt;/strong&gt; table. Create the columns as shown and make &lt;strong&gt;ISBN&lt;/strong&gt; a unique index:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_12.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_5.png" width="644" height="297" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You might want to have a separate Authors table, but the design I was given specifies Author name in the &lt;strong&gt;Book&lt;/strong&gt; table.&lt;/p&gt;  &lt;p&gt;We want to validate &lt;strong&gt;ISBN&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_14.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_6.png" width="644" height="421" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Eventually we’ll want to allow for hyphens and validate that the &lt;strong&gt;ISBN &lt;/strong&gt;is well-formed,  but for now we’ll just check for a &lt;a href="http://en.wikipedia.org/wiki/International_Standard_Book_Number" target="_blank"&gt;length of 10 or 13&lt;/a&gt; and all numeric digits:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;partial &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ISBN_Validate(EntityValidationResultsBuilder results)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ISBN.Length != 10 &amp;&amp; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ISBN.Length != 13)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        results.AddPropertyError("&lt;span style="color: #8b0000"&gt;ISBN must be either 10 or 13 digits long&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;char&lt;/span&gt; ch &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ISBN)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (ch &lt; '0' || ch &gt; '9')
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                results.AddPropertyError("&lt;span style="color: #8b0000"&gt;ISBN must be all numeric&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Probably I could have checked for a Long Positive Integer, but In general I only like to treat numeric strings as numbers when they’re actually used as numbers. Anyway, this code will ultimately have to validate an actual &lt;strong&gt;ISBN&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now we’ll generate a screen so we can do &lt;strong&gt;CRUD&lt;/strong&gt; operations on &lt;strong&gt;Books&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_16.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_7.png" width="597" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Editable Grid Screen&lt;/strong&gt; &lt;strong&gt;(1)&lt;/strong&gt; is what we want. By selecting &lt;strong&gt;Books&lt;/strong&gt; &lt;strong&gt;(2)&lt;/strong&gt; in the &lt;strong&gt;Screen Data&lt;/strong&gt; dropdown we get the &lt;strong&gt;Screen Name&lt;/strong&gt; &lt;strong&gt;(3)&lt;/strong&gt; of &lt;strong&gt;EditableBooksGrid&lt;/strong&gt;. Let’s stick with that, at least for now.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_18.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_8.png" width="644" height="389" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And that’s it. Hit Ctl-F5 and let’s see what we have.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_24.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_11.png" width="1028" height="605" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;We see the screen we just added in the menu &lt;strong&gt;(1)&lt;/strong&gt; and it’s the default tab in a tabbed view &lt;strong&gt;(2)&lt;/strong&gt; that we can page through &lt;strong&gt;(3)&lt;/strong&gt;. We have controls to do CRUD operations &lt;strong&gt;(4)&lt;/strong&gt; and to save and load the &lt;strong&gt;Books&lt;/strong&gt; table &lt;strong&gt;(5)&lt;/strong&gt;. As a bonus, if we’re running in debug mode we can change the screen design at runtime &lt;strong&gt;(6)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We’re about to add some definitions of &lt;strong&gt;Books&lt;/strong&gt;, by creating instances of the &lt;strong&gt;Books&lt;/strong&gt; entity, which will be stored in rows in the &lt;strong&gt;Books&lt;/strong&gt; table, but first let’s adjust the column layout a bit. Even though &lt;strong&gt;ISBN&lt;/strong&gt; is the unique key, I’d prefer to see &lt;strong&gt;Title&lt;/strong&gt; in the first column. That’s pretty easy to do. Select the &lt;strong&gt;EditableBooksGrid&lt;/strong&gt; screen in &lt;strong&gt;Solution&lt;/strong&gt; &lt;strong&gt;Explorer&lt;/strong&gt;, then just drag &lt;strong&gt;Title&lt;/strong&gt; so it’s above &lt;strong&gt;ISBN&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_28.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_13.png" width="1028" height="459" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;By selecting the green plus sign Icon we can enter the &lt;strong&gt;Book&lt;/strong&gt; into an individual form. Below I’ve done that. As soon as I enter a value in &lt;strong&gt;ISBN&lt;/strong&gt; and tab away validation finds and displays my error:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_30.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_14.png" width="598" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So I’ll correct the length, but leave in an alpha character. Below I’ve clicked on the field so you can see how the message is displayed in that case. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_32.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_15.png" width="631" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I’ll enter a ‘valid’ &lt;strong&gt;ISBN&lt;/strong&gt; and leave the required &lt;strong&gt;Title&lt;/strong&gt; and  &lt;strong&gt;Name&lt;/strong&gt; fields blank then click &lt;strong&gt;OK.&lt;/strong&gt; One quirk with this validation is that you can tab away from an empty required field without triggering the error, if it starts out empty. That’s because binding is only triggered when the value changes, and the validation occurs as a result of binding. Leaving an input field empty does not change the value, so these errors of omission are not caught until you click &lt;strong&gt;OK&lt;/strong&gt; and trigger overall form validation.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_34.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_16.png" width="644" height="298" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;To show you the difference, I cleared out the first record entirely by clicking on the ‘X’ icon, entered a character in the &lt;strong&gt;Title&lt;/strong&gt; field, tabbed to and entered &lt;strong&gt;ISBN&lt;/strong&gt;, then tabbed back to &lt;strong&gt;Title&lt;/strong&gt; cleared it and tabbed away. I got this message immediately. Notice the error message wording is different, which implies that the business rule is being defined twice in the underlying code. Fortunately &lt;strong&gt;LightSwitch&lt;/strong&gt; handles that, so I don’t have to remember to maintain it in two places:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_36.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_17.png" width="644" height="267" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now I’ll enter duplicate &lt;strong&gt;ISBN&lt;/strong&gt; numbers. When I click on the &lt;strong&gt;Save&lt;/strong&gt; icon a modal generic error message box appears (not shown) followed by:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_38.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_18.png" width="644" height="319" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;One last thing, and then we’ll move on. This form is wasteful of screen space so let’s make some adjustments, but let’s do it at run-time by clicking F5 to run in debug mode, then clicking on the  &lt;strong&gt;Design Screen&lt;/strong&gt; icon in the upper right corner of the screen. Select &lt;strong&gt;ISBN&lt;/strong&gt; and set the &lt;strong&gt;Width&lt;/strong&gt; to 90 pixels and click &lt;strong&gt;Save&lt;/strong&gt;. You can try MaxWidth, but I ended up with padding on the left when I did, and specifying the number of characters doesn’t work any better than it does in HTML:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_40.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_19.png" width="1028" height="736" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Do the equivalent for the &lt;strong&gt;Name&lt;/strong&gt; fields and it looks a lot more reasonable:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_42.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_20.png" width="685" height="265" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I entered Mark Twain’s first and last name in the wrong order which gives me an opportunity to show you what you get if you select ‘Tom Sawyer’ and click on the Pencil icon:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_44.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_21.png" width="644" height="294" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I correct the name and press ok, but I still have to click on the &lt;strong&gt;Save&lt;/strong&gt; icon to actually make the changes to the data. If I try to exit the screen without clicking on &lt;strong&gt;Save&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_48.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_23.png" width="644" height="292" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And now for something completely different. Not really, we’re just going to the other extreme in the sense that I said I was going to do the tables from the bottom up. But now I’m going to start at the top and define the &lt;strong&gt;Location&lt;/strong&gt; table because &lt;strong&gt;Location&lt;/strong&gt; is the other entity that has no dependencies on other entities / tables, which means I can create the &lt;strong&gt;Location&lt;/strong&gt; screen as soon as I create the table. Then I’m going to create the &lt;strong&gt;Buildings&lt;/strong&gt; table and show you something wonderful.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_50.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_24.png" width="644" height="384" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Actually, I think I’ll go ahead and create the &lt;strong&gt;Buildings&lt;/strong&gt; table. Note the default naming convention in effect. I create a &lt;strong&gt;Building&lt;/strong&gt; class (single tense) and instances of the class, or at least the elements of which must persist, are stored as rows in the &lt;strong&gt;Buildings&lt;/strong&gt; table (multiple tense). &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_52.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_25.png" width="644" height="350" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The address fields are optional for &lt;strong&gt;Building&lt;/strong&gt;. It may be that we want to restrict access to the &lt;strong&gt;Building&lt;/strong&gt; can only be reached through the &lt;strong&gt;Location’s&lt;/strong&gt; address so it’s a business rule that the &lt;strong&gt;Building&lt;/strong&gt; address can be null.&lt;/p&gt;

&lt;p&gt;Now the magic starts to happen. I said up front that a &lt;strong&gt;Location&lt;/strong&gt; may have many &lt;strong&gt;Buildings&lt;/strong&gt;. We can set that up with just a few mouse-clicks:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_54.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_26.png" width="850" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Edit the &lt;strong&gt;Building&lt;/strong&gt; class &lt;strong&gt;(1).&lt;/strong&gt; Click on &lt;strong&gt;Relationship…&lt;/strong&gt; &lt;strong&gt;(2).&lt;/strong&gt; A dialog box comes up as shown above. The &lt;strong&gt;From&lt;/strong&gt; table is &lt;strong&gt;Building&lt;/strong&gt; &lt;strong&gt;(3)&lt;/strong&gt; and it’s on the many side of a one-to-many relationship. In the graphic you can see the infinity sign next to the &lt;strong&gt;Building&lt;/strong&gt; icon &lt;strong&gt;(4)&lt;/strong&gt; and a ‘1’ &lt;strong&gt;(5)&lt;/strong&gt; next to the icon representing the still-to-be-designated ‘Master’ table , which will be &lt;strong&gt;Locations&lt;/strong&gt;. We could have started by editing the &lt;strong&gt;Location&lt;/strong&gt; class, but then we would have to switched around the tables in the &lt;strong&gt;Add New Relationship &lt;/strong&gt;dialog box.&lt;/p&gt;

&lt;p&gt;As shown below, choose &lt;strong&gt;Location&lt;/strong&gt; for the &lt;strong&gt;To&lt;/strong&gt; table &lt;strong&gt;(1).&lt;/strong&gt; The semantics are a little fuzzy in that the table names are actually &lt;strong&gt;Locations&lt;/strong&gt; and &lt;strong&gt;Buildings&lt;/strong&gt;. The right icon &lt;strong&gt;(2)&lt;/strong&gt; is now labeled &lt;strong&gt;Location&lt;/strong&gt; with the enclosed word &lt;strong&gt;Buildings&lt;/strong&gt; representing the &lt;strong&gt;Buildings&lt;/strong&gt; collection associated with the &lt;strong&gt;Location&lt;/strong&gt;. In Sql Server parlance this would equate to the &lt;strong&gt;Building&lt;/strong&gt; rows that hold foreign key pointers on the &lt;strong&gt;Location&lt;/strong&gt; table. The ‘1’ indicates that &lt;strong&gt;Location&lt;/strong&gt; is the one side of the one-to-many relationship.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_58.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_28.png" width="541" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After selecting &lt;strong&gt;Location&lt;/strong&gt;, on the left side we have the &lt;strong&gt;Building&lt;/strong&gt; icon &lt;strong&gt;(3)&lt;/strong&gt; with the embedded word &lt;strong&gt;Location&lt;/strong&gt; representing the one and only &lt;strong&gt;Location&lt;/strong&gt; that the &lt;strong&gt;Building&lt;/strong&gt; can be associated with. Again, this is the &lt;strong&gt;Location&lt;/strong&gt; row that the &lt;strong&gt;Building&lt;/strong&gt; row &lt;strong&gt;Location&lt;/strong&gt; foreign key points to. The infinity sign indicates that &lt;strong&gt;Building&lt;/strong&gt; is on the many side of the one-to-many relationship.&lt;/p&gt;

&lt;p&gt;You can see the referential rules inferred from the relationship. &lt;strong&gt;(4).  &lt;/strong&gt;Until you’re used to the interface it’s possible you’ll get the relationships backwards sometimes. Looking at these rules when you set up the relationship is your best chance of catching that early. In this case, if they said a &lt;strong&gt;Location&lt;/strong&gt; must have a &lt;strong&gt;Building&lt;/strong&gt;, I’d know I got it backwards&lt;/p&gt;

&lt;p&gt;Actually I think if I’d paid closer attention to labels, as in &lt;strong&gt;Navigation&lt;/strong&gt; &lt;strong&gt;Property&lt;/strong&gt; &lt;strong&gt;(5)&lt;/strong&gt; I wouldn’t have had my relationship problems. if you’re not used to the interface and are just zipping along doing your RAD thing it’s easy to take the &lt;strong&gt;Navigation&lt;/strong&gt; &lt;strong&gt;Property&lt;/strong&gt; value in the &lt;strong&gt;From&lt;/strong&gt; column as the &lt;strong&gt;From&lt;/strong&gt; table, when of course it’s just the opposite, so just be aware and maybe you won’t make the same mistake. &lt;/p&gt;

&lt;p&gt;In general, if you are editing the class that represents the table on the many side, in this case &lt;strong&gt;Building&lt;/strong&gt;,  when you click on &lt;strong&gt;Relationship&lt;/strong&gt;… then the default settings in the &lt;strong&gt;Add New Relationship…&lt;/strong&gt; dialog will be the ones you intend.&lt;/p&gt;

&lt;p&gt;Now when we look at the &lt;strong&gt;Building&lt;/strong&gt; class below we see more symbols to indicate the relationship between &lt;strong&gt;Location&lt;/strong&gt; and &lt;strong&gt;Building&lt;/strong&gt;. You can see the ‘1’ next to the &lt;strong&gt;Location&lt;/strong&gt; icon and the infinity symbol next to the &lt;strong&gt;Location&lt;/strong&gt; column / property in the &lt;strong&gt;Building&lt;/strong&gt; table / class. This indicates there may be many &lt;strong&gt;Buildings&lt;/strong&gt;, but because it’s next to the word &lt;strong&gt;Location&lt;/strong&gt; it’s easy to read incorrectly at a glance. I thinks it’s just a matter of building the visual associations through repetition so it becomes second nature.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_60.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_29.png" width="610" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I used the terms ‘column / property’ and ‘table / class’ to emphasize that you don’t really have to worry about which is which. How great is it that you can build tables, add the relationships, and those relationships are automatically expressed in the  generated classes that model that data?&lt;/p&gt;

&lt;p&gt;So here’s the cool part, we’re going to create a screen that lets us maintain both &lt;strong&gt;Locations&lt;/strong&gt; and &lt;strong&gt;Buildings&lt;/strong&gt;. This is the second place you might notice that you got the relationship backwards. If you don’t see a &lt;strong&gt;Location&lt;/strong&gt; &lt;strong&gt;Buildings&lt;/strong&gt; checkbox then you forgot to set up the relationship or you got it backwards:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_62.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_30.png" width="644" height="458" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select &lt;strong&gt;List and Details Screen&lt;/strong&gt; and the &lt;strong&gt;Locations&lt;/strong&gt; table in the&lt;strong&gt; Screen Data&lt;/strong&gt; dropdown. Uncheck &lt;strong&gt;Location Details&lt;/strong&gt; and make sure&lt;strong&gt; Location Buildings&lt;/strong&gt; is checked. Select ‘Ok’ and click ctrl-F5 to run the application:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_64.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_31.png" width="644" height="283" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We select the &lt;strong&gt;Locations List Detail&lt;/strong&gt; entry in the menu &lt;strong&gt;(1)&lt;/strong&gt; which brings up the tabbed page &lt;strong&gt;(2)&lt;/strong&gt;. The &lt;strong&gt;Locations&lt;/strong&gt; list box &lt;strong&gt;(3)&lt;/strong&gt; will show all the &lt;strong&gt;Locations&lt;/strong&gt;. The &lt;strong&gt;Buildings&lt;/strong&gt; list box &lt;strong&gt;(4)&lt;/strong&gt; will show the collection of &lt;strong&gt;Buildings&lt;/strong&gt; associated with the currently selected &lt;strong&gt;Location&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Click on the green plus sign icon under &lt;strong&gt;Locations&lt;/strong&gt; to add one:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_68.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_33.png" width="644" height="292" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now here’s a test for &lt;strong&gt;LightSwitch&lt;/strong&gt;. We haven’t actually added a &lt;strong&gt;Location&lt;/strong&gt; record yet because we haven’t clicked &lt;strong&gt;Save&lt;/strong&gt;. Will LightSwitch allow us to add a &lt;strong&gt;Building&lt;/strong&gt; to the still to be created &lt;strong&gt;Museum of Science Fiction Location&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_70.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_34.png" width="644" height="290" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Here we go:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_72.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_35.png" width="644" height="430" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So far, so good. All that remains is to click on the &lt;strong&gt;Save&lt;/strong&gt; icon, and when I do, it works. &lt;/p&gt;

&lt;p&gt;We haven’t done any validation of the input. What do we need? In the case of &lt;strong&gt;Location&lt;/strong&gt;, I have a general rule I’m making up right now is that every entity needs a unique identifier that can be displayed. &lt;strong&gt;Location&lt;/strong&gt; does not exist within the context of any other entity so for &lt;strong&gt;Location&lt;/strong&gt; the &lt;strong&gt;Name&lt;/strong&gt; property will be unique:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_74.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_36.png" width="644" height="363" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We want &lt;strong&gt;Building&lt;/strong&gt; &lt;strong&gt;Name&lt;/strong&gt; to be unique within &lt;strong&gt;Location&lt;/strong&gt;. &lt;strong&gt;LightSwitch&lt;/strong&gt; is up to it:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_76.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_37.png" width="644" height="262" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_78.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_38.png" width="644" height="333" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LightSwitch&lt;/strong&gt; adds a compound unique index that includes &lt;strong&gt;Name&lt;/strong&gt; and &lt;strong&gt;Location&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_80.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_39.png" width="644" height="246" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I can use the same &lt;strong&gt;Name&lt;/strong&gt; at a different &lt;strong&gt;Location&lt;/strong&gt; however:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_82.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_40.png" width="644" height="258" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now for the &lt;strong&gt;Room&lt;/strong&gt; table:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_84.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_41.png" width="796" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;For now it just has a &lt;strong&gt;Name&lt;/strong&gt; column / property and a many-to-one relationship to &lt;strong&gt;Building&lt;/strong&gt;. Now let’s set up an&lt;strong&gt; Editable Grid Screen&lt;/strong&gt; because I want to make a point about what you will see in the &lt;strong&gt;Buildings&lt;/strong&gt; dropdown. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_86.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_42.png" width="644" height="431" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Not too useful. Remember I said that every entity needs a unique, displayable property. This is why. Fortunately this can be easily done. Edit the &lt;strong&gt;Building&lt;/strong&gt; class and click on &lt;strong&gt;&lt;Add Property&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_88.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_43.png" width="614" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Name it &lt;strong&gt;DisplayName&lt;/strong&gt; and click on the&lt;strong&gt; Is Computed&lt;/strong&gt; checkbox which will result in:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_90.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_44.png" width="644" height="427" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Click on&lt;strong&gt; Edit Method&lt;/strong&gt;:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; LightSwitchApplication
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Building
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; void DisplayName_Compute(ref &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; result)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            result = this.Name + "&lt;span style="color: #8b0000"&gt; / &lt;/span&gt;" + this.Location.Name;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Edit the &lt;strong&gt;Building&lt;/strong&gt; class. Click on &lt;strong&gt;Building&lt;/strong&gt; in the Header. Under &lt;strong&gt;Properties&lt;/strong&gt; set&lt;strong&gt; Summary Property&lt;/strong&gt; to &lt;strong&gt;DisplayName&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_92.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_45.png" width="644" height="464" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And lo:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_94.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_46.png" width="644" height="319" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;One last thing we need to do is make &lt;strong&gt;Room&lt;/strong&gt; &lt;strong&gt;Name&lt;/strong&gt; unique within &lt;strong&gt;Building&lt;/strong&gt;. You can do that by setting the &lt;strong&gt;Include in Unique Index&lt;/strong&gt;  property on for &lt;strong&gt;Name&lt;/strong&gt; and &lt;strong&gt;Building&lt;/strong&gt; in the &lt;strong&gt;Room&lt;/strong&gt; class as we did for &lt;strong&gt;Name&lt;/strong&gt; and &lt;strong&gt;Location&lt;/strong&gt; in the &lt;strong&gt;Building&lt;/strong&gt; class.&lt;/p&gt;

&lt;p&gt;Let’s add a &lt;strong&gt;Room&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_96.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_47.png" width="644" height="263" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now it’s time to create some inventory.We’ll start with &lt;strong&gt;OpenInventory&lt;/strong&gt;, each instance of which represents some quantity of a particular &lt;strong&gt;Book&lt;/strong&gt; that is not currently assigned to any &lt;strong&gt;Location&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_98.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_48.png" width="644" height="302" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Create an &lt;strong&gt;OpenInventory&lt;/strong&gt; class as shown and click on &lt;strong&gt;Choice List&lt;/strong&gt; under &lt;strong&gt;Condition&lt;/strong&gt; Properties; Create the &lt;strong&gt;New&lt;/strong&gt; and &lt;strong&gt;Used&lt;/strong&gt; values that can be assigned to the &lt;strong&gt;Condition&lt;/strong&gt; property. One of the things that differentiates instances of &lt;strong&gt;OpenInventory&lt;/strong&gt; and &lt;strong&gt;AssignedInventory&lt;/strong&gt;  is the &lt;strong&gt;Condition &lt;/strong&gt;of the &lt;strong&gt;Books&lt;/strong&gt;; all the &lt;strong&gt;Books&lt;/strong&gt; within a particular &lt;strong&gt;OpenInventory&lt;/strong&gt; or &lt;strong&gt;AssignedInventory&lt;/strong&gt; instance  are in the same &lt;strong&gt;Condition&lt;/strong&gt;, either &lt;strong&gt;New&lt;/strong&gt; or &lt;strong&gt;Used&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_100.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_49.png" width="514" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now we establish the relationship between &lt;strong&gt;OpenInventory&lt;/strong&gt; and &lt;strong&gt;Book&lt;/strong&gt;. An &lt;strong&gt;OpenInventory&lt;/strong&gt; can only be linked to one &lt;strong&gt;Book&lt;/strong&gt;, but a &lt;strong&gt;Book&lt;/strong&gt; can be linked to many &lt;strong&gt;OpenInventory&lt;/strong&gt; rows. Actually only two, &lt;strong&gt;New&lt;/strong&gt; or &lt;strong&gt;Used&lt;/strong&gt;, which is just a matter of setting another unique index.  By virtue of the choices I defined above, the property will always be restricted to &lt;strong&gt;New&lt;/strong&gt; or &lt;strong&gt;Used&lt;/strong&gt;. If it’s also unique there can only be two instances.&lt;/p&gt;

&lt;p&gt;But that unique index includes both &lt;strong&gt;Book&lt;/strong&gt; and &lt;strong&gt;Condition&lt;/strong&gt;, so let’s add the &lt;strong&gt;Book&lt;/strong&gt; Relationship. &lt;strong&gt;OpenInventory&lt;/strong&gt; is on the many side, so we click on &lt;strong&gt;Relationships&lt;/strong&gt; while editing &lt;strong&gt;OpenInventory&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_102.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_50.png" width="535" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now we can set the &lt;strong&gt;Include in Unique Index&lt;/strong&gt; property on for &lt;strong&gt;Condition&lt;/strong&gt; and &lt;strong&gt;Book&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_104.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_51.png" width="644" height="308" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You have to set them individually. The shot above is setting the property for &lt;strong&gt;Book&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s go ahead and create the &lt;strong&gt;Editable Grid Screen&lt;/strong&gt; for &lt;strong&gt;OpenInventory&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_108.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_53.png" width="644" height="415" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In this case we have a unique identifier but it’s not very helpful. We’ll need to add a computed property to &lt;strong&gt;Book&lt;/strong&gt;.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;partial &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DisplayName_Compute(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; result)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  result = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Title + "&lt;span style="color: #8b0000"&gt; (&lt;/span&gt;" + &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ISBN + "&lt;span style="color: #8b0000"&gt;)&lt;/span&gt;";
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Don’t forget, like I just did, that you have to set the Book class &lt;strong&gt;Summary Property&lt;/strong&gt; value to &lt;strong&gt;DisplayName&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_110.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_54.png" width="921" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I haven’t quite figured out why the Listbox columns sometimes get re-sized automatically and other times not, but you can see that we now have a combination of &lt;strong&gt;Title and ISBN&lt;/strong&gt; displayed for &lt;strong&gt;Book&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_112.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_55.png" width="644" height="370" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Let’s run in debug so we can change the width until we get it right. Hit F5 and click on &lt;strong&gt;Design Screen&lt;/strong&gt; when it comes up:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_116.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_57.png" width="644" height="273" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After clicking &lt;strong&gt;Save&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_120.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_59.png" width="644" height="322" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Close enough. Afterwards I found it’s a little quirky about when it displays the drop down part full-width and when it clips it at the column width, but still close enough for now.&lt;/p&gt;

&lt;p&gt;Let’s test whether the &lt;strong&gt;Condition&lt;/strong&gt; / &lt;strong&gt;Book&lt;/strong&gt; combination is a unique key on &lt;strong&gt;OpenInventory&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_122.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_60.png" width="644" height="338" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Sure enough, I cannot create two &lt;strong&gt;OpenInventory&lt;/strong&gt; rows for the same &lt;strong&gt;Book&lt;/strong&gt; and &lt;strong&gt;Condition&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I also want to change the column order in the form. It’s as simple as changing this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_124.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_61.png" width="644" height="327" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;to this by dragging and dropping:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_126.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_62.png" width="644" height="303" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I also widened the &lt;strong&gt;Book&lt;/strong&gt; Listbox to 180 pixels.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_128.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_63.png" width="644" height="325" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The other columns are still excessively wide, but let’s move on to the &lt;strong&gt;AssignedInventory&lt;/strong&gt; class, each instance of which is like &lt;strong&gt;OpenInventory&lt;/strong&gt; in that it represents some quantity of a particular &lt;strong&gt;Book&lt;/strong&gt; in a particular &lt;strong&gt;Condition&lt;/strong&gt; but adds on the assignment to a particular &lt;strong&gt;Room&lt;/strong&gt; in a particular &lt;strong&gt;Building&lt;/strong&gt; in a particular &lt;strong&gt;Location&lt;/strong&gt;. Accordingly we’re going to require a computed property to display for &lt;strong&gt;Room&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Bur first things first. Here’s the class before we add the relationship to &lt;strong&gt;Book&lt;/strong&gt;. We have to create &lt;strong&gt;New&lt;/strong&gt; and &lt;strong&gt;Used&lt;/strong&gt; choices for &lt;strong&gt;Condition&lt;/strong&gt; again. There may be a way to have &lt;strong&gt;AssignedInventory&lt;/strong&gt; inherit from &lt;strong&gt;OpenInventory&lt;/strong&gt;, layering on the &lt;strong&gt;Room&lt;/strong&gt; property, but trying to do that and reflect the underlying tables at the same time is too much of a distraction. I would have a single &lt;strong&gt;BookInventory&lt;/strong&gt; table with have a nullable &lt;strong&gt;Room&lt;/strong&gt; link to represent both with a single table, but my existing design spec at work calls for separate tables.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_130.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_64.png" width="644" height="430" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AssignedInventory&lt;/strong&gt; is on the many side of the &lt;strong&gt;Book&lt;/strong&gt; relationship, so click on &lt;strong&gt;Relationship&lt;/strong&gt;…&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_132.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_65.png" width="538" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AssignedInventory&lt;/strong&gt; is also on the many side of the &lt;strong&gt;Room&lt;/strong&gt; relationship so click on &lt;strong&gt;Relationship&lt;/strong&gt;… again:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_134.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_66.png" width="540" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And that’s all we need to define &lt;strong&gt;AssignedInventory&lt;/strong&gt;. Let’s see what an &lt;strong&gt;Editable Grid Screen&lt;/strong&gt; looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_136.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_67.png" width="644" height="395" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Not enough information. We don’t know what &lt;strong&gt;Building&lt;/strong&gt; the &lt;strong&gt;Room&lt;/strong&gt; is in. Time for another&lt;strong&gt; Summary Property&lt;/strong&gt;.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;partial &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DisplayName_Compute(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; result)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    result = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Name + "&lt;span style="color: #8b0000"&gt; / &lt;/span&gt;" + &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Building;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;After also making some adjustments to column order and width:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_138.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_68.png" width="644" height="362" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Notice that I concatenated &lt;strong&gt;this.Building&lt;/strong&gt; to &lt;strong&gt;this.Name&lt;/strong&gt; in &lt;strong&gt;DisplayName_Compute; &lt;/strong&gt;what I get from &lt;strong&gt;this.Building&lt;/strong&gt; is the &lt;strong&gt;Summary Property&lt;/strong&gt; of &lt;strong&gt;Building&lt;/strong&gt;, which includes &lt;strong&gt;Location&lt;/strong&gt; in the &lt;strong&gt;Name&lt;/strong&gt;, so &lt;strong&gt;Room&lt;/strong&gt; is truly uniquely identified in the ListBox.&lt;/p&gt;

&lt;p&gt;The combination of &lt;strong&gt;Book&lt;/strong&gt; and &lt;strong&gt;Condition&lt;/strong&gt; also need to be unique, as in &lt;strong&gt;OpenInventory&lt;/strong&gt;, but only within &lt;strong&gt;Room&lt;/strong&gt;.  Therefore we set the &lt;strong&gt;Include in Unique Index&lt;/strong&gt; for &lt;strong&gt;Book&lt;/strong&gt;, &lt;strong&gt;Room&lt;/strong&gt;, and &lt;strong&gt;Condition&lt;/strong&gt;. Notice I’ve also dragged the column names into a more logical order:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_140.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_69.png" width="644" height="421" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_142.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_70.png" width="1028" height="331" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now for &lt;strong&gt;Book&lt;/strong&gt; transfers. We’ll do &lt;strong&gt;OpenInventoryTransfers&lt;/strong&gt; first. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_154.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_76.png" width="838" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I went ahead and defined the relationships and fields in a logical order. In this case the combination of &lt;strong&gt;Book&lt;/strong&gt; and &lt;strong&gt;Condition&lt;/strong&gt; is not unique, even within &lt;strong&gt;Room&lt;/strong&gt; because you could have multiple transfers in process to or from  a single &lt;strong&gt;Room&lt;/strong&gt; for the same &lt;strong&gt;Book&lt;/strong&gt; and &lt;strong&gt;Condition&lt;/strong&gt;. It’s after they are received that the quantity from each will be deducted from the source inventory and added to the destination inventory uniquely identified by the same &lt;strong&gt;Book&lt;/strong&gt; and &lt;strong&gt;Condition &lt;/strong&gt;within the destination.&lt;/p&gt;

&lt;p&gt;Once again it’s necessary to build &lt;strong&gt;New&lt;/strong&gt; and &lt;strong&gt;Used&lt;/strong&gt; choices for &lt;strong&gt;Condition&lt;/strong&gt;, and now we add &lt;strong&gt;DestinationType&lt;/strong&gt; with the choices of &lt;strong&gt;OpenInventory&lt;/strong&gt; and &lt;strong&gt;Room&lt;/strong&gt;. An &lt;strong&gt;OpenInventoryTransfer&lt;/strong&gt; can be in either direction, from &lt;strong&gt;OpenInventory&lt;/strong&gt; to &lt;strong&gt;Room&lt;/strong&gt; or vice-versa. &lt;strong&gt;DestinationType&lt;/strong&gt; identifies which.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_150.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_74.png" width="644" height="468" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ConditionVariance&lt;/strong&gt; and &lt;strong&gt;QuantityVariance&lt;/strong&gt; will be two computed fields that will indicate a variance in what was received from what was sent. Also we require &lt;strong&gt;QuantitySent&lt;/strong&gt; to be greater than zero:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;partial &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ConditionVariance_Compute(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; result)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    result =
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Received &amp;&amp;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        ((&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Condition == "&lt;span style="color: #8b0000"&gt;New&lt;/span&gt;" &amp;&amp; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.QuantityReceivedUsed &gt; 0) ||
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Condition == "&lt;span style="color: #8b0000"&gt;Used&lt;/span&gt;" &amp;&amp; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.QuantityReceivedUsed &gt; 0));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;partial &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; QuantityVariance_Compute(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; result)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    result =
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Received &amp;&amp;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.QuantityReceivedUsed + &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.QuantityReceivedNew != &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.QuantitySent);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;partial &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; QuantitySent_Validate(EntityValidationResultsBuilder results)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.QuantitySent &lt; 1)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        results.AddPropertyError("&lt;span style="color: #8b0000"&gt;QuantitySent must be greater than zero&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Let’s go ahead and create the &lt;strong&gt;Editable Grid Screen&lt;/strong&gt;.  I’ll cut to the chase and show you the detail screen as the field sizes need serious pruning.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_156.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_77.png" width="644" height="456" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Notice that &lt;strong&gt;Condition Variance&lt;/strong&gt; and &lt;strong&gt;Quantity Variance&lt;/strong&gt; are displayed as labels rather than text boxes in the screen &lt;strong&gt;LightSwitch&lt;/strong&gt; created by default:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_210.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_104.png" width="236" height="62" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;That’s because we converted them to computed fields. If they were actual table columns they would be on the form as text boxes:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_214.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_106.png" width="206" height="52" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_158.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_78.png" width="644" height="457" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now that &lt;strong&gt;Room&lt;/strong&gt; is on the one side of some one-to-many relationships we should create a &lt;strong&gt;List and Details Screen&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_160.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_79.png" width="644" height="439" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We see the &lt;strong&gt;AssignedInventory&lt;/strong&gt; collection for the selected &lt;strong&gt;Room&lt;/strong&gt;…&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_162.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_80.png" width="1028" height="294" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;… and the&lt;strong&gt; Open Inventory Transfers Collection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_164.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_81.png" width="1028" height="263" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We can create new &lt;strong&gt;Rooms&lt;/strong&gt;, new &lt;strong&gt;Assigned Inventories&lt;/strong&gt; or &lt;strong&gt;Open Inventory Transfers&lt;/strong&gt; to and from the selected &lt;strong&gt;Room&lt;/strong&gt; from this screen. And you always have the luxury of form based entry when row based entry is too cumbersome:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_166.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_82.png" width="644" height="422" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After clicking &lt;strong&gt;OK&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_168.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_83.png" width="1028" height="286" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Onward to &lt;strong&gt;AssignedInventoryTransfer&lt;/strong&gt;, which is a transfer between two rooms. As you’d expect each &lt;strong&gt;AssignedInventoryTransfer&lt;/strong&gt; has a &lt;strong&gt;Source&lt;/strong&gt; &lt;strong&gt;Room&lt;/strong&gt; and a &lt;strong&gt;Destination&lt;/strong&gt; &lt;strong&gt;Room&lt;/strong&gt;, putting &lt;strong&gt;Room&lt;/strong&gt; on the one side of two one-to-many relationships:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_170.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_84.png" width="563" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;How does this play out in the &lt;strong&gt;Room List and Details Screen&lt;/strong&gt;? We need to re-create it to include the new collections:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_172.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_85.png" width="623" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Hit F5 to run in debug mode and we’ll modify the displayed collection names using Design Screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_176.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_87.png" width="644" height="402" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We can add transfers from this screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_178.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_88.png" width="1028" height="323" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;But first let’s add a business rule that the&lt;strong&gt; Source and Destination Rooms&lt;/strong&gt; cannot be the same:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_180.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_89.png" width="1028" height="581" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #ffffff; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;partial &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AssignedInventoryTransfers_Validate(AssignedInventoryTransfer entity, EntitySetValidationResultsBuilder results)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (entity.Source == entity.Destination)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        results.AddEntityError("&lt;span style="color: #8b0000"&gt;Source and Destination must be different Rooms&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now if we try to create a transfer that violates this rule:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_182.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_90.png" width="644" height="422" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We can get this far:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_184.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_91.png" width="1028" height="256" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;But when we click Save:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_186.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_92.png" width="644" height="274" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We can quickly fix the mistake:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_188.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_93.png" width="1028" height="295" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I think we have a complete set of screens to support basic CRUD on all our tables. I want to do some renaming and pruning. Let’s review:&lt;/p&gt;

&lt;p&gt;We have the&lt;strong&gt; Editable Books Grid&lt;/strong&gt; which allows us to create and maintain &lt;strong&gt;Book&lt;/strong&gt; table rows.  &lt;strong&gt;Book&lt;/strong&gt; definitions stand on their own so we need a standalone form to edit them. Let’s change the screen title to&lt;strong&gt; Book Catalog&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_200.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_99.png" width="1028" height="403" /&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;We can maintain both &lt;strong&gt;Locations&lt;/strong&gt; and &lt;strong&gt;Building&lt;/strong&gt; through&lt;strong&gt; Locations List Detail&lt;/strong&gt; which we’ll rename&lt;strong&gt; Locations And Buildings&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_202.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_100.png" width="1028" height="325" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Editable Rooms Grid&lt;/strong&gt; allows us to maintain &lt;strong&gt;Rooms&lt;/strong&gt; but we can do that in &lt;strong&gt;Rooms List Detail&lt;/strong&gt;, so it’s out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OpenInventory&lt;/strong&gt; can only be maintained in&lt;strong&gt; Editable Open Inventories Grid &lt;/strong&gt;so we keep it under the name &lt;strong&gt;OpenInventoryScreen&lt;/strong&gt;, &lt;strong&gt;OpenInventory&lt;/strong&gt; being taken.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_204.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_101.png" width="1028" height="509" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Both &lt;strong&gt;Editable Assigned Inventories Grid&lt;/strong&gt; and &lt;strong&gt;Editable&lt;/strong&gt; &lt;strong&gt;Open Inventory Transfers Grid&lt;/strong&gt; can go. Assigned Inventories and Inventory transfers are always linked to a &lt;strong&gt;Room&lt;/strong&gt; and so can be maintained through &lt;strong&gt;Rooms List Detail &lt;/strong&gt;which I’m renaming&lt;strong&gt; Rooms And Books Inventory&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.nethttp://www.openlightgroup.net/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_206.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="/Portals/0/Blog/Files/3/167/WLW-LightswitchBookInventoryTracker_984E-image_thumb_102.png" width="1028" height="368" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;All the essential pieces are in place. We can create &lt;strong&gt;Book&lt;/strong&gt; Definitions, &lt;strong&gt;Book&lt;/strong&gt; inventory and &lt;strong&gt;Rooms&lt;/strong&gt; for &lt;strong&gt;Book&lt;/strong&gt; inventory assignment. We can create transfers between &lt;strong&gt;OpenInventory&lt;/strong&gt; and &lt;strong&gt;Room&lt;/strong&gt; and between two &lt;strong&gt;Rooms&lt;/strong&gt;. We can record receipt of those transfers and variances between what was sent and what was received. &lt;/p&gt;

&lt;p&gt;This is getting kind of long, so I’m going to post this as Part 1. One glaring necessity is validation of quantities for transfers. Are enough copies available at the source? And what about transfers that haven’t been completed when determining how many copies of a particular &lt;strong&gt;Book&lt;/strong&gt; are available? Also we need security and accountability in the form of users and roles.&lt;/p&gt;

&lt;p&gt;The next day…&lt;/p&gt;

&lt;p&gt;Another omission just jumped out at me. The &lt;strong&gt;OpenInventory&lt;/strong&gt; entity needs to have an &lt;strong&gt;OpenInventoryTransfer&lt;/strong&gt; collection property and &lt;strong&gt;AssignedInventory&lt;/strong&gt; entity needs to have an &lt;strong&gt;AssignedInventoryTransfer&lt;/strong&gt; collection property – meaning the &lt;strong&gt;OpenInventoryTransfers&lt;/strong&gt; table needs to hold a foreign key on the &lt;strong&gt;OpenInventory&lt;/strong&gt; table, etc. so stay tuned for Part 2. &lt;/p&gt;

&lt;p&gt;Ouch, I also duplicated &lt;strong&gt;Book&lt;/strong&gt; and &lt;strong&gt;Condition&lt;/strong&gt; in OpenInventoryTransfer. I can only think that in my head I saw the combination as the foreign key that &lt;strong&gt;OpenInventoryTransfer&lt;/strong&gt; holds on &lt;strong&gt;OpenInventory&lt;/strong&gt;. My only defense is &lt;strong&gt;LightSwitch&lt;/strong&gt; makes it so easy you don’t do some things you normally do without thinking about.&lt;/p&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/167/LightSwitch-Book-Inventory-Tracker-Part-1.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/167/LightSwitch-Book-Inventory-Tracker-Part-1.aspx#Comments</comments>
      <slash:comments>1</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/167/LightSwitch-Book-Inventory-Tracker-Part-1.aspx</guid>
      <pubDate>Sun, 10 Apr 2011 07:14:43 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=167</trackback:ping>
    </item>
    <item>
      <title>Very Simple Example of ICommand CanExecute Method and CanExecuteChanged Event</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/139/Very-Simple-Example-of-ICommand-CanExecute-Method-and-CanExecuteChanged-Event.aspx</link>
      <description>&lt;p&gt;Michael Washington said I should blog about this, so if it’s too mundane, blame him. I added some animation stuff to hopefully make it a little more interesting.&lt;/p&gt;  &lt;p&gt;Consider a simulation where the ViewModel controls the onscreen action. On the following screen, clicking the Start Button will cause the space ship to fly around the the screen. But the Start Button should only be enabled if the ViewModel actually has access to the space ship and the Speed is valid.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_30.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_13.png" width="644" height="473" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;Try It Out:&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://richardwaddell.adefwebserver.com/CanExecuteChangedSite/CanExecuteChangedExampleTestPage.html" target="_blank"&gt;http://richardwaddell.adefwebserver.com/CanExecuteChangedSite/CanExecuteChangedExampleTestPage.html&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;Download Code:&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://richardwaddell.adefwebserver.com/CanExecuteChangedExample.zip"&gt;http://richardwaddell.adefwebserver.com/CanExecuteChangedExample.zip&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;Acknowledgements:&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://johnpapa.net/silverlight/5-simple-steps-to-commanding-in-silverlight/"&gt;John Papa for DelegateCommand&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;The Details&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;&lt;strong&gt;ICommand&lt;/strong&gt;  provides an interface that can easily be bound to by the &lt;strong&gt;View&lt;/strong&gt; to execute code in the &lt;strong&gt;ViewModel&lt;/strong&gt;. In addition to the &lt;strong&gt;Execute()&lt;/strong&gt; method you might expect, it also calls for a &lt;strong&gt;CanExecute()&lt;/strong&gt; method. &lt;strong&gt;CanExecute()&lt;/strong&gt; returns true if &lt;strong&gt;Execute()&lt;/strong&gt; can currently be ‘executed’ safely. If you bind a &lt;strong&gt;Button.Command&lt;/strong&gt; property to an &lt;strong&gt;ICommand&lt;/strong&gt; implementation, the &lt;strong&gt;Button&lt;/strong&gt; is automatically enabled or disabled according to the value returned by &lt;strong&gt;CanExecute().&lt;/strong&gt; But &lt;strong&gt;CanExecute()&lt;/strong&gt; is a method, not a property, so if conditions change so &lt;strong&gt;CanExecute()&lt;/strong&gt; would return true rather than false, or vice-versa, &lt;strong&gt;Button&lt;/strong&gt; must know to call &lt;strong&gt;CanExecute()&lt;/strong&gt; to find the new value.&lt;/p&gt;  &lt;p&gt;That’s where &lt;strong&gt;CanExecuteChanged&lt;/strong&gt; comes in. &lt;strong&gt;Button&lt;/strong&gt;, through its base class, &lt;strong&gt;ButtonBase&lt;/strong&gt;, is automatically subscribed to the &lt;strong&gt;CanExecuteChanged&lt;/strong&gt; event when the &lt;strong&gt;Button.Command&lt;/strong&gt; property is bound to the &lt;strong&gt;ICommand&lt;/strong&gt;. As you might expect, when &lt;strong&gt;ButtonBase&lt;/strong&gt; catches the &lt;strong&gt;CanExecuteChanged&lt;/strong&gt; Event it responds by calling the &lt;strong&gt;CanExecute()&lt;/strong&gt; method and sets the &lt;strong&gt;Button.Enabled&lt;/strong&gt; state accordingly. So in your code, whenever a condition or property changes that affect what &lt;strong&gt;CanExecute()&lt;/strong&gt; will return, the &lt;strong&gt;CanExecuteChanged&lt;/strong&gt; event should be raised.&lt;/p&gt;  &lt;p&gt;I’ll point out here that &lt;strong&gt;CanStartAnimation()&lt;/strong&gt;, which is the method that you supply when you create &lt;strong&gt;StartAnimationCommand &lt;/strong&gt;, will be called by &lt;strong&gt;CanExecute()&lt;/strong&gt; to determine what value to return. In this simple example, &lt;strong&gt;CanStartAnimation()&lt;/strong&gt; returns true if the &lt;strong&gt;ViewModel&lt;/strong&gt; has access to the spaceShip &lt;strong&gt;FrameworkElement. &lt;/strong&gt;To clarify a little futher&lt;strong&gt;  StartAnimationCommand &lt;/strong&gt;is an &lt;strong&gt;ICommand&lt;/strong&gt; property on &lt;strong&gt;MainPageViewModel&lt;/strong&gt;. Specifically it is an instance of &lt;strong&gt;DelegateCommand&lt;/strong&gt;,, a &lt;a href="http://johnpapa.net/silverlight/5-simple-steps-to-commanding-in-silverlight/"&gt;class generously provided by John Papa&lt;/a&gt;, which of course implements &lt;strong&gt;ICommand&lt;/strong&gt;. The beauty of &lt;strong&gt;DelegateCommand&lt;/strong&gt; is that it lets you define the methods to be called by &lt;strong&gt;CanExecute()&lt;/strong&gt; and &lt;strong&gt;Execute()&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;CanExecute()&lt;/strong&gt; doesn’t merely return the result from &lt;strong&gt;CanStartAnimation()&lt;/strong&gt;. As you can see in the &lt;strong&gt;DelegateCommand&lt;/strong&gt; source for &lt;strong&gt;CanExecute(),&lt;/strong&gt; it determines whether the bool from &lt;strong&gt;CanStartAnimation()&lt;/strong&gt; – which it just sees as a function pointer named &lt;strong&gt;canExecute&lt;/strong&gt; that accepts an object and returns the bool in question, is different from the bool it got before. If so, it raises the &lt;strong&gt;CanExecuteChanged&lt;/strong&gt; event.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; DelegateCommand : ICommand
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    Func&lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&gt; canExecute;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    Action&lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&gt; executeAction;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; canExecuteCache;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DelegateCommand(Action&lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&gt; executeAction, Func&lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&gt; canExecute)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.executeAction = executeAction;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.canExecute = canExecute;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    #region ICommand Members
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; CanExecute(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; temp = canExecute(parameter);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (canExecuteCache != temp)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            canExecuteCache = temp;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (CanExecuteChanged != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                CanExecuteChanged(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; EventArgs());
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; canExecuteCache;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; EventHandler CanExecuteChanged;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        executeAction(parameter);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;So for the &lt;strong&gt;StartAnimationCommand&lt;/strong&gt; &lt;strong&gt;ICommand&lt;/strong&gt; implementation, if anything changes that will affect what &lt;strong&gt;CanStartAnimation()&lt;/strong&gt; will return, simply call &lt;strong&gt;CanStartAnimation(),&lt;/strong&gt; as you can see in &lt;strong&gt;LoadWorldElements()&lt;/strong&gt; below:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; CanExecuteChangedExample
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MainPageViewModel
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; FrameworkElement _SpaceShip = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region WorldCanvas
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Canvas _WorldCanvas;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Canvas WorldCanvas
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._WorldCanvas != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._WorldCanvas = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    LoadWorldElements();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MainPageViewModel()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            StartAnimationCommand = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DelegateCommand(StartAnimation, CanStartAnimation);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            SetWorldCanvasCommand = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DelegateCommand(SetWorldCanvas, CanSetWorldCanvas);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ICommand SetWorldCanvasCommand { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetWorldCanvas(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            WorldCanvas = param &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; Canvas;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; CanSetWorldCanvas(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; param &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; Canvas;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ICommand StartAnimationCommand { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; StartAnimation(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            RunAnimation();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; CanStartAnimation(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _SpaceShip != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LoadWorldElements()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            _SpaceShip =
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                (from child &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; _WorldCanvas.Children
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                 let element = child &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; FrameworkElement
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                 where element.Name == "&lt;span style="color: #8b0000"&gt;spaceShip&lt;/span&gt;"
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                 select element).FirstOrDefault();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #008000"&gt;// Call DelegateCommand.CanExecute to raise the CanExecuteChangedEvent&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            StartAnimationCommand.CanExecute(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RunAnimation()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #008000"&gt;// Animate the LayoutPath&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            Storyboard sb = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Storyboard();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            DoubleAnimation XAnimation = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DoubleAnimation();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            DoubleAnimation YAnimation = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DoubleAnimation();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            sb.Children.Add(XAnimation);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            sb.Children.Add(YAnimation);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            sb.Duration = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Duration(TimeSpan.FromSeconds(3));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            XAnimation.Duration = sb.Duration;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            YAnimation.Duration = sb.Duration;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            XAnimation.To = _WorldCanvas.ActualWidth - _SpaceShip.ActualWidth;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            YAnimation.To = Convert.ToDouble(_SpaceShip.GetValue(Canvas.TopProperty)) + (_SpaceShip.ActualHeight * 2);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            Storyboard.SetTarget(sb, _SpaceShip);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            Storyboard.SetTargetProperty(XAnimation, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyPath("&lt;span style="color: #8b0000"&gt;(Canvas.Left)&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            Storyboard.SetTargetProperty(YAnimation, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyPath("&lt;span style="color: #8b0000"&gt;(Canvas.Top)&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            sb.Begin();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;That covers the basics. I might point out that the parameter to &lt;strong&gt;CanExecute()&lt;/strong&gt; is null in this case because &lt;strong&gt;CanExecute()&lt;/strong&gt; is only interested in _&lt;strong&gt;SpaceShip&lt;/strong&gt;. But in other scenarios &lt;strong&gt;CanExecute()&lt;/strong&gt; might require a parameter. For instance the Button &lt;strong&gt;CommandParameter&lt;/strong&gt; property can be bound:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_28.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb.png" width="644" height="290" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you specify an argument here, you’ll need to pass the same argument to &lt;strong&gt;CanExecute()&lt;/strong&gt; when you’re trying to trigger the &lt;strong&gt;CanExecuteChanged&lt;/strong&gt; event. Actually I’ll go ahead and show an example by adding a textbox where the user can enter the speed and bind the Text property to a Speed string property in &lt;strong&gt;MainPageViewModel&lt;/strong&gt;. If the entered value is other than a positive integer, &lt;strong&gt;CanStartAnimation()&lt;/strong&gt; returns false and the button is disabled.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; CanStartAnimation(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; sSpeed = param &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; String;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (String.IsNullOrWhiteSpace(sSpeed))
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; nSpeed  = 0;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Int32.TryParse(sSpeed, &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; nSpeed) == &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (nSpeed &lt; 1)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _SpaceShip != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And of course when Speed changes we call &lt;strong&gt;CanExecute()&lt;/strong&gt;  which will call &lt;strong&gt;CanStartAnimation()&lt;/strong&gt; which will evaluate the property we just changed, although we are passing it as an argument. &lt;/p&gt;

&lt;p&gt;Which brings up a good point. We could use the property Speed directly as we did the variable _SpaceShip, and much as it pains me, it probably does make more sense to use the property which, no matter what you call it, is a global variable, rather than passing it as an argument. Why? Because now everyplace that calls &lt;strong&gt;CanStartAnimation()&lt;/strong&gt; has to pass the same argument that &lt;strong&gt;Button&lt;/strong&gt; (or any other &lt;strong&gt;FrameworkElement &lt;/strong&gt;that binds to the ICommand) does. &lt;/p&gt;

&lt;p&gt;If there were no argument, then there could be no ambiguity – which stems from the fact in some cases it’s only being called to trigger the &lt;strong&gt;CanExecuteChanged &lt;/strong&gt;event and in others it’s being called by &lt;strong&gt;ButtonBase&lt;/strong&gt; to actually get the return value. If you change what &lt;strong&gt;Button&lt;/strong&gt; passes, you have to remember to change everyplace that was passing the old value to trigger &lt;strong&gt;CanExecuteChanged.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If instead you change a property (global variable) that affects what &lt;strong&gt;CanExecute() &lt;/strong&gt;will return you only have to remove the &lt;strong&gt;CanExecuteChanged-triggering-call&lt;/strong&gt; to &lt;strong&gt;CanExecute()&lt;/strong&gt; from the property setter for the one you are no longer using and add it to the new one. And you have to have a property (global variable) for the UI to bind to, so using it as an argument is redundant. Accordingly, in a ViewModel-centric world it makes sense for the UI (the perceived world) to affect the properties in the ViewModel (the real world) and for events in the UI to trigger actions against those properties. It took me awhile to come around to that point of view, ‘cause I do love my arguments – even when I call them parameters.&lt;/p&gt;

&lt;p&gt;But still, I do need an example:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region Speed
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _Speed = "&lt;span style="color: #8b0000"&gt;300&lt;/span&gt;";
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Speed
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._Speed; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._Speed != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._Speed = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;Speed&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    StartAnimationCommand.CanExecute(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Here are  the  changes to RunAnimation().&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; void RunAnimation(int speed)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            Point currentPosition = SpaceShipPosition;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_sbFlight != null)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                _sbFlight.&lt;span style="color: #0000ff"&gt;Stop&lt;/span&gt;();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            SpaceShipPosition = currentPosition;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            ...
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;Double&lt;/span&gt; distance = ComputeDistance(SpaceShipPosition, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Point(targetX, targetY));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            _sbFlight.Duration = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Duration(TimeSpan.FromSeconds(distance / speed));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            ...
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            _sbFlight.Completed += (sender, eventArgs) =&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Continuous &amp;&amp; CanStartAnimation(Speed))
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    StartAnimation(Speed);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            };
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            _sbFlight.Begin();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Point SpaceShipPosition
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            { 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_SpaceShip != null)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Point(Convert.ToDouble(_SpaceShip.GetValue(Canvas.LeftProperty)), Convert.ToDouble(_SpaceShip.GetValue(Canvas.TopProperty)));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Point(0, 0);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_SpaceShip != null)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    _SpaceShip.SetValue(Canvas.LeftProperty, value.X);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    _SpaceShip.SetValue(Canvas.TopProperty, value.Y);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Notice I changed the StoryBoard to a member variable so I could stop the running animation before starting the next one. If you don’t, things get weird after you click start several times in a row quickly.&lt;/p&gt;

&lt;p&gt;I decided to cut to the chase before laying out the step by step. If you’re interested the rest covers the back story up to the point where I first need to raise the CanExecuteChanged event. &lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;The Basic Project&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Select &lt;strong&gt;MainPageViewModel&lt;/strong&gt; to be the &lt;strong&gt;DataContext&lt;/strong&gt; for &lt;strong&gt;LayoutRoot&lt;/strong&gt; (or &lt;strong&gt;UserControl&lt;/strong&gt;). &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_2.png" width="644" height="224" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_3.png" width="321" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Add an &lt;strong&gt;InvokeCommandAction&lt;/strong&gt; to &lt;strong&gt;LayoutRoot&lt;/strong&gt; to be triggered by the &lt;strong&gt;LayoutRoot.Loaded&lt;/strong&gt; event:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_4.png" width="642" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The Command is &lt;strong&gt;SetWorldCanvas()&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_14.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_6.png" width="644" height="177" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The parameter is &lt;strong&gt;LayoutRoot&lt;/strong&gt; itself:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_12.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_5.png" width="644" height="130" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_16.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_7.png" width="517" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Bind the Button to &lt;strong&gt;StartAnimationCommand&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_18.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_8.png" width="644" height="149" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;But the button appears disabled:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_20.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_9.png" width="644" height="393" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;That’s because &lt;strong&gt;ButtonBase&lt;/strong&gt; calls &lt;strong&gt;CanStartAnimation()&lt;/strong&gt; before &lt;strong&gt;LayoutRoot.Loaded&lt;/strong&gt; calls &lt;strong&gt;SetWorldCanvas(). &lt;/strong&gt;The &lt;strong&gt;WorldCanvas&lt;/strong&gt; property setter calls &lt;strong&gt;LoadWorldElements(),&lt;/strong&gt; which sets _&lt;strong&gt;SpaceShip, &lt;/strong&gt;which will cause &lt;strong&gt;CanExecute()&lt;/strong&gt; to enable &lt;strong&gt;Button. &lt;/strong&gt;But in spite of that the sequence of the calls at startup leaves &lt;strong&gt;Button&lt;/strong&gt; disabled.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_22.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_10.png" width="644" height="329" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_24.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_11.png" width="644" height="281" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LoadWorldElements()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            _SpaceShip =
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                (from child &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; _WorldCanvas.Children
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                 let element = child &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; FrameworkElement
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                 where element.Name == "&lt;span style="color: #8b0000"&gt;spaceShip&lt;/span&gt;"
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                 select element).FirstOrDefault();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #008000"&gt;// Call DelegateCommand.CanExecute to raise the CanExecuteChangedEvent&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            StartAnimationCommand.CanExecute(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Add the line &lt;strong&gt;StartAnimationCommand.CanExecute()&lt;/strong&gt; to &lt;strong&gt;LoadWorldElements()&lt;/strong&gt; and voila.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_26.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="/Portals/0/Blog/Files/3/139/WLW-VerySimpleExampleofICommandCanExecuteMet_1201D-image_thumb_12.png" width="644" height="428" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/139/Very-Simple-Example-of-ICommand-CanExecute-Method-and-CanExecuteChanged-Event.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/139/Very-Simple-Example-of-ICommand-CanExecute-Method-and-CanExecuteChanged-Event.aspx#Comments</comments>
      <slash:comments>1</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/139/Very-Simple-Example-of-ICommand-CanExecute-Method-and-CanExecuteChanged-Event.aspx</guid>
      <pubDate>Sat, 04 Dec 2010 05:16:15 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=139</trackback:ping>
    </item>
    <item>
      <title>Add Tabbed Pages To Your Silverlight Project, Quick and Easy</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/138/Add-Tabbed-Pages-To-Your-Silverlight-Project-Quick-and-Easy.aspx</link>
      <description>&lt;p&gt;&lt;a href="http://www.codeproject.com/KB/silverlight/SuperTabs.aspx"&gt;Michael Washington made such a good case for tabbed pages&lt;/a&gt; that I decided to adapt a project I was already blogging about. I’d reached the point where I’d created  a simple example and now wanted to build on it. Usually, rather than go to the trouble of creating some paging mechanism, I’d just keep on coding and the source underlying the example would be gone forever. With tabbed pages it’s easy to keep each example within its own tabbed page. I’m glad I made the decision, because his example made it easy to make the change:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_18.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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb_8.png" width="879" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you want to really understand what’s going on, I refer you to Michael’s article. I’m just going to supply you with code that will let you easily create and select tabbed pages.&lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;Download Code:&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;&lt;a title="http://richardwaddell.adefwebserver.com/PollResultsBarBehaviorDemo.zip" href="http://richardwaddell.adefwebserver.com/ooNaTabbed.zip"&gt;http://richardwaddell.adefwebserver.com/ooNaTabbed.zip&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;Other Acknowledgements:&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://johnpapa.net/silverlight/5-simple-steps-to-commanding-in-silverlight/"&gt;John Papa for Delegate Command&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;TabbedPageContainer&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;In the main page of my project, the Canvas that will contain the tabbed pages is named &lt;strong&gt;TabbedPageContainer&lt;/strong&gt;. It doesn’t really need a name, I just gave it one so you can easily keep track of it. You can see that it contains a &lt;strong&gt;TabControl&lt;/strong&gt; and that the &lt;strong&gt;TabControl&lt;/strong&gt; has an &lt;strong&gt;AddTabItem&lt;/strong&gt; behavior attached:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb.png" width="644" height="426" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;StackPanel&lt;/strong&gt; above &lt;strong&gt;TabbedPageContainer&lt;/strong&gt; contains a &lt;strong&gt;ComboBox&lt;/strong&gt; that will be used to select pages to load into new &lt;strong&gt;TabItems&lt;/strong&gt;. When a selection is made the &lt;strong&gt;AddTabItem&lt;/strong&gt; behavior is triggered to add the appropriate UserControl. First let’s look at the Behavior:&lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;AddTabItem Behavior&lt;/strong&gt;&lt;/h2&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; ooNaTabbed
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; AddTabItem : TargetedTriggerAction&lt;TabControl&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// The AddTabItem Behavior&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Is intended to be triggered by a change in the SelectedIndex property as bound to by designer&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Determines which UseControl is to be added as the content of the new TabItem, &lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Creates an instance of the UserControl&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Creates a GenericTabHeader control with the appropriate page name to be used as the TabItem Header&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Adds the new UserControl and GenericTabHeader to the TabItem&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Sets references to TabControl and TabItem in the GenericTabHeaderViewModel&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Adds the TabItem to the TabControl&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        TabControl _tabControl;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region SelectedIndexProperty
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; DependencyProperty SelectedIndexProperty = DependencyProperty.Register("&lt;span style="color: #8b0000"&gt;SelectedIndex&lt;/span&gt;",
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(AddTabItem), &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// Designer binds SelectedIndex to combobox SelectedIndex Property - TwoWay binding&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; SelectedIndex
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; {&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.GetValue(SelectedIndexProperty);}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; {&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.SetValue(SelectedIndexProperty, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;);}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnAttached()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnAttached();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            _tabControl = AssociatedObject &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; TabControl;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// The behavior is triggered&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Invoke(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            AddTabToTabControl();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnDetaching()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnDetaching();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddTabToTabControl()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #008000"&gt;// Bail if appropriate&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_tabControl == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; || SelectedIndex &lt; 0)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #008000"&gt;// The header is just the name and a button to close the tab&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            GenericTabHeader tabHeader = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; GenericTabHeader();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #008000"&gt;// We get the ViewModel behind the GenericTabHeader UserControl, bound to by the designer&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            GenericTabHeaderViewModel headerVM = tabHeader.DataContext &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; GenericTabHeaderViewModel;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (headerVM != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #008000"&gt;// Create the TabItem that will be added to the TabControl&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                TabItem tabItem = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TabItem();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #008000"&gt;// Determine which UserControl to create and what to display in the header&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (SelectedIndex)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; 0:
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                        tabItem.Content = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XamlPathList();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                        headerVM.HeaderDisplay = "&lt;span style="color: #8b0000"&gt;Design-Time PathListBox&lt;/span&gt;";
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                        &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; 1:
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                        tabItem.Content = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DynamicPathList();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                        headerVM.HeaderDisplay = "&lt;span style="color: #8b0000"&gt;Run-Time PathListBox&lt;/span&gt;";
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                        &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;default&lt;/span&gt;:
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                        headerVM.HeaderDisplay = &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format("&lt;span style="color: #8b0000"&gt;Unknown selection: {0}&lt;/span&gt;", SelectedIndex);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                        &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #008000"&gt;// Use the header we just created&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                tabItem.Header = tabHeader;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #008000"&gt;// The GenericTabHeaderViewModel needs references to the TabControl and TabItem so it can close the tab when the user clicks on the close button&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                headerVM.TabControlClient = _tabControl;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                headerVM.TabItemClient = tabItem;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #008000"&gt;// And finally, add the new TabItem to the TabControl&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                _tabControl.Items.Add(tabItem);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;h2&gt;&lt;strong&gt;GenericTabHeaderViewModel&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;GenericTabHeader&lt;/strong&gt; is a UserControl used to supply the contents of the &lt;strong&gt;TabItem&lt;/strong&gt;.&lt;strong&gt;Header&lt;/strong&gt;. &lt;strong&gt;GenericTabHeaderViewModel&lt;/strong&gt; provides the functionality:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; ooNaTabbed
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; GenericTabHeaderViewModel : INotifyPropertyChanged
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// GenericTabHeaderViewModel has two functions&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Maintain a HeaderDisplay string property for the tab header name display to bind to&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// - Support a CloseTabCommand ICommand implementation for the tab header close button to bind to&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region Constructor(s)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; GenericTabHeaderViewModel()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            CloseTabCommand = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DelegateCommand(CloseTab, CanCloseTab);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region CloseTabCommand
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ICommand CloseTabCommand { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CloseTab(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #008000"&gt;// Remove this TabItem from the Tab control&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            TabControlClient.Items.Remove(TabItemClient);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; CanCloseTab(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; TabControlClient != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;&amp; TabItemClient != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #008000"&gt;// TabControlClient and TabItemClient are set by the AddTabItem behavior&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region TabControlClient
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; TabControl _TabControlClient;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; TabControl TabControlClient
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._TabControlClient; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._TabControlClient != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._TabControlClient = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;TabControlClient&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region TabItemClient
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; TabItem _TabItemClient;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; TabItem TabItemClient
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._TabItemClient; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._TabItemClient != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._TabItemClient = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;TabItemClient&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region HeaderDisplay
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _HeaderDisplay = "&lt;span style="color: #8b0000"&gt;Tab Header&lt;/span&gt;";
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; HeaderDisplay
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._HeaderDisplay; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._HeaderDisplay != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._HeaderDisplay = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;HeaderDisplay&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion&lt;/pre&gt;&lt;/pre&gt;

&lt;h2&gt;&lt;strong&gt;Bringing it All Together&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Here’s the binding to the behavior:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_14.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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb_6.png" width="1028" height="633" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;You can’t see it clearly, but the &lt;strong&gt;SourceObject&lt;/strong&gt; is set to the &lt;strong&gt;ComboBox&lt;/strong&gt;, and as you can see the behavior is triggered onthe &lt;strong&gt;SelectionChangedEvent&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And here’s the binding of the Behavior &lt;strong&gt;SelectedIndex&lt;/strong&gt; property to the &lt;strong&gt;SelectedIndex&lt;/strong&gt; property of the &lt;strong&gt;ComboBox&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_12.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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb_5.png" width="821" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The upshot being that the change in the &lt;strong&gt;ComboBox&lt;/strong&gt; &lt;strong&gt;SelectionChanged  &lt;/strong&gt;event triggers the behavior, which then uses the property that changes as a result of the event, &lt;strong&gt;SelectedIndex&lt;/strong&gt;, to determine which UserControl to create as content for the new &lt;strong&gt;TabItem&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Speaking of which, here’s how the &lt;strong&gt;ComboBox&lt;/strong&gt; gets loaded:&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;The Grungy Part&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_16.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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb_7.png" width="766" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;As I mentioned in the beginning, this is a quick way to add tabbed pages to your project, and what’s quicker than adding hard-coded list items and determining which is which by their offset in the list? In anything other than a demonstration application you’ll probably want this part of the code to be more robust. In that case you can bind to the ComboBox &lt;strong&gt;SelectedItem&lt;/strong&gt; or &lt;strong&gt;SelectedValue&lt;/strong&gt; properties. When you load the &lt;strong&gt;ComboBox&lt;/strong&gt; you would set the &lt;strong&gt;Value&lt;/strong&gt; property of each &lt;strong&gt;ComboBoxListItem&lt;/strong&gt; to some value, such as an &lt;strong&gt;enum&lt;/strong&gt;, that would specifically identify the selection no matter what order the list is in.&lt;/p&gt;

&lt;h2&gt;&lt;strong&gt;Fixes&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;I guess I should point out that the content of the pages has nothing to do with the subject of the article. They’re part of a project I was working on when I decided to switch to tabbed pages. But even so, the problem that Michael Washington found (and fixed) on the first page should not stand. The animation needs to stop when the user switches away from the page:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_20.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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb_9.png" width="910" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I also decided I wanted the first item in the &lt;strong&gt;ComboBox&lt;/strong&gt; selected automatically, so I added a &lt;strong&gt;SelectFirstItem&lt;/strong&gt; Behavior to be triggered by the &lt;strong&gt;ComboBox&lt;/strong&gt; &lt;strong&gt;Loaded&lt;/strong&gt; event (bound by the Designer in Blend – not shown):&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; ooNaTabbed
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SelectFirstItem : TargetedTriggerAction&lt;TabControl&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ComboBox _ComboBox;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnAttached()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnAttached();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            _ComboBox = AssociatedObject &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; ComboBox;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Invoke(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_ComboBox != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;&amp; _ComboBox.Items.Count &gt; 0)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                _ComboBox.SelectedIndex = 0;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnDetaching()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnDetaching();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The problem is that &lt;strong&gt;AddTabItem&lt;/strong&gt; behavior is triggered on the &lt;strong&gt;ComboBox&lt;/strong&gt; &lt;strong&gt;SelectionChanged&lt;/strong&gt; event. which is not triggered by programmatically changing the value of &lt;strong&gt;CombobBox&lt;/strong&gt; &lt;strong&gt;SelectedIndex&lt;/strong&gt;. So the &lt;strong&gt;AddTabItem&lt;/strong&gt; behavior must be triggered on the &lt;strong&gt;ComboBox&lt;/strong&gt; &lt;strong&gt;SelectedIndex&lt;/strong&gt; &lt;strong&gt;PropertyChanged&lt;/strong&gt; event:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_24.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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb_11.png" width="1028" height="612" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_29.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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb_4.png" width="614" height="737" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The change is subtle, but important. Instead of being triggered by the &lt;strong&gt;ComboBox SelectionChanged&lt;/strong&gt; event, the &lt;strong&gt;AddTabItem&lt;/strong&gt; Behavior is triggered by the change in the &lt;strong&gt;ComboBox SelectedIndex&lt;/strong&gt; property. &lt;strong&gt;AddTabItems&lt;/strong&gt; is now bound to &lt;strong&gt;SelectedIndex&lt;/strong&gt; in two ways. It’s triggered when the property changes, and the behavior &lt;strong&gt;SelectedIndex&lt;/strong&gt; property is bound to the &lt;strong&gt;ComboBox&lt;/strong&gt; &lt;strong&gt;SelectedIndex&lt;/strong&gt; property – which actually makes the most sense – a change in the property you’re interested in causes you to do something with that property, or more accurately the local copy of the property which is kept current through binding. Keep in mind, however, that type of binding, where a change to the UI sets the underlying property is only supported if you set &lt;strong&gt;Binding&lt;/strong&gt; &lt;strong&gt;Direction&lt;/strong&gt; to &lt;strong&gt;TwoWay&lt;/strong&gt; as you see below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_27.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="/Portals/0/Blog/Files/3/138/WLW-AddTabbedPagesToYourProjectQuickandEasy_BDFB-image_thumb_3.png" width="649" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;And one last note; I found that as I add pages I prefer the default tab to open at startup be the last one in the list, so I created an &lt;strong&gt;OpenLastItem&lt;/strong&gt; behavior with the following change to the Invoke method:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Invoke(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_ComboBox != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;&amp; _ComboBox.Items.Count &gt; 0)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                _ComboBox.SelectedIndex = _ComboBox.Items.Count - 1;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/138/Add-Tabbed-Pages-To-Your-Silverlight-Project-Quick-and-Easy.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/138/Add-Tabbed-Pages-To-Your-Silverlight-Project-Quick-and-Easy.aspx#Comments</comments>
      <slash:comments>1</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/138/Add-Tabbed-Pages-To-Your-Silverlight-Project-Quick-and-Easy.aspx</guid>
      <pubDate>Sun, 21 Nov 2010 21:52:53 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=138</trackback:ping>
    </item>
    <item>
      <title>PollResultsBarBehavior &amp;ndash; Binding to Multiple Values Through a Behavior and Custom Dependency Properties</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/136/PollResultsBarBehavior-ndash-Binding-to-Multiple-Values-Through-a-Behavior-and-Custom-Dependency-Properties.aspx</link>
      <description>&lt;p&gt;This is a follow up to my previous article &lt;a href="http://www.openlightgroup.net/Blog/tabid/58/EntryId/135/PollResultsBar-ndash-Binding-to-Multiple-Values-Through-Inheritance-and-Custom-Dependency-Properties.aspx"&gt;PollResultsBar – Binding to Multiple Values Through Inheritance and Custom Dependency Properties&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.nethttp://www.openlightgroup.net/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_12.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="/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_thumb_5.png" width="644" height="441" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In it I describe how to bind a single &lt;strong&gt;ProgressBar&lt;/strong&gt; property to multiple ViewModel properties through use of an inherited class so I can bind the &lt;strong&gt;Maximum&lt;/strong&gt; property to the sum of the Agree and Disagree counts. I found it’s possible to accomplish the same thing through a behavior:&lt;/p&gt; &lt;strong&gt;DownloadCode:&lt;/strong&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://richardwaddell.adefwebserver.com/PollResultsBarBehaviorDemo.zip"&gt;http://richardwaddell.adefwebserver.com/PollResultsBarBehaviorDemo.zip&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;The Behavior&lt;/strong&gt;&lt;/h2&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PollResultsBarDemo
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; PollResultsBarBehavior : Behavior&lt;DependencyObject&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        ProgressBar _progressBar;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; PollResultsBarBehavior()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;	}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnAttached()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnAttached();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            _progressBar = AssociatedObject &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; ProgressBar;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;	}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnDetaching()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnDetaching();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;	}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; DependencyProperty LeftValueProperty =
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;             DependencyProperty.Register("&lt;span style="color: #8b0000"&gt;LeftValue&lt;/span&gt;",
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(PollResultsBarBehavior),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyMetadata(50, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedCallback(OnLeftValueChanged)));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; DependencyProperty RightValueProperty =
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;             DependencyProperty.Register("&lt;span style="color: #8b0000"&gt;RightValue&lt;/span&gt;",
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(PollResultsBarBehavior),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyMetadata(50, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedCallback(OnRightValueChanged)));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; LeftValue
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.GetValue(LeftValueProperty); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.SetValue(LeftValueProperty, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; RightValue
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.GetValue(RightValueProperty); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.SetValue(RightValueProperty, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnLeftValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            SetMaximum(d &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PollResultsBarBehavior);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            SetValue(d &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PollResultsBarBehavior, (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)e.NewValue);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetValue(PollResultsBarBehavior bar, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual))
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (bar._progressBar != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                bar._progressBar.Value = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnRightValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            SetMaximum(d &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PollResultsBarBehavior);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetMaximum(PollResultsBarBehavior bar)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual))
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (bar._progressBar != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                bar._progressBar.Maximum = bar.LeftValue + bar.RightValue;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The code is not that different, we are just applying the Behavior properties to the attached &lt;strong&gt;ProgressBar&lt;/strong&gt; instead of applying new  properties in the inherited class to base properties of the &lt;strong&gt;ProgressBar&lt;/strong&gt; class we inherited from. You could say that the behavior &lt;em&gt;has a&lt;/em&gt; ProgressBar, whereas PollResultsBar &lt;em&gt;is a&lt;/em&gt; ProgressBar.&lt;/p&gt;

&lt;p&gt;Find the behavior under &lt;strong&gt;Assets/Behaviors&lt;/strong&gt; and attach to the &lt;strong&gt;ProgressBar&lt;/strong&gt; you used to replace &lt;strong&gt;PollResultsBar. &lt;/strong&gt;Notice that nothing triggers the behavior. It simply detects changes to its properties and applies them to the &lt;strong&gt;ProgressBar&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-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="/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_thumb_1.png" width="644" height="349" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now bind the behavior LeftValue and RightValue properties by dragging from MainPageViewModel:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-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="/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_thumb_2.png" width="644" height="168" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;and selecting from the dropdown:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-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="/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_thumb_4.png" width="644" height="332" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Do the same with DisagreeCount and the RightValue Property.&lt;/p&gt;

&lt;p&gt;You may notice above that Blend is unhappy with these settings. At some point it may show an exception in the design area and prevent you from getting out of the ItemTemplate and back to MainPage.xaml. In this case close Blend and reopen and everything should be fine. There seemed to be fewer problems if you bind AgreeCount and Disagree count by binding the long way:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_14.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="/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_thumb_6.png" width="644" height="464" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;and then picking AgreeCount:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_16.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="/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_thumb_7.png" width="631" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Well, maybe not. Just tried it again and Blend threw an exception&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_18.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="/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_thumb_8.png" width="963" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;At this point you can’t get out of the ItemTemplate so you have to re-start Blend.&lt;/p&gt;

&lt;p&gt;Fortunately, I found a way to avoid the problem. If I find myself in Design Mode when I’m about to set a ProgressBar property I bail :&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetValue(PollResultsBarBehavior bar, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual))
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (bar._progressBar != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                bar._progressBar.Value = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetMaximum(PollResultsBarBehavior bar)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual))
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (bar._progressBar != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                bar._progressBar.Maximum = bar.LeftValue + bar.RightValue;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;When you run the app you should see:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.nethttp://www.openlightgroup.net/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_12.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="/Portals/0/Blog/Files/3/136/WLW-PollResultsBarBehaviorBindingtoMultipleV_12047-image_thumb_5.png" width="644" height="441" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;It’s hard to say which it the better approach. It probably comes down to which provides the more reusable code, which probably depends on the circumstance.&lt;/p&gt;

&lt;p&gt;I am fascinated by behaviors and the concept of a control that provides the capabilities but is exclusively directed by behaviors in its actual activities, so I’ll probably lean in the direction of using them.&lt;/p&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/136/PollResultsBarBehavior-ndash-Binding-to-Multiple-Values-Through-a-Behavior-and-Custom-Dependency-Properties.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/136/PollResultsBarBehavior-ndash-Binding-to-Multiple-Values-Through-a-Behavior-and-Custom-Dependency-Properties.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/136/PollResultsBarBehavior-ndash-Binding-to-Multiple-Values-Through-a-Behavior-and-Custom-Dependency-Properties.aspx</guid>
      <pubDate>Sun, 31 Oct 2010 03:36:30 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=136</trackback:ping>
    </item>
    <item>
      <title>PollResultsBar &amp;ndash; Binding to Multiple Values Through Inheritance and Custom Dependency Properties</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/135/PollResultsBar-ndash-Binding-to-Multiple-Values-Through-Inheritance-and-Custom-Dependency-Properties.aspx</link>
      <description>&lt;p&gt;I recently had the requirement to create an interface similar to the following:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb.png" width="644" height="150" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The item of interest is the colored bar that shows the ratio between agreements and disagreements. We can use a &lt;strong&gt;ProgressBar&lt;/strong&gt; and set the &lt;strong&gt;Maximum&lt;/strong&gt; property  to the total of the&lt;strong&gt; Agree&lt;/strong&gt; and &lt;strong&gt;Disagree &lt;/strong&gt;counts, and set the &lt;strong&gt;Value&lt;/strong&gt; property to the &lt;strong&gt;Agree&lt;/strong&gt; count. Nothing very tricky except how to bind the &lt;strong&gt;Maximum&lt;/strong&gt; property in the &lt;strong&gt;ProgressBar&lt;/strong&gt; to two separate properties in the ViewModel.&lt;/p&gt;  &lt;p&gt;This may not be the best solution, but it’s a good example of how you can use inheritance and custom Dependency Properties to solve the problem.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;DownloadCode:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://richardwaddell.adefwebserver.com/PollResultsBarDemo.zip"&gt;http://richardwaddell.adefwebserver.com/PollResultsBarDemo.zip&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To start we’ll create a Silverlight application with hosting web site.  &lt;a href="http://www.openlightgroup.net/Blog/tabid/58/EntryId/133/Isolating-the-C-Code-in-Silverlight-Class-Library-Projects.aspx"&gt;Here’s a step-by-step if you need it&lt;/a&gt;; you can ignore all the stuff about isolating the code in a separate Silverlight class library for this simple example, just do the steps to create the Silverlight project and select the option to create the hosting website.&lt;/p&gt;  &lt;p&gt;First we’ll create a &lt;strong&gt;PollResults&lt;/strong&gt; class:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PollResultsBarDemo
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; PollResults
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; PollResults(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; statement, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; agreeCount, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; disagreeCount)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            Statement = statement;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            AgreeCount = agreeCount;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            DisagreeCount = disagreeCount;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Statement { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; AgreeCount { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; DisagreeCount { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then a &lt;strong&gt;PollResultsBarDemoModel&lt;/strong&gt; class to provide a &lt;strong&gt;GetPollResults&lt;/strong&gt; method:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PollResultsBarDemo
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; PollResultsBarDemoModel
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; ObservableCollection&lt;PollResults&gt; GetPollResults()
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            ObservableCollection&lt;PollResults&gt; colResults = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObservableCollection&lt;PollResults&gt;();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colResults.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PollResults("&lt;span style="color: #8b0000"&gt;I'm coo-coo for Cocoa Pops&lt;/span&gt;", 170, 45));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colResults.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PollResults("&lt;span style="color: #8b0000"&gt;Dogs are better than cats&lt;/span&gt;", 60, 60));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colResults.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PollResults("&lt;span style="color: #8b0000"&gt;The world will end in 2012&lt;/span&gt;", 15, 30));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; colResults;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And a &lt;strong&gt;MainPageViewModel&lt;/strong&gt; class to consume it. You’ll notice I called &lt;strong&gt;GetPollResults()&lt;/strong&gt; from the constructor. In the real-world you may or may not want to do this, and you would probably provide a &lt;strong&gt;GetPollResultsCommand&lt;/strong&gt; &lt;strong&gt;ICommand&lt;/strong&gt; property that can be invoked from the &lt;strong&gt;View&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Speaking of the &lt;strong&gt;View&lt;/strong&gt;, open&lt;strong&gt; MainPage.xaml&lt;/strong&gt; in Expression Blend:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_2.png" width="644" height="246" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;At this point I ran into a problem in that Blend initially couldn’t see &lt;strong&gt;MainPageViewModel&lt;/strong&gt; even after re-building and opening and closing. Eventually I removed the constructor and re-built at which point Blend could see it. I put the constructor back in and fortunately Blend could still see it. So I was able to move ahead with:&lt;/p&gt;

&lt;p&gt;We want to assign &lt;strong&gt;MainPageViewModel&lt;/strong&gt; to the &lt;strong&gt;DataContext&lt;/strong&gt; property of &lt;strong&gt;UserControl&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Select &lt;strong&gt;UserControl&lt;/strong&gt; in &lt;strong&gt;Objects and Timeline &lt;/strong&gt;&lt;/li&gt;

  &lt;li&gt;Locate the &lt;strong&gt;DataContext&lt;/strong&gt; property &lt;/li&gt;

  &lt;li&gt;Click the &lt;strong&gt;New&lt;/strong&gt; button next to it &lt;/li&gt;

  &lt;li&gt;A &lt;strong&gt;Select Object&lt;/strong&gt; dialog will appear &lt;/li&gt;

  &lt;li&gt;Select &lt;strong&gt;MainPageViewModel&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_12.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_5.png" width="844" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Once you click on ‘OK’, you can select the &lt;strong&gt;Data&lt;/strong&gt; tab and see that &lt;strong&gt;PollResultsList&lt;/strong&gt; is available:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_14.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_6.png" width="644" height="306" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;(I did this a little out of order, so the &lt;strong&gt;ListBox&lt;/strong&gt; I’m about to add already appears in the screen shots above.)&lt;/p&gt;

&lt;p&gt;Add a &lt;strong&gt;ListBox&lt;/strong&gt; to &lt;strong&gt;LayoutRoot&lt;/strong&gt;. The easiest way is to, with &lt;strong&gt;LayoutRoot&lt;/strong&gt; selected, click on the little white triangle on the icon above the &lt;strong&gt;Assets&lt;/strong&gt; icon, whose default image will be a &lt;strong&gt;Button&lt;/strong&gt; icon, as shown.  Then click on &lt;strong&gt;ListBox&lt;/strong&gt; on the dropdown and the &lt;strong&gt;ListBox&lt;/strong&gt; icon will replace the &lt;strong&gt;Button&lt;/strong&gt; icon on the &lt;strong&gt;Tools&lt;/strong&gt; &lt;strong&gt;Panel&lt;/strong&gt;. Double-click on the &lt;strong&gt;ListBox&lt;/strong&gt; icon and one will be inserted into &lt;strong&gt;LayoutRoot&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_4.png" width="232" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Drag &lt;strong&gt;PollResultsList&lt;/strong&gt; onto &lt;strong&gt;UserControl&lt;/strong&gt; so that you see the message shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_16.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_7.png" width="644" height="339" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I’m a big fan of instant gratification, so I always run stuff the first time I think something will show up:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_18.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_8.png" width="205" height="145" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Setting &lt;strong&gt;Width&lt;/strong&gt; and &lt;strong&gt;Height&lt;/strong&gt; to &lt;strong&gt;Auto&lt;/strong&gt; and the alignment to &lt;strong&gt;Stretch&lt;/strong&gt; will cause the &lt;strong&gt;ListBox&lt;/strong&gt; to fill &lt;strong&gt;LayoutRoot&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_20.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_9.png" width="1028" height="466" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The problem with that is at run-time &lt;a href="http://www.openlightgroup.net/Blog/tabid/58/EntryId/131/More-Simple-Blend-Layout-Techniques-and-Quirks.aspx#eexpands"&gt;you get a ListBox that fills the entire browser window&lt;/a&gt;.  For this example I’m going to continue to fill &lt;strong&gt;LayoutRoot&lt;/strong&gt;, which fills &lt;strong&gt;UserControl&lt;/strong&gt;, with the &lt;strong&gt;ListBox&lt;/strong&gt;, so let’s constrain &lt;strong&gt;UserControl&lt;/strong&gt; to 400 x 600.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_22.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_10.png" width="1028" height="492" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;In case you don’t know, the little white squares next to &lt;strong&gt;Width&lt;/strong&gt; and &lt;strong&gt;Height&lt;/strong&gt; (&lt;strong&gt;Advanced&lt;/strong&gt; &lt;strong&gt;Option&lt;/strong&gt; icons) indicate that they are set to other than their default values. If they were still at their default values the &lt;strong&gt;Advanced&lt;/strong&gt; &lt;strong&gt;Option&lt;/strong&gt; icons would appear gray, as you see next to &lt;strong&gt;HorizontalAlignment&lt;/strong&gt; in the line below &lt;strong&gt;Height&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Don’t confuse default with the initial settings you get when you add a new control in Blend. Quite often they arrive with the &lt;strong&gt;Advanced&lt;/strong&gt; &lt;strong&gt;Options&lt;/strong&gt; icon set to white.&lt;/p&gt;

&lt;p&gt;We need to reformat the list box entries which means editing the &lt;strong&gt;ListBox&lt;/strong&gt; &lt;strong&gt;ItemTemplate&lt;/strong&gt;. Right-click on &lt;strong&gt;ListBox&lt;/strong&gt;, then select &lt;strong&gt;Edit Additional Templates/ Edit Generated Items (ItemTemplate) / Edit Current&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_24.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_11.png" width="1028" height="199" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, our current &lt;strong&gt;ItemTemplate&lt;/strong&gt; is a vertically oriented &lt;strong&gt;StackPanel&lt;/strong&gt; containing three &lt;strong&gt;TextBoxes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_26.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_12.png" width="644" height="445" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We can sort this out pretty quick. Move the bottom &lt;strong&gt;TextBlock&lt;/strong&gt; above the other two and set its &lt;strong&gt;Width&lt;/strong&gt; to &lt;strong&gt;Auto&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_30.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_14.png" width="644" height="402" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Add a new &lt;strong&gt;StackPanel&lt;/strong&gt; to the existing one and set its &lt;strong&gt;Width&lt;/strong&gt; and &lt;strong&gt;Height&lt;/strong&gt; to &lt;strong&gt;Auto&lt;/strong&gt; and  &lt;strong&gt;Orientation&lt;/strong&gt; to &lt;strong&gt;Horizontal&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_34.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_16.png" width="644" height="372" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Starting with the second of the three TextBlocks, cut and paste the bottom two into the new StackPanel.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_36.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_17.png" width="644" height="395" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now all we need is a PollResultsBar to place between the two &lt;strong&gt;TextBlocks&lt;/strong&gt; in the second &lt;strong&gt;StackPanel&lt;/strong&gt;:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Net;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Controls;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Documents;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Ink;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Input;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Media;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Media.Animation;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Shapes;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.ComponentModel;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; PollResultsBarDemo
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; PollResultsBar : ProgressBar
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; DependencyProperty LeftValueProperty =
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;             DependencyProperty.Register("&lt;span style="color: #8b0000"&gt;LeftValue&lt;/span&gt;",
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(PollResultsBar),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyMetadata(0, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedCallback(OnLeftValueChanged)));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; DependencyProperty RightValueProperty =
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;             DependencyProperty.Register("&lt;span style="color: #8b0000"&gt;RightValue&lt;/span&gt;",
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(PollResultsBar),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                                             &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyMetadata(0, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedCallback(OnRightValueChanged)));
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; LeftValue
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.GetValue(LeftValueProperty); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.SetValue(LeftValueProperty, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; RightValue
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.GetValue(RightValueProperty); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.SetValue(RightValueProperty, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnLeftValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            SetValue(d &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PollResultsBar, (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)e.NewValue);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            SetMaximum(d &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PollResultsBar);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetValue(PollResultsBar bar, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            bar.Value = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnRightValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            SetMaximum(d &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PollResultsBar);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetMaximum(PollResultsBar bar)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            bar.Maximum = bar.LeftValue + bar.RightValue;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;The Dependency Properties allow Blend to enable binding to &lt;strong&gt;PollResultsBar&lt;/strong&gt; &lt;strong&gt;LeftValue&lt;/strong&gt; and &lt;strong&gt;RightValue&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;Each Dependency property Registration specifies a method to be called when the property value changes. &lt;/li&gt;

  &lt;li&gt;These methods, &lt;strong&gt;OnLeftValueChanged&lt;/strong&gt; and &lt;strong&gt;OnRightValueChanged&lt;/strong&gt; cast the DependencyObject argument ‘d’ to &lt;strong&gt;PollResultsBar&lt;/strong&gt; and calls &lt;strong&gt;SetMaximum()&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;SetMaximum()&lt;/strong&gt; sets the &lt;strong&gt;ProgressBar&lt;/strong&gt; &lt;strong&gt;Maximum&lt;/strong&gt; property to the sum of &lt;strong&gt;LeftValue&lt;/strong&gt; and &lt;strong&gt;RightValue&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;OnLeftValueChanged&lt;/strong&gt; calls &lt;strong&gt;SetValue()&lt;/strong&gt; which sets the &lt;strong&gt;ProgressBar.Value&lt;/strong&gt; property to &lt;strong&gt;(int)e.NewValue&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After re-building the project, I had to fiddle with the code and closing and re-opening Blend to get the PollResultsBar control is available in&lt;strong&gt; Assets / Project&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_38.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_18.png" width="644" height="184" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Add it to &lt;strong&gt;StackPanel&lt;/strong&gt; and move it between the two &lt;strong&gt;TextBlocks&lt;/strong&gt;. I also added a margin to the left of &lt;strong&gt;PollResultsBar&lt;/strong&gt; and the left of the second &lt;strong&gt;TextBlock&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_42.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_20.png" width="644" height="408" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Drag &lt;strong&gt;AgreeCount&lt;/strong&gt; onto &lt;strong&gt;PollResultsBar&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_46.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_22.png" width="644" height="410" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select &lt;strong&gt;LeftValue&lt;/strong&gt; from the dropdown:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_48.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_23.png" width="644" height="426" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Do the same for &lt;strong&gt;RightValue&lt;/strong&gt;, run the application, and sure enough:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_50.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_24.png" width="222" height="177" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Since &lt;strong&gt;PollResultsBar&lt;/strong&gt; is maintaining the value, I tried to hide &lt;strong&gt;ProgressBar.Maximum&lt;/strong&gt; property from Blend:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; Maximum
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; { base.Maximum = value; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; base.Maximum; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;With no success:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_52.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="/Portals/0/Blog/Files/3/135/WLW-PollResultsBarBindingtoMultipleValuesThr_8C92-image_thumb_25.png" width="644" height="297" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;This seems like a pretty comprehensive way to handle binding to multiple properties in the ViewModel.&lt;/p&gt;

&lt;p&gt;I’m pretty sure you could do the same with a behavior,which will probably be my next blog.&lt;/p&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/135/PollResultsBar-ndash-Binding-to-Multiple-Values-Through-Inheritance-and-Custom-Dependency-Properties.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/135/PollResultsBar-ndash-Binding-to-Multiple-Values-Through-Inheritance-and-Custom-Dependency-Properties.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/135/PollResultsBar-ndash-Binding-to-Multiple-Values-Through-Inheritance-and-Custom-Dependency-Properties.aspx</guid>
      <pubDate>Sat, 30 Oct 2010 20:22:05 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=135</trackback:ping>
    </item>
    <item>
      <title>HisowaModPopUpBehavior with de Oliveira Menu</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/134/HisowaModPopUpBehavior-with-de-Oliveira-Menu.aspx</link>
      <description>&lt;p&gt;This tutorial will take you through the steps necessary to add a &lt;a href="http://www.codeproject.com/KB/silverlight/SilverlightMenu.aspx" target="_blank"&gt;Menu&lt;/a&gt; to a Silverlight UserControl and attach a &lt;a href="http://www.openlightgroup.nethttp://www.openlightgroup.net/Blog/tabid/58/EntryId/123/Silverlight-Behavior-HisowaModPopUpBehavior.aspx" target="_blank"&gt;HisowaModPopUpBehavior&lt;/a&gt; and make them work together.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.nethttp://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_99.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_19.png" width="585" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="3"&gt;The advantages of Marcelo Ricardo de Oliveira’s &lt;/font&gt;&lt;/strong&gt;&lt;a href="http://www.codeproject.com/KB/silverlight/SilverlightMenu.aspx" target="_blank"&gt;&lt;strong&gt;&lt;font size="3"&gt;Silverlight Menu&lt;/font&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;font size="3"&gt;:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;1. It’s easy to implement. &lt;/p&gt;  &lt;p&gt;2. It’s easy to understand. &lt;/p&gt;  &lt;p&gt;3. It’s easy to customize. &lt;/p&gt;  &lt;p&gt;4. You can specify an &lt;strong&gt;ICommand&lt;/strong&gt; to be called when any selection is clicked and determine the selection within the &lt;strong&gt;ICommand&lt;/strong&gt; implementation. &lt;/p&gt;  &lt;p&gt;5. You can catch a &lt;strong&gt;MenuItemClicked&lt;/strong&gt; &lt;strong&gt;event&lt;/strong&gt; and get the selected menu item in the event handler. &lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;strong&gt;The advantages of Haruhiro Osawa’s &lt;/strong&gt;&lt;/font&gt;&lt;a href="http://www.openlightgroup.nethttp://www.openlightgroup.net/Blog/tabid/58/EntryId/123/Silverlight-Behavior-HisowaModPopUpBehavior.aspx" target="_blank"&gt;&lt;font size="3"&gt;&lt;strong&gt;HisowaModPopUpBehavior&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;&lt;strong&gt;:&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;1. You can define your own &lt;strong&gt;UserControl&lt;/strong&gt; to be presented as the UI of a &lt;strong&gt;Popup&lt;/strong&gt; &lt;strong&gt;Window, &lt;/strong&gt;composed of View and ViewModel. &lt;/p&gt;  &lt;p&gt;2. You can customize the frame of the &lt;strong&gt;Popup&lt;/strong&gt; &lt;strong&gt;Window&lt;/strong&gt; through behavior properties. &lt;/p&gt;  &lt;p&gt;3. You can trigger the &lt;strong&gt;Popup&lt;/strong&gt; &lt;strong&gt;Window&lt;/strong&gt; as you would any other behavior, such as on the &lt;strong&gt;MenuItemClicked&lt;/strong&gt; &lt;strong&gt;event&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;4. You can specify an &lt;strong&gt;ICommand&lt;/strong&gt; implementation to be called when the user exits the window &lt;/p&gt;  &lt;p&gt;5. You can access the &lt;strong&gt;ViewModel&lt;/strong&gt; of your &lt;strong&gt;Custom User Interface&lt;/strong&gt; to determine the user’s selection and of course whether the user accepted or declined. &lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;Other Acknowledgements / References:&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;Josh Smith for the &lt;a href="http://www.cauldwell.net/patrick/blog/MVVMBindingToCommandsInSilverlight.aspx" target="_blank"&gt;RelayCommand helper class&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Code-Free Zones and Silverlight Class Libraries&lt;/h2&gt;  &lt;p&gt;I like the idea of keeping all the C# code except for the mandatory code-behind in one or more separate class libraries.&lt;/p&gt;  &lt;p&gt;Therefore, our solution will consist of &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A hosting web application project &lt;/li&gt;    &lt;li&gt;The main Silverlight project  with &lt;/li&gt;    &lt;li&gt;A Silverlight Class Library project &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you need to see how the solution was put together, or if you’re just curious &lt;a href="http://www.openlightgroup.net/Blog/tabid/58/EntryId/133/Isolating-the-C-Code-in-Silverlight-Class-Library-Projects.aspx"&gt;all the steps are described in a separate article&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Views and ViewModels&lt;/h2&gt;  &lt;p&gt;We’ve added a reference to &lt;strong&gt;MenuPopupViewModel.dll&lt;/strong&gt;. Now we’ll create a &lt;strong&gt;MainPageViewModel&lt;/strong&gt; class, build the &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; project and find out if we can see the class when we open &lt;strong&gt;MainPage.xaml&lt;/strong&gt; in Blend.&lt;/p&gt;  &lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Net;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Controls;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Documents;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Ink;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Input;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Media;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Media.Animation;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Shapes;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; MenuPopupViewModel
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MainPageViewModel
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And sure enough, there it is. To add MainPageViewModel as the DataContext for MainPage.UserControl&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Select &lt;strong&gt;UserControl&lt;/strong&gt; in&lt;strong&gt; Objects and Timeline&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;From &lt;strong&gt;Properties/Common&lt;/strong&gt; Properties click on the &lt;strong&gt;New&lt;/strong&gt; button next to &lt;strong&gt;DataContext&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;From the &lt;strong&gt;Select Object&lt;/strong&gt; dialog, select &lt;strong&gt;MainPageViewModel&lt;/strong&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_26.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_11.png" width="1028" height="683" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So far, so good. Our next challenge is to create the menu class in &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt;. Strictly speaking this class should go in a separate assembly since it’s not really part of the &lt;strong&gt;ViewModel&lt;/strong&gt;. As you’ll see, &lt;strong&gt;Menu&lt;/strong&gt; inherits from &lt;strong&gt;Grid&lt;/strong&gt;, so it’s a &lt;strong&gt;UIElement&lt;/strong&gt;, but if we want to maintain &lt;strong&gt;MenuPopUp&lt;/strong&gt; as a code-free zone it should live in a class library, and for convenience we’re leaving it in &lt;strong&gt;MenuPopupViewModel.dll&lt;/strong&gt;. Here’s how the project looks after adding a &lt;strong&gt;Classes&lt;/strong&gt; folder, the two &lt;strong&gt;Silverlight&lt;/strong&gt; &lt;strong&gt;Menu&lt;/strong&gt; files and a helper class that’s included with the &lt;a href="http://www.codeproject.com/KB/silverlight/SilverlightMenu.aspx" target="_blank"&gt;Silverlight Menu sample project&lt;/a&gt;. The helper class, &lt;strong&gt;RelayCommand&lt;/strong&gt;, is from &lt;a href="http://www.cauldwell.net/patrick/blog/MVVMBindingToCommandsInSilverlight.aspx" target="_blank"&gt;Josh Smith and is described on Patrick Cauldwell's Blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_30.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_13.png" width="644" height="255" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After we build &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; and go back to Blend we look at &lt;strong&gt;Assets/Locations/MenuPopupViewModel.csproj&lt;/strong&gt; and see that we now have a &lt;strong&gt;Menu&lt;/strong&gt; control available.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_32.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_14.png" width="1028" height="745" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So you can drag it from here to &lt;strong&gt;Layout&lt;/strong&gt; &lt;strong&gt;Root&lt;/strong&gt; (which has an annoying habit of refusing to work on the first try), or double-click it here to pin it to the tool panel and then double-click to add it to the currently selected control. I chose to drag it, and on the second try it worked:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_34.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_15.png" width="644" height="474" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Out of the box, &lt;strong&gt;Menu&lt;/strong&gt; is placed in the upper-left corner of &lt;strong&gt;LayoutRoot&lt;/strong&gt; and is sized at 100 x 100.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_36.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_16.png" width="763" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And although you can see the &lt;strong&gt;Menu&lt;/strong&gt; control in Blend, when you run the app you get a blank screen, actually the whole page is a blank white page. &lt;a href="http://www.openlightgroup.net/Blog/tabid/58/EntryId/131/More-Simple-Blend-Layout-Techniques-and-Quirks.aspx#eexpands" target="_blank"&gt;That’s because the default settings cause MainPage to expand to fill the browser page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For some reason Menu doesn’t appear, but I don’t want &lt;strong&gt;MainPage&lt;/strong&gt; to fill its container anyway. I want it to be a fixed size, so I’m going to hard-code it to 800 x 600 and leave &lt;strong&gt;LayoutRoot&lt;/strong&gt; set to stretch, and when I run it I see a blank menu along the top.&lt;/p&gt;

&lt;h2&gt;Adding The MenuItems&lt;/h2&gt;

&lt;p&gt;Now let’s add some selections to our menu in the form of &lt;strong&gt;MenuItems&lt;/strong&gt;. As you might expect, the &lt;strong&gt;MenuItem&lt;/strong&gt; collection will be in &lt;strong&gt;MainPageViewModel&lt;/strong&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; MenuItem _MVVMMenuItem;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MenuItem MVVMMenuItem
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._MVVMMenuItem; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._MVVMMenuItem != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._MVVMMenuItem = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;MVVMMenuItem&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;On the face of it this is not a collection of &lt;strong&gt;MenuItems&lt;/strong&gt;. But if we look at the actual &lt;strong&gt;MenuItem&lt;/strong&gt; class…&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;// Author of MenuItem Class: Marcelo Ricardo de Oliveira  http://www.codeproject.com/KB/silverlight/SilverlightMenu.aspx&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; MenuPopupViewModel
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    [ContentProperty("&lt;span style="color: #8b0000"&gt;MenuItems&lt;/span&gt;")]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MenuItem : ObservableCollection&lt;MenuItem&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;…. we see that each &lt;strong&gt;MenuItem&lt;/strong&gt; &lt;em&gt;is a &lt;/em&gt;collection of &lt;strong&gt;MenuItems&lt;/strong&gt;. This is slightly confusing to Blend as we’ll see later when we try to bind to the Name property of the &lt;strong&gt;Selected&lt;/strong&gt; &lt;strong&gt;MenuItem&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, back in &lt;strong&gt;MainPageViewModel&lt;/strong&gt; we initialize &lt;strong&gt;MVVMMenuItem&lt;/strong&gt; in the constructor:&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MainPageViewModel()
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #008000"&gt;// Menu Stuff&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.MVVMMenuItem = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MenuItem() { Name = "&lt;span style="color: #8b0000"&gt;Root&lt;/span&gt;" };
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    var mnuFile = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MenuItem() { Name = "&lt;span style="color: #8b0000"&gt;mnuFile&lt;/span&gt;", Text = "&lt;span style="color: #8b0000"&gt;File&lt;/span&gt;" };
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    var mnuTools = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MenuItem() { Name = "&lt;span style="color: #8b0000"&gt;mnuTools&lt;/span&gt;", Text = "&lt;span style="color: #8b0000"&gt;Tools&lt;/span&gt;" };
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    var mnuHelp = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MenuItem() { Name = "&lt;span style="color: #8b0000"&gt;mnuHelp&lt;/span&gt;", Text = "&lt;span style="color: #8b0000"&gt;Help&lt;/span&gt;" };
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    var mnuExit = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MenuItem() { Name = "&lt;span style="color: #8b0000"&gt;mnuExit&lt;/span&gt;", Text = "&lt;span style="color: #8b0000"&gt;Exit&lt;/span&gt;" };
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    var mnuThemes = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MenuItem() { Name = "&lt;span style="color: #8b0000"&gt;mnuThemes&lt;/span&gt;", Text = "&lt;span style="color: #8b0000"&gt;Themes&lt;/span&gt;" };
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    var mnuAbout = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MenuItem() { Name = "&lt;span style="color: #8b0000"&gt;mnuViewHelp&lt;/span&gt;", Text = "&lt;span style="color: #8b0000"&gt;About Silverlight Menu&lt;/span&gt;" };
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    mnuFile.Add(mnuExit);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    mnuTools.Add(mnuThemes);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    mnuHelp.Add(mnuAbout);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    MVVMMenuItem.Add(mnuFile);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    MVVMMenuItem.Add(mnuTools);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    MVVMMenuItem.Add(mnuHelp);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we have to bind the collection to the menu. You might think you could drag it:&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Don’t Do This!!!!&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_54.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_25.png" width="1028" height="572" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;But every time I tried Blend crashed. So you have to select the &lt;strong&gt;Advanced Option&lt;/strong&gt; Icon next to the &lt;strong&gt;MenuItem&lt;/strong&gt; property Unfortunately, when you do so, you only get these two options.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_56.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_26.png" width="327" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Go with&lt;strong&gt; Custom Expression…&lt;/strong&gt; and enter:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_58.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_27.png" width="1028" height="144" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You should use &lt;strong&gt;Custom expression&lt;/strong&gt; instead of editing the xaml directly because it will validate what you enter, and that’s the only place it gets validated. If you enter it directly and spell it wrong Blend will continue to show the gold border and the data type, such as ‘(Collection)’ in the screen shot above – and the binding will fail silently.   &lt;/p&gt;

&lt;p&gt;However, even though you should always use it, sometimes &lt;strong&gt;Custom&lt;/strong&gt; &lt;strong&gt;expression&lt;/strong&gt; rejects a valid expression, so in that case you have no choice but to edit the xaml (arrrgh):&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"LayoutRoot"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Background&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"#FF588131"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;MenuPopupViewModel&lt;/span&gt;:&lt;span style="color: #800000"&gt;Menu&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"menu"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MenuItem&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding MVVMMenuItem}"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And that’s it, we’re good to go!!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_52.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_24.png" width="644" height="196" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We’re missing an image but that’s ok for now. What we want to do now is to do something when the menu clicks on a menu item. To start with, we’ll create an &lt;strong&gt;ICommand&lt;/strong&gt; implementation to be called when a menu item is clicked:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ICommand MenuCommand
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RelayCommand(p =&gt; DoMenuCommand(p)); }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; void DoMenuCommand(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    var menuItem = (MenuItem)param;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    MessageBox.Show(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format("&lt;span style="color: #8b0000"&gt;You clicked: {0}&lt;/span&gt;", menuItem.Name));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Note that &lt;strong&gt;MenuCommad&lt;/strong&gt; is a property that references an &lt;strong&gt;ICommand&lt;/strong&gt; implementation. It does not use a backing store, instead get calls the &lt;strong&gt;RelayCommand&lt;/strong&gt; constructor passing &lt;strong&gt;DoMenuCommand as &lt;/strong&gt;the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/018hxwa8.aspx" target="_blank"&gt;Action&lt;object&gt;&lt;/a&gt;&lt;/strong&gt; argument and returns the resulting &lt;strong&gt;ICommand&lt;/strong&gt; object. If you’re not familiar with the syntax, a peek at the &lt;strong&gt;RelayCommand&lt;/strong&gt; constructor might help. Notice there’s an overload that allows you to pass in a &lt;strong&gt;canExecute&lt;/strong&gt; &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bfcke1bz.aspx" target="_blank"&gt;Predicate&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;//RelayCommand Implementagion by Josh Smith, &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; described here:
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;//http://www.cauldwell.net/patrick/blog/MVVMBindingToCommandsInSilverlight.aspx
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;//...
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// &lt;summary&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// Creates a &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; command that can always execute.
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// &lt;/summary&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// &lt;param name="&lt;span style="color: #8b0000"&gt;execute&lt;/span&gt;"&gt;The execution logic.&lt;/param&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; RelayCommand(Action&lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&gt; execute)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    : this(execute, null)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// &lt;summary&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// Creates a &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; command.
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// &lt;/summary&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// &lt;param name="&lt;span style="color: #8b0000"&gt;execute&lt;/span&gt;"&gt;The execution logic.&lt;/param&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;/// &lt;param name="&lt;span style="color: #8b0000"&gt;canExecute&lt;/span&gt;"&gt;The execution status logic.&lt;/param&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; RelayCommand(Action&lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&gt; execute, Predicate&lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&gt; canExecute)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (execute == null)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentNullException("&lt;span style="color: #8b0000"&gt;execute&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    _execute = execute;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    _canExecute = canExecute;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;When the &lt;strong&gt;ICommand&lt;/strong&gt; is actually invoked we see that parameter is passed to the &lt;strong&gt;Action&lt;/strong&gt; originally passed into the constructor, in this case &lt;strong&gt;DoMenuCommand&lt;/strong&gt;. We could have added a &lt;strong&gt;Predicate&lt;/strong&gt; to validate that &lt;strong&gt;parameter&lt;/strong&gt; is a &lt;strong&gt;MenuItem&lt;/strong&gt;, but in this case we’re trusting the caller.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;#region ICommand Members
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;[DebuggerStepThrough]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; bool CanExecute(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _canExecute == null ? &lt;span style="color: #0000ff"&gt;true&lt;/span&gt; : _canExecute(parameter);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; EventHandler CanExecuteChanged;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; void Execute(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    _execute(parameter);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;#endregion // ICommand Members&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Ok, we have our &lt;strong&gt;ICommand&lt;/strong&gt; and we know what happens when it gets called. Now we need to make &lt;strong&gt;Menu&lt;/strong&gt; call it when a menu item is clicked. For that we again have to resort to &lt;strong&gt;Custom&lt;/strong&gt; &lt;strong&gt;expression&lt;/strong&gt;. Set the &lt;strong&gt;menu&lt;/strong&gt; &lt;strong&gt;Command&lt;/strong&gt; &lt;strong&gt;property&lt;/strong&gt; to bind to &lt;strong&gt;MenuCommand&lt;/strong&gt; as seen below.&lt;/p&gt;

&lt;p&gt; &lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image97.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image97_thumb.png" width="1028" height="259" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And once again &lt;strong&gt;Custom&lt;/strong&gt; &lt;strong&gt;expression&lt;/strong&gt; may refuse a valid expression, so here’s the raw xaml:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"LayoutRoot"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Background&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"#FF588131"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;MenuPopupViewModel&lt;/span&gt;:&lt;span style="color: #800000"&gt;Menu&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"menu"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MenuItem&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding MVVMMenuItem}"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Command&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding MenuCommand}"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;That single expression is all &lt;strong&gt;menu&lt;/strong&gt; needs to invoke the command, because when we try it out we see that &lt;strong&gt;DoMenuCommand&lt;/strong&gt; does get called:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_62.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_29.png" width="644" height="464" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Here’s how it works. &lt;strong&gt;Command&lt;/strong&gt; is a &lt;strong&gt;Menu&lt;/strong&gt; &lt;strong&gt;DependencyProperty&lt;/strong&gt;:&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;CommandProperty =
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;DependencyProperty.Register("&lt;span style="color: #8b0000"&gt;Command&lt;/span&gt;", &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(ICommand), &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Menu),
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyMetadata(&lt;span style="color: #0000ff"&gt;null&lt;/span&gt;,
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedCallback(OnCommandChanged)));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;You can see that a callback has been defined that will be called when the property changes. And here it is: &lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  command = (ICommand)e.NewValue;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And here’s the actual property.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ICommand Command
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;   &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (ICommand)GetValue(CommandProperty); }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;   &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; { SetValue(CommandProperty, value); }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Step by step:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;MainPage.xaml&lt;/strong&gt; causes Dependency Property &lt;strong&gt;Menu.Command&lt;/strong&gt; to change by binding it to &lt;strong&gt;MainPageViewModel.MenuCommand&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;That change of &lt;strong&gt;Menu.Command&lt;/strong&gt; causes &lt;strong&gt;OnCommandChanged()&lt;/strong&gt; to be called, passing &lt;strong&gt;MainPageViewModel.MenuCommand&lt;/strong&gt; as the event argument property &lt;strong&gt;NewValue&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;OnCommandChanged()&lt;/strong&gt; sets &lt;strong&gt;Menu.command&lt;/strong&gt; to &lt;strong&gt;NewValue &lt;/strong&gt;so it now references &lt;strong&gt;MainPageViewModel.MenuCommand().&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;When a menu selection is clicked &lt;strong&gt;Menu&lt;/strong&gt;, in the event handler shown below,  calls &lt;strong&gt;command.Execute() &lt;/strong&gt;passing &lt;strong&gt;MenuItem&lt;/strong&gt; as the argument. &lt;/li&gt;

  &lt;li&gt;When &lt;strong&gt;RelayCommand&lt;/strong&gt; constructs the &lt;strong&gt;ICommand&lt;/strong&gt; implementation that is returned by the &lt;strong&gt;MenuCommand&lt;/strong&gt; property getter, it sets its internal  &lt;strong&gt;Action&lt;/strong&gt; field,_&lt;strong&gt;execute&lt;/strong&gt; to point to&lt;strong&gt; DoMenuCommand()&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;The result is that when &lt;strong&gt;Menu.command.Execute()&lt;/strong&gt; calls _&lt;strong&gt;execute&lt;/strong&gt;,  &lt;strong&gt;MainPageViewModel.DoMenuCommand()&lt;/strong&gt;  is called with the selected &lt;strong&gt;MenuItem&lt;/strong&gt; as the argument. &lt;/li&gt;
&lt;/ol&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; gridLevel2_MouseLeftButtonUp(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, MouseButtonEventArgs e)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #008000"&gt;// ...&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (command != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                command.Execute(menuItem);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;h3&gt;&lt;/h3&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately that’s not sufficient for our needs. When the user clicks on &lt;strong&gt;Themes&lt;/strong&gt;, we want a &lt;strong&gt;Themes&lt;/strong&gt; &lt;strong&gt;Selection&lt;/strong&gt; &lt;strong&gt;Popup&lt;/strong&gt; window to appear. We need a user interface and that’s not handled very conveniently through the ViewModel.&lt;/p&gt;

&lt;p&gt;And of course that’s where &lt;strong&gt;HisowaModPopUpBehavior&lt;/strong&gt; comes in. &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;We attach the behavior to  &lt;strong&gt;menu&lt;/strong&gt; and trigger it on &lt;strong&gt;MenuItemClicked&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;We define our own UserControl, &lt;strong&gt;ThemeSelectionView &lt;/strong&gt;that we want to appear within the popup along with &lt;strong&gt;ThemeSelectionViewModel&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;We define the &lt;strong&gt;ICommand&lt;/strong&gt;. &lt;strong&gt;InstallThemeCommand&lt;/strong&gt; that we want to be called when the user clicks the &lt;strong&gt;Install&lt;/strong&gt; button. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We add it to &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; classes and rebuild the &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; project.&lt;/p&gt;

&lt;p&gt;Back in Blend, under Assets/Behaviors we now find &lt;strong&gt;HisowaModPopUpBehavior&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_64.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_30.png" width="1028" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Drag the behavior onto menu:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_66.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_31.png" width="644" height="352" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now if we look under &lt;strong&gt;HisowaModPopupBehavior&lt;/strong&gt; Properties at the &lt;strong&gt;EventName&lt;/strong&gt; dropdown we find that menu supports a &lt;strong&gt;MenuItemClicked&lt;/strong&gt; event, so we go with that:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_68.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_32.png" width="1028" height="534" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And remove the Menu Command binding:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_72.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_34.png" width="1028" height="493" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now if we click on any menu item we see this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_74.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_35.png" width="644" height="466" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We haven’t supplied any content, so all we see are the Yes and No buttons. Also, the behavior is the same for all menu items so we need to find a way to discriminate between them. &lt;/p&gt;

&lt;p&gt;Fortunately, behaviors support conditions. Add a comparison condition and bind the &lt;strong&gt;LeftOperand&lt;/strong&gt; value:&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_76.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_36.png" width="1028" height="452" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Bind to menu/&lt;strong&gt;SelectedMenuItem.Name&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_80.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_38.png" width="516" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This is where Blend gets confused. If you look at the value in Use a custom path expression you’ll see that &lt;strong&gt;SelectedMenuItem&lt;/strong&gt; is indexed. But &lt;strong&gt;SelectedMenuItem&lt;/strong&gt; is not a collection. I think Blend is confused because &lt;strong&gt;MenuItem&lt;/strong&gt; itself inherits from &lt;strong&gt;ObservableCollection&lt;/strong&gt;. At any rate, you need to remove the ‘[0].’ from the string so it says &lt;strong&gt;SelectedMenuItem.Name&lt;/strong&gt;. Now enter &lt;strong&gt;mnuThemes&lt;/strong&gt; for the second Value:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_82.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_39.png" width="1028" height="495" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;You should now find that the popup only appears if you click on Tools/Themes.&lt;/p&gt;

&lt;h2&gt;A Better Way That Avoids String Comparisons&lt;/h2&gt;

&lt;p&gt;However, I very much dislike hard-coded strings, and in particular comparisons of hard-coded strings, so let’s look at a better way. We start by adding a public &lt;strong&gt;MenuItem&lt;/strong&gt; property named &lt;strong&gt;ThemesMenuItem&lt;/strong&gt; in &lt;strong&gt;MainPageViewModel&lt;/strong&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; MenuItem _ThemesMenuItem;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MenuItem ThemesMenuItem
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._ThemesMenuItem; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._ThemesMenuItem != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._ThemesMenuItem = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;ThemesMenuItem&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Yeah, there’s a hard-coded string. But I have a snippet that allows me to type in &lt;strong&gt;ThemesMenuItem&lt;/strong&gt; only once when creating the property, so I’d have to work at it to make the Property name that shows up in Blend different from the string I’m passing to &lt;strong&gt;NotifyPropertyChanged&lt;/strong&gt;.  Hard-coded strings are inevitable in a binding-centric world and using them in calls to &lt;strong&gt;NotifyPropertyChanged&lt;/strong&gt; just doesn’t bother me as much as the workarounds.&lt;/p&gt;

&lt;p&gt;Now we initializeour new &lt;strong&gt;ThemesMenuItem&lt;/strong&gt; and add it to the menu in the &lt;strong&gt;MainPageViewModel&lt;/strong&gt; constructor:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;// Old&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;//var mnuThemes = new MenuItem() { Name = "mnuThemes", Text = "Themes" };&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;//mnuTools.Add(mnuThemes);&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;//New&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;ThemesMenuItem = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MenuItem() { Name = "&lt;span style="color: #8b0000"&gt;mnuThemes&lt;/span&gt;", Text = "&lt;span style="color: #8b0000"&gt;Themes&lt;/span&gt;" };
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;mnuTools.Add(ThemesMenuItem);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Instead of comparing the Name of the &lt;strong&gt;Selected&lt;/strong&gt; MenuItem to a hard-coded string, we can now compare &lt;strong&gt;MenuItem&lt;/strong&gt; with &lt;strong&gt;MenuItem&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Bind the first value to &lt;strong&gt;SelectedMenuItem&lt;/strong&gt; instead of &lt;strong&gt;SelectedMenuItem.Name&lt;/strong&gt;. This has the additional benefit that we don’t have to edit the string to get rid of “phantom indexing”, so you can uncheck &lt;strong&gt;Use a custom path expression&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_88.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_42.png" width="1028" height="731" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Bind the second value to the &lt;strong&gt;ThemesMenuItem&lt;/strong&gt; property in the MainPageViewModel instead of entering the string mnuThemes.&lt;/p&gt;

&lt;pre&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_84.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_40.png" width="1028" height="717" /&gt;&lt;/a&gt; &lt;/pre&gt;

&lt;p&gt;Don’t be surprised when &lt;strong&gt;mnuThemes&lt;/strong&gt; continues to appear. Apparently Blend chooses to display the &lt;strong&gt;Name&lt;/strong&gt; property. Here’s the xaml that proves we’re binding to the object:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;ei&lt;/span&gt;:&lt;span style="color: #800000"&gt;ComparisonCondition&lt;/span&gt; &lt;span style="color: #ff0000"&gt;LeftOperand&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding SelectedMenuItem, ElementName=menu}"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;RightOperand&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding ThemesMenuItem}"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;You should get the same results when you click on &lt;strong&gt;Themes&lt;/strong&gt;, but now we’re comparing two objects, &lt;strong&gt;MainPageViewModel.ThemesMenuItem&lt;/strong&gt; with &lt;strong&gt;Menu.SelectedMenuItem&lt;/strong&gt;, which is kind of a big deal in general. The developer can’t break it by changing the &lt;strong&gt;Name&lt;/strong&gt; of the &lt;strong&gt;MenuItem&lt;/strong&gt;. The designer can’t break it by changing the comparison string. Actually, I’m going to do just that (change the value of &lt;strong&gt;Name&lt;/strong&gt;) because I want to show you that that Blend will show the new Name in the second comparison value:&lt;/p&gt;

&lt;p&gt;In MainPageViewModel I changed the name and rebuilt the solution:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;ThemesMenuItem = new MenuItem() { Name = "mnuThemesName", Text = "Themes" };&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The menu continues to work properly and now we see the new name in Blend:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_90.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_43.png" width="644" height="392" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I don’t know the criteria in Blend for displaying a property name as an object identifier, but apparently a string property named “Name” qualifies.&lt;/p&gt;

&lt;h2&gt;Creating the PopUp user interface&lt;/h2&gt;

&lt;p&gt;The genius of &lt;strong&gt;HisowaModPopUpBehavior&lt;/strong&gt; lies in:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Not only does it allow to plug in a user interface of your own design, with its own &lt;strong&gt;ViewModel&lt;/strong&gt;, &lt;/li&gt;

  &lt;li&gt;You can also specify an &lt;strong&gt;ICommand&lt;/strong&gt; to handle the results. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the user clicks on &lt;strong&gt;Themes&lt;/strong&gt;, I want to show them a list of available themes from which they can select. If they click the &lt;strong&gt;Install&lt;/strong&gt; button I want the method &lt;strong&gt;InstallTheme()&lt;/strong&gt; to be called with the selected &lt;strong&gt;Theme&lt;/strong&gt; object as the argument. &lt;strong&gt;InstallTheme&lt;/strong&gt; will show a MessageBox stating “Installing theme &lt;themeName&gt;”.&lt;/p&gt;

&lt;p&gt;First let’s create the user interface we want to be presented by the popup. We’ll start with the view, &lt;strong&gt;ThemeSelectionView&lt;/strong&gt;, in the MenuPopup Silverlight project.&lt;/p&gt;

&lt;p&gt;I’m going to make the size of the &lt;strong&gt;ThemeSelectoinView&lt;/strong&gt; &lt;strong&gt;UserControl&lt;/strong&gt; 300 x 200 and &lt;strong&gt;LayoutRoot&lt;/strong&gt; will expand to fill it. &lt;strong&gt;LayoutRoot&lt;/strong&gt; will have a single column and two rows, one for the header and one for the list of &lt;strong&gt;Theme&lt;/strong&gt; &lt;strong&gt;Names&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;I created a new folder named &lt;strong&gt;Views&lt;/strong&gt; in the &lt;strong&gt;MenuPopUp&lt;/strong&gt; project, right-clicked on it and selected add new Item. From the resulting &lt;strong&gt;New Item&lt;/strong&gt; dialog, choose &lt;strong&gt;UserControl&lt;/strong&gt; and name it &lt;strong&gt;ThemeSelectionView.xaml&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_92.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_44.png" width="998" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You can’t select &lt;strong&gt;UserControl with ViewModel&lt;/strong&gt; because all our ViewModels come from &lt;strong&gt;MenuPopupViewModel.dll&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The details of creating the UserControl that will be used as the Custom User Interface within the popup &lt;a href="http://www.openlightgroup.net/Blog/tabid/58/EntryId/131/More-Simple-Blend-Layout-Techniques-and-Quirks.aspx#mmargins" target="_blank"&gt;appear in a separate blog on Blend and Margins.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_101.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_20.png" width="600" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Since the next thing we need is something to show in the list, let’s return to the ViewModel, in this case &lt;strong&gt;ThemeSelectionViewModel&lt;/strong&gt; which we need to create in the &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; class library. Then we’ll add an &lt;strong&gt;ObservableCollection&lt;/strong&gt; the designer can bind to the &lt;strong&gt;ListBox&lt;/strong&gt;. But to have an &lt;strong&gt;ObservableCollection&lt;/strong&gt; we need something to put in it, so let’s create a &lt;strong&gt;Theme&lt;/strong&gt; class with the single property &lt;strong&gt;Name&lt;/strong&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; MenuPopupViewModel
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Theme
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Theme(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; name)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            Name = name;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Name { &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we can create a collection of &lt;strong&gt;Themes&lt;/strong&gt; in &lt;strong&gt;ThemeSelectionViewModel&lt;/strong&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ObservableCollection&lt;Theme&gt; _ThemesList;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ObservableCollection&lt;Theme&gt; ThemesList
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._ThemesList; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._ThemesList != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._ThemesList = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;ThemesList&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;To keep things separate, I added a &lt;strong&gt;Models&lt;/strong&gt; folder to &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; project and created a &lt;strong&gt;MenuPopUpModel&lt;/strong&gt; class that provides a &lt;strong&gt;GetThemes()&lt;/strong&gt; method: &lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; MenuPopupViewModel
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MenuPopUpModel
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #region GetThemes
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; ObservableCollection&lt;Theme&gt; GetThemes()
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            ObservableCollection&lt;Theme&gt; colThemes = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObservableCollection&lt;Theme&gt;();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colThemes.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Theme("&lt;span style="color: #8b0000"&gt;Middle Earth&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colThemes.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Theme("&lt;span style="color: #8b0000"&gt;World of Warcraft&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colThemes.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Theme("&lt;span style="color: #8b0000"&gt;Farmville&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colThemes.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Theme("&lt;span style="color: #8b0000"&gt;Simpsons&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colThemes.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Theme("&lt;span style="color: #8b0000"&gt;South Park&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colThemes.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Theme("&lt;span style="color: #8b0000"&gt;American Dad&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colThemes.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Theme("&lt;span style="color: #8b0000"&gt;Call To Duty&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            colThemes.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Theme("&lt;span style="color: #8b0000"&gt;Warehouse 13&lt;/span&gt;"));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; colThemes;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        #endregion
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And call it from the &lt;strong&gt;ThemeSelectionViewModel&lt;/strong&gt; constructor:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ThemeSelectionViewModel()
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            ThemesList = MenuPopUpModel.GetThemes();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we need to bind &lt;strong&gt;ThemesList&lt;/strong&gt; to the &lt;strong&gt;ListBox&lt;/strong&gt;, but first we need to set &lt;strong&gt;ThemeSelectionView’s&lt;/strong&gt; &lt;strong&gt;DataContext&lt;/strong&gt; to &lt;strong&gt;ThemeSelectionViewModel&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_112.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_54.png" width="1028" height="742" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now we have access to &lt;strong&gt;ThemeSelectionViewModel.ThemesList&lt;/strong&gt;, so drag it onto ListBox:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_114.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_55.png" width="644" height="472" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You should immediately see this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_116.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_56.png" width="577" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now we bind &lt;strong&gt;HisowaModPopUpBehavior.CustomUI&lt;/strong&gt; to &lt;strong&gt;ThemeSelectionView&lt;/strong&gt;. Notice we’re not pointing it to an object that’s already created, we’re pointing it to a class:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_94.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_45.png" width="1028" height="702" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;When you run the app and select &lt;strong&gt;Themes&lt;/strong&gt; you should see this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_118.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_57.png" width="617" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Ok, now we’re getting somewhere. We want to change the button captions which is simple:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_132.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_64.png" width="644" height="271" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;… and we want to know what was selected if the &lt;strong&gt;Install&lt;/strong&gt; button is clicked.&lt;/p&gt;

&lt;p&gt;First we add a &lt;strong&gt;SelectedTheme&lt;/strong&gt; property to &lt;strong&gt;ThemeSelectionViewModel&lt;/strong&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Theme _SelectedTheme;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Theme SelectedTheme
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._SelectedTheme; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._SelectedTheme != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._SelectedTheme = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;SelectedTheme&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now Bind to ListBox &lt;strong&gt;SelectedItem&lt;/strong&gt;. Click on the &lt;strong&gt;Advanced&lt;/strong&gt; Options icon next to &lt;strong&gt;SelectedItem&lt;/strong&gt; as shown below and select &lt;strong&gt;Data Binding…&lt;/strong&gt; from the dialog that appears:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_120.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_58.png" width="1028" height="620" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Because the &lt;strong&gt;ListBox&lt;/strong&gt; &lt;strong&gt;SelectedItem&lt;/strong&gt; is used to set the value in the bound-to property, we set the binding to &lt;strong&gt;TwoWay&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_122.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_59.png" width="639" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So now we’ve established a property in &lt;strong&gt;ThemeSelectionViewModel&lt;/strong&gt; that will always be bound to the currently selected theme. Next we add an &lt;strong&gt;ICommand&lt;/strong&gt; that &lt;strong&gt;HisowaModPopUpBehavior&lt;/strong&gt; will call when the user selects Install:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;       &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InstallTheme(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; param)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            HisowaModPopUpBehaviorResult _result = param &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; HisowaModPopUpBehaviorResult;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_result.DialogResult.HasValue &amp;&amp; _result.DialogResult.Value)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                ThemeSelectionViewModel vm = _result.DataContext &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; ThemeSelectionViewModel;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (vm.SelectedTheme != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                    MessageBox.Show("&lt;span style="color: #8b0000"&gt;Installing Theme &lt;/span&gt;" + vm.SelectedTheme.Name);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we’re going to bind that &lt;strong&gt;ICommand&lt;/strong&gt; to &lt;strong&gt;HisowaModPopUpBehavior&lt;/strong&gt; property &lt;strong&gt;ReturnICommand&lt;/strong&gt;. But we’re going to do it in a shortcut way I didn’t expect to work. From the &lt;strong&gt;DataContext&lt;/strong&gt; Panel drag &lt;strong&gt;MainPageViewModel&lt;/strong&gt;.&lt;strong&gt;InstallThemeCommand&lt;/strong&gt; to &lt;strong&gt;HisowaModPopUpBehavior&lt;/strong&gt; in the &lt;strong&gt;Objects and Timeline&lt;/strong&gt; panel. You should see the message window “&lt;strong&gt;Data bind [HisowaModPopUpBehavior] to InstallThemeCommand”&lt;/strong&gt; as shown below: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_124.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_60.png" width="1028" height="756" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Drop the &lt;strong&gt;ICommand&lt;/strong&gt; on the behavior and select &lt;strong&gt;ReturnICommand&lt;/strong&gt; from the dropdown that appears:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_128.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_62.png" width="1028" height="742" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And sure enough:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.nethttp://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_99.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_19.png" width="585" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I did add one more little detail. If the ListBox items collection is not empty, I want the first item to be selected when the ListBox is loaded. I was going to add an ICommand, but decided a behavior would be better:&lt;/p&gt;

&lt;p&gt;I’ll be adding the new behavior class, &lt;strong&gt;SelectFirstListBoxItem&lt;/strong&gt; to &lt;strong&gt;MainPageViewModel&lt;/strong&gt;. Visual Studio doesn’t provide &lt;strong&gt;Behavior&lt;/strong&gt; as a &lt;strong&gt;New Item Selection&lt;/strong&gt;, so in Blend I right-click on the &lt;strong&gt;Classes&lt;/strong&gt; folder within the &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; project, select&lt;strong&gt; ”Add New Item”&lt;/strong&gt; and see the following dialog:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_15.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_5.png" width="644" height="421" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Aside from removing all the comments, all you have to do is change one line of code and add about 4.&lt;/p&gt;

&lt;p&gt;First we want to change:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;	&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SelectFirstListBoxItem : Behavior&lt;DependencyObject&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;to:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SelectFirstListBoxItem : TargetedTriggerAction&lt;ListBox&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;TargetedTriggerAction supports the Invoke method allowing us to add:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Invoke(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            ListBox lb = AssociatedObject &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; ListBox;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (lb != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;&amp; lb.Items.Count &gt; 0)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;                lb.SelectedIndex = 0;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Ok, more than 4 lines. I could have crammed into 4, but 6 is not bad.&lt;/p&gt;

&lt;p&gt;if you’re not familiar with behaviors, I want to point out the power that the above implies:&lt;/p&gt;

&lt;p&gt;If the behavior knows the type of its AssociatedObject it can access all the object’s public methods and properties.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;If it knows the type of the object’s &lt;strong&gt;ViewModel&lt;/strong&gt;, it can access all the &lt;strong&gt;ViewModel&lt;/strong&gt; public methods and properties. &lt;/li&gt;

  &lt;li&gt;You could have controls that are driven entirely by their &lt;strong&gt;Behaviors&lt;/strong&gt; based on properties set or bound by the designer. &lt;/li&gt;

  &lt;li&gt;If you put interface references on the back end (in the ViewModel) so everything can be swapped out you’ve essentially given the object infinite flexibility. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s say I’m a Pursuit behavior:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;I am attached to a Predator object. &lt;/li&gt;

  &lt;li&gt;The designer sets or binds properties such as speed, stamina, intelligence, strategies. &lt;/li&gt;

  &lt;li&gt;I monitor Predator properties / subscribe to Predator events, to detect a condition that should trigger a pursuit. &lt;/li&gt;

  &lt;li&gt;When that happens, I call methods on the Predator to actually perform the pursuit based on my properties, whose values change as the pursuit goes on. &lt;/li&gt;

  &lt;li&gt;The methods in step 4 are backed by interface references whose implementations can be swapped out by Predator’s handler (the ViewModel), even in the midst of the pursuit, based on terrain changes, etc. &lt;/li&gt;

  &lt;li&gt;Extend this model to all Predator’s capabilities and Predator becomes an engine entirely driven by Behaviors. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hey, I just came up with the plot for ‘Avatar’.&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Attaching The SelectFirstListBoxItem Behavior&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;After building MenuPopupViewModel, the behavior will be available in Blend:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_39.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_6.png" width="1028" height="312" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Drag it onto the ListBox:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_41.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_7.png" width="644" height="402" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The behavior SourceObject is already set to listBox because it’s attached to listBox. Select &lt;strong&gt;Loaded&lt;/strong&gt; from the &lt;strong&gt;EventName&lt;/strong&gt; dropdown to bind the &lt;strong&gt;Loaded&lt;/strong&gt; event to the behavior &lt;strong&gt;Invoke&lt;/strong&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_45.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_9.png" width="644" height="395" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Before and after:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_77.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_10.png" width="244" height="216" /&gt;&lt;/a&gt; &lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_95.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="/Portals/0/Blog/Files/3/134/WLW-HisowaPopUpBehaviorMenusCodeFreeZonesand_11386-image_thumb_17.png" width="244" height="219" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;DownloadCode:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://richardwaddell.adefwebserver.com/MenuPopup.zip"&gt;http://richardwaddell.adefwebserver.com/MenuPopup.zip&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/134/HisowaModPopUpBehavior-with-de-Oliveira-Menu.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/134/HisowaModPopUpBehavior-with-de-Oliveira-Menu.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/134/HisowaModPopUpBehavior-with-de-Oliveira-Menu.aspx</guid>
      <pubDate>Wed, 27 Oct 2010 20:07:42 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=134</trackback:ping>
    </item>
    <item>
      <title>Isolating the C# Code in Silverlight Class Library Projects</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/133/Isolating-the-C-Code-in-Silverlight-Class-Library-Projects.aspx</link>
      <description>&lt;p&gt;If you’re reading another blog where I place all C# beyond the mandatory in a Silverlight class library rather than the Silverlight application, and it’s not obvious how the solution is put together this tutorial will take you through the steps:&lt;/p&gt;  &lt;p&gt;(1) Creating the Silverlight Application with hosting Web Site &lt;/p&gt;  &lt;p&gt;(2) Adding a Silverlight Class Library to the solution &lt;/p&gt;  &lt;p&gt;(3) Referencing the class library from the application &lt;/p&gt;  &lt;p&gt;(4) Setting Project Dependencies. &lt;/p&gt;  &lt;p&gt;(5) Web Site project settings to consume the xap file / add a new Silverlight application to an existing web site &lt;/p&gt;  &lt;p&gt;(6) Setting MainPage DataContext to a class in the class library &lt;/p&gt;  &lt;h2&gt;&lt;strong&gt;Code-Free Zones and Silverlight Class Libraries&lt;/strong&gt;&lt;/h2&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;From working recently on an &lt;strong&gt;OpenLightGroup&lt;/strong&gt; team project, I’ve become taken with the idea of keeping all C# code out of the Silverlight application project except for the almost vestigial  &lt;strong&gt;UserControl&lt;/strong&gt; code-behinds. No more inadvertent simultaneous edits to the same ViewModel code in Blend and Visual Studio, and I think it helps further emphasize the separation between UI and data to keep the ViewModel, Model, and all other C# source code out of the Silverlight application. I’m at least going to try it out.&lt;/p&gt;  &lt;p&gt;I’ll start by creating the main Silverlight project.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Select &lt;strong&gt;Silverlight Application&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;You can change the Location of the Solution / Project or take the default. &lt;/li&gt;    &lt;li&gt;Give the project a name which will also… &lt;/li&gt;    &lt;li&gt;…be used as the solution name by default. &lt;/li&gt;    &lt;li&gt;Leave the default &lt;strong&gt;Create directory for solution&lt;/strong&gt; checkbox checked &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image1311.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image_thumb91" border="0" alt="image_thumb91" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb91_72956611-50f5-45bb-8c03-28c44b76c607.png" width="1028" height="714" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Take the default in the &lt;strong&gt;New Silverlight Application&lt;/strong&gt; dialog that follows to create a Web site to host the application:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image171.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_thumb111" border="0" alt="image_thumb111" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb111_514e8605-8a2b-46c2-b161-1e293f569aba.png" width="604" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We end up with a directory structure like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image21.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_thumb13" border="0" alt="image_thumb13" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb13_3e4fb46b-7fb8-415e-b5bd-b6d16005e00b.png" width="644" height="154" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We have a &lt;strong&gt;MenuPopUp&lt;/strong&gt; folder to hold the solution and all the project subfolders, at this point consisting of the &lt;strong&gt;MenuPopUp&lt;/strong&gt; Silverlight Project and the &lt;strong&gt;MenuPopUp&lt;/strong&gt;.&lt;strong&gt;Web&lt;/strong&gt; Web Site. &lt;/p&gt;  &lt;p&gt;Ok, we have our Silverlight application and hosting web site. Now we’ll add the library.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Select &lt;strong&gt;Silverlight Class Library&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Give it a name. The primary purpose of this library will be to hold ViewModel classes &lt;/li&gt;    &lt;li&gt;Change the location to the MenuPopUp solution folder and, very important… &lt;/li&gt;    &lt;li&gt;…change the Solution dropdown to &lt;strong&gt;Add to solution&lt;/strong&gt;. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image30.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_thumb18" border="0" alt="image_thumb18" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb18_b23d5870-cb24-4624-a6a8-fb77c1a617c9.png" width="1028" height="710" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now we need to make the &lt;strong&gt;Silverlight application&lt;/strong&gt; see the &lt;strong&gt;Silverlight class library&lt;/strong&gt;. In Solution Explorer, in the &lt;strong&gt;MenuPopUp&lt;/strong&gt; Project, right click on &lt;strong&gt;References&lt;/strong&gt; and then select &lt;strong&gt;Add Reference…&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image39.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_thumb231" border="0" alt="image_thumb231" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb231_9204eed6-7b95-4127-85a1-9d8443542848.png" width="644" height="361" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;An &lt;strong&gt;Add&lt;/strong&gt; &lt;strong&gt;Reference&lt;/strong&gt; dialog appears. Click on the &lt;strong&gt;Projects&lt;/strong&gt; tab, select &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; and click &lt;strong&gt;OK&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image43.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_thumb25" border="0" alt="image_thumb25" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb25_0777c2ed-f766-4048-b839-723ad09ae992.png" width="608" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;Setting Project Dependencies&lt;/h2&gt;  &lt;p&gt;Start by right-clicking on the solution and selecting Project Dependencies…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-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="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb.png" width="644" height="304" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-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="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb_1.png" width="197" height="181" /&gt;&lt;/a&gt; &lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-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="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb_2.png" width="170" height="185" /&gt;&lt;/a&gt; &lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-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="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb_3.png" width="188" height="188" /&gt;&lt;/a&gt;   &lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_18.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="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb_8.png" width="193" height="195" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The application (xap file) is dependent on the class library, the web site is dependent on the xap file, and the class library is dependent on nothing, leading to the build order on the far right. The initial settings  had the web site dependent on nothing, but in fact the site is dependent on the xap file so I feel setting the dependency is prudent.&lt;/p&gt;  &lt;h3&gt;How the XAP file gets to the Web Site ClientBin folder&lt;/h3&gt;  &lt;p&gt;In our case Visual Studio took care of it when we created a hosting web site along with the Silverlight project. But in case  you ever need to do it manually:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Right-click &lt;strong&gt;MenuPopUp.Web&lt;/strong&gt; in Solution Explorer. &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Properties&lt;/strong&gt; in the context menu &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Silverlight&lt;/strong&gt; &lt;strong&gt;Applications&lt;/strong&gt;.  &lt;/li&gt;    &lt;li&gt;Visual Studio added the &lt;strong&gt;MenuPopUp&lt;/strong&gt; project &lt;/li&gt;    &lt;li&gt;The path on the Web Site is &lt;strong&gt;ClientBin&lt;/strong&gt;. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image6.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_thumb4" border="0" alt="image_thumb4" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb4_b5621f3f-fb63-4cb6-a196-3c448934ffca.png" width="1028" height="379" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image13.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_thumb9" border="0" alt="image_thumb9" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb9_d04dc3fd-561b-4d1f-be88-b389f89c9b9c.png" width="1028" height="92" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;A little terse, so let’s see what clicking the Add button shows us:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image17.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_thumb11" border="0" alt="image_thumb11" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb11_07de40b7-2ea5-4340-b35d-ba1c7fdfccc8.png" width="520" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Pretty much speaks for itself. What’s nice about this is you don’t have to change the Silverlight project settings to configure the target for the xap file. Note you can also use this dialog to add a new Silverlight project to an existing web site.&lt;/p&gt;  &lt;h3&gt;Views and ViewModels&lt;/h3&gt;  &lt;p&gt;We’ve added a reference to &lt;strong&gt;MenuPopupViewModel.dll&lt;/strong&gt;. Now we’ll create a &lt;strong&gt;MainPageViewModel&lt;/strong&gt; class, build the &lt;strong&gt;MenuPopupViewModel&lt;/strong&gt; project and find out if we can see the class when we open &lt;strong&gt;MainPage.xaml&lt;/strong&gt; in Blend.&lt;/p&gt;  &lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Net;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Controls;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Documents;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Ink;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Input;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Media;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Media.Animation;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Shapes;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; MenuPopupViewModel
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MainPageViewModel
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And sure enough, there it is. To add MainPageViewModel as the DataContext for MainPage.UserControl&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Select &lt;strong&gt;UserControl&lt;/strong&gt; in&lt;strong&gt; Objects and Timeline&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;From &lt;strong&gt;Properties/Common&lt;/strong&gt; Properties click on the &lt;strong&gt;New&lt;/strong&gt; button next to &lt;strong&gt;DataContext&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;From the &lt;strong&gt;Select Object&lt;/strong&gt; dialog, select &lt;strong&gt;MainPageViewModel&lt;/strong&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles56FA37/image221.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_thumb14" border="0" alt="image_thumb14" src="/Portals/0/Blog/Files/3/133/WLW-IsolatingCodeinSilverlightClassLibraries_11175-image_thumb14_0a756f39-23b1-4a08-87fe-e397a3c6d458.png" width="1028" height="684" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/133/Isolating-the-C-Code-in-Silverlight-Class-Library-Projects.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/133/Isolating-the-C-Code-in-Silverlight-Class-Library-Projects.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/133/Isolating-the-C-Code-in-Silverlight-Class-Library-Projects.aspx</guid>
      <pubDate>Wed, 27 Oct 2010 20:00:03 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=133</trackback:ping>
    </item>
    <item>
      <title>Blend For Beginners: Grid to Canvas to StackPanel</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/132/Blend-For-Beginners-Grid-to-Canvas-to-StackPanel.aspx</link>
      <description>&lt;p&gt;In my opinion, &lt;strong&gt;Canvas&lt;/strong&gt; is better suited than &lt;strong&gt;Grid&lt;/strong&gt; to serve as &lt;strong&gt;LayoutRoot&lt;/strong&gt; (the default name of the main UI Element within &lt;strong&gt;UserControl&lt;/strong&gt;). Using a &lt;strong&gt;Grid&lt;/strong&gt; locks the entire UI into a matrix of rows and columns; you can set properties to allow elements to cross row and column boundaries, but why should you have to. If you use a &lt;strong&gt;Canvas&lt;/strong&gt;, you can position elements wherever you want them, including &lt;strong&gt;Grids&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;Sometimes, though, I don’t think about that when I start coding and I end up in a situation where I want to change &lt;strong&gt;LayoutRoot&lt;/strong&gt; to a &lt;strong&gt;Canvas&lt;/strong&gt; when the page is well along. Fortunately it’s not that tough. But first…&lt;/p&gt;  &lt;h2&gt;Using the Pinned Tools Icon and Waking it Up.&lt;/h2&gt;  &lt;p&gt;To begin with, I’m going to add a &lt;strong&gt;Canvas&lt;/strong&gt; to the existing &lt;strong&gt;LayoutRoot&lt;/strong&gt;. First I find it under &lt;strong&gt;Assets&lt;/strong&gt; and then double-click it to &lt;a href="http://www.openlightgroup.net/Blog/tabid/58/EntryId/127/Simple-Layout-Techniques-In-Blend.aspx#pinningcontrols" target="_blank"&gt;add it to the pinned Controls icon on the Tools Panel&lt;/a&gt;. Probably I won’t need to add a &lt;strong&gt;Canvas&lt;/strong&gt; again, but in principle I find it more convenient to pin the controls so I don’t have to go into &lt;strong&gt;Assets&lt;/strong&gt; if I need one again. Below you can see the &lt;strong&gt;Assets&lt;/strong&gt; icon with the pinned &lt;strong&gt;Controls&lt;/strong&gt; icon below it. Click on the little white triangle and hold to see the list of all pinned &lt;strong&gt;Controls&lt;/strong&gt;. If you select one and then double-click on the pinned control icon it will be inserted in the upper-left corner of the currently selected object in the&lt;strong&gt; Objects and TimeLine&lt;/strong&gt; panel.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_2.png" width="160" height="184" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Sometimes the pinned controls icon will be dimmed and non-responsive. In that case click on the &lt;strong&gt;Assets&lt;/strong&gt; Icon, &lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_1.png" width="29" height="27" /&gt;&lt;/a&gt; and the pinned controls icon should become active.&lt;/p&gt;  &lt;h2&gt;Adding the Canvas&lt;/h2&gt;  &lt;p&gt;With &lt;strong&gt;UserControl&lt;/strong&gt; selected, double-click on the pinned &lt;strong&gt;Canvas&lt;/strong&gt; icon.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_3.png" width="230" height="129" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You’ll find that &lt;strong&gt;Canvas&lt;/strong&gt; was added to &lt;strong&gt;LayoutRoot&lt;/strong&gt;; &lt;strong&gt;UserControl&lt;/strong&gt; can only have one child, so Blend assumes you intended to add it to the UI, not to be the new container for the UI.&lt;/p&gt;  &lt;p&gt;To make &lt;strong&gt;Canvas&lt;/strong&gt; the parent of &lt;strong&gt;LayoutRoot&lt;/strong&gt;, you must drag it (cut and paste won’t work) to &lt;strong&gt;UserControl&lt;/strong&gt; and look for a message as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_4.png" width="445" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Release the mouse button:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_12.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_5.png" width="211" height="207" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now select &lt;strong&gt;LayoutRoot&lt;/strong&gt; properties and delete the name. Then open &lt;strong&gt;Canvas&lt;/strong&gt; properties and enter the name &lt;strong&gt;LayoutRoot&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_14.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_6.png" width="206" height="181" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Assuming you want &lt;strong&gt;LayoutRoot&lt;/strong&gt; to fill &lt;strong&gt;UserControl&lt;/strong&gt;, which you probably do, change &lt;strong&gt;LayoutRoot&lt;/strong&gt; width and height to Auto:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_16.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_7.png" width="644" height="189" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And set alignment to stretch and you should find the dimensions are sized to fill &lt;strong&gt;UserControl&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_18.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_8.png" width="644" height="259" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;Working With the New LayoutRoot&lt;/h2&gt;  &lt;p&gt;My immediate goal is to add a header to the page something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_20.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_9.png" width="644" height="105" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So the first think I’m going to do is make room on the &lt;strong&gt;Canvas&lt;/strong&gt;, which is now &lt;strong&gt;LayoutRoot&lt;/strong&gt;, by shrinking the &lt;strong&gt;Grid&lt;/strong&gt; that was formerly &lt;strong&gt;LayoutRoot&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_28.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_13.png" width="644" height="264" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The height of &lt;strong&gt;UserControl&lt;/strong&gt; is 400 and &lt;strong&gt;LayoutRoot&lt;/strong&gt; is set to Auto / Stretch, so its height is also 400. If I want to leave 80 pixels of height for the header, I reduce the height of &lt;strong&gt;Grid&lt;/strong&gt; to 320 and set the &lt;strong&gt;Top&lt;/strong&gt; property to 80. Again I want to point out that you can hover the mouse over the property and then drag the value up or down. Watching the control move or change size as you do so is much more gratifying than just typing in the new value. &lt;a href="http://www.openlightgroup.net/Blog/tabid/58/EntryId/131/More-Simple-Blend-Layout-Techniques-and-Quirks.aspx#MarginKiller" target="_blank"&gt;Just don’t drag the control itself; the results might be what you want cosmetically, but the underlying property changes may not be as expected.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You could set the upper &lt;strong&gt;Margin&lt;/strong&gt; to 80 and achieve the same result, but in my opinion you don’t want to. Or, if you’re going to use &lt;strong&gt;Margins&lt;/strong&gt;, don’t use the &lt;strong&gt;Left&lt;/strong&gt; and &lt;strong&gt;Top&lt;/strong&gt; properties. Below you can see the resulting xaml after I set the &lt;strong&gt;Top&lt;/strong&gt; property to 80 and the upper &lt;strong&gt;Margin&lt;/strong&gt; to 20. The result will be that &lt;strong&gt;Grid&lt;/strong&gt; is situated 100 pixels from the top of &lt;strong&gt;LayoutRoot&lt;/strong&gt;. This seems too confusing to me. There may be a scenario where you would want to use both, but I can’t think of one.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"461"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"320"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"0,20,0,0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Canvas&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;Top&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"80"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;I also have the &lt;strong&gt;Grid&lt;/strong&gt; &lt;strong&gt;Width&lt;/strong&gt; property hard-coded to the width of &lt;strong&gt;LayoutRoot&lt;/strong&gt; because I want &lt;strong&gt;Grid&lt;/strong&gt; to fill the page horizontally. I tried setting it to Auto and setting the horizontal alignment to stretch with the expectation that it would expand horizontally to fill &lt;strong&gt;LayoutRoot&lt;/strong&gt;, but it did not; it sized itself to its contents. Maybe because its container is a &lt;strong&gt;Canvas&lt;/strong&gt;, maybe because of how the columns are defined. Not something I want to take time to explore right now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LayoutRoot&lt;/strong&gt; needs a &lt;strong&gt;Background&lt;/strong&gt; &lt;strong&gt;Brush&lt;/strong&gt;. I may end up making &lt;strong&gt;Grid&lt;/strong&gt; transparent and so the entire page is the color of &lt;strong&gt;LayoutRoot&lt;/strong&gt;, but for now I’m just going to give it a separate color. Something garish to keep up my rep. I also moved the ‘Statements’ &lt;strong&gt;TextBlock&lt;/strong&gt;, which belongs in the header to &lt;strong&gt;LayoutRoot&lt;/strong&gt; through cut and paste.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_30.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_14.png" width="488" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Notice in &lt;strong&gt;Objects and Timeline&lt;/strong&gt; that &lt;strong&gt;TextBlock&lt;/strong&gt; appears below &lt;strong&gt;Grid&lt;/strong&gt;. This doesn’t cause any problems, but if you take my advice you’ll drag it up above &lt;strong&gt;Grid&lt;/strong&gt; so that the sequence in&lt;strong&gt; Objects and Timeline&lt;/strong&gt; matches the design area to avoid confusion.&lt;/p&gt;

&lt;p&gt;Now to add the header controls. We’ll position each one using the &lt;strong&gt;Top&lt;/strong&gt; and &lt;strong&gt;Left&lt;/strong&gt; properties. I’ll show you the first one. Make sure that &lt;strong&gt;LayoutRoot&lt;/strong&gt; is selected in &lt;strong&gt;Objects and Timeline&lt;/strong&gt;. Them add a &lt;strong&gt;Label&lt;/strong&gt; by dragging from &lt;strong&gt;Assets&lt;/strong&gt; or double-clicking a pinned control on the &lt;strong&gt;Tools Panel&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_32.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_15.png" width="644" height="410" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The results always look discouraging, but it’s really easy to make the necessary adjustments.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_36.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_17.png" width="644" height="408" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Notice I moved the &lt;strong&gt;Label&lt;/strong&gt; to fall after the &lt;strong&gt;TextBlock&lt;/strong&gt; in &lt;strong&gt;Objects and Timeline. &lt;/strong&gt;Now I add a &lt;strong&gt;ComboBox&lt;/strong&gt;, &lt;strong&gt;TextBox&lt;/strong&gt;, and &lt;strong&gt;Button&lt;/strong&gt; using the same techniques. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_38.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_18.png" width="644" height="340" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The hardest part will be to remember to make sure the &lt;strong&gt;LayoutRoot&lt;/strong&gt; is the currently selected object before adding each element. If you forget, just cut and paste it into &lt;strong&gt;LayoutRoot&lt;/strong&gt;. It’s also easy to accidentally change &lt;strong&gt;Margins&lt;/strong&gt; instead of the &lt;strong&gt;Top&lt;/strong&gt; and &lt;strong&gt;Left&lt;/strong&gt; Properties. And you’ll want to give the search &lt;strong&gt;TextBox&lt;/strong&gt; a hard-coded width. Also notice each has been moved to its logical position in &lt;strong&gt;Objects and Timeline&lt;/strong&gt;. We could also give each one a name, but in general you want to avoid naming elements if it’s reasonably clear which one is which from the layout.&lt;/p&gt;

&lt;h2&gt;Hey, I Coulda Used A StackPanel!!!&lt;/h2&gt;

&lt;p&gt;This will work perfectly fine, but what if we want to move the four controls we added as a single unit? We can select all 4 and move them, but that’s kind of a pain. And I’ll bet they’re not all perfectly aligned vertically.&lt;/p&gt;

&lt;p&gt;Fortunately, it’s easy to move them into a &lt;strong&gt;StackPanel&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;(Addendum - I got so absorbed in the ins-and-outs of Auto dimensions and what-not that I forgot to point out the even easier way to place these controls in a &lt;strong&gt;StackPanel&lt;/strong&gt;. Simply select all four in &lt;strong&gt;Objects and Timeline&lt;/strong&gt;, right-click, select &lt;strong&gt;Group Into…,&lt;/strong&gt; and click on &lt;strong&gt;StackPanel&lt;/strong&gt;. The long-winded version just describes a few of the details you might not notice if you do it that way.)&lt;/p&gt;

&lt;p&gt;Add the &lt;strong&gt;StackPanel&lt;/strong&gt; to &lt;strong&gt;LayoutRoot&lt;/strong&gt; by dragging from &lt;strong&gt;Assets&lt;/strong&gt; or double-clicking a pinned &lt;strong&gt;StackPanel&lt;/strong&gt; control. Set the &lt;strong&gt;Orientation&lt;/strong&gt; to &lt;strong&gt;Horizontal&lt;/strong&gt; and give it a &lt;strong&gt;Background &lt;/strong&gt;&lt;strong&gt;Brush&lt;/strong&gt; so you can see where it is. Take the &lt;strong&gt;Width&lt;/strong&gt; and &lt;strong&gt;Height&lt;/strong&gt; out of Auto mode or the size will be zero. Adjust the &lt;strong&gt;Height&lt;/strong&gt; and &lt;strong&gt;Top&lt;/strong&gt; by dragging the values in the textboxes so you get approximately what you see below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_40.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_19.png" width="1028" height="453" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We had to give dimensions to &lt;strong&gt;StackPanel&lt;/strong&gt; in order to see it because we haven’t yet added the four controls. They appear on top of &lt;strong&gt;StackPanel&lt;/strong&gt; because they overlap &lt;strong&gt;StackPanel&lt;/strong&gt; in &lt;strong&gt;LayoutRoot &lt;/strong&gt;and fall after it in the &lt;strong&gt;Objects and Timeline&lt;/strong&gt; list.  If I move &lt;strong&gt;StackPanel&lt;/strong&gt; below the controls in &lt;strong&gt;Objects and Timeline&lt;/strong&gt; they disappear because objects in &lt;strong&gt;Objects and Timeline&lt;/strong&gt; appear on top of overlapping objects higher in the list and vice-versa:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_42.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_20.png" width="644" height="401" /&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;We can add the controls to the &lt;strong&gt;StackPanel&lt;/strong&gt; with a wholesale cut and paste:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_44.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_21.png" width="644" height="332" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Resulting in:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_46.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_22.png" width="644" height="123" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We lost all our &lt;strong&gt;Top&lt;/strong&gt; and &lt;strong&gt;Left&lt;/strong&gt; property settings because they don’t apply in a &lt;strong&gt;StackPanel&lt;/strong&gt;. And I’m happy to confirm that Blend did remove the &lt;strong&gt;Canvas&lt;/strong&gt;.&lt;strong&gt;Top&lt;/strong&gt; and &lt;strong&gt;Canvas&lt;/strong&gt;.&lt;strong&gt;Left&lt;/strong&gt; properties from the xaml. &lt;/p&gt;

&lt;p&gt;It’s easy to fix everything up. Select all four controls and set &lt;strong&gt;VerticalAlignment&lt;/strong&gt; to center:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_48.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_23.png" width="644" height="218" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now adjust the margins by dragging either the left of right &lt;strong&gt;Margin&lt;/strong&gt; property of each control (using the property textboxes) so the controls are horizontally aligned. Personally I would use the left &lt;strong&gt;Margins&lt;/strong&gt;, but it doesn’t matter as long as you’re consistent. Even better, as I just discovered, you can select all four and adjust the value of all of them simultaneously:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_50.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_24.png" width="1028" height="263" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now that the &lt;strong&gt;StackPanel&lt;/strong&gt; has content, I want to change the &lt;strong&gt;Width&lt;/strong&gt; property to &lt;strong&gt;Auto.&lt;/strong&gt; Otherwise, if the width of &lt;strong&gt;LayoutRoot&lt;/strong&gt; is reduced, &lt;strong&gt;StackPanel&lt;/strong&gt; will exceed it. I think I’ll change the &lt;strong&gt;Height&lt;/strong&gt; to &lt;strong&gt;Auto&lt;/strong&gt; as well and make it transparent by removing the &lt;strong&gt;Background&lt;/strong&gt; &lt;strong&gt;Brush&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_52.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_25.png" width="1028" height="371" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;One last thing you could do to tighten up &lt;strong&gt;StackPanel&lt;/strong&gt; is to remove the left &lt;strong&gt;Margin&lt;/strong&gt; from &lt;strong&gt;Label&lt;/strong&gt; and set the &lt;strong&gt;Left&lt;/strong&gt; property of &lt;strong&gt;StackPanel&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_54.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="/Portals/0/Blog/Files/3/132/WLW-ACanvasisNotAGridandaStackPanelisNeither_82CC-image_thumb_26.png" width="1028" height="367" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You’d think you could center &lt;strong&gt;StackPanel&lt;/strong&gt; in LayoutRoot instead of setting the &lt;strong&gt;Left&lt;/strong&gt; property, but the alignment settings seem to have no effect. I did a quick search and didn’t find anything official, but it seems that &lt;strong&gt;Canvas&lt;/strong&gt; doesn’t honor alignment settings.&lt;/p&gt;

&lt;p&gt;But the point is you can now move the set of controls around freely by moving the &lt;strong&gt;StackPanel&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;Nothing much to add. Just that you could use left and upper &lt;strong&gt;Margins&lt;/strong&gt; on a &lt;strong&gt;Canvas&lt;/strong&gt; as equivalent to &lt;strong&gt;Top&lt;/strong&gt; and &lt;strong&gt;Left&lt;/strong&gt;, but the resulting xaml is different. &lt;strong&gt;Canvas.Top&lt;/strong&gt; and &lt;strong&gt;Canvas.Left&lt;/strong&gt; are &lt;a href="http://msdn.microsoft.com/en-us/library/ms749011.aspx?ppud=4" target="_blank"&gt;attached properties&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/132/Blend-For-Beginners-Grid-to-Canvas-to-StackPanel.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/132/Blend-For-Beginners-Grid-to-Canvas-to-StackPanel.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/132/Blend-For-Beginners-Grid-to-Canvas-to-StackPanel.aspx</guid>
      <pubDate>Sun, 24 Oct 2010 21:23:00 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=132</trackback:ping>
    </item>
    <item>
      <title>More Simple Blend Layout Techniques and Quirks</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/131/More-Simple-Blend-Layout-Techniques-and-Quirks.aspx</link>
      <description>&lt;p&gt;I have a habit of starting to explore some aspect of Blend and wandering off topic when I’m blogging. Usually it’s some detail that’s new to me and only comes up because I &lt;em&gt;am&lt;/em&gt; blogging and feel the need to explain each step. So, rather than clutter things up, I’m going to put them in blogs of their own. Nothing earth-shattering and probably not of much use to experienced Blend users. But if I’ve overlooked details in the past, maybe what I learn as I explore them now will be helpful to newbies.&lt;/p&gt;  &lt;h2&gt;MainPage and the Default Hosting Web Site&lt;/h2&gt;  &lt;p&gt;Quite likely, when you create a new Silverlight application you create a web site to host it at the same time, this is the dialog you see in Visual Studio:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb.png" width="603" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I’ve never given much thought of the page that hosts&lt;strong&gt; MainPage.xaml&lt;/strong&gt; or its equivalent, or the default dimensions and alignment settings for &lt;a href="http://msdn.microsoft.com/en-us/library/ms617852(v=VS.95).aspx" target="_blank"&gt;UserControl&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt;, which is the outermost container of the &lt;strong&gt;MainPage&lt;/strong&gt; &lt;strong&gt;UI; &lt;/strong&gt;if you’re talking about the size of &lt;strong&gt;MainPage&lt;/strong&gt; or the hosted Silverlight control, you’re talking about the size of &lt;strong&gt;UserControl&lt;/strong&gt;. Actually, as you’ll see below,the &lt;strong&gt;MainPage&lt;/strong&gt; object &lt;em&gt;is a&lt;/em&gt; &lt;strong&gt;UserControl&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_1.png" width="644" height="299" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;MainPage.xaml&lt;/strong&gt; and ….&lt;/p&gt;  &lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Class&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"BlendQuirks.MainPage"&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;… &lt;strong&gt;MainPage.xaml.cs&lt;/strong&gt; combine to define the &lt;strong&gt;MainPage class&lt;/strong&gt;. &lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; BlendQuirks
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;{
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; partial &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MainPage : UserControl
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MainPage()
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;            InitializeComponent();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Incidentally, if we adhere to the Model-ViewModel or MVVM patterns, which we always should if we’re serious about Silverlight, this is the only code we should see in &lt;strong&gt;MainPage.xaml.cs&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In Blend design mode we make changes to &lt;strong&gt;UserControl&lt;/strong&gt; and contents to define the UI; as we make changes in design Blend makes changes to &lt;strong&gt;MainPage.xaml&lt;/strong&gt;. We could edit the xaml directly, but we almost always don’t want to – in design mode we can see changes to the UI as we make them, and design mode is not subject to typos – including entries into the custom Expression dialog – errors typed there will be caught that would fail silently at runtime if you typed them directly into xaml. &lt;/p&gt;

&lt;p&gt;Before I go any further, let me point out two “special” things about &lt;strong&gt;UserControl&lt;/strong&gt; – which I refer to as if that’s its name, which it’s not, but shorter to type than “UserControl object”.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;It has a &lt;strong&gt;Background&lt;/strong&gt; &lt;strong&gt;Brush&lt;/strong&gt; property, but as far as I can tell the property is always ignored, both in Blend and at run-time. The answers I found on setting it begged the question by advising to set the &lt;strong&gt;Background&lt;/strong&gt; &lt;strong&gt;Brush&lt;/strong&gt; of the &lt;strong&gt;UIElement&lt;/strong&gt; filling &lt;strong&gt;UserControl&lt;/strong&gt; (&lt;strong&gt;LayoutRoot&lt;/strong&gt;). &lt;/li&gt;

  &lt;li&gt;When you have &lt;strong&gt;UserControl&lt;/strong&gt; selected in Blend&lt;strong&gt; Objects and Timelines&lt;/strong&gt; the color will be the color of the &lt;strong&gt;Background&lt;/strong&gt; &lt;strong&gt;Brush&lt;/strong&gt; property in &lt;strong&gt;LayoutRoot&lt;/strong&gt;. &lt;/li&gt;

  &lt;li&gt;If you click on the Hide icon next to &lt;strong&gt;LayoutRoot&lt;/strong&gt; you’ll see that &lt;strong&gt;UserControl&lt;/strong&gt; is black (actually it’s transparent). &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Back to ‘sup with the default settings: If you don’t change anything and run the app you’ll see a blank white page filling the browser. &lt;/p&gt;

&lt;p&gt;That’s because &lt;strong&gt;LayoutRoot&lt;/strong&gt; gets a white &lt;strong&gt;Background&lt;/strong&gt; &lt;strong&gt;Brush&lt;/strong&gt; by default, and when you create a project with a hosting web site as we did above, the default settings are that &lt;a name="eexpands"&gt;everything expands to fill its container&lt;/a&gt;, from the HTML form on the hosting page right on down to &lt;strong&gt;LayoutRoot&lt;/strong&gt; at the bottom. The hosting page is shown below:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"form1"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"height:100%"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"silverlightControlHost"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;object&lt;/span&gt; &lt;span style="color: #ff0000"&gt;data&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"data:application/x-silverlight-2,"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"application/x-silverlight-2"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;width&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"100%"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;height&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"100%"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;		  &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"source"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"ClientBin/BlendQuirks2.xap"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;		  &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"onError"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"onSilverlightError"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;		  &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"background"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"white"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;		  &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"minRuntimeVersion"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"4.0.50826.0"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;		  &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;param&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"autoUpgrade"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"true"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;		  &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;a&lt;/span&gt; &lt;span style="color: #ff0000"&gt;href&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=4.0.50826.0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"text-decoration:none"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 			  &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;img&lt;/span&gt; &lt;span style="color: #ff0000"&gt;src&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://go.microsoft.com/fwlink/?LinkId=161376"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;alt&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Get Microsoft Silverlight"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"border-style:none"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;		  &lt;span style="color: #0000ff"&gt;&lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;a&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;&lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;object&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;iframe&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"_sl_historyFrame"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"visibility:hidden;height:0px;width:0px;border:0px"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;iframe&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;&lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;I’m going to set the background color of the hosting object from white to orange and put some margins around LayoutRoot so you can see for yourself that:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;UserControl&lt;/strong&gt; is transparent. &lt;/li&gt;

  &lt;li&gt;The hosting object expands to fill the div which expands to fill the form which expands to fill the page. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;LayoutRoot&lt;/strong&gt; expands to fill &lt;strong&gt;UserControl&lt;/strong&gt;, allowing for the margins. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_32.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_14.png" width="244" height="218" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You can also add margins to &lt;strong&gt;UserControl&lt;/strong&gt;, although you probably wouldn’t. Actually you probably wouldn’t add margins to &lt;strong&gt;LayoutRoot&lt;/strong&gt; either. It makes more sense for the hosting container to determine how much of itself, if any, should show around the edges.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_34.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_15.png" width="244" height="240" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;One more point about the dimensions. Even though we see that&lt;strong&gt; BlendQuirks2 / MainPage / UserControl&lt;/strong&gt; is expanding to fill its container, in Blend we see the dimensions of &lt;strong&gt;UserControl&lt;/strong&gt; are set to Auto(400) x Auto(300).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_30.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_13.png" width="644" height="175" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you look at the xaml, you’ll see those dimensions apply to design mode. This can be confusing, because the properties would look exactly the same if &lt;strong&gt;LayoutRoot&lt;/strong&gt; was set to 400 x 300 and &lt;strong&gt;UserControl&lt;/strong&gt; was auto-sizing to accommodate.&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Class&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"BlendQuirks2.MainPage"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;x&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;d&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.microsoft.com/expression/blend/2008"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;mc&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #ff0000"&gt;mc&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Ignorable&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"d"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #ff0000"&gt;d&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;DesignHeight&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"300"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;d&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;DesignWidth&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"400"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Background&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"#FF9B3939"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Grid&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"LayoutRoot"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Background&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"White"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;d&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;IsHidden&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"True"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Opacity&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"0"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;&lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;UserControl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;If you removed these design mode dimension settings you’d find that &lt;strong&gt;UserControl&lt;/strong&gt; collapses to nothing when viewed in Blend, but would still fill the screen at run-time because the alignment is still set to stretch.&lt;/p&gt;

&lt;p&gt;When the dimensions are set to Auto, if you set the alignment to any setting other than stretch, &lt;strong&gt;UserControl&lt;/strong&gt; will collapse to nothing at runtime as well, sizing  itself to accommodate its content, &lt;strong&gt;LayoutRoot. &lt;/strong&gt;Since &lt;strong&gt;LayoutRoot&lt;/strong&gt; is empty &lt;strong&gt;UserControl&lt;/strong&gt; is sized to 0 x 0. &lt;/p&gt;

&lt;p&gt;Back to filling the screen; if you position an element in the lower-right:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_36.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_16.png" width="1028" height="498" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You get something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_38.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_17.png" width="243" height="244" /&gt;&lt;/a&gt; &lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_40.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_18.png" width="244" height="101" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So that’s the default. Everything expands to fill its container. &lt;/p&gt;

&lt;p&gt;If you want to control the run-time size of &lt;strong&gt;MainPage&lt;/strong&gt; so it’s same size as in Blend you could do it in the host page:&lt;/p&gt;

&lt;pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;&lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"silverlightControlHost"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"height:300px;width:400px;"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;p&gt; &lt;/p&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_42.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_19.png" width="562" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;But it’s more likely you’ll want to hard-code the dimensions of UserControl:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_44.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_20.png" width="644" height="329" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_46.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_21.png" width="569" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Notice that even though the alignment of &lt;strong&gt;UserControl&lt;/strong&gt; is set to stretch it no longer expands to fill its container. Nor does it expand to accommodate its contents. I set &lt;strong&gt;LayoutRoot&lt;/strong&gt; width to 450 resulting in:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_48.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="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb_22.png" width="608" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You’ll also find that non of the other &lt;strong&gt;UserControl&lt;/strong&gt; alignment settings have any affect, at least as far as I can tell. &lt;/p&gt;

&lt;p&gt;One last point about dimensions and alignment. Don’t overlook that you can bind them to data in the ViewModel, or to other properties of other controls on the page; the latter probably would be more useful in manipulating the contents of &lt;strong&gt;UserControl&lt;/strong&gt; than &lt;strong&gt;UserControl&lt;/strong&gt; itself, but both open up all kinds of  interesting possibilities.&lt;/p&gt;

&lt;h2&gt;&lt;a name="mmargins"&gt;Maintaining Margins when re-sizing in Blend&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;In the course of some project, I was trying to create a simple page with a heading and a &lt;strong&gt;ListBox&lt;/strong&gt;. I wanted the heading text and &lt;strong&gt;ListBox&lt;/strong&gt; to stay aligned within their row and column if the grid is re-sized, let’s look in and see how I’m doing:&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;UserControl&lt;/strong&gt; sized to 300 x 200 and &lt;strong&gt;LayoutRoot&lt;/strong&gt;  dimension set to Auto and  alignment set to stretch, give &lt;strong&gt;LayoutRoot&lt;/strong&gt; a background color and hover and click the mouse as shown below to create a new row. Don’t worry about the size being precise. We’re going to lay this out so you can resize after the fact and the contents will re-position or re-size as necessary. This is one of the few occasions when I’m ok with clicking on the design surface.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles3938789/image186.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_thumb108" border="0" alt="image_thumb108" src="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb108_cf7150fd-d010-48e4-b983-d9afd924ada9.png" width="644" height="404" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;LayoutRoot&lt;/strong&gt; selected, browse &lt;strong&gt;Assets/Controls&lt;/strong&gt; for the &lt;strong&gt;Label&lt;/strong&gt; control and drag it onto &lt;strong&gt;LayoutRoot&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles3938789/image193.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_thumb113" border="0" alt="image_thumb113" src="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb113_8e162ade-bec2-4ad3-a430-d1a16cafcf0b.png" width="1014" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Resulting in:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles3938789/image198.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_thumb116" border="0" alt="image_thumb116" src="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb116_6f4abbf9-a9c8-4c1a-b65c-b8714afdf861.png" width="1028" height="449" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Since this is a heading, I’m just going to center it horizontally and vertically. I’ll also set the &lt;strong&gt;Content&lt;/strong&gt; to &lt;strong&gt;Themes&lt;/strong&gt; and adjust the font size:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles3938789/image203.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_thumb119" border="0" alt="image_thumb119" src="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb119_dfca194a-fafa-4a41-b307-117c1575f9f4.png" width="1028" height="708" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Make sure &lt;strong&gt;LayoutRoot&lt;/strong&gt; is selected again and drag a &lt;strong&gt;ListBox&lt;/strong&gt; control onto it from &lt;strong&gt;Assets&lt;/strong&gt;. It’s right next to the &lt;strong&gt;Label&lt;/strong&gt; you just dragged. It’s going to show up as a 100 x 100 white box at the upper left corner of &lt;strong&gt;LayoutRoot&lt;/strong&gt;. We’re going to change the row to 1, set the dimensions to Auto, and the alignment to stretch. We’re also going to add margins all around…&lt;/p&gt;

&lt;p&gt;…Ok, this is kind of funny. By default, meaning this is the setting Blend gave it when I dropped the &lt;strong&gt;ListBox&lt;/strong&gt; on &lt;strong&gt;LayoutRoot&lt;/strong&gt;, the row is already set to 1, but the margin is set to position the &lt;strong&gt;ListBox&lt;/strong&gt; in the upper left corner of the entire grid:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles3938789/image211.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_thumb123" border="0" alt="image_thumb123" src="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb123_0808aef9-30a2-4342-a79d-6b7b08aba6c6.png" width="612" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You gotta think that some routine in Blend  wants it in row 1 and another wants it to be in the upper-left corner and this is the compromise. This is why you want to pay attention to position and size settings when you first add controls in Blend instead of just yanking and banking.&lt;/p&gt;

&lt;p&gt;Remember I said we were going to lay the &lt;strong&gt;UserControl&lt;/strong&gt; out so the contents adjust to re-sizing? Turns out that only works if you can restrain yourself from re-sizing by dragging grab bars. In the screen shot below, I’m trying to position &lt;strong&gt;ListBox&lt;/strong&gt; so it re-sizes itself to fill its row and column while maintaining a 10 pixel margin all around.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles3938789/image2211.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_thumb129" border="0" alt="image_thumb129" src="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb129_0b4a7901-e94b-4deb-9159-951a18da6272.png" width="1028" height="564" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a name="MarginKiller"&gt;Turns out if I increase the width of&lt;/a&gt; &lt;strong&gt;UserControl&lt;/strong&gt; by dragging the right side that &lt;strong&gt;ListBox&lt;/strong&gt; doesn’t resize itself, and if I go back to &lt;strong&gt;ListBox&lt;/strong&gt; properties I find that the margin has changed to accommodate the change in &lt;strong&gt;UserControl&lt;/strong&gt; instead of &lt;strong&gt;ListBox&lt;/strong&gt; resizing to fill the additional space:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.openlightgroup.netfile:///C:/Users/Rich/AppData/Local/Temp/WindowsLiveWriter393614076/supfiles3938789/image216.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_thumb126" border="0" alt="image_thumb126" src="/Portals/0/Blog/Files/3/131/WLW-MoreSimpleBlendLayoutTechniquesandQuirks_108D4-image_thumb126_83156d75-ad13-411b-a6f5-cdd77120a263.png" width="1028" height="462" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;However, if I re-size &lt;strong&gt;UserControl&lt;/strong&gt; by entering the value or, as I prefer, hovering the mouse over the width and then dragging it so you can see the width change dynamically, then the margins remain unchanged and the &lt;strong&gt;ListBox&lt;/strong&gt; resizes as I intended it to. Yet another reason to avoid using the mouse to drag or resize elements in the design area.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;Blend is great, but you have to keep your head in the game when you’re working with it. I’d say the most important thing is to use the Properties panel to make adjustment to the UI, not the design surface, at least if you’re still in my league – if I could play the piano, I would, but I can’t, so I don’t.  Doesn’t mean you shouldn’t learn.&lt;/p&gt;&lt;br /&gt;&lt;a href=http://openlightgroup.net/Blog/tabid/58/EntryId/131/More-Simple-Blend-Layout-Techniques-and-Quirks.aspx&gt;More ...&lt;/a&gt;</description>
      <author />
      <comments>http://openlightgroup.net/Blog/tabid/58/EntryId/131/More-Simple-Blend-Layout-Techniques-and-Quirks.aspx#Comments</comments>
      <slash:comments>0</slash:comments>
      <guid isPermaLink="true">http://openlightgroup.net/Blog/tabid/58/EntryId/131/More-Simple-Blend-Layout-Techniques-and-Quirks.aspx</guid>
      <pubDate>Sat, 23 Oct 2010 16:58:54 GMT</pubDate>
      <trackback:ping>http://www.openlightgroup.netDesktopModules/BlogTrackback.aspx?id=131</trackback:ping>
    </item>
    <item>
      <title>Simple Layout Techniques In Blend</title>
      <link>http://openlightgroup.net/Blog/tabid/58/EntryId/127/Simple-Layout-Techniques-In-Blend.aspx</link>
      <description>&lt;p&gt;Just to set the record straight, I’m usually not all that enthusiastic about visual programming tools. I rarely use the UI in Visual Studio to add controls, Silverlight or ASP.NET – in fact about the only time I do use it is to set properties. But Blend is different. Just having a view-centric tool that you can use to reach out to the ViewModel without ever touching a line of code helps in visualizing the relationships and in appreciating just what binding is about.&lt;/p&gt;  &lt;p&gt;But, much as I love Blend, sometimes it confuses me. To this day the dimensions assumed by some auto-sized controls bewilders me. So when I say simple layout techniques, I mean simple. It’s sort of a path hacked out by an earlier explorer that may not be the best, but avoids falling into the swamp.&lt;/p&gt;  &lt;p&gt;So to start with I’ll show you the feature-complete but aesthetically challenged first pass at the UI for one of the pages of a project I just started. The Application is called Test Me, and the first iteration will show two TextBlocks, one for the question and one for the answer. Essentially this version is the equivalent of flash cards. You read the question in the question box and when you’re ready click on the ‘Show’ button to see the answer. The ‘Next’ button, as you’d expect, causes the next question to be displayed.&lt;/p&gt;  &lt;p&gt; &lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_118.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_56.png" width="644" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;Preliminaries: Auto-Size and Stretch Alignment&lt;/h2&gt;  &lt;h3&gt;&lt;/h3&gt;  &lt;p&gt;Before starting on the actual project, I’d like to explore the consequences of auto-sizing and alignment. Generally speaking, an auto-sized element sizes itself according to its contents, unless its alignment is set to ‘Stretch’, in which case it will size itself to fill its container. I say generally speaking, not only because there are other properties, such as margins, to consider, but also because sometimes the results are not what you would expect.&lt;/p&gt;  &lt;p&gt;So let’s establish the size of the entire page by setting the UserControl dimensions to 640x480 (not shown). Let’s look at what affect this has on our main UIElement, LayoutRoot. In the screenshot below, if we (1) Select LayoutRoot (2) Set LayoutRoot alignment to stretch and (3) Set Width and Height to Auto, LayoutRoot makes itself the same size as the encompassing UserControl as we’d expect:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_20.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" src="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_3.png" width="644" height="375" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;What happens if we set the alignment to anything other than ‘Stretch’? As you can see below, with (1) LayoutRoot selected, I (2) Set horizontal alignment to ‘Center’ (3) Layout root sizes itself to zero width and (4) Appears as a vertical line with a dot in the center in the design area.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_28.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_5.png" width="644" height="379" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We should be able to give LayoutRoot some width by adding an element. Now select LayoutRoot in Objects and Timeline and double-click the button icon to add one.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image36.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image36_thumb.png" width="329" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Well, not what I would have expected, which is a Button sized to its content of ‘Button’. If you can’t tell, the Button is at (1). It's positioned in the upper left corner (2), and the dimensions are set to a Width of 6 … and there’s our problem. Our button is only 6 pixels wide because the width is hard-coded. And see the little white dot to the right? That indicates the Width value has been changed from the default, which is Auto. Why? I don’t know. The point is that the safest way out of this kind of situation is not to start grabbing things with the mouse cursor, but instead to check the properties panel to see what the problem might be. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_30.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_9.png" width="644" height="315" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you click on the white dot and select reset from the resulting dialog, the Width will be set to Auto, or, you can just double-click on the Auto-Size icon:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_34.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_14.png" width="31" height="27" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And we see the button width set to Auto and therefore sized according to its content.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_36.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_15.png" width="644" height="281" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Ok, one more point from this rather contrived example and we’ll move on to the project.&lt;/p&gt;  &lt;p&gt;We can see that LayoutRoot sizes its width according to the width of the button. Let’s see what happens when we give Button a left margin.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_38.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_16.png" width="644" height="344" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see, LayoutRoot has resized itself to accommodate Button’s left margin. A cool way to do this is to hover your mouse over the Margin setting and when it changes, hold the left button down and you can increment the value by dragging up or right and decrement by dragging down or left; LayoutRoot on the design surface widens or narrows as you drag.&lt;/p&gt;  &lt;p&gt;Now let’s say you had gone at this by trying to “manually’ widen LayoutRoot by grabbing a drag-box (1) and dragging to the right. Well, because you resized LayoutRoot to a specific size, the Width is no longer set to Auto (2).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_40.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_17.png" width="644" height="347" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Would you notice, or would you just keep dragging to increase the width, and then try to drag the button to the right? You might end up with the correct appearance, but as you add more elements it becomes more and more difficult because things keep re-positioning themselves in unexpected ways. You can end up with a StackPanel, for instance, positioned entirely on the wrong part of the page. But the buttons ‘within’ are positioned correctly because their margins are set so they appear entirely outside the stack panel. They will continue to be stacked, so if the StackPanel is transparent, you might not notice that the panel is in the wrong place – until you need to make some changes in a hurry and every change you make affects something else, and so on, and so on….&lt;/p&gt;  &lt;p&gt;In the example below you can see that the Buttons (1) are all contained in StackPanel, which I have colored Green so you can see it. By setting the left margin of all three buttons to a negative number (2), I can position the buttons entirely outside the StackPanel. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_46.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_20.png" width="644" height="402" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now if you’ll notice at (3), the button’s vertical alignment is set to ‘Stretch’. Why doesn’t the button stretch vertically to the height of the stack panel? I’m sure there’s a good reason, such as the fact that it’s contained in a stack panel whose orientation is vertical. To test that theory out, I removed the offsets so the buttons appeared in the stack panel where you’d expect, then changed the stack panel orientation to horizontal.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_48.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_21.png" width="1028" height="459" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see, the buttons have now all stretched to fill the stack panel vertically. The offsets at the top are from the vertical margins set on the buttons that spaced them vertically when the orientation was vertical. &lt;/p&gt;  &lt;p&gt;When you think about it this makes sense. You’d expect a vertically oriented stack panel to be tall and narrow. It’s reasonable that you’d want buttons to fill the space horizontally but constrain their height, and vice-versa. We get this behavior in spite of the fact that the default Horizontal and Vertical alignments for Button are Stretch, so as you can see, just because an element has its alignment set to ‘Stretch’ doesn’t necessarily mean the setting will be honored.&lt;/p&gt;  &lt;p&gt;Ok, enough about the dangers of blundering around off the path. It’s ok to explore, but you have to keep your head about you so you can get back if you need instead of falling in the swamp where even Ctrl-Z won’t help you. But I guess I should come up with a rule to justify what I’ve said so far. I guess it would be:&lt;/p&gt;  &lt;h3&gt;&lt;font color="#8000ff"&gt;&lt;font size="5" face="Monotype Corsiva"&gt;Richard’s Rules Of Blend #1&lt;/font&gt; &lt;/font&gt;– Avoid sizing and positioning elements in the design area using the mouse. It deprives you of situational awareness.&lt;/h3&gt;  &lt;p&gt;The most insidious effect is that what’s onscreen may look correct, but because you just grabbed and dragged, you may end up with an intricately balanced tangle of margin settings that will fundamentally bite you two weeks later when you need to add new elements. Ctrl-Z your fundament out of that.&lt;/p&gt;  &lt;p&gt;You can still resize elements “dynamically”, by making them grow or shrink. As I mentioned above in the example where I incremented the button’s left margin – hover the mouse over the Margin setting you want to change, when the cursor changes, hold the left button down and drag the mouse to increment or decrement the value. This works for most numeric fields, such as width or height. It’s super useful, which is ironic, because when I first saw it I thought it was gimmicky. Don’t bother to tell me if I’m misusing the word “irony”. Ironically, I’m ok with it.&lt;/p&gt;  &lt;h2&gt;   &lt;h2&gt;Down To Business&lt;/h2&gt; &lt;/h2&gt;  &lt;p&gt;If you’ve been following along, get rid of everything except LayoutRoot, set its dimensions to Auto and alignment to ‘Stretch’. The UserControl is a page and we always want the UI to fill the entire page.&lt;/p&gt;  &lt;p&gt;We know we want two columns and that each column should have a heading, a text area, and a button arranged vertically. We could take all this into account before we start, but I want to show you how you can layer these things on as you go along. So let’s just start with the heading. &lt;/p&gt;  &lt;h3&gt;&lt;a name="PinningControls"&gt;Pinning Controls to the Tools Panel&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;First, go to (1) Assets, (2) Controls and double click on  (3) Label.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_52.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_23.png" width="644" height="399" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This will result in the label icon (4) showing up under the Assets icon (1). The label icon is actually a Pinned Controls icon which may represent several pinned controls. The label appears because it is the currently selected pinned Control.&lt;/p&gt;  &lt;p&gt;Now double-click on the label / pinned controls icon and end up with a (1) Label, sized to its content (2), positioned at the upper-left of its container (3).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_54.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_24.png" width="644" height="307" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With a few simple property changes we can get the results we want with no fuss:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_58.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_26.png" width="709" height="772" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Plus scroll down below Common Properties to set font size:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_60.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_27.png" width="270" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This brings us to:&lt;/p&gt;  &lt;h3&gt;&lt;font color="#8000ff"&gt;&lt;font size="5" face="Monotype Corsiva"&gt;Richard’s Rules Of Blend #2&lt;/font&gt; &lt;/font&gt;– Place, then Position and Size. &lt;/h3&gt;  &lt;p&gt;Get in the habit of placing controls by selecting the target in &lt;strong&gt;Objects and Timeline&lt;/strong&gt;, then inserting the control by double-clicking if possible, or by dragging from Assets. The real point is to avoid the habit of grabbing controls and drawing them on the design area. Unless you know what you’re doing you may end up with unwanted margin settings or flat out errors in placing the control in the wrong container – and then there’s inadvertently changing the size of existing elements. Once you have the control in the right container just adjust the properties as required.&lt;/p&gt;  &lt;p&gt;Ok, this is getting good to me – here’s:&lt;/p&gt;  &lt;h3&gt;&lt;font color="#8000ff"&gt;&lt;font size="5" face="Monotype Corsiva"&gt;Richard’s Rules Of Blend #3&lt;/font&gt; &lt;/font&gt;– Use Margins Consistently&lt;/h3&gt;  &lt;p&gt;This will come pretty naturally if you avoid using the mouse for positioning. Notice above I positioned the Label vertically by setting the upper margin. The controls are stacked vertically, so it makes sense to use the margin above each one to control the space  between them, in a StackPanel at least (in a grid it would be the space from the top of the row). It also makes sense to avoid setting the bottom margin (with one exception), but that’s what happens if you drag elements around to position them. For a horizontal stack panel you’d want to set the left margin and leave the right margin alone. The same principle would apply in grid rows and columns except the margins are from the row or column border, not the adjacent control.&lt;/p&gt;  &lt;p&gt;As for the color, unless I already know the color I want, I just pick some arbitrary color so I can easily spot the dimensions of the element in the design area, even if it may end up being transparent in the long run.&lt;/p&gt;  &lt;p&gt;In the screen below I’ve added a background color to LayoutRoot, but the point in this screen is to make sure you have LayoutRoot selected and double-click on the TextBlock icon:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_62.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_28.png" width="1028" height="652" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You may have to scroll the design area to the upper left to see it:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_64.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_29.png" width="1028" height="550" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I want to set the background color of the TextBlock, which has no Background brush. We can give it a background color by wrapping it within a border. I like to add assets to the tool bar as I use them, so after adding the border by finding it in Assets and double-clicking I get something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_66.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_30.png" width="199" height="169" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Make sure LayoutRoot is selected then double-click on the border icon to add a Border Element to LayoutRoot. Then, in the Objects and Timeline Panel, cut and paste TextBlock into the Border, then set Border’s background brush:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_68.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_31.png" width="1028" height="494" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now it’s easy to tell where TextBlock is. But you know, things are getting too spread out. I know I want a column of centered elements, but as it is it’s not convenient to see the center and the left edge at the same time.  Now you may have noticed that every new element is added to the upper left corner of layout root by virtue of their alignment settings. And you may have further noticed that LayoutRoot is a grid and every element is added with a Column property of zero.&lt;/p&gt;  &lt;p&gt;So, assuming we want LayoutRoot to remain a grid, which we do, the most useful approach would be to add a column to LayoutRoot. It’s quite easy to do this visually. Simply hover over the point shown and click to position a column at that point.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_70.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="/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_thumb_32.png" width="1028" height="411" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;However, let me show you an alternative which is useful when you need to set the widths with precision. Select LayoutRoot and look under the Properties tab to  (1)Layout . Click on the icon at (2) and select the button next to ColumnDefinitions at (3):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.openlightgroup.net/Portals/0/Blog/Files/3/127/WLW-SimpleLayoutTechniquesInBlend_8241-image_74.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px;
