<?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:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
    <channel>
        <title>Raffaeu Bermuda Blog</title>
        <link>http://blog.raffaeu.com/Default.aspx</link>
        <description>NET Coder relocated in Bermuda</description>
        <language>en-US</language>
        <copyright>Raffaeu</copyright>
        <managingEditor>raffaeu@raffaeu.com</managingEditor>
        <generator>Subtext Version 2.0.0.43</generator>
        <image><link>http://creativecommons.org/licenses/by/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image>
        <creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RaffaeuEnglishBlog" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
            <title>Inversion of Control with NET Framework.</title>
            <category>Design Pattern</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/BqhfHudLlDg/inversion-of-control-with-net-framework.aspx</link>
            <description>&lt;p&gt;Today I want to break-out my series of posts about WPF to talk about an interesting design pattern. The Inversion of Control or Dependency Injection. You can find a clear definition at this address: &lt;a href="http://martinfowler.com/articles/injection.html" target="_blank"&gt;Martin Fowler&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;What is it the Dependency Injection?&lt;/h3&gt;  &lt;p&gt;The dependency injection is a way to inject some information and configuration inside an object, from another one. In this way we keep our object abstract and recyclable.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/InversionofControlwithNETFramework_C7A8/image.png" rel="lightbox[IoC]"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/InversionofControlwithNETFramework_C7A8/image_thumb.png" width="260" height="217" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see in this example, we have two concrete tasks, and each one has an &lt;strong&gt;execute&lt;/strong&gt; command that is exposed by the interface &lt;strong&gt;IBaseTask&lt;/strong&gt;. This will be our bridge from the interface and the concrete implementation.&lt;/p&gt;  &lt;h3&gt;Manually Dependency Injection.&lt;/h3&gt;  &lt;p&gt;Now, if we would like to run our example, manually, we should write something like this code:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: IBaseTask firstTask = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RunTask();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: firstTask.Execute();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: IBaseTask secondTask = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WalkTask();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: secondTask.Execute();&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And the code in each task should be something like that:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; WalkTask : IBaseTask {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:     #region IBaseTask Members
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TaskName {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:         &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:         &lt;span style="color: #0000ff"&gt;set&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Execute() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:         Console.WriteLine("&lt;span style="color: #8b0000"&gt;I am a Walk task&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13:     #endregion
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15: &lt;/pre&gt;&lt;/pre&gt;

&lt;h3&gt;Microsoft Unity for Dependency Injection.&lt;/h3&gt;

&lt;p&gt;Microsoft Unity is an open source project done by the Microsoft patterns and practice. It can be downloaded here: &lt;a title="http://unity.codeplex.com/" href="http://unity.codeplex.com/"&gt;http://unity.codeplex.com/&lt;/a&gt; and the actual version is the 1.2 present also in the enterprise library 4.1&lt;/p&gt;

&lt;p&gt;After you install it, you will have a folder with some .dlls that you have to reference into your solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/InversionofControlwithNETFramework_C7A8/image_3.png" rel="lightbox[IoC]"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/InversionofControlwithNETFramework_C7A8/image_thumb_3.png" width="260" height="200" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now let’s go back to our project and let’s change the code in order to have Unity and not a concrete implementation of our interface.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #008000"&gt;//Unity container&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: IUnityContainer container = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UnityContainer();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: &lt;span style="color: #008000"&gt;//Type association&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: container.RegisterType&amp;lt;IBaseTask, WalkTask&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5: IBaseTask firstTask = container.Resolve&amp;lt;IBaseTask&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6: firstTask.Execute();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;This is the first step, but as you can notice, it’s not so far from a concrete implementation. I mean, in this way we still have to &lt;strong&gt;procedural declare&lt;/strong&gt; the type we want to convert to our interface.&lt;/p&gt;

&lt;p&gt;The next step will be to remove the type association and use a configuration file. First of all we need to declare in our &lt;strong&gt;app.config &lt;/strong&gt;file the unity section:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;xml version="1.0" encoding="utf-8" &lt;span style="color: #0000ff"&gt;?&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configSections&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;section&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Unity"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, 
&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:              Microsoft.Practices.Unity.Configuration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configSections&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we need to associate some type to our container. This is easy.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Unity&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;typeAliases&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:       &lt;span style="color: #008000"&gt;&amp;lt;!-- Lifetime manager types --&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;typeAlias&lt;/span&gt; &lt;span style="color: #ff0000"&gt;alias&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"singleton"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:            &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Microsoft.Practices.Unity.ContainerControlledLifetimeManager,
&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:                Microsoft.Practices.Unity" &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;typeAlias&lt;/span&gt; &lt;span style="color: #ff0000"&gt;alias&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"external"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:            &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Microsoft.Practices.Unity.ExternallyControlledLifetimeManager,
&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:                Microsoft.Practices.Unity" &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:       &lt;span style="color: #008000"&gt;&amp;lt;!-- Custom types --&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #80ff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;typeAlias&lt;/span&gt; &lt;span style="color: #ff0000"&gt;alias&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"myInterface"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"InversionOfControl.Model.IBaseTask, InversionOfControl"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #80ff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;typeAliases&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;As you can see at the end, we are going to declare our IBaseTask interface. Remember always to declare the complete path otherwise Unity will search the class into the Unity namespace!!&lt;/p&gt;

&lt;p&gt;Now let’s build a couple of custom map inside the XML file:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;containers&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;container&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"firstContainer"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;types&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #80ff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;type&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"myInterface"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;mapTo&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"InversionOfControl.Model.RunTask, InversionOfControl"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"RunMapping"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #80ff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:           &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;type&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"myInterface"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;mapTo&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"InversionOfControl.Model.WalkTask, InversionOfControl"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"WalkMapping"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:         &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;types&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:       &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;container&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;containers&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Unity&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, we are using our &lt;strong&gt;Alias&lt;/strong&gt; to declare the interface and then we are giving a &lt;strong&gt;custom name&lt;/strong&gt; the our mapping. Now we can go back to our code and do some fancy operations.&lt;/p&gt;

&lt;p&gt;Declare the configuration section and initialize the container:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: IUnityContainer container = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UnityContainer();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("&lt;span style="color: #8b0000"&gt;Unity&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: section.Containers["&lt;span style="color: #8b0000"&gt;firstContainer&lt;/span&gt;"].Configure(container);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then let’s &lt;strong&gt;Inject&lt;/strong&gt; a couple of objects inside our interface:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: IBaseTask firstTask = 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:    container.Resolve&amp;lt;IBaseTask&amp;gt;("&lt;span style="color: #8b0000"&gt;RunMapping&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: firstTask.Execute();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: IBaseTask secondTask = 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:    container.Resolve&amp;lt;IBaseTask&amp;gt;("&lt;span style="color: #8b0000"&gt;WalkMapping&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6: secondTask.Execute();&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Very easy right? In our example we are going to write in a procedural way which mapping we want to use, but of course this information should be retrieved at run-time from a Database or a serialized object.&lt;/p&gt;

&lt;h3&gt;Inject property and change values at run-time.&lt;/h3&gt;

&lt;p&gt;Until now our objects were exposing an execute method that was simply printing some fixed text in the console. But we have a &lt;strong&gt;name property&lt;/strong&gt; so we should change the execute method with something like that:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Execute() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:     Console.WriteLine
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:       ("&lt;span style="color: #8b0000"&gt;I am a Run task. My name is: {0}&lt;/span&gt;",
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:       TaskName);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we have two ways to initialize the TaskName property value without using a procedural code inside the program. First of all we have to say that the &lt;strong&gt;TaskName &lt;/strong&gt;property of each concrete implementation has a dependency:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: [Dependency()]
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TaskName {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:    &lt;span style="color: #0000ff"&gt;get&lt;/span&gt;;&lt;span style="color: #0000ff"&gt;set&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And now we can change the configuration in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;type&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"myInterface"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;mapTo&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"InversionOfControl.Model.WalkTask, InversionOfControl"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"WalkMapping"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;typeConfig&lt;/span&gt; &lt;span style="color: #ff0000"&gt;extensionType&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Microsoft.Practices.Unity.Configuration.TypeInjectionElement,
&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:                      Microsoft.Practices.Unity.Configuration"&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"TaskName"&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;propertyType&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"System.String"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;value&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"SecondTask"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;property&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:   &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;typeConfig&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;We are assigning for the mapping called &lt;strong&gt;WalkMapping&lt;/strong&gt; a value of “SecondTask” for the property &lt;strong&gt;TaskName&lt;/strong&gt;. This solution is fine but it’s still fixed. I mean, and if I would like to change the value at run-time and I cannot access the serialization of my object?&lt;/p&gt;

&lt;p&gt;Here is coming the second solution:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: container.Configure&amp;lt;InjectedMembers&amp;gt;()
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:    .ConfigureInjectionFor&amp;lt;RunTask&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:    &lt;span style="color: #008000"&gt;//.ConfigureInjectionFor&amp;lt;IBaseTask&amp;gt;(&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:    &lt;span style="color: #008000"&gt;//.ConfigureInjectionFor&amp;lt;WalkTask&amp;gt;(&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:       &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; InjectionProperty("&lt;span style="color: #8b0000"&gt;TaskName&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;12345&lt;/span&gt;"));&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;I put a couple of comments to show you what you can configure.&lt;/p&gt;

&lt;p&gt;I hope this short article will be useful to evaluate this amazing IoC framework.&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/IoC" rel="tag"&gt;IoC&lt;/a&gt; &lt;a href="http://technorati.com/tag/Unity" rel="tag"&gt;Unity&lt;/a&gt; &lt;a href="http://technorati.com/tag/Dependency Injection" rel="tag"&gt;Dependency Injection&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/73.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=BqhfHudLlDg:6x_m-fpQZ40:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=BqhfHudLlDg:6x_m-fpQZ40:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=BqhfHudLlDg:6x_m-fpQZ40:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=BqhfHudLlDg:6x_m-fpQZ40:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=BqhfHudLlDg:6x_m-fpQZ40:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=BqhfHudLlDg:6x_m-fpQZ40:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=BqhfHudLlDg:6x_m-fpQZ40:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=BqhfHudLlDg:6x_m-fpQZ40:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/BqhfHudLlDg" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/07/07/inversion-of-control-with-net-framework.aspx</guid>
            <pubDate>Tue, 07 Jul 2009 21:10:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/73.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/07/07/inversion-of-control-with-net-framework.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/73.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/73.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/07/07/inversion-of-control-with-net-framework.aspx</feedburner:origLink></item>
        <item>
            <title>WPF and MVVM tutorial 07, the List search.</title>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/hAzBg7hIbNw/wpf-and-mvvm-tutorial-07-the-list-search.aspx</link>
            <description>&lt;p&gt;Ok, starting from this post we are going to do something really interesting. In this episode we need to create a simple List windows, but as you will see the logic will not be so different then a one-to-many form.&lt;/p&gt;  &lt;p&gt;This will be the final result:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial07theListsearch_C352/image.png" rel="lightbox[Tutorial07]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial07theListsearch_C352/image_thumb.png" width="260" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The ViewModel for the List Window.&lt;/p&gt;  &lt;p&gt;First of all we need to create the view model. The view model should have the following commands:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;New – Add a new Customer &lt;/li&gt;    &lt;li&gt;Save – Save all the changes we did … &lt;/li&gt;    &lt;li&gt;Edit – Edit the current selected customer &lt;/li&gt;    &lt;li&gt;Delete – Delete the current selected customer &lt;/li&gt;    &lt;li&gt;Text box and search button – to operate search activity &lt;/li&gt;    &lt;li&gt;Exit the form &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Then we need to add the following objects:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;An observable collection for the list of customers &lt;/li&gt;    &lt;li&gt;A current customer object, but this is not mandatory … &lt;/li&gt;    &lt;li&gt;The search information we retrieve from the view, or better, the view sends to us. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The final result will be this view model class:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial07theListsearch_C352/image_3.png" rel="lightbox[Tutorial07]"&gt;&lt;img style="border-right-width: 0px; margin: 2px 10px 5px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial07theListsearch_C352/image_thumb_3.png" width="110" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Let’s have a look at the View Model commands. As you know when we assign a RelayCommand, we can do it in 2 ways:&lt;/p&gt;  &lt;p&gt;By passing with a lambda expression the corresponding action.&lt;/p&gt;  &lt;p&gt;By passing with a lambda expression the corresponding action and a predicate (something like true/false).&lt;/p&gt;  &lt;p&gt;So for some commands like &lt;strong&gt;Save&lt;/strong&gt; or &lt;strong&gt;Delete&lt;/strong&gt; we can also build a predicate action like &lt;strong&gt;CanSave? CanDelete?&lt;/strong&gt; and encapsulating some validation logic inside.&lt;/p&gt;  &lt;p&gt;So the code should look like:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h3&gt;The RelayCommands.&lt;/h3&gt;  &lt;p&gt;Simple command like &lt;strong&gt;Create a new customer&lt;/strong&gt;:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #008000"&gt;//Private field&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ViewCommand newCommand;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: &lt;span style="color: #008000"&gt;//Public property to be assigned in the XAML code&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ViewCommand NewCommand {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:    &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:       &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (newCommand == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:          newCommand = 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:          &lt;span style="color: #008000"&gt;//Lambda expression for assigning the action&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:          &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ViewCommand(param =&amp;gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.NewCustomer());
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:       &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; newCommand;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13: &lt;span style="color: #008000"&gt;//Real routine executed in the ViewModel&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14: &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; NewCustomer() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15:    NavigationActions.OpenCustomerView();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 16: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 17: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Or something more complex like Delete a customer:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #008000"&gt;//Private command field&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ViewCommand deleteCommand;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: &lt;span style="color: #008000"&gt;//Public databinded ICommand&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ViewCommand DeleteCommand {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:    &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:       &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (deleteCommand == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:       deleteCommand = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ViewCommand(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:           param=&amp;gt;&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.DeleteCustomer(),
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:           &lt;span style="color: #008000"&gt;//Lambda expression for evaluating the execution&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:           param=&amp;gt;&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.CanDeleteCustomer
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:           );
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12:       }   
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13:       &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; deleteCommand;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14:    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 16: &lt;span style="color: #008000"&gt;//Real delete command&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 17: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteCustomer() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 18:    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (SelectedCustomer != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 19:       &lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(NavigationActions.QueryConfirmation(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 20:          "&lt;span style="color: #8b0000"&gt;Delete Customer.&lt;/span&gt;",
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 21:          &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #8b0000"&gt;"Do you want to delete {0}?"&lt;/span&gt;,SelectedCustomer.FirstName))){
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 22:          ListOfCustomers.Remove(SelectedCustomer);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 23:          repository.DeleteCustomer(SelectedCustomer);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 24:       }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 25:    } &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 26:       NavigationActions.ShowError(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 27:         "&lt;span style="color: #8b0000"&gt;Delete Customer.&lt;/span&gt;", 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 28:         "&lt;span style="color: #8b0000"&gt;You must select a Customer!&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 29:    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 30: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 31: &lt;span style="color: #008000"&gt;//Additional logic can go here ...&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 32: &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; CanDeleteCustomer {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 33:    &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 34: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 35: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then of course we will have two different command for Edit a Customer or create a new one, and at the end the difference will be just here:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #008000"&gt;//Open the Customer window empty&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: NavigationActions.OpenCustomerView();

&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: NavigationActions.OpenCustomerView(SelectedCustomer);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: &lt;span style="color: #008000"&gt;//Open the Customer window passing a Customer&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5: &lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The others commands are the same, but if you want in my solution you can find the complete implementation.&lt;/p&gt;

&lt;h3&gt;Loading and working with a Collection.&lt;/h3&gt;

&lt;p&gt;After we build all the commands and we bind them to the XAML code, we need to load our entities. For this we will use a ObservableCollection List that we will implement in the initialization of our View Model, so when the Window will open we will also load the Collection inside the ListView.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #008000"&gt;//We need an instance of our repository&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: CustomerRepository repository;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: &lt;span style="color: #008000"&gt;//This will contain our Customers&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: ObservableCollection&amp;lt;Customer&amp;gt; listOfCustomers;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5: &lt;span style="color: #008000"&gt;//This will be the current selected customer&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6: Customer selectedCustomer;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CustomersViewModel() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (repository == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:       &lt;span style="color: #008000"&gt;//Initialization of the Repository&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:       repository = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomerRepository();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12:    Initialization of the List
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13:    listOfCustomers = 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14:       &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObservableCollection&amp;lt;Customer&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15:          repository.GetAllCustomers());
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 16:    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SearchText = "&lt;span style="color: #8b0000"&gt;Some text to search ...&lt;/span&gt;";
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 17: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 18: &lt;span style="color: #008000"&gt;//Binded property containing the Customer list&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 19: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ObservableCollection&amp;lt;Customer&amp;gt; ListOfCustomers {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 20:    &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; listOfCustomers; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 21: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 22: &lt;/pre&gt;&lt;/pre&gt;

&lt;h3&gt;INotifyPropertyChanged&lt;/h3&gt;

&lt;p&gt;If we want to &lt;strong&gt;advise&lt;/strong&gt; the UI that we loaded a new customers list, we have to build a ViewModel that implements the INotifyPropertyChanged in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: #region INotifyPropertyChanged Members
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; NotifyPropertyChanged(String info) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (PropertyChanged != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:       PropertyChanged(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:          &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:          &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedEventArgs(info)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:       );
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14: #endregion&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And then change the property code in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ObservableCollection&amp;lt;Customer&amp;gt; ListOfCustomers {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:     
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:     &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; listOfCustomers; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (listOfCustomers != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:             listOfCustomers = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:             NotifyPropertyChanged("&lt;span style="color: #8b0000"&gt;ListOfCustomers&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now, everytime we are going to load something new into the collection, or we are going to use a &lt;strong&gt;view of the collection&lt;/strong&gt; the ViewModel will send a message in the view saying “Hey, look I changed something in the list, update the UI!!”.&lt;/p&gt;

&lt;h3&gt;Some XAML code.&lt;/h3&gt;

&lt;p&gt;Now we have the Commands, the Model and we need to bind them to the view.&lt;/p&gt;

&lt;p&gt;Loading the viewmodel into the view:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: ...
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #800000"&gt;vm&lt;/span&gt;=
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:    "&lt;span style="color: #ff0000"&gt;clr&lt;/span&gt;-&lt;span style="color: #ff0000"&gt;namespace&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;MVVM&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;ViewModel&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:    &lt;span style="color: #ff0000"&gt;assembly&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;MVVM.ViewModel&lt;/span&gt; /&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6: ...
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7: &amp;lt;&lt;span style="color: #ff0000"&gt;Window&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;DataContext&lt;/span&gt;&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:    &amp;lt;&lt;span style="color: #ff0000"&gt;vm&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;CustomersViewModel&lt;/span&gt;/&amp;gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9: &amp;lt;/&lt;span style="color: #ff0000"&gt;Window&lt;/span&gt;.&lt;span style="color: #ff0000"&gt;DataContext&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Binding one command to a Button:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"btnNew"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Command&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding Path = NewCommand}"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Binding the List to the ListView and assigning the selected customer:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ListView&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:   &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"lstCustomers"&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #80ff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:   &lt;span style="color: #ff0000"&gt;ItemsSource&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding Path=ListOfCustomers}"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #80ff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:   &lt;span style="color: #ff0000"&gt;SelectedItem&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding Path=SelectedCustomer}"&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #80ff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:   &lt;span style="color: #ff0000"&gt;SelectionMode&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Single"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:   &lt;span style="color: #ff0000"&gt;IsSynchronizedWithCurrentItem&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"True"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:   &lt;span style="color: #ff0000"&gt;HorizontalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Stretch"&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:   &lt;span style="color: #ff0000"&gt;VerticalAlignment&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Stretch"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:   &lt;span style="color: #ff0000"&gt;MinHeight&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"100"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The IsSynchronizedWithCurrentItem bind the listview and the selecteditem together.&lt;/p&gt;

&lt;p&gt;Now, what we should be able to do here is to Load the customers, press delete and wipe one or more then one. Then:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;If we close the window and we reopen it the Customer will re-appear again. &lt;/li&gt;

  &lt;li&gt;If we commit all the changes with the SaveCommand and the we close and re-open the window, the Customer will not be there anymore. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this lesson we will see only how to implement the search function. In the next one we will see each single command in details.&lt;/p&gt;

&lt;p&gt;The user types some text and after that he searches for a result.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; FindCustomers() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:    &lt;span style="color: #008000"&gt;//If there is no text, prompt an error&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:    &lt;span style="color: #008000"&gt;//In the future this will be a XAML trigger&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SearchText == &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Empty || &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SearchText == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:         NavigationActions.ShowError("&lt;span style="color: #8b0000"&gt;Search Customers.&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;Please enter some text ...&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:    &lt;span style="color: #008000"&gt;//Keep the search text and build a dynamic query for the DAL&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:     ListOfCustomers = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ObservableCollection&amp;lt;Customer&amp;gt;(
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:         repository.GetCustomersByQuery(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:         p =&amp;gt; p.CompanyName.StartsWith(SearchText)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12:         || p.FirstName.StartsWith(SearchText)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13:         || p.LastName.StartsWith(SearchText)));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;At this point we will have a first final search solution like these screenshots:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial07theListsearch_C352/image_4.png" rel="lightbox[Tutorial07]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="left" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial07theListsearch_C352/image_thumb_4.png" width="260" height="191" /&gt;&lt;/a&gt; &lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial07theListsearch_C352/image_5.png" rel="lightbox[Tutorial07]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial07theListsearch_C352/image_thumb_5.png" width="260" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p /&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/MVVM" rel="tag"&gt;MVVM&lt;/a&gt; &lt;a href="http://technorati.com/tag/Model View ViewModel" rel="tag"&gt;Model View ViewModel&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/72.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hAzBg7hIbNw:MVMBQg_l8OQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hAzBg7hIbNw:MVMBQg_l8OQ:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hAzBg7hIbNw:MVMBQg_l8OQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=hAzBg7hIbNw:MVMBQg_l8OQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hAzBg7hIbNw:MVMBQg_l8OQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=hAzBg7hIbNw:MVMBQg_l8OQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hAzBg7hIbNw:MVMBQg_l8OQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=hAzBg7hIbNw:MVMBQg_l8OQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/hAzBg7hIbNw" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/07/03/wpf-and-mvvm-tutorial-07-the-list-search.aspx</guid>
            <pubDate>Fri, 03 Jul 2009 19:01:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/72.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/07/03/wpf-and-mvvm-tutorial-07-the-list-search.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/72.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/72.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/07/03/wpf-and-mvvm-tutorial-07-the-list-search.aspx</feedburner:origLink></item>
        <item>
            <title>WPF and MVVM tutorial 06, start up form.</title>
            <category>WPF</category>
            <category>Design Pattern</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/n5KbgWT5DYk/wpf-and-mvvm-tutorial-06-start-up-form.aspx</link>
            <description>&lt;p&gt;Today we are going to create the start-up form of our project and use the first ViewModel to run the application logic.&lt;/p&gt;  &lt;p&gt;The result we want to obtain will be:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial06startupform_BE33/image.png" rel="lightbox[Tutorial06]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial06startupform_BE33/image_thumb.png" width="260" height="245" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The View Model for the Startup form.&lt;/p&gt;  &lt;p&gt;In our project, let’s go to the ViewModel section and create a new class. This class will inherit from the basic View Model class like the code below:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; StartViewModel : ViewModel {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; StartViewModel() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we need to create 2 commands that we will then associate to two buttons in our XAML form. One will start the application and one will shut-down the application.&lt;/p&gt;

&lt;p&gt;This is the implementation we need to do in our ViewModel in order to create the Relay Command:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ViewCommand startCommand;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ViewCommand StartCommand {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:     &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:         &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (startCommand == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:             startCommand = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ViewCommand
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:                  (param =&amp;gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.StartApplication());
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; startCommand;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we need a delegate for the relay command in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; StartApplication() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:   NavigationActions.OpenCustomersView();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The first XAML Form of our Application.&lt;/p&gt;

&lt;p&gt;I am not a guru in windows design, especially the fancy UI but the final project will have a startup form like this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial06startupform_BE33/image_3.png" rel="lightbox[Tutorial06]"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial06startupform_BE33/image_thumb_3.png" width="260" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;First of all add a new XAML form into the UI layer and then let’s see at the XAML code:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Window&lt;/span&gt; &lt;span style="color: #ff0000"&gt;x&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;Class&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"MVVM.WPFView.Start"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:     &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:     &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;x&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;:&lt;span style="color: #ff0000"&gt;vm&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"clr-namespace:MVVM.ViewModel;assembly=MVVM.ViewModel"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:         &lt;span style="color: #ff0000"&gt;Title&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"MVVM AdventureWorks Application."&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:         &lt;span style="color: #ff0000"&gt;Height&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"500"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"500"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:         &lt;span style="color: #ff0000"&gt;WindowStartupLocation&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"CenterScreen"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;WindowState&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Normal"&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:         &lt;span style="color: #ff0000"&gt;WindowStyle&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"None"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;If you look at the line 4, we added a reference to our viewmodel namespace. In this way we can use in a declarative way the objects in the viewmodel namespace, directly into XAML (I personally hate to use procedural code into XAML!)&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1:     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Window.DataContext&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;vm&lt;/span&gt;:&lt;span style="color: #800000"&gt;StartViewModel&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:     &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Window.DataContext&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we add as a resource, the StartViewModel view model into our Window. In this way when the window will load the XAML declaration will inform the CLR to load a default instance of our view model.&lt;/p&gt;

&lt;p&gt;Now let’s view the two buttons:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Button&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"btnStart"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Margin&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"5"&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: &lt;span style="color: #ff0000"&gt;IsDefault&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"True"&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: &lt;span style="color: #ff0000"&gt;Command&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"{Binding Path=StartCommand}"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The binding will be the &lt;strong&gt;Relay Command&lt;/strong&gt; we have previously created in the View model class. Easy right?&lt;/p&gt;

&lt;p&gt;Now, the next step will be to build the View model to show all the customers. Then we will build some specific command for the C.R.U.D. operations.&lt;/p&gt;

&lt;p&gt;Stay tuned!&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/MVVM" rel="tag"&gt;MVVM&lt;/a&gt; &lt;a href="http://technorati.com/tag/Model View ViewModel" rel="tag"&gt;Model View ViewModel&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/71.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=n5KbgWT5DYk:px79Abton6s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=n5KbgWT5DYk:px79Abton6s:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=n5KbgWT5DYk:px79Abton6s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=n5KbgWT5DYk:px79Abton6s:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=n5KbgWT5DYk:px79Abton6s:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=n5KbgWT5DYk:px79Abton6s:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=n5KbgWT5DYk:px79Abton6s:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=n5KbgWT5DYk:px79Abton6s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/n5KbgWT5DYk" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/06/17/wpf-and-mvvm-tutorial-06-start-up-form.aspx</guid>
            <pubDate>Wed, 17 Jun 2009 16:31:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/71.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/06/17/wpf-and-mvvm-tutorial-06-start-up-form.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/71.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/71.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/06/17/wpf-and-mvvm-tutorial-06-start-up-form.aspx</feedburner:origLink></item>
        <item>
            <title>WPF and MVVM tutorial 05, The basic ViewModel.</title>
            <category>WPF</category>
            <category>Design Pattern</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/3Mvp1wI_SV0/wpf-and-mvvm-tutorial-05-the-basic-viewmodel.aspx</link>
            <description>&lt;p&gt;As we saw in the previous posts, a view model should be an abstract implementation of what the view needs to show about the model. We should implement an observable collection of something, we should implement an INotifyPropertyChanged interface and we should have a collection of &lt;a href="http://blog.raffaeu.com/archive/2009/06/15/wpf-and-mvvm-tutorial-04-the-commands.aspx" target="_blank"&gt;RelayCommands&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;For these reasons, it simply to understand that we need a basic abstract ViewModel class, just to recycle some code.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial05ThebasicViewModel_7961/image.png" rel="lightbox[Tutorial05]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial05ThebasicViewModel_7961/image_thumb.png" width="260" height="235" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;The Basic View Model.&lt;/h3&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; MVVM.ViewModel {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ViewModel:INotifyPropertyChanged,IDisposable {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:         INavigationActions navigator;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ViewModel() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:             navigator = Application.Current &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; INavigationActions;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (navigator != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:                 navigator.PropertyChanged += application_PropertyChanged;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:         }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13:         &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; application_PropertyChanged(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, PropertyChangedEventArgs e) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "&lt;span style="color: #8b0000"&gt;View&lt;/span&gt;")
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15:                 OnPropertyChanged("&lt;span style="color: #8b0000"&gt;View&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 16:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 17: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 18:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; INavigationActions NavigationActions {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 19:             &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 20:                 &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; navigator;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 21:             }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 22:             &lt;span style="color: #0000ff"&gt;set&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 23:                 &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (navigator != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 24:                     SetAction(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 25:                     OnPropertyChanged("&lt;span style="color: #8b0000"&gt;NavigationActions&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 26:                 }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 27:             }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 28:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 29: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 30:         &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetAction(INavigationActions &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 31:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (navigator != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 32:                 navigator.PropertyChanged -= application_PropertyChanged;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 33:             navigator = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 34:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (navigator != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 35:                 navigator.PropertyChanged += application_PropertyChanged;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 36:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 37: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 38:         #region INotifyPropertyChanged Members
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 39:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 40:         &lt;span style="color: #808080"&gt;/// Raised when a property has a new value&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 41:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 42:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 43:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 44:         &lt;span style="color: #808080"&gt;/// Raise the event&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 45:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 46:         &lt;span style="color: #808080"&gt;/// &amp;lt;param name="propertyName"&amp;gt;Property name that has new value&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 47:         &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 48:             PropertyChangedEventHandler handler = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.PropertyChanged;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 49:             &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (handler != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 50:                 var e = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedEventArgs(propertyName);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 51:                 handler(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, e);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 52:             }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 53:         }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 54:         #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 55: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 56:         #region IDisposable Members
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 57:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 58:         &lt;span style="color: #808080"&gt;/// Implementation of the dispose method&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 59:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 60:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispose() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 61:             &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.OnDispose();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 62:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 63:         &lt;span style="color: #808080"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 64:         &lt;span style="color: #808080"&gt;/// The child class should implement a personal dispose procedure&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 65:         &lt;span style="color: #808080"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 66:         &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnDispose() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 67:             &lt;span style="color: #008000"&gt;//do nothing because abstract&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 68:         }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 69: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 70:         #endregion
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 71:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 72: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;A small summary of our code:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;An implementation of the INotifyPropertyChanged that we can use in the concrete views. &lt;/li&gt;

  &lt;li&gt;An implementation of the IDisposable in order to &lt;strong&gt;clean&lt;/strong&gt; our objects like collections and repositories. &lt;/li&gt;

  &lt;li&gt;An INavigator interface to implement the navigation of our application. In this case I am using the &lt;a href="http://www.codeproject.com/KB/WPF/CompositeWpfApp.aspx" target="_blank"&gt;navigator pattern for composite WPF applications&lt;/a&gt;. Beware because this is &lt;strong&gt;my implementation&lt;/strong&gt; for the navigation but it depends on how you design your app (multi-win, tab, MDI). &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;The INavigator implementation.&lt;/h3&gt;

&lt;p&gt;The are thousands of ways to implement a navigator engine. The only common purpose in MVVM is that the View Model doesn’t know the View but the View knows the View Model. So in our example which part of the View can interact with the application and doesn’t need to know the View Model? The app.xaml file!&lt;/p&gt;

&lt;p&gt;My idea is this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial05ThebasicViewModel_7961/image_3.png" rel="lightbox[Tutorial05]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial05ThebasicViewModel_7961/image_thumb_3.png" width="260" height="197" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We will have a simple interface in the &lt;strong&gt;ViewModel namespace&lt;/strong&gt; which will identify the &lt;strong&gt;navigation commands&lt;/strong&gt; we want to execute:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; INavigationActions:INotifyPropertyChanged 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:     &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OpenCustomersView();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OpenCustomerView();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:     &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OpenOrdersView();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:     &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OpenOrderView();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:     &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CloseCurrentView();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:     &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CloseApplication();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:     &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; QueryConfirmation(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; title, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; message);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:     &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShowError(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; title, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; message);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;In this way we can call everything from our viewmodel that doesn’t know the view.&lt;/p&gt;

&lt;p&gt;Now we just need to implement the view in the Application file in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; partial &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; App : Application,INavigationActions,INotifyPropertyChanged {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:     #region INavigationActions Members
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OpenCustomersView() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:         CustomersView customersView = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CustomersView();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:         customersView.Show();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OpenCustomerView() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OpenOrdersView() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 16: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 17:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OpenOrderView() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 18: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 19:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 20: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 21:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CloseCurrentView() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 22: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 23:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 24: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 25:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CloseApplication() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 26:         Application.Current.Shutdown();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 27:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 28: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 29:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; QueryConfirmation(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; title, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; message) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 30:         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; MessageBox.Show(title, message, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 31:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 32: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 33:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShowError(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; title, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; message) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 34:         MessageBox.Show(title, message, MessageBoxButton.YesNo, MessageBoxImage.Error);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 35:     }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;And there we go!!&lt;/p&gt;

&lt;p&gt;Ops I forgot to mention that in the basic View Model we need to handle the INavigation&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ViewModel() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2:     navigator = Application.Current &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; INavigationActions;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:     &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (navigator != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:         navigator.PropertyChanged 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:         += application_PropertyChanged;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;For the rest you need to wait the next tutorial!!&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/MVVM" rel="tag"&gt;MVVM&lt;/a&gt; &lt;a href="http://technorati.com/tag/Model View ViewModel" rel="tag"&gt;Model View ViewModel&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/70.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3Mvp1wI_SV0:HaGbqXPoqPg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3Mvp1wI_SV0:HaGbqXPoqPg:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3Mvp1wI_SV0:HaGbqXPoqPg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=3Mvp1wI_SV0:HaGbqXPoqPg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3Mvp1wI_SV0:HaGbqXPoqPg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=3Mvp1wI_SV0:HaGbqXPoqPg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3Mvp1wI_SV0:HaGbqXPoqPg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=3Mvp1wI_SV0:HaGbqXPoqPg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/3Mvp1wI_SV0" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/06/16/wpf-and-mvvm-tutorial-05-the-basic-viewmodel.aspx</guid>
            <pubDate>Tue, 16 Jun 2009 21:11:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/70.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/06/16/wpf-and-mvvm-tutorial-05-the-basic-viewmodel.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/70.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/70.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/06/16/wpf-and-mvvm-tutorial-05-the-basic-viewmodel.aspx</feedburner:origLink></item>
        <item>
            <title>WPF and MVVM tutorial 04, The Commands.</title>
            <category>WPF</category>
            <category>C#</category>
            <category>Design Pattern</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/jpQSwbHg_aU/wpf-and-mvvm-tutorial-04-the-commands.aspx</link>
            <description>&lt;p&gt;In the previous posts we saw the basic of our project, &lt;a href="http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-02-the-model.aspx" target="_blank"&gt;the model&lt;/a&gt; (domain entities) and a &lt;a href="http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-03-the-user-repository.aspx" target="_blank"&gt;simple repository&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Note: please note that the sample I wrote about an agnostic UnitOfWork is just to show you a simple pattern to handle L2S but it can be done better.&lt;/em&gt;&lt;/p&gt;  &lt;h3&gt;The ViewModel.&lt;/h3&gt;  &lt;p&gt;What is the view model? Well the simplest explanation is enclosed in this definition: the view model should be the datacontext of our view. It should provide the commands, the observable collections used in the view and the error logic.&lt;/p&gt;  &lt;p&gt;Before starting to view how to build the basic abstract class for the viewmodel I want to talk about the Relay Command and the Routed Command and their differences.&lt;/p&gt;  &lt;h3&gt;Routed or Relay command?&lt;/h3&gt;  &lt;p&gt;I have found a useful &lt;a href="http://joshsmithonwpf.wordpress.com/2008/03/18/understanding-routed-commands/" target="_blank"&gt;explanation here&lt;/a&gt;, in the Josh Smith blog. Routed events are events designed to work in a tree of elements. When a user click the text over a button, the even travels over the tree until it will find the Click event of the chrome button.  This is how a button implements a routed events:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Button:ButtonBase
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3:    &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Button()
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:    {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5:       Button.ClickEvent = EventManager.RegistedRoutedEvent
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6:          ("&lt;span style="color: #8b0000"&gt;Click&lt;/span&gt;", RoutingStrategy.Bubble,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7:           &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(RoutedEventHandler), &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Button));
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; RoutedEventHandler Click
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10:    {
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11:       add { AddHandler(Button.ClickEvent,&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
&lt;/pre&gt;&lt;pre style="background-color: #ffff80; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12:       remove { RemoveHandler(Button.ClickEvent,&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13:    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14:    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15:       OnMouseLeftButtonDown(MouseButtonEventArgs e){
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 16:       RaiseEvent(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RoutedEventArgs(Button.ClickEvent,&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 17:    }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 18: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;strong&gt;commands&lt;/strong&gt; in WPF represent a more independent action from their user interface. Also WPF and NET expose a default set of commands that we can easily handle in our application, like:&lt;/p&gt;

&lt;p&gt;Application command, ComponentCommand, MediaCommand, NavigationCommand and EditingCommand.&lt;/p&gt;

&lt;p&gt;They inherit all, from the &lt;strong&gt;ICommand&lt;/strong&gt; interface. So for each command you want to implement, it should inherit from ICommand in this way:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  1: #region ICommand Members
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  2: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  3: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; CanExecute(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter) {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  4:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _canExecute == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; ? &lt;span style="color: #0000ff"&gt;true&lt;/span&gt; : _canExecute(parameter);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  5: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  6: 
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  7: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; EventHandler CanExecuteChanged {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  8:     add { CommandManager.RequerySuggested += &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt;  9:     remove { CommandManager.RequerySuggested -= &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 10: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 11: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 12: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Execute(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; parameter) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 13:     _execute(parameter);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 14: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 15: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 13px"&gt; 16: #endregion&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;So it becomes simple to understand that we should have a View Model abstract class that contains an abstract implementation of a collection of ICommand. Then we can inherits each view model from this one!&lt;/p&gt;

&lt;p&gt;So our conclusion is that:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The key difference is that RoutedCommand is an ICommand implementation that uses a RoutedEvent to route through the tree until a CommandBinding for the command is found, while RelayCommand does no routing and instead directly executes some delegate. In a M-V-VM scenario a RelayCommand (DelegateCommand in Prism) is probably the better choice all around.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The final implementation of the Relay command should be something like:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial04TheCommands_C781/image.png" rel="lightbox[Tutorial4]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandMVVMtutorial04TheCommands_C781/image_thumb.png" width="195" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In the next tutorial we will see how to build the abstract layer for a basic view model with a basic collection of relay commands.&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/MVVM" rel="tag"&gt;MVVM&lt;/a&gt; &lt;a href="http://technorati.com/tag/Model View ViewModel" rel="tag"&gt;Model View ViewModel&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/69.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=jpQSwbHg_aU:VocrN2AYz0c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=jpQSwbHg_aU:VocrN2AYz0c:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=jpQSwbHg_aU:VocrN2AYz0c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=jpQSwbHg_aU:VocrN2AYz0c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=jpQSwbHg_aU:VocrN2AYz0c:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=jpQSwbHg_aU:VocrN2AYz0c:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=jpQSwbHg_aU:VocrN2AYz0c:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=jpQSwbHg_aU:VocrN2AYz0c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/jpQSwbHg_aU" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/06/15/wpf-and-mvvm-tutorial-04-the-commands.aspx</guid>
            <pubDate>Mon, 15 Jun 2009 17:08:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/69.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/06/15/wpf-and-mvvm-tutorial-04-the-commands.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/69.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/69.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/06/15/wpf-and-mvvm-tutorial-04-the-commands.aspx</feedburner:origLink></item>
        <item>
            <title>Technorati test.</title>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/4A38ViUskiY/technorati-test.aspx</link>
            <description>&lt;p&gt;kyrprtqfs9&lt;/p&gt; &lt;a href="http://technorati.com/claim/kyrprtqfs9" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;img src="http://blog.raffaeu.com/aggbug/68.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=4A38ViUskiY:PBTZFwD_xls:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=4A38ViUskiY:PBTZFwD_xls:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=4A38ViUskiY:PBTZFwD_xls:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=4A38ViUskiY:PBTZFwD_xls:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=4A38ViUskiY:PBTZFwD_xls:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=4A38ViUskiY:PBTZFwD_xls:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=4A38ViUskiY:PBTZFwD_xls:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=4A38ViUskiY:PBTZFwD_xls:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/4A38ViUskiY" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/06/11/technorati-test.aspx</guid>
            <pubDate>Thu, 11 Jun 2009 12:22:33 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/68.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/06/11/technorati-test.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/68.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/68.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/06/11/technorati-test.aspx</feedburner:origLink></item>
        <item>
            <title>WPF and MVVM tutorial 03, The user repository.</title>
            <category>Design Pattern</category>
            <category>WPF</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/6eIWjGOqs7E/wpf-and-vmmv-tutorial-03-the-user-repository.aspx</link>
            <description>&lt;p&gt;Before starting to view in depth our model, or to design the views, I want to complete the DAL layer. Now that we have our unit of work implementation and our data context we need to implement a couple of repositories.&lt;/p&gt;  &lt;p&gt;If you want to view how it should work a repository, I suggest &lt;a href="http://martinfowler.com/eaaCatalog/repository.html" target="_blank"&gt;this interesting article from Martin Fowler&lt;/a&gt;. The &lt;strong&gt;presenter&lt;/strong&gt; &lt;strong&gt;should be:&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;The Flow of our application.&lt;/h3&gt;  &lt;p&gt;During the time I saw different repositories. One for each entity, one for each View and so on. My approach, usually, is to use a relationship of 1-to-1 from the view and the repository. So in our case we will have:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial03Therepository_8F3C/image.png" rel="lightbox[Tutorial3]"&gt;&lt;img style="border-right-width: 0px; margin: 2px 10px 5px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial03Therepository_8F3C/image_thumb.png" width="176" height="260" /&gt;&lt;/a&gt; 1 - The user opens the program and has to decide (search a customer, view all customers)&lt;/p&gt;  &lt;p&gt;2 – A list will be presented to the user (filtered or not) and he will have to select &lt;strong&gt;one customer&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;3 – A third view will show the details of the user, with two sub-view (address and order details).&lt;/p&gt;  &lt;p&gt;So this is the flow that we will follow. For these reasons, you will easily understand that we need a couple of repositories: A) a user repository, B) an order repository.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h3&gt;The User repository.&lt;/h3&gt;  &lt;p&gt;The user repository has to give us a way to execute any kind of CRUD operation against our database. So we should have something like:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial03Therepository_8F3C/image_3.png" rel="lightbox[Tutorial3]"&gt;&lt;img style="border-right-width: 0px; margin: 2px 10px 5px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial03Therepository_8F3C/image_thumb_3.png" width="257" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Here there are some basic operations we must be able to accomplish with our repository.&lt;/p&gt;  &lt;p&gt;1) Get a specific Customer or Get all of them.&lt;/p&gt;  &lt;p&gt;2) Add, Update or Drop a Customer.&lt;/p&gt;  &lt;p&gt;3)Commit the changes to the data-model.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;The code is very simple. First of all we need to create a &lt;strong&gt;sealed repository&lt;/strong&gt;, so that nobody will &lt;em&gt;&lt;strong&gt;play&lt;/strong&gt; with it&lt;strong&gt;, &lt;/strong&gt;&lt;/em&gt;for this purpose there is the IUnitOfWOrk interface …&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;sealed&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CustomerRepository {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2:     &lt;span style="color: #008000"&gt;//Create an istance (it's static) of our Unit of Work&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; IUnitOfWork _service;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:     &lt;span style="color: #008000"&gt;//but let's give it a read-only access&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IUnitOfWork Service {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _service; }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     &lt;span style="color: #008000"&gt;//create a new istance of the Unit of work&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CustomerRepository() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:         _service = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UnitOfWork();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:     }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Then we need to implement the custom methods to retrieve the information we need from our model. Fortunately we have a &lt;strong&gt;&lt;em&gt;generic unit of work&lt;/em&gt;&lt;/strong&gt; so the code behind it’s very very simple!&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #008000"&gt;//Add a new customer&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddCustomer(Customer _customer) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     Service.Add&amp;lt;Customer&amp;gt;(_customer);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5: &lt;span style="color: #008000"&gt;//Drop an existing one&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteCustomer(Customer _customer) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:     Service.Delete&amp;lt;Customer&amp;gt;(_customer);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9: &lt;span style="color: #008000"&gt;//Update an existing dirty customer&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UpdateCustomer(Customer _customer) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:     Service.Update&amp;lt;Customer&amp;gt;(_customer);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13: Get a specific customer
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Customer GetCustomer(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 15:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Service.GetById&amp;lt;Customer&amp;gt;(p =&amp;gt; p.CustomerID == id);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 16: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 17: &lt;span style="color: #008000"&gt;//Get all of them&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 18: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IList&amp;lt;Customer&amp;gt; GetAllCustomers() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 19:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Service.GetAll&amp;lt;Customer&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 20: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;We should also implement a &lt;strong&gt;&lt;em&gt;filtered GetAllCustomers&lt;/em&gt;&lt;/strong&gt; but we will use the View Model to do that in our example.&lt;/p&gt;

&lt;h3&gt;Customer class diagram.&lt;/h3&gt;

&lt;p&gt;Now we are pretty fine with our Customer model. What we have know is a model, a repository and a CRUD implementation for the customer and the related entities (Address and so on …). The final result in our DAL layer is this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial03Therepository_8F3C/image_4.png" rel="lightbox[Tutorial3]"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial03Therepository_8F3C/image_thumb_4.png" width="260" height="175" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great we can already build now 3 views (CustomersView, CustomerView, FilteredCustomersView) just by using one repository. TO be honest we should be able to do everything but I want to keep separate the Order section.&lt;/p&gt;

&lt;p&gt;In the next step I will give an overview of the ViewModel, and the View interaction, then we will start to build the views and then the relative ViewModels.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;font color="#808000"&gt;Ndr. I saw that this series of articles is being read by a nice number of people. Please post any ideas, suggestion or whatever you think about … I will appreciate.&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/MVVM" rel="tag"&gt;MVVM&lt;/a&gt; &lt;a href="http://technorati.com/tag/Model View ViewModel" rel="tag"&gt;Model View ViewModel&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/67.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=6eIWjGOqs7E:eAPOR1v8Wqw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=6eIWjGOqs7E:eAPOR1v8Wqw:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=6eIWjGOqs7E:eAPOR1v8Wqw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=6eIWjGOqs7E:eAPOR1v8Wqw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=6eIWjGOqs7E:eAPOR1v8Wqw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=6eIWjGOqs7E:eAPOR1v8Wqw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=6eIWjGOqs7E:eAPOR1v8Wqw:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=6eIWjGOqs7E:eAPOR1v8Wqw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/6eIWjGOqs7E" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-03-the-user-repository.aspx</guid>
            <pubDate>Fri, 05 Jun 2009 19:18:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/67.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-03-the-user-repository.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/67.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/67.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-03-the-user-repository.aspx</feedburner:origLink></item>
        <item>
            <title>WPF and MVVM tutorial 02, The model.</title>
            <category>WPF</category>
            <category>Design Pattern</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/OkMJDhdZnl4/wpf-and-vmmv-tutorial-02-the-model.aspx</link>
            <description>&lt;p&gt;In the &lt;a href="http://blog.raffaeu.com/archive/2009/06/03/wpf-and-vmmv-tutorial-01-introduction.aspx" target="_blank"&gt;first part&lt;/a&gt; of this tutorial we saw the MVVM model and how it works.&lt;/p&gt;  &lt;p&gt;In this part of our tutorial we will work directly with the Entity Model and LinqToSQL. I am using a database-first approach so in my opinion using LinqToSQL will be better then Entitiy Framework. I am going also to show you an easy way to build a custom Unit Of Work to manage the context status with Linq 2 SQL.&lt;/p&gt;  &lt;h3&gt;The Visual Studio Project.&lt;/h3&gt;  &lt;p&gt;First of all open a blank Visual Studio solution, I called it &lt;strong&gt;WPF.Tutorial.VMMV&lt;/strong&gt;. Add two projects on it: 1) WPF Application …UI and 2) Class Library (…DAL).&lt;/p&gt;  &lt;p&gt;The final layout should be this one (in my picture the model is already inside).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial02Themodel_A958/NewPicture8.png" rel="lightbox[Tutorial2]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="New Picture (8)" border="0" alt="New Picture (8)" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial02Themodel_A958/NewPicture8_thumb.png" width="260" height="250" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;The Data model.&lt;/h3&gt;  &lt;p&gt;If you have installed the Adventure Works database in the past you already know what I am talking about. The model I will use in the tutorial will come up with this layout:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial02Themodel_A958/NewPicture7.png" rel="lightbox[Tutorial2]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="New Picture (7)" border="0" alt="New Picture (7)" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial02Themodel_A958/NewPicture7_thumb.png" width="260" height="182" /&gt;&lt;/a&gt;We will have a customer with the personal information and the related orders with the order information. &lt;/p&gt;  &lt;p&gt;Go into the DAL project and from the menu choose &lt;strong&gt;add new file –&amp;gt; LinqToSQL&lt;/strong&gt; and call it DataModel. Now you need to connect you data model into your AW database and drag in the design pane the tables you need. At the end you should come up with the same layout I have in the previous picture.&lt;/p&gt;  &lt;h3&gt;The Unit of Work.&lt;/h3&gt;  &lt;p&gt;If you do not what I am talking about, this is the &lt;a href="http://www.martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank"&gt;explanation by Martin Fowler&lt;/a&gt;. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;A Unit of Work keeps track of everything you do during a business transaction that can affect the database. When you're done, it figures out everything that needs to be done to alter the database as a result of your work.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Of course with LinqToSQL we do not need a Unit of Work because L2S by itself is the data context, but because it is not able to manage the disposing in a good way, here are my 2 cents about.&lt;/p&gt;  &lt;p&gt;We need a contract, in this way an interface in the DAL that will implement the Unit of Work:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial02Themodel_A958/image.png" rel="lightbox[Tutorial2]"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial02Themodel_A958/image_thumb.png" width="260" height="249" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;First of all let’s build the C.R.U.D. implementation into a simple interface. In this case I am going to use the generics and the Linq expression because my project will work only with Linq so I do not need an high level of abstraction:&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; WPF.Tutorials.VMMV.DAL {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IUnitOfWork {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6:         &lt;span style="color: #008000"&gt;//Basic C.R.U.D. operations&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:         &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Add&amp;lt;T&amp;gt;(T _entity) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:         &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Delete&amp;lt;T&amp;gt;(T _entity) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:         &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Update&amp;lt;T&amp;gt;(T _entity) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:         &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Commit();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:         &lt;span style="color: #008000"&gt;//Basic Select operations&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12:         IList&amp;lt;T&amp;gt; GetAll&amp;lt;T&amp;gt;() where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13:         T GetById&amp;lt;T&amp;gt;(Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt; _condition) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14:     }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 15: }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we need the real Unit of Work that will inherit from our contract. We want also to inherit from IDisposable because otherwise we will not be able to keep alive our datacontext during the crud operations.&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4: &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5: 
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6: &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; WPF.Tutorials.VMMV.DAL {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7:     &lt;span style="color: #008000"&gt;//Inherits IUnitOfWork and IDisposable&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; UnitOfWork:IUnitOfWork,IDisposable {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:         &lt;span style="color: #008000"&gt;//A Static instance of the Linq Data Context&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10:         &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; DataModelDataContext _service;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11:         &lt;span style="color: #008000"&gt;//The default constructor&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12:         &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; UnitOfWork() {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13:             _service = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataModelDataContext();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14:         }&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now, the second step is to &lt;strong&gt;&lt;em&gt;translate&lt;/em&gt;&lt;/strong&gt; the UoW in something readable for Linq:&lt;/p&gt;

&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 480px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #008000"&gt;//Add a new entity to the model&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  2: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Add&amp;lt;T&amp;gt;(T _entity) where T: &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  3:     var table = _service.GetTable&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  4:     table.InsertOnSubmit(_entity);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  5: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  6: &lt;span style="color: #008000"&gt;//Delete an existing entity from the model&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  7: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Delete&amp;lt;T&amp;gt;(T _entity) where T: &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  8:     var table = _service.GetTable&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  9:     table.DeleteOnSubmit(_entity);
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 10: }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 11: &lt;span style="color: #008000"&gt;//Update an existing entity&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 12: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Update&amp;lt;T&amp;gt;(T _entity) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 13:     var table = _service.GetTable&amp;lt;T&amp;gt;();
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 14:     table.Attach(_entity,&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 15: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 16: &lt;span style="color: #008000"&gt;//Commit all the pending changes in the data context&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 17: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Commit() {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 18:     _service.SubmitChanges();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 19: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 20: &lt;span style="color: #008000"&gt;//Get the entire Entity table&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 21: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IList&amp;lt;T&amp;gt; GetAll&amp;lt;T&amp;gt;()where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 22:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _service.GetTable&amp;lt;T&amp;gt;().ToList();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 23: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 24: &lt;span style="color: #008000"&gt;//Get the first occurence that reflect the Linq Query&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 25: &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; T GetById&amp;lt;T&amp;gt;(Func&amp;lt;T, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt; _condition) where T : &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 26:     &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _service.GetTable&amp;lt;T&amp;gt;().Where(_condition).FirstOrDefault();
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 27: }
&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt; 28: &lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we have a complete Unit of Work that we will use in each repository. Ops I forgot to mention that we will not have a real repository in our solution but a view model …&lt;/p&gt;

&lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/MVVM" rel="tag"&gt;MVVM&lt;/a&gt; &lt;a href="http://technorati.com/tag/Model View ViewModel" rel="tag"&gt;Model View ViewModel&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/66.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=OkMJDhdZnl4:l22673PAQFc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=OkMJDhdZnl4:l22673PAQFc:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=OkMJDhdZnl4:l22673PAQFc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=OkMJDhdZnl4:l22673PAQFc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=OkMJDhdZnl4:l22673PAQFc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=OkMJDhdZnl4:l22673PAQFc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=OkMJDhdZnl4:l22673PAQFc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=OkMJDhdZnl4:l22673PAQFc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/OkMJDhdZnl4" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-02-the-model.aspx</guid>
            <pubDate>Fri, 05 Jun 2009 13:02:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/66.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-02-the-model.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/66.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/66.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/06/05/wpf-and-vmmv-tutorial-02-the-model.aspx</feedburner:origLink></item>
        <item>
            <title>WPF and MVVM tutorial 01, Introduction.</title>
            <category>WPF</category>
            <category>Silverlight</category>
            <category>Design Pattern</category>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/rxE5adGZfw4/wpf-and-vmmv-tutorial-01-introduction.aspx</link>
            <description>&lt;p&gt;With Microsoft WPF technology, a new pattern is born and is going to be called &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" target="_blank"&gt;MVVM&lt;/a&gt; (Model View ViewModel). This pattern is an hybrid from the old MVC and the old MVP patterns. Why a new pattern for the presentation?&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;First of all WPF technology is giving us a kind of technology that can completely change the approach to design and code the UI. With the VMMV we can completely design an agnostic UI that doesn’t know the Model we are going to pass to it. &lt;/li&gt;    &lt;li&gt;Recycle, I will show you in this tutorial how to simply convert a WPF application into a Silverlight app. &lt;/li&gt;    &lt;li&gt;Better delegation and better design for a real n-tier application. In this example we will use LinqToSQL and WPF to build a complete n-tier application with the VMMV. &lt;/li&gt;    &lt;li&gt;Something that I do not like, TESTING THE UI!! Yes we can test the UI with WPF and VMMV combination. &lt;/li&gt;    &lt;li&gt;Abstractation. Now the view can be really abstract and you can use just a generic.xaml file and then give a style template to your model. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;This is the schema (in my opinion) on how it should work an application with WPF and the VMMV implementation:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial01TheDataModel_F169/image.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://blog.raffaeu.com/Images/blog_raffaeu_com/WindowsLiveWriter/WPFandVMMVtutorial01TheDataModel_F169/image_thumb.png" width="221" height="260" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;MODEL&lt;/strong&gt;: anyone that has already worked on an n-tier application knows what it is. The model is the group of entities that will be exposed. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;VIEW&lt;/strong&gt;: the view is the graphical code XAML used to generate the UI, nothing more then that. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;VIEWMODEL&lt;/strong&gt;: the model for the view … or … the view for the model?! Anyway is a model of the view. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Before starting this tutorial I suggest you to download:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E" target="_blank"&gt;Visual Studio 2008 SP1&lt;/a&gt; and &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ab99342f-5d1a-413d-8319-81da479ab0d7" target="_blank"&gt;NET Framework 3.5 SP1&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;The complete &lt;a href="http://msftdbprodsamples.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=18407" target="_blank"&gt;AdventureWork&lt;/a&gt; database template for SQL &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/express/sql/default.aspx" target="_blank"&gt;SQL Express 2008&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The next tutorial will show you how to create a simple DAL layer with LinQtoSQL and how we can implement the &lt;a href="http://www.martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank"&gt;Unit of Work&lt;/a&gt; pattern to build a simple but solid data layer for our application.&lt;/p&gt;  &lt;p&gt;You can also download the &lt;a href="http://wpf.codeplex.com/Wiki/View.aspx?title=WPF%20Model-View-ViewModel%20Toolkit" target="_blank"&gt;Visual Studio template here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Tags: &lt;a href="http://technorati.com/tag/MVVM" rel="tag"&gt;MVVM&lt;/a&gt; &lt;a href="http://technorati.com/tag/Model View ViewModel" rel="tag"&gt;Model View ViewModel&lt;/a&gt; &lt;a href="http://technorati.com/tag/WPF" rel="tag"&gt;WPF&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/65.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=rxE5adGZfw4:_QM_jLzRAGU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=rxE5adGZfw4:_QM_jLzRAGU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=rxE5adGZfw4:_QM_jLzRAGU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=rxE5adGZfw4:_QM_jLzRAGU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=rxE5adGZfw4:_QM_jLzRAGU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=rxE5adGZfw4:_QM_jLzRAGU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=rxE5adGZfw4:_QM_jLzRAGU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=rxE5adGZfw4:_QM_jLzRAGU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/rxE5adGZfw4" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/06/03/wpf-and-vmmv-tutorial-01-introduction.aspx</guid>
            <pubDate>Wed, 03 Jun 2009 20:41:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/65.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/06/03/wpf-and-vmmv-tutorial-01-introduction.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/65.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/65.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/06/03/wpf-and-vmmv-tutorial-01-introduction.aspx</feedburner:origLink></item>
        <item>
            <title>NET RIA Service, #Part1 install.</title>
            <category>Silverlight</category>
            <category>C#</category>
            <category>NET World</category>
            <link>http://feedproxy.google.com/~r/RaffaeuEnglishBlog/~3/igzJBmPZWmI/net-ria-service-part1-install.aspx</link>
            <description>&lt;p&gt;In these series of posts I want to show how easy is to work with Visual Studio 2010, Silverlight 3 beta and the NET RIA Service.&lt;/p&gt;  &lt;h4&gt;Prerequisites and tutorials.&lt;/h4&gt;  &lt;p&gt;First of all we need to know what is NET RIA Service and how they can help us to write better business RIA applications.&lt;/p&gt;  &lt;p&gt;NOTE: Unfortunately NET RIA will NOT work with the beta1 preview of Visual Studio 2010 so I recommend to use them into VS 2008 SP1.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/03/19/what-is-net-ria-services.aspx" target="_blank"&gt;Brad Adams and NET RIA Service overview&lt;/a&gt; has a very interesting post about the architecture of NET RIA Service.&lt;/p&gt;  &lt;p&gt;Then, you must also watch the &lt;a href="http://blogs.msdn.com/brada/archive/2009/03/17/mix09-building-amazing-business-applications-with-silverlight-3.aspx" target="_blank"&gt;web cast at the MIX 2009&lt;/a&gt;. This will give a real touch of this technology that I am loving!&lt;/p&gt;  &lt;p&gt;After all, you need now to work with the NET RIA service. I am going to write a series of posts about that, but you can also follow the tutorials over the web.&lt;/p&gt;  &lt;p&gt;In order to develop with Silverlight 3 beta you need:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Visual Studio 2008 SP1 or Visual Studio 2010 CTP &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=76bb3a07-3846-4564-b0c3-27972bcaabce&amp;amp;displaylang=en" target="_blank"&gt;NET RIA Services May 2009 preview&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://silverlight.net/getstarted/silverlight3/default.aspx" target="_blank"&gt;Silverlight 3&lt;/a&gt; runtime and toolkit &lt;/li&gt;    &lt;li&gt;Follow one of the &lt;a href="http://silverlight.net/learn/videocat.aspx?cat=12#sl3" target="_blank"&gt;numerous tutorial&lt;/a&gt; available &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you plan to work with Windows 7 and Visual Studio 2010, you can have a look also at my post on &lt;strong&gt;&lt;a href="http://blog.raffaeu.com/archive/2009/05/31/vmware-workstation-bridge-network-and-windows-7.aspx" target="_blank"&gt;How to RDP into a Windows 7 virtual machine&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;After that you will be able to follow my tutorials.&lt;/p&gt;&lt;img src="http://blog.raffaeu.com/aggbug/64.aspx" width="1" height="1" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=igzJBmPZWmI:enoPxJ2sEpc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=igzJBmPZWmI:enoPxJ2sEpc:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=igzJBmPZWmI:enoPxJ2sEpc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=igzJBmPZWmI:enoPxJ2sEpc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=igzJBmPZWmI:enoPxJ2sEpc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?i=igzJBmPZWmI:enoPxJ2sEpc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=igzJBmPZWmI:enoPxJ2sEpc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?a=igzJBmPZWmI:enoPxJ2sEpc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/RaffaeuEnglishBlog?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RaffaeuEnglishBlog/~4/igzJBmPZWmI" height="1" width="1"/&gt;</description>
            <dc:creator>Raffaeu</dc:creator>
            <guid isPermaLink="false">http://blog.raffaeu.com/archive/2009/05/31/net-ria-service-part1-install.aspx</guid>
            <pubDate>Sun, 31 May 2009 16:02:00 GMT</pubDate>
            <wfw:comment>http://blog.raffaeu.com/comments/64.aspx</wfw:comment>
            <comments>http://blog.raffaeu.com/archive/2009/05/31/net-ria-service-part1-install.aspx#feedback</comments>
            <wfw:commentRss>http://blog.raffaeu.com/comments/commentRss/64.aspx</wfw:commentRss>
            <trackback:ping>http://blog.raffaeu.com/services/trackbacks/64.aspx</trackback:ping>
        <feedburner:origLink>http://blog.raffaeu.com/archive/2009/05/31/net-ria-service-part1-install.aspx</feedburner:origLink></item>
    </channel>
</rss>
