<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8559115372310954339</id><updated>2024-08-31T21:08:53.594-07:00</updated><category term="MVVM"/><category term="Metro-styled"/><category term="Microsoft"/><category term="Visual Studio 12 RC"/><category term="Win32"/><category term="WinRT"/><category term="Windows 7"/><category term="Windows 8"/><category term="c#"/><title type='text'>Pradeep&#39;s Blog</title><subtitle type='html'>Presenting my views and samples on various upcoming Microsoft technologies like MVVM, Metro-styled applications, WPF, WCF, Prism and windows 8 preview</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://programmingwpf.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8559115372310954339/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://programmingwpf.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05327169565069030388</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8559115372310954339.post-4259542156320840985</id><published>2012-08-02T09:39:00.000-07:00</published><updated>2012-08-02T19:43:58.724-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c#"/><category scheme="http://www.blogger.com/atom/ns#" term="Metro-styled"/><category scheme="http://www.blogger.com/atom/ns#" term="Microsoft"/><category scheme="http://www.blogger.com/atom/ns#" term="MVVM"/><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio 12 RC"/><category scheme="http://www.blogger.com/atom/ns#" term="Win32"/><category scheme="http://www.blogger.com/atom/ns#" term="Windows 7"/><category scheme="http://www.blogger.com/atom/ns#" term="Windows 8"/><category scheme="http://www.blogger.com/atom/ns#" term="WinRT"/><title type='text'>Windows 8: an arranged marriage of windows 7 and windows phone</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;:&lt;br /&gt;
Ever since Windows 8 was announced, it has been a hot topic of discussion primarily due of the fact that it sounded as a bold migration step from Microsoft for many technical and marketing reasons.&amp;nbsp;People were not expecting company like Microsoft to put ASP.Net, WPF, Silverlight on the backseat and give way to open source technologies like HTML 5 and JavaScript. But we all must understand that to bring a revolutionary change, bold steps are a must. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;First day of marriage&lt;/strong&gt;:&lt;br /&gt;
I recently downloaded &lt;span class=&quot;st&quot;&gt;&lt;a href=&quot;http://www.google.com.sg/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;frm=1&amp;amp;source=web&amp;amp;cd=2&amp;amp;sqi=2&amp;amp;ved=0CG4QFjAB&amp;amp;url=http%3A%2F%2Fwindows.microsoft.com%2Fen-US%2Fwindows-8%2Fdownload%2F&amp;amp;ei=85YaUOvzOZGSiQf2j4CACw&amp;amp;usg=AFQjCNGcIuRFHirmeVLfnw0aHHURQS46eQ&quot;&gt;Windows 8 Release Preview&lt;/a&gt; as I was planning develop a Metro styled application for one of my clients. Please note Metro-styled applications&amp;nbsp;can only be developed on Windows 8&amp;nbsp;operating system, there is no virtual or simulator&amp;nbsp;available on windows 7 or prior versions to support Metro styled application development.&amp;nbsp;As expected the first impression was that it has great looks but navigation was a pain, simply because we(including myself) are so accustomed to existing style of windows. But let me tell you that once we get comfortable with the new way of navigation, it will be all fine.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx3JO3MkWI759ws8hmcRI4pJeO_lm4fDB7Qv9bx5VjEcvLJ08syU57Sb2S4MUmFrrHuf_t2N6IIZ6b1aMbw5e68xnzAv63hkaXkcWj37pP4OhWCQHjKxLR_fRqgRGnTi3xMrlZ-uJOXvE/s1600/front.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx3JO3MkWI759ws8hmcRI4pJeO_lm4fDB7Qv9bx5VjEcvLJ08syU57Sb2S4MUmFrrHuf_t2N6IIZ6b1aMbw5e68xnzAv63hkaXkcWj37pP4OhWCQHjKxLR_fRqgRGnTi3xMrlZ-uJOXvE/s320/front.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-33844045-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://&#39; : &#39;http://&#39;) + &#39;stats.g.doubleclick.net/dc.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;st&quot;&gt;&lt;strong&gt;Cultural shock on honeymoon&lt;/strong&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;st&quot;&gt;Not all honeymoons are pleasant. At times you need to spend some time understanding each other. Since we users are so comfortable with existing layout of windows, it become a bit irritating to find out how to perform some basic tasks like :&lt;/span&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span class=&quot;st&quot;&gt;How to close the application, as my metro styled application doesn&#39;t shows the close button?&lt;br /&gt;&lt;em&gt;Solution: You can close your application by&amp;nbsp;holding the application at the top and then dragging it towards the bottom of the screen or by pressing ALT-F4.&lt;/em&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Where&#39;s the start menu?&lt;br /&gt;&lt;em&gt;Solution: Your start menu is now a complete screen which becomes visible when you take your mouse to the left bottom corner of your screen. In fact all four corners of the screen now have something for you. they are now better known as hot corners.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Why was my application suspended when I just navigated to another application?&lt;br /&gt;&lt;em&gt;Solution: My application was suspended because it was a metro-styled application. A metro-styled application is different from normal desktop application. When the window is not active, it either goes to suspended&amp;nbsp;or closed state&lt;/em&gt;.&lt;br /&gt;&lt;img alt=&quot;App lifecycle&quot; id=&quot;js_tut_state_diagram&quot; src=&quot;http://i.msdn.microsoft.com/dynimg/IC576232.png&quot; title=&quot;App lifecycle&quot; xmlns=&quot;&quot; /&gt;&lt;/li&gt;
&lt;li&gt;Why is my right click not working?&lt;br /&gt;&lt;em&gt;Solution: Since windows 8 is designed to behave more like a smartphone or tablet than a PC, it seems to be a deliberate attempt to replace it with pinning. The items will get pinned when you right click.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;How do I shutdown?&lt;br /&gt;&lt;em&gt;Solution: Since windows 8 is designed to behave more like a smartphone or tablet than a PC, 
simply going to sleep when it’s not being used. If you do want to shut down, or 
have a need to restart, open the Charms Bar, select Settings, and then 
the Power button, which will reveal the Shutdown and 
Restart commands.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
and many more... however once you ready to accept the fact windows 8 is an OS more for smartphone or tablet than a PC, you will find things coming in smooth.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Is it a love marriage or arranged marriage&lt;/strong&gt;:&lt;br /&gt;
Now lets us look into the two parties that are getting married: Windows Phone and Windows 7.&lt;br /&gt;
A windows phone application run as if they are running on an OS that cannot do multitasking (except for music player and all). If you switch from one application to another, the first one goes to sleep. Similarly on Windows 7 or any other desktop OS, you open several application and each continue to&amp;nbsp;do the task they we performing until its complete, irrespective of the fact that its on&amp;nbsp;topmost window or not.&amp;nbsp;you are downloading, playing game and listening to music at the same time.&lt;br /&gt;
Windows 8 is neither a complete smartphone OS nor a complete desktop OS. Its something which is in between of the two and slightly biased towards smartphones. Metro style based application behave the way Windows Phone applications behave and desktop applications behave the way a normal win32 application behave. &lt;em&gt;So in short its an arranged marriage&lt;/em&gt;.&amp;nbsp;It supports both Win32 applications (better known as desktop applications) and WinRT (metro styled applications).&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Desktop applications are here to stay&lt;/strong&gt;:&lt;br /&gt;
Metro styled application are a good fit for small to medium sized applications that are complete in themselves. It the beginning of metro-styled applications but not the end of desktop applications. Both will continue to be there and live side by side. Big enterprise applications and distributed applications will continue to be desktop applications. Its not easy to imagine a metro styled application replacing them anytime soon. Even Visual Studio 12 RC is not metro styled application.&amp;nbsp;It would make&amp;nbsp;debugging an application using visual studio impossible&amp;nbsp;as&amp;nbsp;visual studio will&amp;nbsp;go into&amp;nbsp;suspended mode&amp;nbsp;when debugging&amp;nbsp;application gets launched.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br /&gt;
Windows 8 is bold but a necessary move by Microsoft. It might not be a hit as it neither a complete smartphone OS&amp;nbsp;nor a complete desktop OS, but it is the soldier who will make the way for next generation. This will make the future of Windows 9 brighter and&amp;nbsp;comfortable. We hope that Microsoft will WinRT&amp;nbsp;more real-time (than runtime). &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingwpf.blogspot.com/feeds/4259542156320840985/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingwpf.blogspot.com/2012/08/windows-8-arranged-marriage-of-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8559115372310954339/posts/default/4259542156320840985'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8559115372310954339/posts/default/4259542156320840985'/><link rel='alternate' type='text/html' href='http://programmingwpf.blogspot.com/2012/08/windows-8-arranged-marriage-of-windows.html' title='Windows 8: an arranged marriage of windows 7 and windows phone'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05327169565069030388</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx3JO3MkWI759ws8hmcRI4pJeO_lm4fDB7Qv9bx5VjEcvLJ08syU57Sb2S4MUmFrrHuf_t2N6IIZ6b1aMbw5e68xnzAv63hkaXkcWj37pP4OhWCQHjKxLR_fRqgRGnTi3xMrlZ-uJOXvE/s72-c/front.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8559115372310954339.post-3801280027821809871</id><published>2012-07-31T04:15:00.000-07:00</published><updated>2012-08-02T19:45:05.683-07:00</updated><title type='text'>WPF/Silverlight: Step By Step Guide to MVVM</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;

  var _gaq = _gaq || [];
  _gaq.push([&#39;_setAccount&#39;, &#39;UA-33844045-1&#39;]);
  _gaq.push([&#39;_trackPageview&#39;]);

  (function() {
    var ga = document.createElement(&#39;script&#39;); ga.type = &#39;text/javascript&#39;; ga.async = true;
    ga.src = (&#39;https:&#39; == document.location.protocol ? &#39;https://&#39; : &#39;http://&#39;) + &#39;stats.g.doubleclick.net/dc.js&#39;;
    var s = document.getElementsByTagName(&#39;script&#39;)[0]; s.parentNode.insertBefore(ga, s);
  })();

&lt;/script&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;http://www.codeproject.com/KB/WPF/StepByStepGuideToMVVM/MVVMDemo.zip&quot;&gt;Download MVVMDemo.zip - 28.44 KB&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://www.codeproject.com/KB/WPF/StepByStepGuideToMVVM/MVVMDemoCode.zip&quot;&gt; Download MVVMDemoCode.zip - 75.62 KB &lt;/a&gt;

&lt;br /&gt;
&lt;br /&gt;
MVVM is the short form for Model-View-ViewModel pattern widely used in WPF/Silverlight programming. This design pattern was introduced by John Gossman primarily for segregation and easy testability of View, ViewModel and Model.
&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;img alt=&quot;Model - View - ViewModel&quot; src=&quot;http://programmingwpf.files.wordpress.com/2011/06/mvvm.png&quot; /&gt;&lt;/div&gt;
Let me first explain the &lt;b&gt;three parts of MVVM&lt;/b&gt;:
&lt;br /&gt;
&lt;h2&gt;
Model&lt;/h2&gt;
Model as we all know represents the data layer.
&lt;br /&gt;
&lt;h2&gt;
View&lt;/h2&gt;
View represents the UI or the looks.
&lt;br /&gt;
&lt;h2&gt;
View Model&lt;/h2&gt;
View Model is the middle man and its responsibility is to tweek the data from model in such a way that it can be consumed by the View. For some people MVVM is a steep learning curve. Let me assure you its very easy if you keep four thing in mind.

You can also call these four steps as the &lt;b&gt;GURU MANTRA of MVVM&lt;/b&gt;.
&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;img alt=&quot;mvvm.png&quot; height=&quot;441&quot; src=&quot;http://www.codeproject.com/KB/WPF/StepByStepGuideToMVVM//mvvm.png&quot; width=&quot;539&quot; /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 14.4pt; margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;1) &lt;b&gt;Try to have minimum code behind&lt;/b&gt;. That is your View.xaml.cs is supposed to have almost no code. Not even event handlers. This does not mean absolute zero code is a must, what I mean to say is that we should have minimum code behind. An exception would cases like where the logic is &lt;i&gt;pure View oriented&lt;/i&gt; (and is very specific to that view only) and has nothing to do with ViewModel or Model or even &lt;i&gt;other Views of same ViewModel&lt;/i&gt;. For example on mouse over you want to slide in the tooltip, you may opt to do it in xaml.cs (of course you could have also done it by using trigger in xaml itself, but just cooking it as an example). There is no harm in having such code behind as it does not has anything to do with ViewModel or Model.
Having said this, I would like to mention a few &lt;b&gt;exceptions&lt;/b&gt; to the above rule.
a) Dependency properties will always be part of code behind, hence it does not mean that you should avoid dependency property in MVVM.
b) Sometimes you have to use third party controls which are not MVVM compliant. In such cases too you end up having some code behind. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 14.4pt; margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;2) &lt;b&gt;All Events or actions should be treated as Command&lt;/b&gt;. Your question would be how to do that, my control has click event behavior but no command. My answer is there are several ways to do that. All this will be explained in detail in the rest of the article. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 14.4pt; margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;3) &lt;b&gt;ViewModel is the DataContext of View&lt;/b&gt;. So neither View has instance ViewModel and nor does ViewModel has instance of View. Its incorrect and ugly to type cast View.DataContext to ViewModel. This will break your true MVVM model. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 14.4pt; margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif; font-size: 10pt;&quot;&gt;4) &lt;b&gt;Design ViewModel and View independent of each other&lt;/b&gt;. This means that you must design the view by keeping in mind that if tomorrow the view is supposed to be replaced with another view (another look and feel), it should not require the ViewModel or model to change. Hence do not code anything in ViewModel that is specific to the view and also do not code anything in the view that is specific to ViewModel&lt;/span&gt;.&lt;/div&gt;
&lt;h2&gt;
Homework before starting MVVM&lt;/h2&gt;
1) Learn and clear concepts on Databinding.
2) Learn how to use Dependency Properties.
3) Learn use of Converters.
4) Last but not the least INotifyPropertyChanged.

