<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Jesse Liberty - Silverlight Geek</title>
	
	<link>http://jesseliberty.com</link>
	<description>More Signal - Less Noise</description>
	<lastBuildDate>Mon, 06 Sep 2010 18:09:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JesseLiberty-SilverlightGeek" /><feedburner:info uri="jesseliberty-silverlightgeek" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><thespringbox:skin xmlns:thespringbox="http://www.thespringbox.com/dtds/thespringbox-1.0.dtd">http://feeds.feedburner.com/JesseLiberty-SilverlightGeek?format=skin</thespringbox:skin><geo:lat>42.477142</geo:lat><geo:long>-71.442205</geo:long><creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><image><link>http://silverlight.net/blogs/JesseLiberty</link><url>http://silverlight.net/blogs/jesseliberty/BlogImages/SLLogo.jpg</url><title>Silverlight Geek Blog</title></image><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FJesseLiberty-SilverlightGeek" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FJesseLiberty-SilverlightGeek" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FJesseLiberty-SilverlightGeek" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/JesseLiberty-SilverlightGeek" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FJesseLiberty-SilverlightGeek" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FJesseLiberty-SilverlightGeek" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FJesseLiberty-SilverlightGeek" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FJesseLiberty-SilverlightGeek" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:browserFriendly>More signal; less noise.</feedburner:browserFriendly><item>
		<title>iPhone to Windows Phone 7 – Diving Deeper</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/ERPHwnY2B3o/</link>
		<comments>http://jesseliberty.com/2010/09/04/iphone-to-windows-phone-7-diving-deeper/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 12:38:13 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[.NET and Language Features]]></category>
		<category><![CDATA[Essentials]]></category>
		<category><![CDATA[Mini-Tutorial]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[iPhoneToWP7]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[i2WTutorial]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/09/04/iphone-to-windows-phone-7-diving-deeper/</guid>
		<description>Go to First Tutorial In this tutorial, we’ll expand upon the work done in the previous tutorial and we’ll look more closely at a few key issues. MVVM As an iPhone Developer your thinking is adapted to and influenced by the Model-View-Controller pattern. The very good news is that the pattern for Windows Phone 7 [...]</description>
			<content:encoded><![CDATA[<p><a href="http://jesseliberty.com/wp-content/uploads/2010/09/i2WLogo2Tutorials.jpg"><img style="margin: 10px 0px; display: inline; border-width: 0px;" title="i2WLogo2-Tutorials" src="http://jesseliberty.com/wp-content/uploads/2010/09/i2WLogo2Tutorials_thumb.jpg" border="0" alt="i2WLogo2-Tutorials" width="368" height="73" /></a></p>
<p><a href="http://jesseliberty.com/2010/08/23/i2w-an-iphone-developers-guide-to-creating-windows-phone-7-applications-tutorial/" target="_blank">Go to First Tutorial</a></p>
<p>In this tutorial, we’ll expand upon the work done in the previous tutorial and we’ll look more closely at a few key issues.</p>
<h1>MVVM</h1>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/09/iStock_WindowXSmall.jpg"><img style="margin: 10px 30px 10px 0px; display: inline; border-width: 0px;" title="iStock_WindowXSmall" src="http://jesseliberty.com/wp-content/uploads/2010/09/iStock_WindowXSmall_thumb.jpg" border="0" alt="iStock_WindowXSmall" width="240" height="136" align="left" /></a> As an iPhone Developer your thinking is adapted to and influenced by the Model-View-Controller pattern. <strong>The very good news is that the pattern for Windows Phone 7 (WP7) development, <em>MVVM</em>, is very closely related to MVC. </strong></p>
<p><strong><span id="more-3376"></span><br />
</strong></p>
<p><a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank">Wikipedia</a> notes that <strong>MVVM evolved at Microsoft out of the Model-View-Presenter</strong> pattern developed by <a href="http://en.wikipedia.org/wiki/Martin_Fowler" target="_blank">Martin Fowler</a>,  <strong>which was based, in turn on MVC</strong>.  The originators of MVVM often refer to it as a specialization of Model-View-Presenter.   Wikipedia goes on to say,</p>
<blockquote><p>Largely based on the Model-view-controller pattern (MVC), MVVM is targeted at modern UI development platforms… in which there is a User Experience (UX) developer who has different requirements than a more “traditional” developer (i.e. oriented toward business logic and back end development). The View-Model of MVVM is “basically a value converter on steroids” meaning that the View-Model is responsible for exposing the data objects from the Model in such a way that those objects are easily managed and consumed. In this respect, the View-Model is more Model than View, and handles most if not all of the View’s display logic (though the demarcation between what functions are handled by which layer is a subject of ongoing discussion and exploration).</p></blockquote>
<p>It is important to understand that <strong>MVVM and Silverlight co-evolved</strong>, each influencing the other, and thus the “hand in glove” fit between them is no coincidence.</p>
<p>In MVVM both the View and the Model are identical in meaning to what they mean in MVC</p>
<p>The ViewModel is the <em>Model of the View</em>, that is, it is an abstraction of the view and, most important, (just about) all the user-generated view code is kept in the view model (rather than in the code-behind for the View as can also be done in WP7 programming).  Numerous writers have commented that the VM is really a specialized controller that acts as a data binder and converter; changing Model information in to View information, and passing commands from the View that may affect the Model.</p>
<h3>Three Core Concepts</h3>
<p>We’ve been talking about <strong>n-tier development, decoupling, scoping, visibility </strong>and related topics since at least 1990. I’m pretty sure that when they were cracking the Enigma machine in World War II, they discussed decoupling the code-breaker module from the UI (did they have UI then?)</p>
<p><strong>MVVM, at its heart has three core concepts</strong>:</p>
<p><img style="margin: 10px 30px 10px 0px;" title="MVVMSketch" src="http://jesseliberty.com/wp-content/uploads/2010/05/MVVMSketch_thumb.jpg" border="0" alt="MVVMSketch" width="133" height="240" align="left" /></p>
<p><strong>Core Concept #1</strong>:  <strong>Separate your User Interface concerns (View) from your Business objects and behaviors</strong> (View Model) and from your data/persistence layer <strong>(</strong>Model<strong>)</strong>.</p>
<p><strong>Core Concept #2: Don’t Look Up</strong>.</p>
<p>We tend to conceptualize the View at the top, the ViewModel  in the middle and the model  at the bottom.  The View can know about the ViewModel, the ViewModel about the Model, and the Model, like the cheese, stands alone.</p>
<p><strong>Core Concept #3 – And this is the killer: Binding.</strong></p>
<p>In MVVM the mechanism for the ViewModel to provide data to the View, is for the View to set the ViewModel as its DataContext.  That is so cool; it takes a while to realize the implications.  Further, we don’t just bind data, as I’ll show below.</p>
<p>[ click on any image to see it full size ]</p>
<h4>Why Would You Want To Do That, &amp; What Does It Cost?</h4>
<p>The huge advantages of MVVM (and MVC) are that</p>
<ul>
<li><em><strong>you write less code</strong></em></li>
<li><strong>you have enormously increased the testability of your application</strong>.</li>
</ul>
<p>It is a bear to try to test a UI object because the pesky UI gets in the way. ViewModels have no UI, they have just the things you want to test: “does it behave as expected? and is the data correct at any given instant?”</p>
<p>So, the cost is negative; that is, by adopting MVVM you don’t work harder, you work less, and in exchange for doing less, your code is easier to write, to read, to maintain and to test. Not bad.</p>
<h3>Concrete Guidelines</h3>
<p>Because MVVM is somewhat new, and because I’m totally disinterested in <a href="http://en.wikipedia.org/wiki/Pilpul" target="_blank">pilpul</a> I will arbitrarily suggest the following guidelines:</p>
<ol>
<li>Do not bother with MVVM for any program that takes less than 1 hour to write.</li>
<li>Move as much logic as possible from the view to the VM, but try not to become obsessed</li>
<li>Use a MVVM library (life is short!)   We’ll use the (free) <a href="http://mvvmlight.codeplex.com/" target="_blank">MVVM Light Toolkit</a> in this series.</li>
<li>Chillax</li>
</ol>
<h3>Creating An MVVM Application</h3>
<p>Let’s return to the application started in the previous tutorial, and add two-way binding so that we can update the records. That will give us an opportunity to examine, in a bit more detail, the responsibilities of the Model, ViewModel and View, and will allow us also to talk a bit more about event handling.</p>
<p>Because we are early in the tutorials, there is value in starting from scratch.  Create a new project of type MVVMLight (WP7) [If you don’t see this option you do not have the  <a href="http://mvvmlighttoolkit.CodePlex.com" target="_blank">MVVM Light Toolkit</a> installed.].  Call your new application i2w_CustomerData</p>
<p>Here, for your cut and past convenience, is the Xaml from the example in the previous tutorial, except that I’ve removed the bottom two rows (Notes and Male/Female) and added a button (Next)</p>
<pre class="brush: xml; collapse: true;">&lt;Grid.RowDefinitions&gt;
   &lt;RowDefinition Height="1*" /&gt;
   &lt;RowDefinition Height="1*" /&gt;
   &lt;RowDefinition Height="1*" /&gt;
   &lt;RowDefinition Height="1*" /&gt;
   &lt;RowDefinition Height="1*" /&gt;
   &lt;RowDefinition Height="1*" /&gt;
   &lt;RowDefinition Height="1*" /&gt;
   &lt;RowDefinition Height="1*" /&gt;
&lt;/Grid.RowDefinitions&gt;
&lt;Grid.ColumnDefinitions&gt;
   &lt;ColumnDefinition Width="1*" /&gt;
   &lt;ColumnDefinition Width="2*" /&gt;
&lt;/Grid.ColumnDefinitions&gt;
&lt;TextBlock Grid.ColumnSpan="1"
           Grid.RowSpan="1"
           Height="30"
           HorizontalAlignment="Right"
           Margin="5"
           Name="NamePrompt"
           Text="Full Name"
           VerticalAlignment="Center" /&gt;
&lt;TextBlock Height="30"
           HorizontalAlignment="Right"
           Margin="5"
           Name="AddressPrompt"
           Text="Street Address"
           VerticalAlignment="Center"
           Grid.Row="1" /&gt;
&lt;TextBlock Height="30"
           HorizontalAlignment="Right"
           Margin="5"
           Name="CityStateZipPrompt"
           Text="City, State, Zip"
           VerticalAlignment="Center"
           Grid.Row="2" /&gt;
&lt;TextBlock Height="30"
           HorizontalAlignment="Right"
           Margin="5"
           Name="PhonePrompt"
           Text="Phone"
           VerticalAlignment="Center"
           FontWeight="Bold"
           Grid.Row="3" /&gt;
&lt;TextBlock FontWeight="Bold"
           Height="30"
           HorizontalAlignment="Right"
           Name="FaxPrompt"
           Text="Fax"
           VerticalAlignment="Center"
           Margin="5"
           Grid.Row="4" /&gt;
&lt;TextBlock FontWeight="Bold"
           Height="30"
           HorizontalAlignment="Right"
           Name="EmailPrompt"
           Text="Email"
           VerticalAlignment="Center"
           Margin="5"
           Grid.Row="5" /&gt;
&lt;TextBlock FontWeight="Bold"
           Height="30"
           HorizontalAlignment="Right"
           Name="NotesPrompt"
           Text="Notes"
           VerticalAlignment="Center"
           Margin="5"
           Grid.Row="7" /&gt;
&lt;TextBox Grid.Column="1"
         Height="70"
         HorizontalAlignment="Left"
         Margin="5,0,0,5"
         Name="FullName"
         VerticalAlignment="Bottom"
         Width="303"
         Text="{Binding Name}" /&gt;
&lt;TextBox Height="70"
         HorizontalAlignment="Left"
         Margin="5,0,0,5"
         Name="Address"
         VerticalAlignment="Bottom"
         Width="303"
         Grid.Column="1"
         Grid.Row="1"
         Text="{Binding Address}" /&gt;
&lt;StackPanel Grid.Column="1"
            Grid.Row="2"
            Grid.RowSpan="1"
            HorizontalAlignment="Stretch"
            Name="cityStateZipStack"
            VerticalAlignment="Stretch"
            Orientation="Horizontal"&gt;
   &lt;TextBox Height="70"
            Name="City"
            Width="150"
            HorizontalAlignment="Left"
            VerticalAlignment="Bottom"
            Margin="5,0,0,5"
            Text="{Binding City}" /&gt;
   &lt;TextBox Height="70"
            Name="State"
            Width="74"
            HorizontalAlignment="Left"
            VerticalAlignment="Bottom"
            Margin="0,0,0,5"
            Text="{Binding State}"
 /&gt;
   &lt;TextBox Height="70"
            Name="Zip"
            Width="93"
            Margin="0,0,0,5"
            Text="{Binding Zip}" /&gt;
&lt;/StackPanel&gt;
&lt;TextBox Height="70"
         HorizontalAlignment="Left"
         Margin="5,0,0,5"
         Name="Phone"
         VerticalAlignment="Bottom"
         Width="303"
         Grid.Column="1"
         Grid.Row="3"
         Text="{Binding WorkPhone}" /&gt;
&lt;TextBox Height="70"
         HorizontalAlignment="Left"
         Margin="5,0,0,5"
         Name="Fax"
         VerticalAlignment="Bottom"
         Width="303"
         Grid.Column="1"
         Grid.Row="4"
         Text="{Binding Fax}" /&gt;
&lt;TextBox Height="70"
         HorizontalAlignment="Left"
         Margin="5,0,0,5"
         Name="Email"
         VerticalAlignment="Bottom"
         Width="303"
         Grid.Column="1"
         Grid.Row="5"
         Text="{Binding WorkEmail}" /&gt;

&lt;Button
         Name="Next"
         Content="Next"
         Width="150"
         Grid.Column="1"
         Grid.Row="7"
         /&gt;</pre>
<h3>Creating the Model</h3>
<p>Once again, we’ll create a Customer.cs class in the model,</p>
<pre class="brush: csharp; collapse: true;"> public class Customer
 {

     public string First { get; set; }
     public string Last { get; set; }
     public string Address { get; set; }
     public string City { get; set; }
     public string State { get; set; }
     public string Zip { get; set; }
     public string HomePhone { get; set; }
     public string WorkPhone { get; set; }
     public string Fax { get; set; }
     public string WorkEmail { get; set; }
     public string HomeEmail { get; set; }
     public bool IsMale { get; set; }
     public string Notes { get; set; }
     public int CreditRating { get; set; }
     public DateTime FirstContact { get; set; }
     public DateTime LastContact { get; set; }

     public Customer(
         string first,
         string last,
         string address,
         string city,
         string state,
         string zip,
         string homePhone,
         string workPhone,
         string fax,
         string workEmail,
         string homeEmail,
         bool isMale,
         string notes,
         Int16 creditRating,
         DateTime firstContact,
         DateTime lastContact)
     {
         First = first;
         Last = last;
         Address = address;
         City = city;
         State = state;
         Zip = zip;
         HomePhone = homePhone;
         WorkPhone = workPhone;
         Fax = fax;
         HomeEmail = homeEmail;
         WorkEmail = workEmail;
         IsMale = isMale;
         Notes = notes;
         CreditRating = creditRating;
         FirstContact = firstContact;
         LastContact = lastContact;
     }
}</pre>
<p>This time, however, let’s add to the model and create a collection of customers,</p>
<pre class="brush: csharp; collapse: true;">public class CustomerCollection
{
    private readonly List&lt; Customer &gt; _customers = new List&lt; Customer &gt;();

    public CustomerCollection()
    {
        GenerateCustomers( 500 );
    }

    public List&lt; Customer &gt; Customers
    {
        get { return _customers; }
    }

    public void GenerateCustomers( int howMany )
    {
        var firsts = new List&lt; String &gt;
                     {
                         "Abe",
                         "Alice",
                         "Barry",
                         "Basha",
                         "Charlie",
                         "Colette",
                         "David",
                         "Davida",
                         "Edgar",
                         "Elizabeth",
                         "Frank",
                         "Fran",
                         "George",
                         "Gary",
                         "Harry",
                         "Isaac",
                         "Jesse",
                         "Jessica",
                         "Kevin",
                         "Katrina",
                         "Larry",
                         "Linda",
                         "Mark",
                         "Melinda",
                         "Nick",
                         "Nancy",
                         "Oscar",
                         "Ophilia",
                         "Peter",
                         "Patricia",
                         "Quince",
                         "Quintina",
                         "Robert",
                         "Roberta",
                         "Shy",
                         "Sarah",
                         "Tom",
                         "Teri",
                         "Uberto",
                         "Uma",
                         "Victor",
                         "Victoria",
                         "Walter",
                         "Wendy",
                         "Xerxes",
                         "Xena",
                         "Yaakov",
                         "Yakira",
                         "Zach",
                         "Zahara"
                     };

        var lasts = new List&lt; String &gt;
                    {
                        "Anderson",
                        "Baker",
                        "Connors",
                        "Davidson",
                        "Edgecumbe",
                        "Franklin",
                        "Gregory",
                        "Hines",
                        "Isaacson",
                        "Johnson",
                        "Kennedy",
                        "Liberty",
                        "Mann",
                        "Nickerson",
                        "O'Dwyer",
                        "Patterson",
                        "Quimby",
                        "Richardson",
                        "Stevenson",
                        "Tino",
                        "Usher",
                        "Van Dam",
                        "Walker",
                        "Xenason",
                        "Yager",
                        "Zachery"
                    };
        var streets = new List&lt; String &gt;
                      {
                          "Ash",
                          "Beech",
                          "Cedar",
                          "Dogwood",
                          "Elm",
                          "Filbert",
                          "Ginkgo",
                          "Hawtorn",
                          "Ironwood",
                          "Juniper",
                          "Katsura",
                          "Lilac",
                          "Magnolia",
                          "Nectarine",
                          "Oak",
                          "Palm",
                          "Quince",
                          "Redwood",
                          "Sassafrass",
                          "Tupelo",
                          "Vibrunum",
                          "Walnut",
                          "Yellowwood",
                          "Zelkova"
                      };
        var cities = new List&lt; String &gt;
                     {
                         "Acton",
                         "Boston",
                         "Canton",
                         "Dell",
                         "Everstone",
                         "Flintwood",
                         "Gary",
                         "Houston",
                         "Imperial",
                         "Jackson",
                         "Kalamazoo",
                         "Levinworth",
                         "Macon",
                         "New York",
                         "Oak Hill",
                         "Paducah",
                         "Quinzy",
                         "Rochester",
                         "South Falls",
                         "Terra Haute",
                         "Union",
                         "Victoria",
                         "Waipio",
                         "Xenia",
                         "York",
                         "Zanesville"
                     };
        var isp = new List&lt; String &gt;
                  {
                      "ATT",
                      "Verizon",
                      "Hotmail",
                      "Gmail",
                      "Sprintnet",
                      "Yahoo"
                  };
        var states = new List&lt; String &gt;
                     {
                         "AL",
                         "AK",
                         "AS",
                         "AR",
                         "CA",
                         "CO",
                         "CT",
                         "DE",
                         "FL",
                         "GA",
                         "HI",
                         "ID",
                         "IL",
                         "IN",
                         "IA",
                         "KS",
                         "KY",
                         "LA",
                         "ME",
                         "MD",
                         "MA",
                         "MI",
                         "MN",
                         "MS",
                         "MO",
                         "MT",
                         "NE",
                         "NV",
                         "NH",
                         "NJ",
                         "NM",
                         "NY",
                         "NC",
                         "ND",
                         "OH",
                         "OK",
                         "PA",
                         "RI",
                         "SC",
                         "SD",
                         "TN",
                         "TX",
                         "UT",
                         "VA",
                         "WA",
                         "WI",
                         "WY"
                     };

        var random = new Random();
        for ( int i = 0; i &lt; howMany; i++ )
        {
            string first = firsts[ random.Next( 0, firsts.Count ) ];
            string last = lasts[ random.Next( 0, lasts.Count ) ];
            int streetNumberInt = random.Next( 101, 999 );
            string streetNumber = streetNumberInt.ToString();
            string zipCode = random.Next( 10000, 99999 ).ToString();
            string homePhone = random.Next( 200, 999 ) + "-555-"
                               + random.Next( 2000, 9099 );
            string workPhone = random.Next( 200, 999 ) + "-555-"
                               + random.Next( 2000, 9099 );
            string fax = random.Next( 200, 999 ) + "-555-"
                         + random.Next( 2000, 9099 );
            string homeEmail = first + "@"
                               + isp[ random.Next( 0, isp.Count ) ]
                               + ".com";
            string workEmail = last + "@"
                               + isp[ random.Next( 0, isp.Count ) ]
                               + ".com";
            bool isMale = ( random.Next( 1, 3 ) ) % 2 == 0
                              ? true
                              : false;
            var creditRating = ( short ) random.Next( 100, 800 );
            var firstContact = new DateTime( 2010, 1, 1 );
            DateTime lastContact = DateTime.Now;

            _customers.Add(
                           new Customer(
                               first,
                               last,
                               streetNumber + " "
                               +
                               streets[
                                       random.Next(
                                                   0, streets.Count - 1 )
                                   ]
                               + " Street",
                               cities[
                                      random.Next( 0, cities.Count - 1 )
                                   ],
                               states[
                                      random.Next( 0, states.Count - 1 )
                                   ],
                               zipCode,
                               workPhone,
                               homePhone,
                               fax,
                               homeEmail,
                               workEmail,
                               isMale,
                               "No notes at this time",
                               creditRating,
                               firstContact,
                               lastContact ) );
        }
    }
}</pre>
<p>The constructor of this class generates 500 random records and places them in a List&lt;Customer&gt;. the class consists of a public property, <em>Customers</em>, that returns the collection, and otherwise nothing but the method, <em>GenerateCustomers</em>, which mixes and matches names, cities, etc. to create records.</p>
<h3>Data</h3>
<p>It is tempting to create a search function and an update, but that complexity can wait for a later tutorial. Let’s keep things simple and just display the records one after the other.</p>
<p>The work of controlling the View is done in the ViewModel which will implement the INotifyPropertyChanged Interface.</p>
<h2>Interfaces</h2>
<p>An Interface is a contract that a class implements.  The Interface itself is declared with members, much like a class, but the members are not implemented. The Interface dictates what an implementing class will provide, and clients of the implementing class can count on those elements being present.  In this example, the binding mechanism depends on the VM</p>
<h3>How You implement An Interface</h3>
<p>You fulfill the contract by implementing all the methods and events of the Interface. That is, if the interface looks like this:</p>
<pre class="brush: csharp;">interface Writeable
{
   void Read();
   void Write();
}</pre>
<p>(and notice that the interface does not have to begin with a capital I, though just about every interface from Microsoft does: INotifyProopertyChanged, IEnumerable, IClaudius…)</p>
<p>There is no implementation in the interface itself (nor does it have a return value or a public/private designation).  If your class states that it imlements this interface3, it must supply a body for both methods,</p>
<pre class="brush: csharp;">class foo : Writeable
{
   public void Think()
   {
      System.DialogBox.Show("I Think Therefore I Might Be");
    }

   public void Read()
   {
         System.DialogBox.Show("So Many Books, So Little Time.");
   }

   public void Write()
    {
       System.DialogBox.Show("To err is human, to write, divine.");
     }
}</pre>
<p>The implementing class is of course free to add additional methods and events.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td width="500" valign="top">For more on delegates please see the C# documentation or my books <em>Programming C# and </em> <em>Learning C#</em>.</td>
</tr>
</tbody>
</table>
<p>In this case, the INotifyPropertyChanged interface has only one member, the event PropertyChanged.  While it is up to you how you implement this event, you must follow its declaration, passing in an object and an instance of PropertyChangedEventArgs. The PropertyChangedEventArgs class has one member that you must provide: the name of the property that has changed. In our case, we want to say that every property has changed rather than sort through which properties are different in the new record vs. the old.</p>
<h3>How You Declare the Interface</h3>
<p>Add the interface you wish to declare you implement after declaring the class from which you derive:</p>
<pre class="brush: csharp; collapse: true;">public class MainViewModel : ViewModelBase, INotifyPropertyChanged</pre>
<h3>Implementing the View Model</h3>
<p>The ViewModel in this case derives from <em>ViewModelBase</em> supplied by the MVVM Light Toolkit, which also implements INotifyPropertyChanged, so the declaration shown above is legal but redundant.</p>
<p>The base class follows the common idiom and implements a method RaisePropertyChanged that takes a property name and passes it along to the event (after doing some housekeeping that need not concern us now).</p>
<pre class="brush: csharp;">// MainViewModel.cs
public void Next()
 {
     _currentCustomer = _customerCollection.Customers[++_currentOffset];
     base.RaisePropertyChanged("Name");</pre>
<p>When the event is called, the named property updates, using the data context in the view code behind,</p>
<pre class="brush: csharp;">// MainPage.xaml.cs
void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
 {
     vm = new MainViewModel();
     DataContext = vm;</pre>
<p>In our case, the data context is the ViewModel itself.  That works because the VM has properties for each of the controls on the page,</p>
<pre class="brush: csharp;">//MainViewModel.cs
 public string Address { get { return _currentCustomer.Address; } }
 public string City { get { return _currentCustomer.City;  } }
 public string State { get { return _currentCustomer.State; } }
 public string Zip { get { return _currentCustomer.Zip; } }
 public string WorkPhone { get { return _currentCustomer.WorkPhone; } }
 public string Fax { get { return _currentCustomer.Fax; } }
 public string WorkEmail { get { return _currentCustomer.WorkEmail; } }
 public string Name { get { return _currentCustomer.First + " " + _currentCustomer.Last; } }
</pre>
<p>Notice that this time we’re wrapping all the properties rather than using a pass through to the customer collection.</p>
<p>Here is the complete code for the ViewModel,</p>
<pre class="brush: csharp;">using GalaSoft.MvvmLight;
using i2W_CustomerData.Model;

namespace i2W_CustomerData.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        private int _currentOffset = -1;
        private readonly CustomerCollection _customerCollection = new CustomerCollection();

        public string Address { get { return _currentCustomer.Address; } }
        public string City { get { return _currentCustomer.City; } }
        public string State { get { return _currentCustomer.State; } }
        public string Zip { get { return _currentCustomer.Zip; } }
        public string WorkPhone { get { return _currentCustomer.WorkPhone; } }
        public string Fax { get { return _currentCustomer.Fax; } }
        public string WorkEmail { get { return _currentCustomer.WorkEmail; } }
        public string Name { get { return _currentCustomer.First + " " + _currentCustomer.Last; } }

        private Customer _currentCustomer;
        public Customer CurrentCustomer
        {
            get { return _currentCustomer; }
        }

        public string ApplicationTitle { get { return "iPhone To WP7"; } }

        public string PageName { get { return "Customer"; } }

        public MainViewModel()
        {
            _currentCustomer = new Customer();
            Next();
        }

        public void Next()
        {
            _currentCustomer = _customerCollection.Customers[++_currentOffset];
            base.RaisePropertyChanged("Name");
            base.RaisePropertyChanged("Address");
            base.RaisePropertyChanged("City");
            base.RaisePropertyChanged("State");
            base.RaisePropertyChanged("Zip");
            base.RaisePropertyChanged("WorkPhone");
            base.RaisePropertyChanged("Fax");
            base.RaisePropertyChanged("WorkEmail");
        }
    }
}</pre>
<p>And, finally, here is the complete source for the code behind for the MainPage.xaml</p>
<pre class="brush: csharp;">using i2W_CustomerData.ViewModel;

namespace i2W_CustomerData
{
    public partial class MainPage
    {
        private MainViewModel vm;

        public MainPage()
        {
            InitializeComponent();
            Loaded += MainPage_Loaded;
        }

        void MainPage_Loaded(
             object sender, System.Windows.RoutedEventArgs e)
        {
            vm = new MainViewModel();
            DataContext = vm;
            Next.Click += NextClick;
        }

        void NextClick(
           object sender, System.Windows.RoutedEventArgs e)
        {
            vm.Next();
        }
    }
}</pre>
<p>Before we wrap this up, let’s focus in on the keyword <em>event</em>.  As an iPhone programmer, there is an intuitive, almost visceral sense of what an event is, but the keyword has a very specific meaning in C#.  To understand that, we have to back up and look at delegates.</p>
<h1>Event Handling and Delegates</h1>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/09/Obama.jpg"><img style="margin: 10px 30px 10px 0px; display: inline; border-width: 0px;" title="Obama" src="http://jesseliberty.com/wp-content/uploads/2010/09/Obama_thumb.jpg" border="0" alt="Obama" width="240" height="197" align="left" /></a> When a head of state dies, the president of the United States typically doesn’t have time to attend the funeral personally. Instead, he dispatches a delegate. Often this delegate is the vice president, but sometimes the VP is unavailable and the president must send someone else, such as the secretary of state or even the “first lady.” He doesn’t want to “hardwire” his delegated authority to a single person; he might delegate this responsibility to anyone who is able to execute the correct funeral-protocol. The president defines in advance what responsibility will be delegated (attend the funeral), what parameters will be passed (condolences, kind words, warnings to potential usurpers), and what value he hopes to get back (good will, oil). He then assigns a particular person to that delegated responsibility at “runtime” as the course of his presidency progresses.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td width="500" valign="top">Some of the material in this article was <span style="text-decoration: line-through;">stolen</span> <span style="text-decoration: line-through;">borrowed</span> <em>adapted</em> from <em>Programming C# 5th Edition</em>.</td>
</tr>
</tbody>
</table>
<p>[Note, I’m a big fan of our president, this picture is offered with affection. It is a small, articulated action figure given to me for my last birthday, taken in front of an intentionally soft image of the capital ]</p>
<h4>I Made The Button, <em>You</em> Handle What Happens When It Is Clicked</h4>
<p>The programmer who creates a control such as a button often will not be the programmer who puts that button into an application.  The control writer defines what events the control will support (click, selection changed, etc.) and the control user defines what happens for the events the control user is interested in responding to. Note that the control user need not react to every event, but on the other hand, adding a button that doesn’t react to being pressed is frowned upon. The way the control user indicates what is to happen is to write a method that will handle the event, and then tell the event which method to call when that event is “fired.”  It does that with delegates.</p>
<p>In C#, as in Cocoa Touch, delegates have the responsibility for taking action on behalf of other objects.  In C# however, delegates are created within a class, and that class is <em>not</em> the delegate.</p>
<h3>Delegates</h3>
<p>Technically, a delegate is a reference type used to encapsulate a method with a specific signature and return type (and even more technically, the return type is not part of the signature of a method).</p>
<p>You can encapsulate any matching method in that delegate.</p>
<p>An event is just a delegate that has been constrained in a few useful ways. For example, while a delegate can be used to invoke a method anywhere, events can only be invoked by the object that declares them (that is to say, if the button has a click event, only the button can raise that click event.)</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ERPHwnY2B3o:KA_MkxZeU24:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ERPHwnY2B3o:KA_MkxZeU24:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ERPHwnY2B3o:KA_MkxZeU24:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=ERPHwnY2B3o:KA_MkxZeU24:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ERPHwnY2B3o:KA_MkxZeU24:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=ERPHwnY2B3o:KA_MkxZeU24:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ERPHwnY2B3o:KA_MkxZeU24:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=ERPHwnY2B3o:KA_MkxZeU24:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ERPHwnY2B3o:KA_MkxZeU24:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/ERPHwnY2B3o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/09/04/iphone-to-windows-phone-7-diving-deeper/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/09/04/iphone-to-windows-phone-7-diving-deeper/</feedburner:origLink></item>
		<item>
		<title>Great SL Competency Test Part 1 (Answer)</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/6kdve-8Ja0A/</link>
		<comments>http://jesseliberty.com/2010/09/01/great-sl-competency-test-part-1-answer/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 18:40:34 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Essentials]]></category>
		<category><![CDATA[Patterns & Skills]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/09/01/great-sl-competency-test-part-1-answer/</guid>
		<description>On August 23rd I published part 1 of The Great Silverlight Competency Test.&amp;#160; The key tasks were to… …write a Silverlight program mimicking a problem report system,&amp;#160; that allows you to go to your db and call up a record by phone number and view and/or edit all of the following fields. Do not implement [...]</description>
			<content:encoded><![CDATA[<p>On August 23rd I published part 1 of <a href="http://jesseliberty.com/2010/08/23/the-great-silverlight-competency-test-part-1-2/" target="_blank"><em>The Great Silverlight Competency Test</em></a><em>.&#160; </em>The key tasks were to…</p>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/09/RunningProject.jpg"><img style="border-bottom: 0px; border-left: 0px; margin: 10px 30px 10px 0px; display: inline; border-top: 0px; border-right: 0px" title="Running Project" border="0" alt="Running Project" align="left" src="http://jesseliberty.com/wp-content/uploads/2010/09/RunningProject_thumb.jpg" width="202" height="240" /></a></p>
<p>…write a Silverlight program mimicking a problem report system,&#160; that allows you to go to your db and call up a record by phone number and view and/or edit all of the following fields. <em>Do not implement membership or roles</em> feel free to prepopulate the db with randomized data.&#160; </p>
<ul>
<li>Full name </li>
<li>Address </li>
<li>Email(s) </li>
<li>Phone(s) </li>
<li>Date of first contact </li>
<li>Date of last contact </li>
<li>Reason for calling (1 of 5 possible) </li>
<li>Product (1 of 20 possible) </li>
<li>Computer(s) running on </li>
<li>Description of problem </li>
</ul>
<p>The idea was to be able to do this in under an hour.&#160; This posting will review one solution.&#160; </p>
<p> <span id="more-3367"></span><br />
<h3>The Database</h3>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/09/CustomerTables.jpg"><img style="border-bottom: 0px; border-left: 0px; margin: 10px 20px 10px 0px; display: inline; border-top: 0px; border-right: 0px" title="Customer Tables" border="0" alt="Customer Tables" align="left" src="http://jesseliberty.com/wp-content/uploads/2010/09/CustomerTables_thumb.jpg" width="216" height="240" /></a> To begin, I created three tables and a view in a new database called <em>Customers</em></p>
<ul>
<li><em>Customer</em></li>
<li><em>Product</em></li>
<li><em>Reason</em></li>
<li><em>CustomerView</em></li>
</ul>
<p>The customerView joins the three tables, allowing the tables to be normalized, but simplifying the data retrieval.</p>
<h3>The Application</h3>
<p>I chose to create a Business Application as they are born with significant database support.&#160; This created two projects, BusinessApplication1 and BusinessApplication1.web (okay, not the best naming).&#160; </p>
<p>Within the .web project I chose Project-&gt;Add New and selected Data in the templates and then ADO.NET Entity Data Model.&#160; I chose to base it on my database and picked the CustomerView, generating an Entity Data Model named CustomerView.edmx and with it CustomerView.Designer.cs.</p>
<p>I then returned to Add-&gt;New and added a WCF Data Service.&#160; With this in hand, I turned to BusinessApplication1 (the client) and added a Service Reference to the new WCF Data Service.&#160; Great, I can get the data. </p>
<h3></h3>
<h3>The UI</h3>
<p>To keep the UI very simple, I created a grid with three rows, the bottom of which houses a grid with the rows for the form, itself having two columns.&#160; Each item in the second column is bound to a property of the page,</p>
<pre class="brush: xml;"> &lt;TextBlock
     Text=&quot;{Binding Address1}&quot;
     VerticalAlignment=&quot;Center&quot;
     Grid.Row = &quot;1&quot;
     Grid.Column=&quot;1&quot; /&gt;

 &lt;TextBlock
     Text=&quot;{Binding Address2}&quot;
     VerticalAlignment=&quot;Center&quot;
     Grid.Row = &quot;2&quot;
     Grid.Column=&quot;1&quot; /&gt;</pre>
<h3>The Code </h3>
<p>When the user enters a phone number and presses the button, a query is created and executed asynchronously.&#160; [Note, this code is insufficiently bullet-proofed]</p>
<pre class="brush: csharp;">private void ExecuteQuery( object o, object routedEventArgs )
{

    _customers = new DataServiceCollection&lt; CustomerView &gt;();
    _customers.LoadCompleted += CustomersLoadCompleted;
    var svc =
        new CustomerViewEntities(
            new Uri( &quot;http://localhost:52878/CustomerViewService.svc&quot; ) );

    IOrderedQueryable&lt; CustomerView &gt; query = from c in svc.CustomerViews
                                         where c.phone == Phone.Text
                                         orderby c.last , c.phone
                                         select c;
    _customers.LoadAsync( query );
}</pre>
<p>When the data is loaded I extract the first (and only) record and assign values to the properties,</p>
<pre class="brush: csharp;">void CustomersLoadCompleted( object sender, LoadCompletedEventArgs e )
{
    if ( _customers.Continuation != null )
    {
        _customers.LoadNextPartialSetAsync();
    }
    else
    {
        CustomerView cust = _customers[ 0 ];
        First = cust.first;
        Last = cust.last;
        Address1 = cust.address1;
        Address2 = cust.address2;
        City = cust.city;
        State = cust.state;
        Zip = cust.zip;
        PhoneNumber = cust.phone;
        FirstContact = cust.firstContact;
        LastContact = cust.lastContact;
        Reason = cust.reason;
        ProductName = cust.productName;
        Computer = cust.computer;
        Problem = cust.problem;
    }
}</pre>
<p>Each property has a backing variable and calls the PropertyChangedEventHandler to notify the UI that it has been updated. For example,</p>
<pre class="brush: csharp;"> public string PhoneNumber
 {

     get { return _phoneNumber; }
     set { _phoneNumber = value; OnPropertyChanged(&quot;PhoneNumber&quot;); }

 }</pre>
<p><strong>Score Yourself</strong></p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">Created a database </td>
<td valign="top" width="250">10 points</td>
</tr>
<tr>
<td valign="top" width="250">Relational db with 2 or more tables and normalized</td>
<td valign="top" width="250">+5 points</td>
</tr>
<tr>
<td valign="top" width="250">Accessed the db through a web service of any kind or through another sustainable approach</td>
<td valign="top" width="250">10 points</td>
</tr>
<tr>
<td valign="top" width="250">Mapped the UI to bound data</td>
<td valign="top" width="250">20 points</td>
</tr>
<tr>
<td valign="top" width="250">Selected data in the db with a where clause that used the phone number using LINQ or a SPROC</td>
<td valign="top" width="250">15 points</td>
</tr>
<tr>
<td valign="top" width="250">Display worked as you intended</td>
<td valign="top" width="250">20 points</td>
</tr>
<tr>
<td valign="top" width="250">Your program works and does what it should reliably, handling missing records and entry errors</td>
<td valign="top" width="250">20 points</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>I made up these numbers and criteria, so please remember that it is the journey, not the destination that counts.&#160; </p>
<p>Note, I’ve not made the source available as I’ll be tinkering with it and then releasing it with a video.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=6kdve-8Ja0A:UMmkWNMZeXk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=6kdve-8Ja0A:UMmkWNMZeXk:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=6kdve-8Ja0A:UMmkWNMZeXk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=6kdve-8Ja0A:UMmkWNMZeXk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=6kdve-8Ja0A:UMmkWNMZeXk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=6kdve-8Ja0A:UMmkWNMZeXk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=6kdve-8Ja0A:UMmkWNMZeXk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=6kdve-8Ja0A:UMmkWNMZeXk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=6kdve-8Ja0A:UMmkWNMZeXk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/6kdve-8Ja0A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/09/01/great-sl-competency-test-part-1-answer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/09/01/great-sl-competency-test-part-1-answer/</feedburner:origLink></item>
		<item>
		<title>A Program I Want</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/4chvKZBuEBE/</link>
		<comments>http://jesseliberty.com/2010/08/31/a-program-i-want/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 15:32:33 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Quick Hit]]></category>
		<category><![CDATA[Reviews & Opinions]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/08/31/a-program-i-want/</guid>
		<description>I want a program that I can say “Watch what I do to this file” (change properties, unblock, etc.) and then be able to say “now do this for all the other files in the directory.”&amp;#160;&amp;#160; Can’t be too hard to write, can it?&amp;#160;</description>
			<content:encoded><![CDATA[<p>I want a program that I can say “Watch what I do to this file” (change properties, unblock, etc.) and then be able to say “now do this for all the other files in the directory.”&#160;&#160; Can’t be too hard to write, can it?&#160; <img src='http://jesseliberty.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=4chvKZBuEBE:g2g0pYUXoZQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=4chvKZBuEBE:g2g0pYUXoZQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=4chvKZBuEBE:g2g0pYUXoZQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=4chvKZBuEBE:g2g0pYUXoZQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=4chvKZBuEBE:g2g0pYUXoZQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=4chvKZBuEBE:g2g0pYUXoZQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=4chvKZBuEBE:g2g0pYUXoZQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=4chvKZBuEBE:g2g0pYUXoZQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=4chvKZBuEBE:g2g0pYUXoZQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/4chvKZBuEBE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/08/31/a-program-i-want/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/08/31/a-program-i-want/</feedburner:origLink></item>
		<item>
		<title>The Great Silverlight Competency Test [2]</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/ij-SsNPHQDE/</link>
		<comments>http://jesseliberty.com/2010/08/30/the-great-silverlight-competency-test-part-1/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 14:30:00 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Patterns & Skills]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Silverlight 4]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/08/23/the-great-silverlight-competency-test-part-1/</guid>
		<description>This is the second of twelve questions in The Great Silverlight Competency Test –  each of which I believe a competent Silverlight Programmer ought to be able to complete within no more than 1 hour. Each of the twelve tests will appear on Monday, a viable solution will be provided 10 days later on the [...]</description>
			<content:encoded><![CDATA[<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/iStock_WomanEChoiceXSmall.jpg"><img style="margin: 10px 30px 10px 0px; display: inline; border: 0px;" title="businesswoman pressing a button" src="http://jesseliberty.com/wp-content/uploads/2010/08/iStock_WomanEChoiceXSmall_thumb.jpg" border="0" alt="businesswoman pressing a button" width="240" height="159" align="left" /></a> This is the second of twelve questions in <em><span style="color: #ff0000;">The Great Silverlight Competency Test</span></em> –  each of which I believe a competent Silverlight Programmer ought to be able to complete within no more than 1 hour.</p>
<p><span id="more-3253"></span></p>
<p>Each of the twelve tests will appear on Monday, a viable solution will be provided 10 days later on the following Wednesday.</p>
<p>The solution I provide will tell you how to self-score your own solution (each on a scale of 0-100), and at the end I&#8217;ll try to provide a metric for the entire experience.  25 points for each bug you find in <em>my</em> code!</p>
<p>On the honor system you may post your scores into the <a href="http://jesseliberty.com/2010/08/07/giving-away-programming-c-4-one-per-week/" target="_blank">book giveaway</a> and I will give one of the top scorers a copy of the book. (Microsoft employees not eligible, void where prohibited, yadda yadda).</p>
<p>Please feel free to help one another by discussing the problem, ideas and questions in the comments for each exercise.</p>
<p>[ <a href="http://jesseliberty.com/2010/08/23/the-great-silverlight-competency-test-part-1/" target="_blank">First posting in series here ]</a></p>
<h3>Competency #2 (of 12)</h3>
<h4>Create a custom button that has non-standard visual behavior when you hover over it, and when you click it but which otherwise acts exactly like a button.</h4>
<p>Demonstrate in a working program.</p>
<p>Note: No further clarification will be provided, design as you see fit.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ij-SsNPHQDE:QYztl5X5rkE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ij-SsNPHQDE:QYztl5X5rkE:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ij-SsNPHQDE:QYztl5X5rkE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=ij-SsNPHQDE:QYztl5X5rkE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ij-SsNPHQDE:QYztl5X5rkE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=ij-SsNPHQDE:QYztl5X5rkE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ij-SsNPHQDE:QYztl5X5rkE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=ij-SsNPHQDE:QYztl5X5rkE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=ij-SsNPHQDE:QYztl5X5rkE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/ij-SsNPHQDE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/08/30/the-great-silverlight-competency-test-part-1/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/08/30/the-great-silverlight-competency-test-part-1/</feedburner:origLink></item>
		<item>
		<title>Tag-based Feeds</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/G5X5xlPP1Wc/</link>
		<comments>http://jesseliberty.com/2010/08/29/tag-based-word-press-queries-through-feedburner/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 18:12:09 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Blogging]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/08/29/tag-based-word-press-queries-through-feedburner/</guid>
		<description>In this posting I will show how to create Feedburner feeds based on queries in Word Press using the  Feedburner plugins. Begin by setting up your full site feed on Feedburner. Next, modify the Feedburner plugin as described by Brad Grier here. For each tag you want a feed for Go to Feedburner and paste [...]</description>
			<content:encoded><![CDATA[<p>In this posting I will show how to create Feedburner feeds based on queries in Word Press using the  Feedburner plugins.</p>
<p><span id="more-3341"></span></p>
<p>Begin by setting up your full site feed on <a href="http://feedburner.com">Feedburner</a>.</p>
<p>Next, modify the Feedburner plugin as described by Brad Grier <a href="http://blog.bradgrier.com/2008/06/23/tweaking-your-feedburner-feedsmith-plugin-to-support-wordpress-25-tag-feeds-easy/">here</a>.</p>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/Feedburner.jpg"><img style="margin: 10px 30px 10px 0px; display: inline; border: 0px;" title="Feedburner" src="http://jesseliberty.com/wp-content/uploads/2010/08/Feedburner_thumb.jpg" border="0" alt="Feedburner" width="240" height="158" align="left" /></a></p>
<h4>For each tag you want a feed for</h4>
<ul>
<li>Go to Feedburner and paste the full feed name in this format:   <strong>jesseliberty.com/?tag=hvp</strong></li>
<li>Click Next</li>
<li>Of the three choices, pick the third, with the specific feed</li>
<li>Click Next</li>
<li>Note the feed address that is provided for you on the next screen (e.g., <a href="http://feeds.feedburner.com/JesseLibertyHVP">http://feeds.feedburner.com/JesseLibertyHVP</a>)</li>
<li>On the final screen you can subscribe to that feed</li>
</ul>
<p>That’s it, you’re done!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=G5X5xlPP1Wc:2PxfyD6aO5k:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=G5X5xlPP1Wc:2PxfyD6aO5k:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=G5X5xlPP1Wc:2PxfyD6aO5k:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=G5X5xlPP1Wc:2PxfyD6aO5k:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=G5X5xlPP1Wc:2PxfyD6aO5k:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=G5X5xlPP1Wc:2PxfyD6aO5k:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=G5X5xlPP1Wc:2PxfyD6aO5k:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=G5X5xlPP1Wc:2PxfyD6aO5k:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=G5X5xlPP1Wc:2PxfyD6aO5k:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/G5X5xlPP1Wc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/08/29/tag-based-word-press-queries-through-feedburner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/08/29/tag-based-word-press-queries-through-feedburner/</feedburner:origLink></item>
		<item>
		<title>How I Learned To Stop Worrying and Get Organized</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/PvWWwN5qG4I/</link>
		<comments>http://jesseliberty.com/2010/08/29/how-i-learned-to-stop-worrying-and-get-organized/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 15:02:59 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Reviews & Opinions]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Getting Organized]]></category>
		<category><![CDATA[Tasks]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/08/29/how-i-learned-to-stop-worrying-and-get-organized/</guid>
		<description>I have ADD, (“oh look, something shiny!”) which means getting organized is a challenge, and making sure I can put my hands on any given piece of information a huge life-long effort, but technology has helped a lot, and after trying, discarding, returning to and otherwise manipulating every conceivable combination, I have a system that [...]</description>
			<content:encoded><![CDATA[<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/BusyMan.jpg"><img style="margin: 0px 30px 10px 0px; display: inline; border: 0px;" title="BusyMan" src="http://jesseliberty.com/wp-content/uploads/2010/08/BusyMan_thumb.jpg" border="0" alt="BusyMan" width="160" height="240" align="left" /></a> I have ADD, (“oh look, something shiny!”) which means <strong>getting organized is a challenge</strong>, and making sure I can put my hands on any given piece of information a <em>huge</em> life-long effort, but <strong>technology has helped a lot</strong>, and after trying, discarding, returning to and otherwise manipulating every conceivable combination,<strong> I have a system that works so well i thought I’d share it</strong>.</p>
<h3></h3>
<h3><span id="more-3337"></span></h3>
<h3>Organizational Systems</h3>
<p><strong>This posting is about handling  <em>ToDo</em> items and </strong><em><strong>Appointments</strong>. </em>A second organizational area is email and notes and a third is office organization. These will be handled in subsequent posts.</p>
<p><strong>Here is what I do</strong>. I won’t try to justify any of it as it will take too long and sound idiotic…</p>
<h1>To Do</h1>
<p>I<strong> use different software on different platforms</strong>, but what is critical is that they are <strong>all synchronized all the time</strong>.   If not, I’m dead.</p>
<p>I buy the basic premise of <em>Getting Things Done, </em>as I understand it, which is:</p>
<blockquote><p>If you try to keep track of everything you have to do in your head, you’ll always be doing the wrong thing and forgetting the most important thing. Thus <strong>you need a system that you totally trust to be reliable</strong>, into which you can put tasks and <em>forget them</em> until they appear, ready for you to take action.  You should never be looking at a task that isn’t ready for action, and <strong>you should be seeing the most important task you can take action on right now</strong>.</p></blockquote>
<p>The key to making GTD work, which took me a long time was to <strong>stop putting deadlines on things that didn’t have real deadlines</strong>.  My fear was that without a deadline I’d forget about it.  Bzzzz. Still your turn. With everything having a deadline, everything got ignored and was “late.”</p>
<p>Much better is to give a deadline when you absolutely must, and then set a sufficient reminder, <em>but,</em> to make this work you <em>must</em> schedule at least one (better two) times a day when an alarm goes off to remind you to review your <em>focus</em> tasks.  Set up right, focus shows you the 3-5 tasks that are</p>
<ul>
<li>Most important to do now</li>
<li>Actionable now (no point seeing something you can’t take action on</li>
</ul>
<p>My system is to use three criteria for making the focus list:</p>
<ul>
<li><strong>Due today or over-due</strong> OR</li>
<li><strong>Marked top priority</strong> (saved for the very rare)</li>
<li><strong>Marked Next Action</strong></li>
</ul>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/TaskAngel.jpg"><img style="margin: 0px 20px 0px 0px; display: inline; border-width: 0px;" title="Task Angel" src="http://jesseliberty.com/wp-content/uploads/2010/08/TaskAngel_thumb.jpg" border="0" alt="Task Angel" width="244" height="100" align="left" /></a>To make this work I use the following fields in my various platform-specific tasks lists (all of which are synch’d through <a href="http://toodledo.com">Toodledo</a></p>
<p><span style="text-decoration: underline;">Date Time Start/Due</span></p>
<p>Few tasks are designated with a due date, and even fewer with a start date (don’t start before this date) but those that are have real deadlines.</p>
<p>[Click on image for full size]</p>
<p><span style="text-decoration: underline;">Status</span></p>
<p>The statuses that I use are</p>
<ul>
<li><strong>Next Action</strong> &#8211; Move to focus list</li>
<li><strong>Active</strong> – Do this as time allows</li>
<li><strong>Planning</strong> – No action, still in planning stage</li>
<li><strong>Waiting</strong> – Dependent on an action by someone else</li>
<li><strong>Hold</strong> – No action for now</li>
<li><strong>Postponed</strong> – No action for foreseeable future</li>
<li><strong>Reference</strong> – No action ever but need to have this in the list for some reason</li>
</ul>
<p>Of these, The first four are used a lot, the last three rarely.</p>
<p><span style="text-decoration: underline;">Priority</span></p>
<ul>
<li><strong>Low</strong></li>
<li><strong>Medium</strong></li>
<li><strong>High</strong></li>
<li><strong>Top</strong></li>
</ul>
<p>Top is reserved and used only for those things that have to go on the focus list right now.  Especially rare as that is what <em>Next Action</em> is for.</p>
<p><span style="text-decoration: underline;">Context</span></p>
<ul>
<li><strong>Computer</strong></li>
<li><strong>Phone</strong></li>
<li><strong>Out</strong></li>
<li><strong>Redmond</strong></li>
<li><strong>Wife</strong></li>
<li><strong>None</strong></li>
</ul>
<p>Context tells me where I have to be to be able to do this task. None means anywhere.  Nice thing about this is when I’m in Redmond (e.g.,) I can just see those things that I need to do there.</p>
<p><span style="text-decoration: underline;">Folder</span></p>
<ul>
<li><strong>Admin</strong></li>
<li><strong>Learning</strong></li>
<li><strong>IT</strong></li>
<li><strong>Projects</strong></li>
<li><strong>Personal</strong></li>
</ul>
<p>This is an arbitrary way to divide up my tasks.  IT is any computer fussing. Projects is the center of attention except on weekends when it switches to personal. I can filter out by folder so that helps a lot.</p>
<p><span style="text-decoration: underline;">Creating and Maintaining Tasks</span></p>
<p>Key to making this work is that<strong> I can enter a task from anywhere, see my tasks anywhere and fuss with them at a very convenient place</strong>.</p>
<p><span style="text-decoration: underline;">See them anywhere</span></p>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/toodledo.jpg"><img style="margin: 10px 20px 10px 0px; display: inline; border: 0px;" title="toodledo" src="http://jesseliberty.com/wp-content/uploads/2010/08/toodledo_thumb.jpg" border="0" alt="toodledo" width="240" height="105" align="left" /></a> I can see a synchronized task list on my phone [Tasks or Toodledo] , on the web [Toodledo]  and on my computer [<a href="http://mypocketsoft.com/taskangel/default.aspx">TaskAngel</a>].</p>
<p>I can enter at each location with the above software as well, and I tend to “fuss with” the tasks using Task Angel as computers beat phones every time for that sort of thing.</p>
<p><span style="text-decoration: underline;">Doing the Most Important Things, Except…</span></p>
<p>Based on the rules above (focus list has only Next Action or Top Priority or Due) I will be working on the most important task at any moment. But then there are those things that linger, that are medium priority, never feel like they make next action and have no due date. They can sit for months. Thus, I’ve added my own task which is around the first of the month those tasks bump up one level of priority (Medium –&gt; High –&gt; Top) and so nothing sits on the task list for more than a few months even if it is trivial.  A hack, but it seems to work.</p>
<p><span style="text-decoration: underline;">Mail It In</span></p>
<p>One of the great features of toodledo is I can send myself a mail (I use a pre-canned message that<em> </em>I leave copies of in my drafts folder) for new tasks, so if I’m not at a convenient location I can just mail the task to myself and it appears in the folder “Inbox” with some indication of priority and if there is a due date.</p>
<p><span style="text-decoration: underline;">Phone It in</span></p>
<p>Similarly, if I’m in the car, I can call <a href="http://jott.com">Jott</a>, and dictate the to-do item. Works great.</p>
<p><span style="text-decoration: underline;">Supplement</span></p>
<p>The key supplement to all this is an alarm at 9am and 2pm to remind me to review the FOCUS tasks. Since I’m not putting due dates I can’t set alarms on many tasks, but twice a day review solves that problem cleanly.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=PvWWwN5qG4I:HgSbokgum6E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=PvWWwN5qG4I:HgSbokgum6E:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=PvWWwN5qG4I:HgSbokgum6E:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=PvWWwN5qG4I:HgSbokgum6E:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=PvWWwN5qG4I:HgSbokgum6E:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=PvWWwN5qG4I:HgSbokgum6E:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=PvWWwN5qG4I:HgSbokgum6E:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=PvWWwN5qG4I:HgSbokgum6E:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=PvWWwN5qG4I:HgSbokgum6E:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/PvWWwN5qG4I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/08/29/how-i-learned-to-stop-worrying-and-get-organized/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/08/29/how-i-learned-to-stop-worrying-and-get-organized/</feedburner:origLink></item>
		<item>
		<title>Migrated from 32 bit to 64 bit – Wow!</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/qhJL4WMRD_A/</link>
		<comments>http://jesseliberty.com/2010/08/29/migrated-from-32-bit-to-64-bit-wow/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 13:37:47 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Reviews & Opinions]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[64 Bit]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/08/29/migrated-from-32-bit-to-64-bit-wow/</guid>
		<description>Made a quick and dirty video about it…  Be sure to watch in full screen.</description>
			<content:encoded><![CDATA[<p>Made a quick and dirty video about it…  Be sure to watch in full screen.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/XtjkDCw7T_k&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/XtjkDCw7T_k&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qhJL4WMRD_A:9L5IWzmCKXM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qhJL4WMRD_A:9L5IWzmCKXM:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qhJL4WMRD_A:9L5IWzmCKXM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=qhJL4WMRD_A:9L5IWzmCKXM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qhJL4WMRD_A:9L5IWzmCKXM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=qhJL4WMRD_A:9L5IWzmCKXM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qhJL4WMRD_A:9L5IWzmCKXM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=qhJL4WMRD_A:9L5IWzmCKXM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qhJL4WMRD_A:9L5IWzmCKXM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/qhJL4WMRD_A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/08/29/migrated-from-32-bit-to-64-bit-wow/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/08/29/migrated-from-32-bit-to-64-bit-wow/</feedburner:origLink></item>
		<item>
		<title>i2W: An iPhone Developer’s First Windows Phone 7 Application</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/vhJX2uHhmMo/</link>
		<comments>http://jesseliberty.com/2010/08/27/i2w-an-iphone-developers-first-windows-phone-7-application/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 16:26:57 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Mini-Tutorial]]></category>
		<category><![CDATA[Tools and Utilities]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[iPhoneToWP7]]></category>
		<category><![CDATA[i2WTutorial]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/08/27/i2w-an-iphone-developers-first-windows-phone-7-application/</guid>
		<description>Go to first Tutorial In this tutorial we will build a meaningful, and nontrivial Windows phone 7 application. This will give us the opportunity to explore layout controls, interactive controls, Visual Studio and a good bit more. [Updated 8/30/2010] Let&amp;#8217;s start by taking a look at the application were going to build. The application opens [...]</description>
			<content:encoded><![CDATA[<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/i2WLogo21.jpg"><img style="margin: 10px 0px; display: inline; border-width: 0px;" title="i2WLogo2" src="http://jesseliberty.com/wp-content/uploads/2010/08/i2WLogo2_thumb1.jpg" border="0" alt="i2WLogo2" width="320" height="63" /></a></p>
<p><a href="http://jesseliberty.com/2010/08/23/i2w-an-iphone-developers-guide-to-creating-windows-phone-7-applications-tutorial/" target="_blank">Go to first Tutorial</a></p>
<p>In this tutorial we will build a meaningful, and nontrivial Windows phone 7 application. This will give us the opportunity to explore layout controls, interactive controls, Visual Studio and a good bit more.</p>
<p>[Updated 8/30/2010]</p>
<p><span id="more-3315"></span><a href="http://jesseliberty.com/wp-content/uploads/2010/08/form.jpg"><img style="border-width: 0px; margin: 10px 25px 10px 0px; float: left; display: inline;" title="form" src="http://jesseliberty.com/wp-content/uploads/2010/08/form_thumb.jpg" border="0" alt="form" width="177" height="240" /></a> <strong>Let&#8217;s start by taking a look at the application were going to build.</strong></p>
<p>The application <strong>opens with a form</strong>, and that form is <strong>populated by data binding</strong>.</p>
<table border="2" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td width="500" valign="top">Note: All images are cropped. To see the full size (but still cropped) version, double click on the image</td>
</tr>
</tbody>
</table>
<p>Let’s walk through the creation of this first demo program step by step.</p>
<table border="2" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td width="500" valign="top">
<h3>A Word On The Development Environment</h3>
<p>Before we begin, let me note that I make the assumption that you are a professional iPhone developer, and thus are not afraid to invest in purchasing the right tools.</p>
<p>While, as noted in the previous tutorial, it is possible to write Windows Phone 7 applications using Visual Studio Express, I will demonstrate using Visual Studio 2010 Ultimate.</p>
<p>In addition, as a practical matter, MVVM (the principle design pattern for Windows Phone 7) is easiest when supported by a library, and so I will use the <em>free</em> <a href="http://mvvmlight.codeplex.com/" target="_blank">MVVM Light Toolkit</a>.</p>
<p>Additionally, you’ll notice that my screen shots include a menu member <a href="http://jesseliberty.com/2010/05/28/code-rush-vs-resharper/" target="_blank">Resharper and/or Code Rush</a>; using one of these two supplements to Visual Studio is not required, but they do provide a far more efficient programming experience.</td>
</tr>
</tbody>
</table>
<h3>Visual Studio, Expression Blend, XCode and Interface Builder</h3>
<p>It is tempting to draw a <strong>parallel</strong> in which<strong> Visual Studio maps to XCode</strong> and <strong>Expression Blend maps to Interface Builder</strong>.  This isn’t wrong so much as incomplete, because you <strong><em>can</em> create your entire interface in Visual Studio</strong> (and many folks do) but <strong>for more</strong> <strong>advanced UI development, Blend is the tool of choice</strong>.  We <em>could </em>start off by creating the form itself in Blend (and some would argue we should) but we’ll keep things simple by doing all our work for now in Visual Studio, introducing Blend in a following tutorial.</p>
<h3>Solutions, Projects and Files, Oh My</h3>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/MVVMForPhone.jpg"><img style="margin: 10px 20px 10px 0px; display: inline; border-width: 0px;" title="MVVM For Phone" src="http://jesseliberty.com/wp-content/uploads/2010/08/MVVMForPhone_thumb.jpg" border="0" alt="MVVM For Phone" width="240" height="128" align="left" /></a> To begin, <strong>open Visual Studio</strong>, click on <em>New Project</em> and in the left pane (Templates) choose <em>Visual C#</em> and then <strong><em>Silverlight For Windows Phone 7</em>.</strong> In the right hand side, choose the MVVM Light Toolkit. Give Visual Studio 2010 a few minutes to settle down and you’ll find that Visual Studio 2010 and the MVVM Light Toolkit have cooperated to create a project with numerous files and folders.  You can see these in Solution Explorer window, which is typically on the upper left hand side of your development environment and which you can open either from the menu (View-&gt;Solution Explorer) or with the hot keys that are shown on the menu.</p>
<p>Because<strong> all such windows can be opened from a menu</strong>, I will eschew walking you through each, and will only point out those menu choices which may be otherwise confusing.</p>
<p>For now, we’ll ignore the Properties and Reference items (though feel free to explore on your own, just take a compass and plenty of rope and you’ll be fine).</p>
<p>The key files we care about right now are MainPage.xaml and, under the ViewModel folder MainViewModel.cs.  The former, MainPage.xaml has an associated <em>code behind</em> file which you can expose with the very familiar turn down.</p>
<p><strong>Double click on MainViewModel.cs</strong> to populate the edit windows. Your initial view will be a split pane with the <strong><em>design view</em> on one side and the <em>code view</em> on the other</strong>.  The code view, in this case, will be populated with a good bit o<strong>f</strong> Xaml.  We’ll close the Xaml window for now to focus on the Design view.</p>
<h3>A Very Quick Tour of Visual Studio</h3>
<p>To close the Code View make sure the Design View it is on the left (you can switch it with the double arrow button <a href="http://jesseliberty.com/wp-content/uploads/2010/08/DoubleArrow.jpg"><img style="margin: 10px 0px; display: inline; border-width: 0px;" title="DoubleArrow" src="http://jesseliberty.com/wp-content/uploads/2010/08/DoubleArrow_thumb.jpg" border="0" alt="DoubleArrow" width="21" height="24" /></a> between the panes) and then click the double-arrowhead <a href="http://jesseliberty.com/wp-content/uploads/2010/08/DoubleArrowHead.jpg"><img style="margin: 10px 0px; display: inline; border-width: 0px;" title="DoubleArrowHead" src="http://jesseliberty.com/wp-content/uploads/2010/08/DoubleArrowHead_thumb.jpg" border="0" alt="DoubleArrowHead" width="19" height="16" /></a> to close the code view. Finally, make sure that the Properties window is  visible on the right (F4) and the toolbox is pinned open on the left ( Control-Alt-X).  In the illustration below, I’ve labeled 7 areas. Let’s go over them one by one:</p>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/VisualStudio.jpg"><img style="margin: 10px auto; display: block; float: none; border-width: 0px;" title="Visual Studio" src="http://jesseliberty.com/wp-content/uploads/2010/08/VisualStudio_thumb.jpg" border="0" alt="Visual Studio" width="640" height="449" /></a></p>
<p>Area 1 is the <strong>toolbox</strong>. Note that at the upper right hand corner (circled) are three symbols. The first allows you to</p>
<p>Area 2 is the <strong>Application String</strong> and Area 3 is the <strong>Page Title</strong> string; we’ll return to these shortly.</p>
<p>Area 4 is the ContentPanel  and we’ll be doing most of our design work here.</p>
<p>Area 5 is the <strong>Solution Explorer</strong>, which is above the Properties window by convention (you can of course move any window to any position)</p>
<p>The <strong>properties window</strong> is divided into area 6, where the name of the selected object is set and where you can switch the properties window from Properties view to Events view (more on events later in this tutorial).  Area 7 is where the properties are set (you can see some of the Text properties exposed in this illustration).</p>
<p>Note the arrows emanating from the design panel.  The upper two are used to switch between Code and Design when one of the windows is hidden.  The lower three split the window vertically or horizontally, and reveal (or hide) the right hand (or lower) window respectively.</p>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/OnlineHelp.jpg"><img style="margin: 10px 25px 10px 0px; display: inline; border-width: 0px;" title="Online Help'" src="http://jesseliberty.com/wp-content/uploads/2010/08/OnlineHelp_thumb.jpg" border="0" alt="Online Help'" width="219" height="240" align="left" /></a> Above all of this is the menu and of course the most important menu entry is Help, which offers a variety of ways to receive help. To see one of its most powerful features at work, place the cursor anywhere in the RowDefinition keyword (approximately line 47) and press F1.  The first time you press F1 you’ll be asked if you want to use local or internet help. If you have an internet connection, by all means ask for online help. A browser window will open with help on the RowDefinition keyword. Sweet.</p>
<p>As of this writing the on-line help file has tabs for each supported language. We’ll use the C# tab (which will set the C# tab for the entire page and which is sticky and thus persists to the next time you open the window).</p>
<p>Each entry follows the pattern of identifying the class, the namespace and assembly (we’ll cover both as we go). Syntax is demonstrated by language, and the <em>Remarks </em>section provides detailed information and links to related topics.</p>
<p>The examples section follows the Remarks section and provides copyable code to get you started.</p>
<p>After the Examples come the Inheritance Hierarchy, showing where your class fits in, and notes on Thread Safety, Platform, Versions and, finally a See Also section for related topics.</p>
<p>You also have much of this information locally in Silverlight.chm – a Windows Help file that was loaded when you installed Silverlight.</p>
<h3>Creating The Form</h3>
<p>Let’s return to the project and begin to create the form. <strong>For now we’re going to do all the work in the design view</strong>, though you’ll see later that everything done in Design view instantly updates the Xaml view, and vice versa.</p>
<h4>Layout Controls</h4>
<p><strong>It is common to distinguish those controls used for layout from those used for interacting with the user</strong>, though the distinction is, in truth arbitrary.  In any case, there are quite a few layout controls, though <strong>the two we care most about are the Grid and the StackPanel</strong>.</p>
<p>The Grid is the most powerful and (nearly) ubiquitous layout control – something of a UITableView on steroids. Click in the Content Panel (area 4 above) and the edges of the Grid that was placed there for you will light up.   Move your cursor in the margin and lines will appear. Click and horizontal lines become rows, vertical lines become columns.  You’ll want to create two columns (the left taking about 1/3 of the grid) and 8 rows of approximately equal size.</p>
<p>Click in the Grid and notice that the properties window has a ColumnDefinitions property and a RowDefinitions Property.  Here you can make the spacing more exact.  You can do so with precise sizes (e.g., 25px) or with percentages, or with relative sizing (e.g., 2* and 3* will create two columns with the first taking 2/5 of the available space.).  I chose 1* (which you can shorten to *) and 2* for the columns, and seven rows of 1*.</p>
<p>You can of course open these instead of creating the rows and columns first in the designer.</p>
<h3>Setting the Application Name and the Page Title</h3>
<p>Click on the Application Title or the Page Title (areas 2 and 3 above)</p>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/PropertiesForFirstTextBlock.jpg"><img style="margin: 10px 30px 10px 0px; display: inline; border-width: 0px;" title="Properties For First TextBlock" src="http://jesseliberty.com/wp-content/uploads/2010/08/PropertiesForFirstTextBlock_thumb.jpg" border="0" alt="Properties For First TextBlock" width="240" height="162" align="left" /></a> <strong>We’ll use the left column for the prompts</strong>. Drag a <strong>TextBlock</strong> (used for displaying text) into the first row (row offset 0), first column and place it more or less in the center. Then switch over to the properties window and set the following properties:</p>
<ul>
<li>Name=NamePrompt  (In area 6 above)</li>
<li>Common::Text=Full Name</li>
<li>Layout::Width=auto</li>
<li>Layout::Height=30</li>
<li>Layout::HorizontalAlignment=Right</li>
<li>Layout::VerticalAlignment=Center</li>
<li>Margin=5</li>
<li>Layout::Padding=0</li>
<li>Layout::MinWidth=30</li>
<li>Layout::MinHeight=30</li>
<li>Layout::MaxWidth=0</li>
<li>Layout::MaxHeight=0</li>
<li>Layout::Grid.Column=0</li>
<li>Layout::Grid.Columnspan=1</li>
<li>Layout::Grid.Row=0</li>
<li>Layout::Grid.Rowspn=1</li>
</ul>
<h4>Adding the Remaining Prompts</h4>
<p>Drag six more prompts onto the form, setting them identically, except for the Text and the Row.  The rows will be 1,2,3,4,5 and 7 and the Text will be</p>
<ul>
<li>Street Address</li>
<li>City, State, Zip</li>
<li>Phone</li>
<li>Fax</li>
<li>Email</li>
<li>Notes</li>
</ul>
<p>You can leave all the rest alone except that under Text you’ll want to <strong>click the Bold button</strong> and you’ll want to set the prompt names (or use the default as the only reason to have meaningful names is when you need to address the objects programmatically, which we won’t do with these labels) and don’t forget to set the Grid.Row appropriately.</p>
<p>The row you skipped will be used for the Male &amp; Female RadioButtons without a prompt.</p>
<table border="2" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td width="500" valign="top">The fact that so many of the properties are identical may be giving you the willies. Not to worry, we can fix this with Styles, a topic taken up in a future tutorial.  The complete Xaml is below, to facilitate cut and paste.</td>
</tr>
</tbody>
</table>
<h4>Adding the Input Controls</h4>
<p>Next, you’ll want to<strong> add the input controls</strong>. Add <strong>TextBox</strong> objects to rows 0,1,3,4,5 and 7 . Set the following properties:</p>
<ul>
<li>Name=Name (or StreetAddress, etc.)</li>
<li>Common::Text=Full Name (or street address, etc.)</li>
<li>Layout::Width=300</li>
<li>Layout::Height=70</li>
<li>Layout::HorizontalAlignment=Left</li>
<li>Layout::VerticalAlignment=Center</li>
<li>Margin=5</li>
<li>Layout::Padding=0</li>
<li>Layout::MinWidth=30</li>
<li>Layout::MinHeight=30</li>
<li>Layout::MaxWidth=0</li>
<li>Layout::MaxHeight=0</li>
<li>Layout::Grid.Column=0</li>
<li>Layout::Grid.Columnspan=1</li>
<li>Layout::Grid.Row=0</li>
<li>Layout::Grid.Rowspn=1</li>
</ul>
<h3>Using the Stack Panel</h3>
<p>You skipped over the input control for row 2 (the third from the top) because you want to place three text boxes in that row (for city, state and zip, respectively).  If you just set all three to the same row and column they will appear on top of one another. What you want is to “stack” them, but in this case not one on top of the other, rather one next to the other.</p>
<p>Drag a StackPanel onto the form and set its properties as follows:</p>
<li>Common:Orientation = Horizontal</li>
<li>Layout::HorizontalAlignment=Stretch</li>
<li>Layout::VerticalAlignment=Stretch</li>
<li>Margin=0</li>
<li>Layout::Padding=0</li>
<li>Layout::MinWidth=0</li>
<li>Layout::MinHeight=0</li>
<li>Layout::MaxWidth=Infinity</li>
<li>Layout::MaxHeight=Infinity</li>
<li>Layout::Grid.Column=0</li>
<li>Layout::Grid.Columnspan=1</li>
<li>Layout::Grid.Row=0</li>
<li>Layout::Grid.Rowspn=1Setting the Horizontal and vertical Alignments to stretch with no margin causes the StackPanel to expand to fill the cell. Next, place three TextBox controls within the StackPanel (on top) and set their properties as follows:
<ul>
<li>Name=City</li>
<li>Width=150</li>
<li>Height=70</li>
<li>HorizontalAlignment=Left</li>
<li>VerticalAlignment=Bottom</li>
<li>Margin=0,0,0,5</li>
<li>Text=City</li>
<li>Name=State</li>
<li>Width=74</li>
<li>Height=70</li>
<li>Margin=0,0,0,5</li>
<li>Text= State</li>
<li>Name=Zip</li>
<li>Width=93</li>
<li>Height=70</li>
<li>Margin=0,0,0,5</li>
<li>Text= Zip</li>
</ul>
<p>Notice that controls within the StackPanel do <em>not </em>need Grid coordinates.</p>
<p>Finally, you’ll want to add the two RadioButtons in row offset 6.  Again create a StackPanel, and within the StackPanel place two RadioButton controls:</p>
<ul>
<li>Name=Male</li>
<li>Content=Male</li>
<li>GroupName=Sex</li>
<li>IsChecked=True</li>
<li>Name=Female</li>
<li>Content=Female</li>
<li>GroupName=Sex</li>
<li>IsChecked=False</li>
</ul>
<p>The GroupName creates a Radio Button Group allowing the buttons to be mutually exclusive.</p>
<p>That is your UI.</p>
<h3>Running the Application</h3>
<p>Before we go any further, if you haven’t yet done so, <strong>run the application</strong>.  You can do this by clicking Build-&gt;Rebuild Your First Application (or control-shift-B) and then clicking Debug-&gt;Run (F5) or you can skip the first step and just run, as that will force a rebuild.  Your application will come up in the emulator, with populated fields!  Hoo ha!</p>
<p>When you are done enjoying the first version of your app, stop debugging (press the stop debugging button on the toolbar or Debug-&gt;Stop Debugging) but do not close the emulator.  The emulator takes a while to “boot up” and you can leave it running; it will attach to your program each time you rebuild and re-run.</p>
<h3>Data Binding</h3>
<p>Unfortunately, we are rarely called upon to populate a form with known values. <strong>Somewhat more common is to populate the form from data, often data retrieved from a database, possibly via a web service</strong>.  We won’t worry about how to retrieve the data in this tutorial, but let’s take the plunge into Data Binding – the technology of telling the View how to obtain the data it needs.  Since we are doing this with MVVM, we’ll have the ViewModel obtain the data from the Model, message it as required by business rules and then use binding to allow the View to have no code in the MainPage.xaml.cs file. (This greatly assists with testing).</p>
<p>To make this work we need to do two things:</p>
<ul>
<li>Create data in the Model</li>
<li>Create the View Model with public properties to which each control can bind</li>
<li>Update the View…</li>
</ul>
<p>Ok, Three Things, we need to</p>
<ul>
<li>Create data in the Model</li>
<li>Create the View Model with public properties to which each control can bind</li>
<li>Update the View setting each control’s binding</li>
<li>Set the data…</li>
</ul>
<p>Four things! Yes! Four things…</p>
<ul>
<li>Create data in the Model</li>
<li>Create the View Model with public properties to which each control can bind</li>
<li>Update the View setting each control’s binding</li>
<li>Set the data context</li>
<li><a href="http://en.wikipedia.org/wiki/The_Spanish_Inquisition_(Monty_Python)" target="_blank">Pretty Red Uniforms</a></li>
</ul>
<h3>Create Data In The Model</h3>
<p>While in a “real” application you’ll get your data from a data source such as a web service (which may in turn get the data from a database) for now we’ll create an instance of a “Customer” class right in local code. Create a Customer.cs class in the Model folder that looks like this:</p>
<pre class="brush: xml;">using System;

namespace Your_First_Application.Model
{
    public class Customer
    {

        public string First { get; set; }
        public string Last { get; set;  }
        public string Address { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Zip { get; set; }
        public string HomePhone { get; set; }
        public string WorkPhone { get; set; }
        public string Fax { get; set; }
        public string WorkEmail { get; set; }
        public string HomeEmail { get; set; }
        public bool IsMale { get; set; }
        public string Notes { get; set; }
        public int CreditRating { get; set;  }
        public DateTime FirstContact { get; set; }
        public DateTime LastContact { get; set; }

    }
}</pre>
<h4>C# For Objective-C Programmers</h4>
<p>These are called “automatic” properties.  When you write</p>
<pre class="brush: xml;">public string First { get; set; }</pre>
<p>the compiler treats it exactly as if you had written</p>
<pre class="brush: xml;">private string _secretvariable
public string First
{
   get { return _secretVariable; }
   set { _secretVariable = value; }
}</pre>
<p>That is, it is as if you had created a <em>backing store</em> for the value (in this case the string _secretVariable) and the get accessor returned that value. The set accessor sets the value of the backing store to the value passed in to the set accessor. Here’s how you use either form</p>
<pre class="brush: xml;">First = "Mary";        // call the setter
//....
string fn = First;     // call the getter</pre>
<p>The first line calls the setter and the string Mary is passed in as <em>value</em>.</p>
<p>The second line represents intervening code.</p>
<p>The third line uses the getter to retrieve “Mary” and assign it to the local string variable <em>fn</em>.</p>
<h3>Why Not Use Fields?</h3>
<p>If we’re using automatic properties, why not use public fields? <a href="http://weblogs.asp.net/jgalloway" target="_blank">Jon Galloway</a> points out that this is a common question and that one of the better answers was given by <a href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx" target="_blank">Scott Guthrie</a>:</p>
<blockquote><p><em>Note about that we aren&#8217;t actually adding any logic in the getters/setters of our properties &#8211; instead we just get/set the value directly to a field.  This begs the question &#8211; then why not just use fields instead of properties?  Well &#8211; there are a lot of downsides to exposing public fields. Two of the big problems are: 1) you can&#8217;t easily databind against fields, and 2) if you expose public fields from your classes you can&#8217;t later change them to properties (for example: to add validation logic to the setters) without recompiling any assemblies compiled against the old class. </em></p></blockquote>
<h3>Finishing the Customer Class</h3>
<p>With the properties in place we need a way to generate an instance. <strong>Best would be if we didn’t have to have an instance to create one, and so we’ll add a static method</strong> that returns a pre-filled instance.  <strong>Static methods can be called on the <em>class</em></strong> rather than on an instance (as you’ll see in just a moment).</p>
<pre class="brush: xml;">public static Customer GetCustomer()
{
    var newCust = new Customer(
        "Martha",
        "Washington",
        "1640 Pennsylvania Avenue",
        "New York",
        "NY",
        "11214",
        "617-555-4663",
        "781-555-9675",
        "212-555-5353",
        "jesseliberty@jesseliberty.com",
        "none",
        false,
        "VIP - Treat nicely",
        700,
        new DateTime(1955,07,10),
        new DateTime(2010,06,06));
    return newCust;
}</pre>
<p>This method does nothing more than to <strong>create an instance of the class, populate its fields and then return that instance</strong>.  <em>You would never do this in production code</em>, but it does give us an instance of the Customer class <em>as if</em> we had obtained it from a web service.  All that is missing is the constructor that we’re calling (that takes a value for each property),</p>
<pre class="brush: csharp;">public Customer(
    string first,
    string last,
    string address,
    string city,
    string state,
    string zip,
    string homePhone,
    string workPhone,
    string fax,
    string workEmail,
    string homeEmail,
    bool isMale,
    string notes,
    Int16 creditRating,
        DateTime firstContact,
        DateTime lastContact )
{
    First = first;
    Last = last;
    Address = address;
    City = city;
    State = state;
    Zip = zip;
    HomePhone = homePhone;
    WorkPhone = workPhone;
    Fax = fax;
    HomeEmail = homeEmail;
    WorkEmail = workEmail;
    IsMale = isMale;
    Notes = notes;
    CreditRating = creditRating;
    FirstContact = firstContact;
    LastContact = lastContact;

}</pre>
<p>That’s the model.</p>
<h3>The ViewModel</h3>
<p>The job of the ViewModel is to manage this data, bind it to the view and handle user input and user actions. We’ll postpone a discussion of user input and user actions until a future tutorial, but let’s create the view model with public properties for each of the values in the Customer that we want to display in the view. Here’s the complete MainViewModel.cs file</p>
<pre class="brush: csharp;">using GalaSoft.MvvmLight;
using Your_First_Application.Model;

namespace Your_First_Application.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        public string ApplicationTitle
        {
            get { return "Your First Application"; }
        }

        public string PageName
        {
            get { return "Customer"; }
        }

        private readonly Customer cust = Customer.GetCustomer();

        public string Name { get { return cust.First + " " + cust.Last; } }
        public string Street { get { return cust.Address; } }
        public string City { get { return cust.City; } }
        public string State { get { return cust.State; } }
        public string Zip { get { return cust.Zip; } }
        public string Phone { get { return cust.WorkPhone; } }
        public string Fax { get { return cust.Fax; } }
        public string Email { get { return cust.WorkEmail; } }
        public bool IsMale { get { return cust.IsMale == true; } }
        public bool IsFemale { get { return !IsMale; } }
        public string Notes { get { return cust.Notes; } }
    }
}</pre>
<p>The first two public properties are put in place by the MVVM Light Toolkit, the 11 at the bottom are the properties to which we’ll bind the 11 user controls.</p>
<h3>Setting the Data Context</h3>
<p>Notice that the values that <strong>we’re binding to are values on the customer object</strong>. How will the UI elements know what object has these properties?  That is handled by the <strong>Data Context property</strong> of the control, or its container (grid) or the container’s container (the page).  With MVVM Light Toolkit this work is done with the DAtaContext Locator object, which you’ll find was declared in the Xaml file,</p>
<pre class="brush: csharp;">DataContext="{Binding Main, Source={StaticResource Locator}}"&gt;</pre>
<p>This declaration was <strong>created for you by the MVVM Light Toolkit</strong> and so you do not have to worry about it; it just works.</p>
<h3>Binding at the UI Level</h3>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/Binding.jpg"><img style="margin: 10px 20px 10px 0px; display: inline; border-width: 0px;" title="Binding" src="http://jesseliberty.com/wp-content/uploads/2010/08/Binding_thumb.jpg" border="0" alt="Binding" width="240" height="170" align="left" /></a> It is time to <strong>bind the controls to the properties in the ViewModel</strong>.  Return to the View and click on one of the TextBox controls.  Delete the content and select binding. The dialog that opens will ask which public property you wish to bind to.</p>
<p>The tiny gold barrel on the line with the Text property indicates that you have a known data source.  The dialog box that opens has four tabs:</p>
<ul>
<li>Source</li>
<li>Path</li>
<li>Converter</li>
<li>Options</li>
</ul>
<p>Source is the data context (though you can have other sources, a topic for a later tutorial)</p>
<p>Path is the property to which you’ll bind</p>
<p>Converter allows the binding object to convert the type and/or to format the data</p>
<p>Options is where you pick one of the three types of binding:</p>
<ol>
<li>One Time</li>
<li>One Way</li>
<li>Two Way</li>
</ol>
<p>OneTime binding sets the binding and shuts down the binding connection.</p>
<p>OneWay binding is for read-only data</p>
<p>TwoWay binding allows the user to update the data you are displaying.  We’ll look at TwoWay binding in an early upcoming tutorial.</p>
<h3>Creating the UI in Xaml</h3>
<p>While drag and drop and setting properties works very well, you may find that your friends who do Silverlight programming do not take advantage of this. Rather they write these<strong> simple UI designs directly in the Xaml</strong>.  This is very much an artifact of the days in which coding the Xaml directly was the only option, but you may be interested in how to do such a thing.  Easy, peasy.  Return to the split screen and examine the Xaml that was generated.  Change the Xaml and see how the UI changes. Change the UI and see how the Xaml changes.  Here is the complete Xaml for our page,</p>
<pre class="brush: xml; collapse: true;">&lt;phone:PhoneApplicationPage x:Class="Your_First_Application.MainPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            SupportedOrientations="Portrait"
                            Orientation="Portrait"
                            mc:Ignorable="d"
                            d:DesignWidth="480"
                            d:DesignHeight="768"
                            shell:SystemTray.IsVisible="True"
                            DataContext="{Binding Main, Source={StaticResource Locator}}"&gt;

   &lt;!--LayoutRoot contains the root grid where all other page content is placed--&gt;
   &lt;Grid x:Name="LayoutRoot"
         Background="Transparent"&gt;
      &lt;Grid.RowDefinitions&gt;
         &lt;RowDefinition Height="Auto" /&gt;
         &lt;RowDefinition Height="*" /&gt;
      &lt;/Grid.RowDefinitions&gt;

      &lt;!--TitlePanel contains the name of the application and page title--&gt;
      &lt;StackPanel x:Name="TitlePanel"
                  Grid.Row="0"
                  Margin="24,24,0,12"&gt;
         &lt;TextBlock x:Name="ApplicationTitle"
                    Text="{Binding ApplicationTitle}"
                    Style="{StaticResource PhoneTextNormalStyle}" /&gt;
         &lt;TextBlock x:Name="PageTitle"
                    Text="{Binding PageName}"
                    Margin="-3,-8,0,0"
                    Style="{StaticResource PhoneTextTitle1Style}" /&gt;
      &lt;/StackPanel&gt;

      &lt;!--ContentPanel - place additional content here--&gt;
      &lt;Grid x:Name="ContentGrid"
            Grid.Row="1"
            Height="617"
            VerticalAlignment="Bottom"&gt;
         &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition Height="1*" /&gt;
            &lt;RowDefinition Height="1*" /&gt;
            &lt;RowDefinition Height="1*" /&gt;
            &lt;RowDefinition Height="1*" /&gt;
            &lt;RowDefinition Height="1*" /&gt;
            &lt;RowDefinition Height="1*" /&gt;
            &lt;RowDefinition Height="1*" /&gt;
            &lt;RowDefinition Height="1*" /&gt;
         &lt;/Grid.RowDefinitions&gt;
         &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition Width="1*" /&gt;
            &lt;ColumnDefinition Width="2*" /&gt;
         &lt;/Grid.ColumnDefinitions&gt;
         &lt;TextBlock Height="30"
                    HorizontalAlignment="Right"
                    Margin="5"
                    Name="NamePrompt"
                    Text="Full Name"
                    VerticalAlignment="Center"
                    FontWeight="Bold"
                    Grid.Row="0" /&gt;
         &lt;TextBlock FontWeight="Bold"
                    Height="30"
                    HorizontalAlignment="Right"
                    Name="streetPrompt"
                    Text="Street Address"
                    VerticalAlignment="Center"
                    Margin="5"
                    Grid.Row="1" /&gt;
         &lt;TextBlock FontWeight="Bold"
                    Height="30"
                    HorizontalAlignment="Right"
                    Name="cityStateZipPrompt"
                    Text="City, State, Zip"
                    VerticalAlignment="Center"
                    Margin="5"
                    Grid.Row="2" /&gt;
         &lt;TextBlock Height="30"
                    HorizontalAlignment="Right"
                    Margin="5"
                    Name="PhonePrompt"
                    Text="Phone"
                    VerticalAlignment="Center"
                    FontWeight="Bold"
                    Grid.Row="3" /&gt;
         &lt;TextBlock FontWeight="Bold"
                    Height="30"
                    HorizontalAlignment="Right"
                    Name="FaxPrompt"
                    Text="Fax"
                    VerticalAlignment="Center"
                    Margin="5"
                    Grid.Row="4" /&gt;
         &lt;TextBlock FontWeight="Bold"
                    Height="30"
                    HorizontalAlignment="Right"
                    Name="EmailPrompt"
                    Text="Email"
                    VerticalAlignment="Center"
                    Margin="5"
                    Grid.Row="5" /&gt;

         &lt;TextBlock FontWeight="Bold"
                    Height="30"
                    HorizontalAlignment="Right"
                    Name="NotesPrompt"
                    Text="Notes"
                    VerticalAlignment="Center"
                    Margin="5"
                    Grid.Row="7" /&gt;

         &lt;TextBox Name="FullName"
                  Width="303"
                  Height="70"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Bottom"
                  Margin="5,0,0,5"
                  Grid.Column="1"
                  Text="{Binding Name}" /&gt;
         &lt;TextBox Name="Street"
                  Width="303"
                  Height="70"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Bottom"
                  Margin="5,0,0,5"
                  Grid.Row="1"
                  Grid.Column="1"
                  Text="{Binding Street}" /&gt;
         &lt;StackPanel Orientation="Horizontal"
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Stretch"
                     Margin="0"
                     Grid.Row="2"
                     Grid.Column="1"&gt;
            &lt;TextBox Name="City"
                     Width="150"
                     Height="70"
                     HorizontalAlignment="Left"
                     VerticalAlignment="Bottom"
                     Margin="0,0,0,5"
                     Text="{Binding City}" /&gt;
            &lt;TextBox Name="State"
                     Width="74"
                     Height="70"
                     Margin="0,0,0,5"
                     Text="{Binding State}" /&gt;
            &lt;TextBox Name="Zip"
                     Width="93"
                     Height="70"
                     Margin="0,0,0,5"
                     Text="{Binding Zip}" /&gt;
         &lt;/StackPanel&gt;
         &lt;TextBox Height="70"
                  HorizontalAlignment="Left"
                  Margin="5,0,0,5"
                  Name="Phone"
                  VerticalAlignment="Bottom"
                  Width="303"
                  Grid.Column="1"
                  Grid.Row="3"
                  Text="{Binding Phone}" /&gt;
         &lt;TextBox Height="70"
                  HorizontalAlignment="Left"
                  Margin="5,0,0,5"
                  Name="Fax"
                  VerticalAlignment="Bottom"
                  Width="303"
                  Grid.Column="1"
                  Grid.Row="4"
                  Text="{Binding Fax}" /&gt;
         &lt;TextBox Height="70"
                  HorizontalAlignment="Left"
                  Margin="5,0,0,5"
                  Name="Email"
                  VerticalAlignment="Bottom"
                  Width="303"
                  Grid.Column="1"
                  Grid.Row="5"
                  Text="{Binding Email}" /&gt;
         &lt;StackPanel Orientation="Horizontal"
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Stretch"
                     Margin="5"
                     Grid.Row="6"
                     Grid.Column="1"&gt;
            &lt;RadioButton Name="Male"
                         Content="Male"
                         GroupName="Sex"
                         IsChecked="{Binding IsMale}"
                         FontSize="20" /&gt;
            &lt;RadioButton Name="Female"
                         Content="Female"
                         GroupName="Sex"
                         IsChecked="{Binding IsFemale}"
                         FontSize="20" /&gt;
         &lt;/StackPanel&gt;
         &lt;TextBox Height="72"
                  HorizontalAlignment="Left"
                  Margin="5,0,0,5"
                  Name="Notes"
                  VerticalAlignment="Bottom"
                  Width="290"
                  Grid.Column="1"
                  Grid.Row="7"
                  Text="{Binding Notes}" /&gt;
      &lt;/Grid&gt;
   &lt;/Grid&gt;
&lt;/phone:PhoneApplicationPage&gt;</pre>
<h4>You can obtain the complete source code for this application <a href="http://jesseliberty.com/files/YourFirstApplication.zip" target="_blank">here</a>.</h4>
<h3>Avoiding Property Wrappers</h3>
<p>An argument can certainly be made that too many of the properties in the ViewModel are nothing but pass-through wrappers for the same properties in Customer.  You can avoid that by making a Customer object a public property of the ViewModel and then binding to that directly.  If you prefer that style, you would want to change the ViewModel to look like this:</p>
<pre class="brush: csharp;">public class MainViewModel : ViewModelBase
{
    public string ApplicationTitle
    {
        get { return "Your First Application"; }
    }

    public string PageName
    {
        get { return "Customer"; }
    }

    private   Customer cust = Customer.GetCustomer();
    public   Customer Cust { get { return cust; } }

    public string Name { get { return cust.First + " " + cust.Last; } }
    public bool IsMale { get { return cust.IsMale == true; } }
    public bool IsFemale { get { return !IsMale; } }
}</pre>
<p>You’ll need to update the Xaml file to bind to WorkPhone and WorkEmail (as the ViewModel is no longer translating for you).</p>
<p>Finally, you’ll need to bind explicitly to the Customer property for most of the  fields, and to the ViewModel for the couple (Name and Male/Female) that will use Properties on the VM rather than on the Customer</p>
<pre class="brush: csharp;">public MainPage()
{
    InitializeComponent();
    var vm = new MainViewModel();
    DataContext = vm.Cust;
    FullName.DataContext = vm;
    Male.DataContext = Female.DataContext = vm;
}</pre>
<p>We create an instance of the ViewModel, and then set the DataContext of the View to the Cust property of the ViewModel.  We then set the DataContext of FullName to the ViewModel instance, and finally we set Male.DataContext and FemaleDataContext to the vm as well.</p>
<p>Mind Map</p>
<p><em>This is the kind of thing that people who like this kind of thing like.</em></p>
<p>[Click on the map to see it full size]</p>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/MindMapDataBinding2.jpg"><img class="aligncenter size-medium wp-image-3325" style="display: block; float: none; margin-left: auto; margin-right: auto;" title="MindMapDataBinding2" src="http://jesseliberty.com/wp-content/uploads/2010/08/MindMapDataBinding2-300x212.jpg" alt="" width="300" height="212" /></a></p>
<p><a href="http://jesseliberty.com/2010/09/04/iphone-to-windows-phone-7-diving-deeper/" target="_blank">Go to next tutorial</a></li>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=vhJX2uHhmMo:CZHXv5KOTWU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=vhJX2uHhmMo:CZHXv5KOTWU:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=vhJX2uHhmMo:CZHXv5KOTWU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=vhJX2uHhmMo:CZHXv5KOTWU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=vhJX2uHhmMo:CZHXv5KOTWU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=vhJX2uHhmMo:CZHXv5KOTWU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=vhJX2uHhmMo:CZHXv5KOTWU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=vhJX2uHhmMo:CZHXv5KOTWU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=vhJX2uHhmMo:CZHXv5KOTWU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/vhJX2uHhmMo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/08/27/i2w-an-iphone-developers-first-windows-phone-7-application/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/08/27/i2w-an-iphone-developers-first-windows-phone-7-application/</feedburner:origLink></item>
		<item>
		<title>The Open Source Project Spec: With Reference To Me</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/qFmscL_DSCI/</link>
		<comments>http://jesseliberty.com/2010/08/26/the-open-source-project-spec-with-reference-to-me/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 21:03:00 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[HyperVideo Player]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[HVP]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[WithReferenceToMe]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/08/27/the-open-source-project-spec-with-reference-to-me/</guid>
		<description>http://WithReferenceTo.Me The application that we&amp;#8217;ll be developing in the next phase of the HVP will allow the user to record and then look up everything that happened from day to day. With this application, each day you can record: Music you listen to Pictures you take Who you sent and received email from Who you [...]</description>
			<content:encoded><![CDATA[<h1><a href="http://WithReferenceTo.Me">http://WithReferenceTo.Me</a></h1>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/golden_ball_3_iStock_000008619033XSmall.jpg"><img style="margin: 10px 20px 10px 0px; display: inline; border-width: 0px;" title="stand out from the crowd" src="http://jesseliberty.com/wp-content/uploads/2010/08/golden_ball_3_iStock_000008619033XSmall_thumb.jpg" border="0" alt="stand out from the crowd" width="240" height="159" align="left" /></a></p>
<p>The application that we&#8217;ll be developing in<a href="http://withreferenceto.me" target="_blank"> the next phase of the HVP</a> will allow the user to record and then look up everything that happened from day to day.</p>
<p><span id="more-3279"></span></p>
<p>With this application, each day you can record:</p>
<ul>
<li>Music you listen to</li>
<li>Pictures you take</li>
<li>Who you sent and received email from</li>
<li>Who you chatted with</li>
<li>Where you were and where you went</li>
<li>Notes you make about the day</li>
<li>Accomplishments</li>
<li>Insights and ideas</li>
<li>People you meet…</li>
</ul>
<p>you get the idea.</p>
<p>Some of this is recorded automatically for you while the application is running. Some you enter. Some will be manual today with a goal of making it automated in future versions.  The data you record will be local to your phone unless you choose to upload it to the (to be created) web site.</p>
<h3>Plus ça change&#8230;</h3>
<p>Yes, this is a change in the vision for the next phase, but I think it will better illustrate</p>
<ul>
<li>The phone functionality</li>
<li>Transmedia Storytelling</li>
<li>Coding for WP7</li>
</ul>
<h3>Development Schedule</h3>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td width="358" valign="top"><strong>Item</strong></td>
<td width="142" valign="top"><strong>Working Due Date</strong></td>
</tr>
<tr>
<td width="358" valign="top">Graphic Design</td>
<td width="142" valign="top">October 29</td>
</tr>
<tr>
<td width="358" valign="top">Initial MVVM Design</td>
<td width="142" valign="top">October 29</td>
</tr>
<tr>
<td width="358" valign="top">Begin coding and unit tests</td>
<td width="142" valign="top">October 29</td>
</tr>
<tr>
<td width="358" valign="top">First release</td>
<td width="142" valign="top">November 20</td>
</tr>
<tr>
<td width="358" valign="top">Interim release</td>
<td width="142" valign="top">December 3</td>
</tr>
<tr>
<td width="358" valign="top">Interim Release</td>
<td width="142" valign="top">December 17</td>
</tr>
<tr>
<td width="358" valign="top">Code Complete – Alpha</td>
<td width="142" valign="top">January 2</td>
</tr>
<tr>
<td width="358" valign="top">Bugs Fixed – Beta</td>
<td width="142" valign="top">January 9</td>
</tr>
<tr>
<td width="358" valign="top">Release Candidate</td>
<td width="142" valign="top">January 16</td>
</tr>
<tr>
<td width="358" valign="top">First Release</td>
<td width="142" valign="top">Feb13, 2011</td>
</tr>
</tbody>
</table>
<p>NB: due to scheduling conflicts, this is a 1 month delay in the project.</p>
<div class="wlWriterHeaderFooter" style="margin: 0px; padding: 0px 0px 0px 0px;">This work is licensed under a <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons  license.</a></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qFmscL_DSCI:3-3AtS9GkZM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qFmscL_DSCI:3-3AtS9GkZM:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qFmscL_DSCI:3-3AtS9GkZM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=qFmscL_DSCI:3-3AtS9GkZM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qFmscL_DSCI:3-3AtS9GkZM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=qFmscL_DSCI:3-3AtS9GkZM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qFmscL_DSCI:3-3AtS9GkZM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=qFmscL_DSCI:3-3AtS9GkZM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=qFmscL_DSCI:3-3AtS9GkZM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/qFmscL_DSCI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/08/26/the-open-source-project-spec-with-reference-to-me/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/08/26/the-open-source-project-spec-with-reference-to-me/</feedburner:origLink></item>
		<item>
		<title>Programmer Superstitions</title>
		<link>http://feedproxy.google.com/~r/JesseLiberty-SilverlightGeek/~3/feLfYzM5e0c/</link>
		<comments>http://jesseliberty.com/2010/08/26/one-from-the-vault-programmer-superstitions/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 13:10:49 +0000</pubDate>
		<dc:creator>Jesse Liberty</dc:creator>
				<category><![CDATA[Essentials]]></category>
		<category><![CDATA[Patterns & Skills]]></category>
		<category><![CDATA[Reviews & Opinions]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://jesseliberty.com/2010/08/26/one-from-the-vault-programmer-superstitions/</guid>
		<description>There are a number of practices that we engage in &amp;#8211;– no, that we cling to, and defend, and teach to others,  – that amount to magical thinking, or at best, rational failure. This is often just fine, no harm done (other than to our self-image as rational geeks) but some of these totemic-rituals are [...]</description>
			<content:encoded><![CDATA[<p>There are a<strong> number of practices that we engage in</strong> &#8211;– no, that we cling to, and defend, and teach to others,  – that amount to <strong>magical thinking,</strong> or at best, rational failure.</p>
<p><a href="http://jesseliberty.com/wp-content/uploads/2010/08/POTION_istock.jpg"><img style="margin: 10px 25px 10px 0px; display: inline; border: 0px;" title="Green poison" src="http://jesseliberty.com/wp-content/uploads/2010/08/POTION_istock_thumb.jpg" border="0" alt="Green poison" width="240" height="166" align="left" /></a></p>
<p>This is often just fine, no harm done (other than to our self-image as rational geeks) but <strong>some of these totemic-rituals are stumbling blocks in our ability to produce reliable software. </strong></p>
<p>From time to time we might want to stop and question our most cherished assumptions to see if we&#8217;ve fallen into any of these traps:</p>
<ul>
<li><strong>Secrecy and Mystery</strong></li>
<li><strong>Ancestor Worship</strong></li>
<li><strong><a href="http://en.wikipedia.org/wiki/Apophenia" target="_blank">Apophenia</a></strong></li>
<li><strong>Argument From Authority</strong></li>
</ul>
<p><span id="more-3274"></span></p>
<h3>Secrecy and Mystery: <strong>Data Hiding</strong></h3>
<p>I’ve been writing in and teaching C++ and C# for twenty years. I know well the iron-clad rule of object -oriented programming that <strong>class data should be hidden</strong> (private) and accessed through either a property (C#) or an accessor function (C++). Thus:</p>
<pre class="brush: csharp;">public class Employee
{
    private string name;
    public string Name
    {
       get { return name;}
       set { name = value;}
    }
}
</pre>
<p><strong>There are good reasons for this rule.</strong> Data hiding makes for a better decoupling of classes, and allows the programmer to intercept the access of private data and apply rules or other processing. It is possible, for example, to check whether the client accessing a value has the correct permissions to see or modify that value, and also to massage the data in appropriate ways.</p>
<p><strong>But look closely</strong> at the example shown above: it is not unusual. The backing data is stored as a private local variable, and full access is provided with a get and a set accessor, neither of which do anything but return or set the value. That is,<strong> the accessors add no immediate value at all</strong>. The typing penalty is solved with automatic properties,</p>
<pre class="brush: csharp;">public class Employee
{

    public string Name
    {
       get; set;
    }
}
</pre>
<p>But to some degree this just hides the problem.  After all, why not write</p>
<pre class="brush: csharp;">public class Employee
{
    public string Name;
}
</pre>
<p>Don&#8217;t panic when you see this; consider that there is little difference from the automatic property and it is a heck of a lot more straight forward.</p>
<p><a href="http://images2.wikia.nocookie.net/__cb20060220185544/psychology/images/thumb/4/47/Asch_experiment.png/270px-Asch_experiment.png"><img style="margin: 0px; display: inline; border: 0px;" title="270px-Asch_experiment" src="http://jesseliberty.com/wp-content/uploads/2010/08/270pxAsch_experiment.png" border="0" alt="270px-Asch_experiment" width="240" height="196" align="left" /></a> The last, desperate excuse, as you will find in many computer books, including my own (I add with some chagrin), is that making the backing variable private (or using automatic variables, and changing them when needed) allows you to change how you store the data without breaking any client of your Employee class. You could, for example, decide some time in the future to retrieve the name from a database.</p>
<p>The rational  part of me suspects that the number of person hours wasted, both by all the hocus pocus of properties  is swamped by any possible benefit. And, yet, I can’t quite bring myself to eschew the properties.</p>
<p>The problem is that can&#8217;t justify my reluctance rationally. Either this is a superstition, or more likely, it is the <strong><a href="http://psychology.wikia.com/wiki/Asch_conformity_experiments" target="_blank">Asch conformity effect</a></strong>, in which students were shown three lines,  one distinctly longer than the other, but confederates of the experimenter in the audience insisted that the shorter was longer.<strong> If three confederates or more made the false assumption, the subjects were likely to go along more than a third of the time(!) </strong></p>
<p><strong>Ancestor Worship</strong></p>
<p>Let’s take an example where we are not only being irrational, but also making our lives harder and our code more expensive to write and to maintain.</p>
<p>You may want to sit down for this one, but I’m going to dare to ask: <strong>why do we insist that C-derived languages</strong> (such as C#) <strong>continue to be case sensitive</strong>?  Other than paying homage to Kernighan and Ritchie I believe I can safely say after 20+ years of writing in C, C++ and C# that <strong>the disadvantages of case sensitivity swamp the advantages</strong>.</p>
<p>The only clear advantage I have ever found is the ability to have make the name of a property be the PascalCase version of the camelCase name of the backing variable</p>
<pre class="brush: csharp;">private int age;
public int Age { get { //... } set { //.... } }
</pre>
<p><strong>In exchange for that convenience, we enjoy hours of debugging, trying to find where we inadvertently introduced a new variable or method name because of a misplaced shift-key.</strong></p>
<p>And even in the best case, the argument is obsolete,  as the convention now is to use an underscore</p>
<pre class="brush: csharp;">private int _age;
public int Age { get { //... } set { //.... } }
</pre>
<p>Has any bright graduate student done research on the cost/benefit of case sensitivity? Is there any rational reason that in 2010 C# continues this &#8216;“tradition”&#8217; that was established 30+ ago? Or might it be a lingering fear of showing disrespect to the icons of our industry; the mighty heroes who created the C family, defeated Troy and bequeathed us the scriptures by which we live?</p>
<p><em>Or Maybe Not…</em></p>
<p>There is an argument that case sensitivity makes more sense with some human languages other than English, and may even make sense as an optimization for some data structures, such as hash tables. Such arguments, however, speak to the need for an optimizing compiler to handle the issue; there is no reason for the language to do so.</p>
<p>C++ programmers like to suffer anyway, so this just feeds the beast.</p>
<p><strong>Ancestor Worship II</strong></p>
<p>Here’s another example of latent ancestor worship (or at least of very old habits dying hard). <strong>There is a wonderful myth that American standard rail road tracks are the width they are</strong> (4 feet, 8.5 inches) because that is the way they built them in England, which the English did because that is the way they were gauged by the first tramways, which in turn was done because that is the width of wagon wheels created to fit in the wheel ruts in old English roads that were <strong>in turn dug by by Imperial Roman Chariots.</strong></p>
<p>The myth has <strong>tremendous lasting power</strong> (you can find it all over the net) <strong>because it feels right</strong> (<em>expectation bias</em>?) . We do that kind of thing a lot; we build the streets of Boston on old cow paths; we unconsciously follow old patterns, even when  those patterns no longer make sense or are necessary.</p>
<p>How many times have you seen (or written) code like this:</p>
<pre class="brush: csharp;">for ( int i = 0; i &lt; innerArrayLength; i++ )
{
    for ( int j = 0; j &lt; outerArrayLength; j++ )
    {
        myArray[i][j] = i * j;
    }
}</pre>
<p><strong>Why are the counter variables i and j</strong>?  Old cow paths. It turns out that in Fortran (remember Fortran? Remember Eisenhower?) the integer variables were the letters I through N (which comes from an even older tradition of mathematicians using i to n as subscripts for integers), and, well, we just got into the habit. This one is fairly harmless, a ritualized and vestigial part of the programming mind that we’re surprisingly reluctant to let go of.</p>
<h3>Pattern Recognition</h3>
<p>One of the most powerful forms of magical thinking is <strong>Apophenia: seeing patterns or connections in random data</strong>. The tendency towards Apophenia is probably hardwired into the human brain; it is the price we pay for the very advantageous  human ability of pattern recognition (an adaptive part of our intelligence that helps us know when to run and when to hunt) but it can also lead us astray (arguably it is the basis of our belief in many pseudo-sciences).</p>
<p><strong>Apophenia</strong> is certainly pervasive in consulting. A classic example was the tendency to study “&#8217;excellence&#8217;” in successful companies in the 1980s; trying to extract those apparent essential elements that lead to success.</p>
<p>Unfortunately, not only was it far more complex and difficult for other companies to reproduce success following these patterns, even the iconic companies themselves felt the worm turn over time. They kept repeating their patterns, but the outcomes were different. What went wrong?</p>
<p>It was not clear that <strong>the patterns of &#8216;“excellence”&#8217; we were “seeing” in successful companies</strong> (great customer service, their caring attention to employees and attention to details) were as easily connected with success as we had thought. Correlation is not always causation, as we so often learn (<em><a href="http://en.wikipedia.org/wiki/Post_hoc_ergo_propter_hoc">post hoc ergo propter hoc</a></em>).</p>
<p><strong>Argument From Authority</strong></p>
<p><strong>Argument from Authority</strong>, to disagree with <a href="http://www.samueljohnson.com/refuge.html">Samuel Johnson</a>, <strong>is</strong> <strong>the true last refuge of scoundrels. </strong></p>
<p>Some years ago I testified as an &#8216;“expert witness&#8217;” in a civil lawsuit, at which the opposing &#8216;“expert witness”&#8217; asserted that the &#8216;“failure”&#8217; of the project could be attributed to a lack of strict compliance with the ISO 9000 standard.</p>
<p>Smart people can have a reasonable discussion about whether ISO 9000 will improve the likelihood of success on very large projects (e.g. , the software for the mission to Mars). I personally would not like to work on a software project that is managed using anything like such a bureaucratic, heavyweight, inflexible, document-intensive, rigid processes, but that does not necessarily mean that I can prove that no project would ever benefit from it.</p>
<p>I had no hesitation, however, in asserting under oath, that the fact that various authorities asserted this was the right process for every project was abject nonsense.  I went on, at the arbiter&#8217;s insistence, that my personal assessment was that  a project with ten developers would benefit from strict adherence to ISO 9000 like a drowning man would benefit from being thrown an anchor. It was my opinion that knee-jerk reliance on a process like ISO 9000 to guide you through each project is a form of Apophenia; <strong>the connection between the pattern of ISO 9000 compliance steps and success, however measured, is imaginary</strong>. And, I concluded, supporting that theory with <em>Argument From Authority</em> was, at the least, irrational.</p>
<p><strong>Looking where the light is</strong></p>
<p>There is an old joke about a man searching for his keys under a street lamp. He lost the keys in the alley behind him, but this is where he can see.</p>
<p>In our desperate attempt to gain control over very complex processes, with so much money at stake, and so many examples of previous failures, <strong>we often fall victim to seeing apparent patterns </strong>(be they processes or otherwise) where they do not exist. We examine various projects and say:</p>
<blockquote><p>“&#8217;Ah ha! I see why this project worked and that one didn’t: the difference was too much/ (too little)  analysis (/ design) (/ documentation) (/ process) (/ oversight) (/ communication).</p>
<p>And all we have to do is increase/  (decrease) the number/ le (length) (/ duration) (/ sequence) (/ complexity) (/ formality) of the meetings (/ documents/ ) (diagrams) (/ studies) (/ sign-offs) , etc.</p></blockquote>
<p>These false patterns lead us astray; offering us the promise that if we paint by the numbers, we too can be Renoir.  It may be, however, that the variables of successful process are far more complex; including, if we are terribly unlucky, factors over which we have little or no control; or, only marginally better, factors over which we will have no control until our tools and technologies mature.</p>
<p>Or, it may just may be that some developers are better at the &#8216;“art”&#8217; of programming and shipping product; and that the old adage &#8216;“’tis a poor carpenter who blames his tools”&#8217; applies to software as well as it does to other crafts.</p>
<p><strong>The Scientific Method</strong></p>
<p>Over the years, at least to some degree, society has given up many (though not all) of its superstitions when presented with more compelling alternatives. One of the most effective techniques for distinguishing between superstition and truth (or some approximation of truth) is the scientific method; in short, controllable, measurable, reproducible effects <em>that are disprovable.</em></p>
<p>It’s hard to do that sort of thing when you’re trying to hit a deadline, and it’s particularly hard to sort out all the alternatives when there are so few objective comparisons.</p>
<p>When was the last time you were able to find anything like an objective answer to the question “which is better: Java or .NET?” (Please don’t write in, my mailbox fills quickly).</p>
<p>It is particularly interesting that the work done at Universities and Research Centers is often not only unrelated to, but totally disparaged by, the folks who write code for a living. That is not the way things work in other Engineering fields and I’m not convinced we can afford the disconnect for much longer.</p>
<p><strong>We seem to be writing 21st century software with a 12th  century mindset</strong> and that can’t be good.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=feLfYzM5e0c:ncIMClc_5Nk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=feLfYzM5e0c:ncIMClc_5Nk:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=feLfYzM5e0c:ncIMClc_5Nk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=feLfYzM5e0c:ncIMClc_5Nk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=feLfYzM5e0c:ncIMClc_5Nk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=feLfYzM5e0c:ncIMClc_5Nk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=feLfYzM5e0c:ncIMClc_5Nk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?i=feLfYzM5e0c:ncIMClc_5Nk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?a=feLfYzM5e0c:ncIMClc_5Nk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/JesseLiberty-SilverlightGeek?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/JesseLiberty-SilverlightGeek/~4/feLfYzM5e0c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jesseliberty.com/2010/08/26/one-from-the-vault-programmer-superstitions/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://jesseliberty.com/2010/08/26/one-from-the-vault-programmer-superstitions/</feedburner:origLink></item>
	</channel>
</rss>