Let&#39;s start of with the basics first:

&lt;b&gt;Data Binding&lt;/b&gt;: Data binding is the process that establishes a connection between the application UI and business logic. If the binding has the correct settings and the data provides the proper notifications, then, when the data changes its value, the elements that are bound to the data reflect changes automatically. Data binding can also mean that if an outer representation of the data in an element changes, then the underlying data can be automatically updated to reflect the change. For example, if the user edits the value in a TextBox element, the underlying data value is automatically updated to reflect that change.

&lt;b&gt;Dependency Property&lt;/b&gt;: Dependency properties are just like normal CLR properties, but with a X-factor. The X-factor is that these properties have inbuilt support for data binding , animation, styling ,value expressions, property validation , per-type default calues. At the end of the day we need dependency properties to be able to save state of UI Elements. It won&#39;t be incorrect to say that dependency property will always be part of View&#39;s code behind and normal (CLR) properties are more likely to be part of ViewModel or Model. Just like there is a syntax to define CLR properties ( setter, getter ), there is a syntax for dependency property as well. The syntax is:
&lt;br /&gt;
&lt;pre&gt;public class MySampleControl : Control
{
   &lt;b&gt; // Step 1: Register the dependency property &lt;/b&gt;
    public static readonly DependencyProperty SpecialBrushProperty =
            DependencyProperty.Register(&quot;SpecialBrush&quot;, typeof(Brush),
            typeof(MySampleControl));

    &lt;b&gt;// Step 2: Provide set/get accessors for the property &lt;/b&gt;
    public Brush SpecialBrush
    {
        get { return (Brush)base.GetValue(SpecialBrushProperty); }
        set { base.SetValue(SpecialBrushProperty, value); }
    }
}&lt;/pre&gt;
Please note that there are other ways to declare setter and getter for dependency properties. Also note that there several ways and combination to register a dependency properties like registering it as attached property (which in turn makes the dependency property inheritable its value down the visual tree. Example if you change the font of the Grid control, all its children also start showing the font of the parent Grid) etc.

&lt;b&gt;Converters&lt;/b&gt;: Data Conversion or Value Conversion is generally required when your view needs that data to be slightly tweaked from what it is currently. For example, in the view you want to show traffic light kind of signals based on the state of your project. That is green if your project is from 8 to 10, yellow if its rating is 5-7 and red if it’s less. Here there is no point keeping a variable corresponding to the color in your ViewModel, looks ugly. Here the showing project rating as color is a pure View requirement. Tomorrow if this view is to be replaced with another view where you show project rating as number, your color variable will turn out to be a complete waste. So how do you do that, solution is simple use Value converters, Value converters are purely part of View, it’s the view who wants the color to be green, yellow or red and ViewModel doesn’t care about the color. A value converter must derive from IValueConverter or IMultiValueConverter(in case you have multiple values to be used as input. Like in the traffic light example, let’s suppose your green color is to be shown when project is healthy and deadline is within acceptable limit. So we have two inputs, rating and deadline).
&lt;br /&gt;
&lt;pre&gt;[ValueConversion(typeof(Project), typeof(Brush))]
public class ColorConverter : &lt;b&gt;IValueConverter&lt;/b&gt;
{

    public object &lt;b&gt;Convert&lt;/b&gt;(object value, Type targetType,
        object parameter, CultureInfo culture)
    {
        Project project = (Project)value;
        if (project.Rating &amp;gt;= 8)//its healthy if rating is 8 to 10
              return new SolidColorBrush(Colors.Green);
        else if (project.Rating &amp;gt;= 5) )//its ok if rating is 5 to 7
              return new SolidColorBrush(Colors.Yellow);
        else //less its unhealthy
              return new SolidColorBrush(Colors.Red);
    }    

    public object &lt;b&gt;ConvertBack&lt;/b&gt;(object value, Type targetType,
        object parameter, CultureInfo culture)
    {
        return null;
    }
}&lt;/pre&gt;
&lt;b&gt;INotifyPropertyChanged&lt;/b&gt;: INotifyPropertyChanged has been there since Winform arena. It’s not a new concept in WPF/Silverlight. It’s an interface that you would like to implement in your ViewModel to notify you View that something got changed. Observable Collection and Dependency Property are some which have inbuilt notification mechanism. For such properties you may not require to raise the notification through code.
&lt;br /&gt;
&lt;pre&gt;public class SomeViewModel : ViewModelBase, &lt;b&gt;INotifyPropertyChanged&lt;/b&gt;
{
     ….
     ….
    private Module _SelectedModule;
    public Module SelectedModule
    {
            get
            {
                return _SelectedModule;
            }
            set
            {
                _SelectedModule = value;
                &lt;b&gt;RaisePropertyChanged&lt;/b&gt;(&quot;SelectedModule&quot;);
            }
    }
    …
    …
    &lt;b&gt;#region INotifyPropertyChanged &lt;/b&gt;
    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName)
    {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
    }
    &lt;b&gt;#endregion &lt;/b&gt;&lt;/pre&gt;
Coming back to the real thing, lets start of with the Model: Rest of the post, I shall explain by means of the a demo application for displaying employee information:

&lt;b&gt;Model&lt;/b&gt;: As the name suggest, it holds the data&#39;s model. Some people prefer to call model as data model. All your database select queries will first populate the data model which in turn will be used by ViewModel and View. As an example, I hereby demonstrate an Employee class. This class has properties corresponding to my data fields like name, notes, age etc.
&lt;br /&gt;
&lt;pre&gt;public class Employee : IDataErrorInfo, INotifyPropertyChanged
{
    #region Constructor
    public Employee(string id = &quot;&quot;, string name = &quot;&quot;, uint age = 0, string notes = &quot;&quot;)
    {
        _id = id;
        _name = name;
        _age = age;
        _notes = notes;
    }
    #endregion

    #region Properties
    private string _id = string.Empty;

    public string ID
    {
        get { return _id; }
        set
        {
            _id = value;
            RaisePropertyChanged(&quot;ID&quot;);
        }
    }

    private string _name = string.Empty;

    public string Name
    {
        get { return _name; }
        set
        {
            _name = value;
            RaisePropertyChanged(&quot;Name&quot;);
        }
    }

    private uint _age = 0;

    public uint Age
    {
        get { return _age; }
        set
        {
            _age = value;
            RaisePropertyChanged(&quot;Age&quot;);
        }
    }

    private string _notes = string.Empty;

    public string Notes
    {
        get { return _notes; }
        set
        {
            _notes = value;
            RaisePropertyChanged(&quot;Notes&quot;);
        }
    }
    #endregion

    #region IDataErrorInfo
    public string Error
    {
        get
        {
            return this[string.Empty];
        }
    }

    public string this[string propertyName]
    {
        get
        {

            string result = string.Empty;
            propertyName = propertyName ?? string.Empty;

            if (propertyName == string.Empty || propertyName == &quot;ID&quot;)
            {
                if (string.IsNullOrEmpty(this.ID))
                {
                    result = &quot;Employee ID is invalid. ID cannot be null or blank&quot;;
                }
                else if (System.Text.RegularExpressions.Regex.IsMatch(this.ID, &quot;[/!@#?/}[}{ ]&quot;))
                {
                    result = &quot;Employee ID is invalid. ID cannot have special characters&quot;;
                }
            }
            else if (propertyName == &quot;Name&quot;)
            {
                if (string.IsNullOrEmpty(this.Name))
                {
                    result = &quot;Name is invalid. ID cannot be null or blank&quot;;
                }
            }
            else if (propertyName == &quot;Age&quot;)
            {
                if (Age &amp;gt; 150 || Age &amp;lt; 0)
                {
                    result = &quot;Age is invalid. Age should be between 0 and 150&quot;;
                }
            }

            return result;
        }
    }
    #endregion

    #region INotifyPropertyChanged
    [field: NonSerialized]
    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    #endregion
}&lt;/pre&gt;
In have inherited my model from IDataErrorInfo and INotifyPropertyChanged, &lt;i&gt;but the same is not mandatory while designing your model&lt;/i&gt;. the same is done for data validation implementation and not MVVM. There is not much to explain in the model, lets proceed to the next level ViewModel.

&lt;b&gt;ViewModel&lt;/b&gt;: In the beginning of this blog I had mentioned that ViewModel is nothing but DataContext of View. Since ViewModel&#39;s responsibility is to play mediator between View amd Model, it will always have an instance of Model class and to reflect change in model, it will notify View via notification (INotifyPropertyChanged etc) or databinding. All Commands of the View are processed/handled here. Keep in mind that a ViewModel may have multiple views, so never code anything which is specific to a given view here. Considering our example for Employee, in our view we have list of employees on the left side and selected employees details on right side, so our viewModel which is supposed to be DataContext of View, must provide list of employees and a property to represent selection. Hence we end up having two properties in our viewModel, Employees and SelectedEmployee.
&lt;br /&gt;
&lt;pre&gt;    public class EmployeeListViewModel : INotifyPropertyChanged
    {
        public ObservableCollection&lt;employee&gt; Employees { get; private set; }

        public EmployeeListViewModel()
        {
            Employees = MVVMDemo.DataHelper.EmployeeDataHelper.CookEmployeesData();
        }

        private Employee _SelectedEmployee;
        public Employee SelectedEmployee
        {
            get
            {
                return _SelectedEmployee;
            }
            set
            {
                _SelectedEmployee = value;
                RaisePropertyChanged(&quot;SelectedEmployee&quot;);
            }
        }

        #region INotifyPropertyChanged
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }&lt;/employee&gt;&lt;/pre&gt;
&lt;b&gt;View&lt;/b&gt;: &lt;span style=&quot;font-family: Verdana,sans-serif; font-size: 10pt;&quot;&gt;View is the look and feel. View is represented by xaml and its xaml.cs files. All your animations, decorations, themes, controls etc. sit here. The view is to be coded keeping in mind that tomorrow if you want to display your data in a different way, it should not require you to touch the ViewModel or Model at all. For example if you want to display you list of employees in a datagrid or listbox or tree or even tabs, it should not be a matter of concern for you ViewModel or Model, it’s purely the job of View to change the look and feel because at the end of the day it’s the same data that has to be presented in slightly different way. In our example of Employee list, View has a ListView of left side and selected employees details are displayed on the right side. So for this we have a xaml and xaml.cs in place. But the xaml.cs hardly has anything significant; hence code for it can be ignored for now.&lt;/span&gt;

EmployeeListView.xaml :
&lt;br /&gt;
&lt;pre&gt; &lt;window height=&quot;300&quot; title=&quot;Employee View&quot; width=&quot;720&quot; x:class=&quot;MVVMDemo.View.EmployeeListView&quot; xmlns:view=&quot;clr-namespace:MVVMDemo.View&quot; xmlns:vm=&quot;clr-namespace:MVVMDemo.ViewModel&quot; xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot; xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;&gt;
    &lt;window .datacontext=&quot;.datacontext&quot;&gt;
        &lt;vm:employeelistviewmodel&gt;
    &lt;/vm:employeelistviewmodel&gt;&lt;/window&gt;
    &lt;grid&gt;
        &lt;grid .columndefinitions=&quot;.columndefinitions&quot;&gt;
            &lt;columndefinition width=&quot;152*&quot;&gt;
            &lt;columndefinition width=&quot;568*&quot;&gt;
        &lt;/columndefinition&gt;&lt;/columndefinition&gt;&lt;/grid&gt;
        &lt;listview grid.column=&quot;0&quot; horizontalalignment=&quot;Stretch&quot; itemssource=&quot;{Binding Employees, UpdateSourceTrigger=PropertyChanged}&quot; selectedvalue=&quot;{Binding SelectedEmployee, UpdateSourceTrigger=PropertyChanged}&quot; verticalalignment=&quot;Stretch&quot; x:name=&quot;listEmp&quot;&gt;
            &lt;listview .view=&quot;.view&quot;&gt;
                &lt;gridview&gt;
                    &lt;gridviewcolumn displaymemberbinding=&quot;{Binding ID}&quot; header=&quot;ID&quot; width=&quot;40&quot;&gt;
                    &lt;gridviewcolumn displaymemberbinding=&quot;{Binding Name}&quot; header=&quot;Name&quot; width=&quot;100&quot;&gt;
                &lt;/gridviewcolumn&gt;&lt;/gridviewcolumn&gt;&lt;/gridview&gt;
            &lt;/listview&gt;
        &lt;/listview&gt;
        &lt;view:employeeview datacontext=&quot;{Binding SelectedEmployee, UpdateSourceTrigger=PropertyChanged}&quot; grid.column=&quot;1&quot;&gt;
    &lt;/view:employeeview&gt;&lt;/grid&gt;
&lt;/window&gt;&lt;/pre&gt;
EmployeeView.xaml:
&lt;br /&gt;
&lt;pre&gt;&lt;usercontrol minheight=&quot;245&quot; minwidth=&quot;400&quot; x:class=&quot;MVVMDemo.View.EmployeeView&quot; xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; xmlns:vm=&quot;clr-namespace:MVVMDemo.ViewModel&quot; xmlns:wc=&quot;clr-namespace:System.Windows.Controls;assembly=PresentationFramework&quot; xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot; xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;&gt;
    &lt;grid&gt;
        &lt;grid .resources=&quot;.resources&quot;&gt;
            &lt;storyboard x:key=&quot;FlashErrorIcon&quot;&gt;
                &lt;objectanimationusingkeyframes begintime=&quot;00:00:00&quot; storyboard.targetproperty=&quot;(UIElement.Visibility)&quot;&gt;
                    &lt;discreteobjectkeyframe keytime=&quot;00:00:00&quot; value=&quot;{x:Static Visibility.Hidden}&quot;&gt;
                    &lt;discreteobjectkeyframe keytime=&quot;00:00:00.4000000&quot; value=&quot;{x:Static Visibility.Visible}&quot;&gt;
                    &lt;discreteobjectkeyframe keytime=&quot;00:00:00.8000000&quot; value=&quot;{x:Static Visibility.Hidden}&quot;&gt;
                    &lt;discreteobjectkeyframe keytime=&quot;00:00:01.6000000&quot; value=&quot;{x:Static Visibility.Visible}&quot;&gt;
                    &lt;discreteobjectkeyframe keytime=&quot;00:00:02.4000000&quot; value=&quot;{x:Static Visibility.Hidden}&quot;&gt;
                    &lt;discreteobjectkeyframe keytime=&quot;00:00:03.2000000&quot; value=&quot;{x:Static Visibility.Visible}&quot;&gt;
                    &lt;discreteobjectkeyframe keytime=&quot;00:00:01&quot; value=&quot;{x:Static Visibility.Visible}&quot;&gt;
                &lt;/discreteobjectkeyframe&gt;&lt;/discreteobjectkeyframe&gt;&lt;/discreteobjectkeyframe&gt;&lt;/discreteobjectkeyframe&gt;&lt;/discreteobjectkeyframe&gt;&lt;/discreteobjectkeyframe&gt;&lt;/discreteobjectkeyframe&gt;&lt;/objectanimationusingkeyframes&gt;
            &lt;/storyboard&gt;
            &lt;style targettype=&quot;{x:Type TextBox}&quot;&gt;
                &lt;Style.Triggers&gt;
                    &lt;trigger Property=&quot;Validation.HasError&quot; Value=&quot;true&quot;&gt;
                        &lt;setter Property=&quot;Background&quot; Value=&quot;Pink&quot;/&gt;
                        &lt;setter Property=&quot;Foreground&quot; Value=&quot;Black&quot;/&gt;
                    &lt;/Trigger&gt;
                &lt;/Style.Triggers&gt;
                &lt;setter Property=&quot;Validation.ErrorTemplate&quot;&gt;
                    &lt;Setter.Value&gt;
                        &lt;controltemplate&gt;
                            &lt;dockpanel LastChildFill=&quot;True&quot;
                                       ToolTip=&quot;{Binding ElementName=controlWithError,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}&quot;&gt;
                                &lt;ellipse DockPanel.Dock=&quot;Right&quot;
                                 ToolTip=&quot;{Binding ElementName=controlWithError,
                                     Path=AdornedElement.(Validation.Errors)[0].ErrorContent}&quot;
                                 Width=&quot;15&quot; Height=&quot;15&quot;
                                 Margin=&quot;-25,0,0,0&quot;
                                 StrokeThickness=&quot;1&quot; Fill=&quot;IndianRed&quot; &gt;
                                    &lt;Ellipse.Stroke&gt;
                                        &lt;lineargradientbrush EndPoint=&quot;1,0.5&quot; StartPoint=&quot;0,0.5&quot;&gt;
                                            &lt;gradientstop Color=&quot;#FFFA0404&quot; Offset=&quot;0&quot;/&gt;
                                            &lt;gradientstop Color=&quot;#FFC9C7C7&quot; Offset=&quot;1&quot;/&gt;
                                        &lt;/LinearGradientBrush&gt;
                                    &lt;/Ellipse.Stroke&gt;
                                    &lt;Ellipse.Triggers&gt;
                                        &lt;eventtrigger RoutedEvent=&quot;FrameworkElement.Loaded&quot;&gt;
                                            &lt;beginstoryboard Storyboard=&quot;{StaticResource FlashErrorIcon}&quot;/&gt;
                                        &lt;/EventTrigger&gt;
                                    &lt;/Ellipse.Triggers&gt;
                                &lt;/Ellipse&gt;
                                &lt;textblock DockPanel.Dock=&quot;Right&quot;
                                ToolTip=&quot;{Binding ElementName=controlWithError,
                                     Path=AdornedElement.(Validation.Errors)[0].ErrorContent}&quot;
                                Foreground=&quot;White&quot;
                                FontSize=&quot;10&quot;
                                Margin=&quot;-15,5,0,0&quot; FontWeight=&quot;Bold&quot;&gt;!
                            &lt;TextBlock.Triggers&gt;
                                &lt;eventtrigger RoutedEvent=&quot;FrameworkElement.Loaded&quot;&gt;
                                    &lt;beginstoryboard Storyboard=&quot;{StaticResource FlashErrorIcon}&quot;/&gt;
                                &lt;/EventTrigger&gt;
                            &lt;/TextBlock.Triggers&gt;
                                &lt;/TextBlock&gt;
                                &lt;border BorderBrush=&quot;Red&quot; BorderThickness=&quot;1&quot;&gt;
                                    &lt;adornedelementplaceholder Name=&quot;controlWithError&quot;/&gt;
                                &lt;/Border&gt;

                            &lt;/DockPanel&gt;
                        &lt;/ControlTemplate&gt;
                    &lt;/Setter.Value&gt;
                &lt;/Setter&gt;
            
&lt;/style&gt;
        &lt;/grid&gt;
        &lt;grid .rowdefinitions=&quot;.rowdefinitions&quot;&gt;
            &lt;rowdefinition height=&quot;50*&quot;&gt;
            &lt;rowdefinition height=&quot;33*&quot;&gt;
            &lt;rowdefinition height=&quot;33*&quot;&gt;
            &lt;rowdefinition height=&quot;33*&quot;&gt;
            &lt;rowdefinition height=&quot;63*&quot;&gt;
            &lt;rowdefinition height=&quot;33*&quot;&gt;
        &lt;/rowdefinition&gt;&lt;/rowdefinition&gt;&lt;/rowdefinition&gt;&lt;/rowdefinition&gt;&lt;/rowdefinition&gt;&lt;/rowdefinition&gt;&lt;/grid&gt;
        &lt;grid .columndefinitions=&quot;.columndefinitions&quot;&gt;
            &lt;columndefinition width=&quot;75*&quot;&gt;
            &lt;columndefinition width=&quot;425*&quot;&gt;
        &lt;/columndefinition&gt;&lt;/columndefinition&gt;&lt;/grid&gt;
        &lt;textblock fontfamily=&quot;Tahoma&quot; fontstyle=&quot;Italic&quot; fontweight=&quot;Bold&quot; foreground=&quot;DodgerBlue&quot; grid.columnspan=&quot;2&quot; horizontalalignment=&quot;Center&quot; text=&quot;Employee Details&quot; verticalalignment=&quot;Center&quot;&gt;
        &lt;textblock grid.column=&quot;0&quot; grid.row=&quot;1&quot; horizontalalignment=&quot;Right&quot; margin=&quot;5&quot; text=&quot;ID :&quot; verticalalignment=&quot;Center&quot;&gt;
        &lt;textbox grid.column=&quot;1&quot; grid.row=&quot;1&quot; margin=&quot;5,5,15,5&quot; text=&quot;{Binding ID,ValidatesOnDataErrors=true, NotifyOnValidationError=true}&quot;&gt;
        &lt;textblock grid.column=&quot;0&quot; grid.row=&quot;2&quot; horizontalalignment=&quot;Right&quot; margin=&quot;5&quot; text=&quot;Name :&quot; verticalalignment=&quot;Center&quot;&gt;
        &lt;textbox grid.column=&quot;1&quot; grid.row=&quot;2&quot; margin=&quot;5,5,15,5&quot; text=&quot;{Binding Name,ValidatesOnDataErrors=true, NotifyOnValidationError=true}&quot;&gt;
        &lt;textblock grid.column=&quot;0&quot; grid.row=&quot;3&quot; horizontalalignment=&quot;Right&quot; margin=&quot;5&quot; text=&quot;Age :&quot; verticalalignment=&quot;Center&quot;&gt;
        &lt;textbox grid.column=&quot;1&quot; grid.row=&quot;3&quot; margin=&quot;5,5,15,5&quot; text=&quot;{Binding Age,ValidatesOnDataErrors=true, NotifyOnValidationError=true}&quot;&gt;
        &lt;textblock grid.column=&quot;0&quot; grid.row=&quot;4&quot; horizontalalignment=&quot;Right&quot; margin=&quot;5&quot; text=&quot;Notes :&quot; verticalalignment=&quot;Center&quot;&gt;
        &lt;textbox grid.column=&quot;1&quot; grid.row=&quot;4&quot; margin=&quot;5,5,15,5&quot; text=&quot;{Binding Notes}&quot;&gt;
    &lt;/textbox&gt;&lt;/textblock&gt;&lt;/textbox&gt;&lt;/textblock&gt;&lt;/textbox&gt;&lt;/textblock&gt;&lt;/textbox&gt;&lt;/textblock&gt;&lt;/textblock&gt;&lt;/grid&gt;
&lt;/usercontrol&gt;&lt;/pre&gt;
&lt;h2&gt;
Some useful MVVM Frameworks&lt;/h2&gt;
Also do not forget to check out a few handy tools/Frameworks for MVVM :
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://compositewpf.codeplex.com/&quot; target=&quot;_blank&quot;&gt;PRISM (Microsoft)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://mvvmlight.codeplex.com/&quot; target=&quot;_blank&amp;quot;&quot;&gt;MVVM Light (Laurent Bugnion)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://waf.codeplex.com/&quot; target=&quot;_blank&quot;&gt;WPF Application Framework&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cinch.codeplex.com/&quot; target=&quot;_blank&quot;&gt;Chinch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://caliburn.codeplex.com/&quot;&gt;Caliburn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=8559115372310954339&quot;&gt;Caliburn Micro&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://coremvvm.codeplex.com/&quot; target=&quot;_blank&quot;&gt;Core MVVM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://wpfonyx.codeplex.com/&quot; target=&quot;_blank&quot;&gt;Onyx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.orktane.com/category/nRoute.aspx&quot; target=&quot;_blank&quot;&gt;nRoute&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://mvvmfoundation.codeplex.com/&quot; target=&quot;_blank&quot;&gt;MVVM Foundation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://live.visitmix.com/MIX10/Sessions/EX15&quot;&gt;How to build your own MVVM Framework&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingwpf.blogspot.com/feeds/3801280027821809871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://programmingwpf.blogspot.com/2012/07/download-mvvmdemo.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8559115372310954339/posts/default/3801280027821809871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8559115372310954339/posts/default/3801280027821809871'/><link rel='alternate' type='text/html' href='http://programmingwpf.blogspot.com/2012/07/download-mvvmdemo.html' title='WPF/Silverlight: Step By Step Guide to MVVM'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05327169565069030388</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>