<?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: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-4757484069882229120</id><updated>2011-11-27T15:39:52.227-08:00</updated><category term='Mansoor'/><category term='PRISM'/><category term='MVVM'/><category term='Entity Framework'/><category term='ASP.NET'/><category term='Silverlight'/><title type='text'>Mansoor's Collection of .Net Articles</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-6309174754620378203</id><published>2010-06-01T10:03:00.000-07:00</published><updated>2010-06-04T21:50:31.846-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PRISM'/><category scheme='http://www.blogger.com/atom/ns#' term='MVVM'/><title type='text'>how to build an outlook style application with prism v2 – Part 2</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/erwinvandervalk/archive/2009/04/29/how-to-build-an-outlook-style-application-with-prism-v2-part-2.aspx"&gt;how to build an outlook style application with prism v2 – Part 2&lt;/a&gt;: "&lt;p&gt;A while ago, I put an example application on my blog on &lt;a title="How to build an outlook style application - Part 1" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/03/02/how-to-build-an-outlook-style-application.aspx"&gt;how to build an outlook style application&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;The last couple of weeks, I’ve been working on a new version of this app. I’ve done some bugfixes, but also included support for opening use cases in a popup window. It’s turning out to be quite an advanced demo of what’s possible with Prism. But while I’m playing with it, I can’t help but be amazed with the things I can push Prism into doing :)&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://cid-be4acdc9251c75df.skydrive.live.com/self.aspx/Public/OutlookStyleApp%20-%20Blog%2020090918.zip"&gt;&lt;span style="color:#ff9900;"&gt;&amp;lt;Outlook style app&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You will need the following references to make the solution work:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/CompositeWPF"&gt;&lt;span style="color:#ff9900;"&gt;Prism&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=unity"&gt;&lt;span style="color:#ff9900;"&gt;Unity&lt;/span&gt;&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;So there are a couple of things I didn’t explain in my previous blog:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;How to do ViewModel first development? &lt;/li&gt;&lt;br /&gt;&lt;li&gt;How to open a Use Case in a popup? &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Why I’m using ObservableObject in my ViewModels? &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;So here goes:&lt;/p&gt;&lt;br /&gt;&lt;h1&gt;ViewModel first development&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;I’m a big van of ViewModel first development. So what does that mean?&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;I create my ViewModels &lt;strong&gt;&lt;u&gt;before&lt;/u&gt;&lt;/strong&gt; i create my Views. This allows me to create testable viewmodels that absolutely don’t rely on any visual aspects. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;My application code programs against ViewModels, not Views. Most of my code doesn’t need to know about the views. Only when a ViewModel needs to be displayed should you load up the view to display it. &lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;There are a couple of big advantages to this approach:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;You can easily unit test your UI logic, without relying on visual elements. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;I can easily reskin my app. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;You don’t have to forward data from your views to your view models. This is something I have always found annoying with a View First approach. For example, if you have a view that displays a person and needs a PersonID to do it. With view first, your code has to talk to the view. So the view needs a PersonID property. But actually, the logic of your view needs that PersonID, so it needs to be forwarded to your ViewModel. Annoying, tedious, error prone!!! &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;I wanted to be able to put ViewModels into my regions and to have some code that would provide the visualization onto it. So the code I want to be able to write is:&lt;/p&gt;&lt;br /&gt;&lt;div&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// 1: Setup visualizations (typically in Module.Initialize)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// Whenever an EmailMainViewModel is displayed, visualize it with an EmailMainView&lt;/span&gt;&lt;br /&gt;modelVisualizationRegistry.Register&amp;lt;EmailMainViewModel, EmailMainView&amp;gt;();&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;// 2: Add ViewModels to region (view discovery, view injection or any other method)&lt;/span&gt;&lt;br /&gt;region.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; EmailMainViewModel());&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;h6&gt;&lt;/h6&gt;&lt;br /&gt;&lt;h1&gt;&lt;/h1&gt;&lt;br /&gt;&lt;h1&gt;ViewModel First internals&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;If you’re interested in how I built the ViewModel First code? here it is:&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;ModelVisualizer&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;The first step into creating the view model first appraoch was to create a ModelVisualizer class. The reason for this was: 'The prism region adapters will put the content of the regions directly into the control that hosts the region (for example, a contentcontrol). There is no extensionpoint to sit in between that.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;So I created something that I could put in a region, that would hold BOTH the View and the ViewModel. It would be the glue between the view and the viewmodel and:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Set the View as the content in the Visual Tree. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Set the ViewModel as the datacontext for the View. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Forward common information between the ViewModel and the View (such as the RegionContext or the IsActive values) &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;The following diagram explains my ModelVisualizer. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplicationwithp_C86C/image_2.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplicationwithp_C86C/image_thumb.png" border="0" height="311" width="519" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;The ModelVisualizer IS a ContentControl. So it can be placed inside the Visual Tree. It will set the View as the content. It will also set the ViewModel as the datacontext of the view (so the view can bind to all the information in the ViewModel). Lastly, the IModelVisualizer implements the IRegionContextAware and IActiveAware interfaces, and will synchronize these interfaces with the View and ViewModel if they implement the interfaces. &lt;/p&gt;&lt;br /&gt;&lt;h2&gt;Visualizing Region&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;The ModelVisualizer worked great. However, it demanded that all my code knew about the ModelVisualizer. I didn’t want to do that, because I wanted to make it implicit. There were some issues with that though, because due to the current implementation the region adapters, I didn’t have an extension point to create my visualizations implicitly. I couldn’t change the type of region that was created by adapters and I couldn’t change how the adapters set the content of the region to the hostcontrol. But I solved that with a little trick, that I call my VisualizingRegion.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The trick was: while I couldn’t change what type of region was being created, I could control what type of region was registered to the RegionManager (because there is a regionbehavior that does the registration. So I just wrapped the Region that was created by the regionadapters in my own region (the visualizing region) and registered my own visualizing region to the regionmanager. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;The only way a consumer can get access to the Region is through the RegionManager, so that solved the problem :) &lt;/p&gt;&lt;br /&gt;&lt;h1&gt;Easier Solution to region context&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;In Prism V2, we introduced the concept of &lt;a title="Explaination of regioncontext" href="http://blogs.msdn.com/erwinvandervalk/archive/2008/11/22/prism-v2-drop-6-composite-application-guidance-for-wpf-and-silverlight.aspx"&gt;RegionContext&lt;/a&gt;. The RegionContext is a way that a view that hosts a region can share some of it’s information with any childviews that are loaded into it’s region. While I really liked the concept of RegionContext, I didn’t really like the implementation of it. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;So I created the IRegionContextAware interface. It has one property (the regioncontext as an ObservableObject) and the RegionContextAwareRegionBehavior that would sync the context of the region with the RegionContextAware properties. &lt;/p&gt;&lt;br /&gt;&lt;h2&gt;&lt;/h2&gt;&lt;br /&gt;&lt;h2&gt;&lt;/h2&gt;&lt;br /&gt;&lt;h1&gt;Opening a Use Case (or ViewModel) in a popup&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;One thing I thought was an interesting challenge was opening a viewmodel in a (non modal) popup. So why would this be challenging:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;You can have many instances of the same popup open at the same time. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Viewmodels shouldn’t know if they are opened in the main window (perhaps in several tabs) or in a popup. This should be decided by the designer, preferably in XAML. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;The code I wanted to be able to write is:&lt;/p&gt;&lt;br /&gt;&lt;div   style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; max-height: 200px;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;&lt;div    style="border-style: none; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create an UseCase to write new email messages&lt;/span&gt;&lt;/pre&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; NewEmailUseCase newEmailUseCase = ApplicationModel.CreateObjectInScopedRegionManager&amp;lt;NewEmailUseCase&amp;gt;();&lt;/pre&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;  &lt;/pre&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Add some data to the Email message use case (in this case, a blank new email)&lt;/span&gt;&lt;/pre&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; newEmailUseCase.Message = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; EmailMessage();&lt;/pre&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;  &lt;/pre&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Show the email (in a popup, but the consumer doesn't know that)&lt;/span&gt;&lt;/pre&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; ApplicationModel.ShowUseCase(newEmailUseCase);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;The problem with opening several instances of the same popup is: Regions are identified by name in the regionmanager. If you have several popups of the same type open, each popup needs it’s own RegionManager, or else the region names will collide.  In my scenario, I decided that the Popup has most of the same region names as the main shell. That way, any ViewModel or use case could be loaded in either the popup or the main window. &lt;/p&gt;&lt;br /&gt;&lt;h2&gt;Creating use cases in a scoped regionmanager&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;Ok, so i need to create a scoped regionmanager. That’s not to hard, just do: RegionManager.CreateRegionManager() and you have one. However, I wanted the consuming code NOT to have to think about this. It should be blissfully ignorant about the fact that it’s in a scoped regionmanager or not. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Since all most of my objects are created by a DI Container, and it injects all of the dependencies to my object, I decided to use that to solve this problem. So I created a scoped Container and registered the scoped regionmanager with that. Then I created my use case from the newly created scoped container, and if it needs a regionmanager, it would automatically get the scoped regionmanager. Pretty neat huh. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;So schematic, that looks like this:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplicationwithp_C86C/image_8.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplicationwithp_C86C/image_thumb_3.png" border="0" height="383" width="483" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;So when the use case (in green) get’s created, it and it’s dependencies would get the scoped regionmanager injected. Without knowing about the scoped containers or scoped regionmanager. &lt;/p&gt;&lt;br /&gt;&lt;h2&gt;Adding use cases to popups&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;Adding the use case to a popup (in the application model) works like this:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplicationwithp_C86C/image_4.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplicationwithp_C86C/image_thumb_1.png" border="0" height="426" width="614" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Create the use case.&lt;br /&gt;&lt;/strong&gt;Your code creates a new use case instance, for example new NewEmailUseCase(); The application model has a method to create a use case within a new RegionManager scope (as described before). &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Show use case.&lt;br /&gt;&lt;/strong&gt;Your code calls the Application model to show the use case. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Add to region.&lt;br /&gt;&lt;/strong&gt;The application model (which is logic) doesn’t even know if the use case is displayed in a popup or not. It just adds the use case to a region. The region itself is defined in the Shell.XAML. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Visualize the Use case&lt;br /&gt;&lt;/strong&gt;Just as a visualization (view) can be registered for ViewModels, i’ve also registered a visualization for Use Cases. In this case, I’ve registered a window (called Popup.XAML) as visualization. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Show /Close the popup on activate.&lt;br /&gt;&lt;/strong&gt;Now that the visualization is there, I had to create some code to show and close the popup. I decided that, if i Activate() the use case, the popup should be displayed. If I deactivate Use case, the popup should be closed and the use case should be removed from the region. This functionality I put in a RegionBehavior, because it can easily monitor if something is added or removed from a region. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Assign scoped region manager to the popup&lt;br /&gt;&lt;/strong&gt;Lastly, the popup window needs to know the RegionManager that the Use Case wants to use. So I’ve created the IRegionManagerAware interface. If a usecase implements that interface, anything that’s placed inside the region will get this region manager assigned. &lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;As you can see, there are quite a lot of moving bits for showing a use case into a popup. Of course, it would have been A LOT easier to give ‘your code’ (an other use case or something) the knowledge that a view can be opened in popup.  &lt;/p&gt;&lt;br /&gt;&lt;h1&gt;ObservableObject for easier binding&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;If you look at my viewmodels, you’ll see that I make use of the ObservableObject a LOT. It’s a very simple object, one that just takes a type and wraps it in a INotifyPropertyChanged. The nice thing about this is, that I don’t have to add any INotifyPropertyChanged code in my ViewModels anymore. That makes it soooo much easier to do 2 way databinding in WPF. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;The only problem is, that to get to the value, you often have to do: viewModel.MyProperty.&lt;strong&gt;Value &lt;/strong&gt;to get to the actual value of MyProperty. But I thought that’s worth it since now I don’t have to write INotifyPropertyChanged code for my properties anymore. &lt;/p&gt;&lt;br /&gt;&lt;h1&gt;&lt;/h1&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;h1&gt;Conclusion&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;Like I mentioned, before, this outlook style app has become quite an advanced demo of what’s possible with Prism. But I hope it gives you some idea’s on what’s possible with it. I’m also in the process of creating a video walkthrough of this application. But I’ll let you know when that’s done!&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Keep practicing!&lt;/p&gt;&lt;br /&gt;&lt;p&gt;_Erwin&lt;/p&gt;&lt;br /&gt;&lt;p&gt;[UPDATE]&lt;/p&gt;&lt;br /&gt;&lt;p&gt;If you get an System.Threading.SynchronizationLockException from Unity: Don’t worry! I had turned on ‘break on all exceptions’ so the debugger is also breaking on these handled exceptions. Just continue and the app will run fine, or change that debug setting.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9576266" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-6309174754620378203?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/6309174754620378203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-to-build-outlook-style-application_01.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/6309174754620378203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/6309174754620378203'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-to-build-outlook-style-application_01.html' title='how to build an outlook style application with prism v2 – Part 2'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-5928867875379085272</id><published>2010-06-01T10:02:00.001-07:00</published><updated>2010-06-04T21:53:23.713-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVVM'/><title type='text'>how do i do… With the Model-View-ViewModel pattern</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/erwinvandervalk/archive/2009/08/12/how-do-i-do-with-the-model-view-viewmodel-pattern.aspx"&gt;how do i do… With the Model-View-ViewModel pattern&lt;/a&gt;: "&lt;p&gt;While building the Composite Application Guidance for WPF and Silverlight (AKA Prism V2), we relied heavily on the Model View ViewModel pattern. But while this pattern is definitely the best thing ever, it took me a while to come to grips with it:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;First of all, I have a mostly Windows Forms and ASP.Net background. With these technologies, I typically applied different separated presentation patterns, such as Model View Presenter. So when I tried to build WPF and Silverlight applications, I tried to apply the same techniques. But what I found was, that building WPF and Silverlight applications is significantly different from those other technologies. When I tried to apply the Model View ViewModel pattern, I kept running into questions. How do I do “X” in this pattern. &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;At first glance, the Model View ViewModel does not differ that much from other separated patterns such as Model View Presenter. It certainly tries to achieve similar goals, but it does it in subtly different ways. &lt;/p&gt;  &lt;p&gt;In this series of blog posts, I’m going to describe how to apply the Model View ViewModel pattern and what kind of challenges you’ll have to overcome and what kind of decisions you’ll have to make. Over the next couple of weeks, I’m going to be writing about these topics:&lt;/p&gt;  &lt;h1&gt;How do I:&lt;/h1&gt;  &lt;p&gt;&lt;em&gt;(Inside the MVVM pattern)&lt;/em&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a title="The differences between the MVVM pattern and other Separated Presentation patterns" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/14/the-difference-between-model-view-viewmodel-and-other-separated-presentation-patterns.aspx"&gt;Describe the differences between the MVVM pattern and other separated presentation patterns&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="Implementing the Model View ViewModel pattern" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/18/implementing-the-model-view-viewmodel-pattern.aspx"&gt;Implement the Model View ViewModel pattern&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="Adapting a simple vs complex model" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/31/how-do-i-adapt-a-simple-vs-complex-model.aspx"&gt;Adapt a simple vs complex model to the View&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/09/18/how-to-apply-a-viewmodel-to-new-windows.aspx"&gt;Work with popups and modal dialogs&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a title="How to trigger animations from the view, without using code behind." href="http://blogs.msdn.com/erwinvandervalk/archive/2009/10/12/how-to-work-with-animations-in-silverlight-in-the-mvvm-pattern.aspx"&gt;Trigger animations from the View (without code behind)&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Avoid code behind while building Views &lt;/li&gt;    &lt;li&gt;Work with asynchronous methods &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;em&gt;(When applying the MVVM pattern to an application)&lt;/em&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Instantiate my Views / ViewModels &lt;/li&gt;    &lt;li&gt;Create a logical ViewModel structure of my application &lt;/li&gt;    &lt;li&gt;Implement automatic datatemplate selection in Silverlight &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Hope you’ll find these topics interesting. If there are specific things you are struggling with, let me know. If i have time, I’ll try to write something about that as well. &lt;/p&gt;  &lt;p&gt;&lt;a title="MVVM demo app" href="http://cid-be4acdc9251c75df.skydrive.live.com/self.aspx/Public/MVVMDemoApp%202009-10-13.zip"&gt;&amp;lt;Download demo app&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note, you’ll need to download the following references:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd458809.aspx"&gt;Prism&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/silverlightut"&gt;Silverlight testing framework&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;As I’m publishing new blog posts, I’ll keep updating this app, so check back sometimes for updated versions..&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9865196" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-5928867875379085272?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/5928867875379085272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-do-i-do-with-model-view-viewmodel.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/5928867875379085272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/5928867875379085272'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-do-i-do-with-model-view-viewmodel.html' title='how do i do… With the Model-View-ViewModel pattern'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-8313127067117867713</id><published>2010-06-01T10:02:00.000-07:00</published><updated>2010-06-04T21:55:06.925-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVVM'/><title type='text'>the difference between model-view-viewmodel and other separated presentation patterns</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/erwinvandervalk/archive/2009/08/14/the-difference-between-model-view-viewmodel-and-other-separated-presentation-patterns.aspx"&gt;the difference between model-view-viewmodel and other separated presentation patterns&lt;/a&gt;: "&lt;p&gt;This is the second blog post in a series on the Model View ViewModel pattern. Before I’m going to dive into the details of the Model View ViewModel pattern, I thought it is handy to describe the differences and similarities between this pattern and other separated presentation patterns. &lt;/p&gt;  &lt;p&gt;&lt;a title="How do I do ... With the MVVM pattern." href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/12/how-do-i-do-with-the-model-view-viewmodel-pattern.aspx"&gt;&amp;lt;Back to the intro&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="Implementing the Model ViewViewModel pattern" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/18/implementing-the-model-view-viewmodel-pattern.aspx"&gt;&amp;lt;Next: Implement the Model View ViewModel pattern&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;There are quite a number of Separated Presentation patterns out there. Model View Controller, Model View Presenter, Presentation Model, Passive View, Supervising Controller, Model- View-ViewModel and many many more:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_5.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_thumb.png" border="0" height="264" width="399" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;When you look at these patterns, sure, the arrows are in different directions. But is that the only difference? Is a controller the same as a presenter or a presentation model? How would you compare Model View Presenter vs Model View ViewModel. In this blog post, I’m going to describe these differences and similarities between the most common separated presentation patterns. &lt;/p&gt;  &lt;h1&gt;&lt;/h1&gt;  &lt;h1&gt;Building an UI without Separated presentation patterns&lt;/h1&gt;  &lt;p&gt;How would you build a UI without using a separated presentation pattern. Typically, you’d create a form or user control, drag your controls on it and put the logic in the code behind. The code in the Code behind is very closely coupled to the UI, because it directly interacts with the controls on the screen. This approach is nice and straight forward, but only for really simple views. Because when the logic becomes more complicated, maintaining such a UI can become a nightmare!&lt;/p&gt;  &lt;p&gt;The root of the problem lies in the fact that building a UI this way violates the &lt;a href="http://en.wikipedia.org/wiki/Single_responsibility_principle"&gt;single responsibility principle&lt;/a&gt;. This principle states:&lt;em&gt; “A class should have only a single reason for change.” &lt;/em&gt;If a UI component has code for visualization, logic and data, it effectively has several reasons for changing. For example, if you wish to change the type of controls that are used to display the data, that change should not affect the logic. However, because the logic is so closely tied to the controls, it has to change too. This is a ‘&lt;a href="http://en.wikipedia.org/wiki/Code_smell"&gt;code smell&lt;/a&gt;’ that signals that the single responsibility principle is violated. &lt;/p&gt;  &lt;p&gt;So the Form or User Control holds both the code to draw the UI (controls, etc..), the logic of the UI (What happens when you click a button) and the data of the UI (The data that the UI works with), you’ll run into the following problems&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Decreased Maintainability&lt;/strong&gt;      &lt;br /&gt;A change in either the UI, the logic or the data will most likely cause changes in the others. This makes it a lot harder to make changes and decreases maintainability of the UI.      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Decreased Testability       &lt;br /&gt;&lt;/strong&gt;The logic and Data of an application can be written in such a way that each component can be unit tested in isolation. However, the UI related code is inherently very hard to Unit Test, because it often needs user interaction to trigger logic in the UI. Also, any visualization often needs to be judged by a human to see if it ‘looks right’. If the UI related code is mixed with Logic and Data, you loose the testability of the Logic and Data.  &lt;em&gt;Note, there are automated UI testing solutions available. However, they ‘mimic’ the user interaction. They are typically harder to setup and maintain than unit tests, but also they are often only useable as integration tests, because they need the entire application to be set up.&lt;/em&gt; &lt;br /&gt;  &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Decreased Reusability       &lt;br /&gt;&lt;/strong&gt;If your UI related code is mixed with logic and with data, it becomes a lot harder to make that code reusable. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h1&gt;The goals of separated presentation patterns&lt;/h1&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;While the individual patterns are quite different, the goals of these patterns are actually quite similar. Separate UI related code (Views) from Logic related code (Presenters, Controllers, ViewModels, etc..) and from the Data (Models). This allows each of these to evolve independently. For example, you are able to change the Look and Feel of your application, without affecting the logic or the data. &lt;/p&gt;  &lt;p&gt;Secondly because the Logic and Data is separated from the visualization, the logic and the data can be unit tested in isolation. For very straightforward applications, this might not be very significant. For example, if your application is a simple data editor. However, if you have more complicated UI logic, it will quickly become very valuable to be able to automatically verify that your UI logic works as expected. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h1&gt;Model View Controller pattern&lt;/h1&gt;  &lt;p&gt;One of the very first separated presentation patterns was the &lt;a href="http://en.wikipedia.org/wiki/Model-view-controller"&gt;Model-View-Controller&lt;/a&gt; pattern. This pattern was developed by &lt;a href="http://en.wikipedia.org/wiki/Trygve_Reenskaug"&gt;Trygve Reenskaug&lt;/a&gt;.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;span style="font-size:130%;"&gt;In 1979!!!! &lt;/span&gt;&lt;span style="font-size:78%;"&gt;(I wasn’t even born then)&lt;/span&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Anyway, this pattern was developed for building Smalltalk applications. But in those days, computer programming was a bit different than today. There was no Windows. No graphical user interface. No Controls library. If you wanted a UI, you had to draw it yourself. If you wanted to interact with input devices such as keyboards. &lt;em&gt;(Where there even &lt;a href="http://en.wikipedia.org/wiki/Computer_mice"&gt;mice&lt;/a&gt; in those days?)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;But what Trygve did was quite revolutionary. Where everybody was mixing the visualization code, User interaction code, logic and data together, he came up with a pattern to separate these into separate classes, each with a distinct responsibility. &lt;/p&gt;  &lt;p&gt;The problem with the MVC pattern is that it’s very likely the most misunderstood pattern in the world. And I think it’s caused by the naming. Trygne originally called the pattern Model-View-Editor, but later settled on the name Model View Controller. Now I can understand what a Model is (data) and what a View is (Something i can look at, the UI). But what is a controller? Is an ‘&lt;a href="http://www.martinfowler.com/eaaCatalog/applicationController.html"&gt;Application Controller&lt;/a&gt;’ the same controller as the controller in the MVC pattern?  &lt;span style="font-size:78%;"&gt;&lt;em&gt;(No, but you can see where some of the confusion comes from)&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_10.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_thumb_4.png" border="0" height="449" width="647" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So what are those Models, Views and Controllers&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_10.png"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Model       &lt;br /&gt;&lt;/strong&gt;The model typically is the data of your application and the logic to retrieve and persist that data. Often, this is a domain model that can be based on a database or the results from web services. In some cases, that domain model maps perfectly to what you see on the screen, but in other cases it has to be adapted, aggregated or extended to be usable.      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;View&lt;/strong&gt;      &lt;br /&gt;The View was responsible for drawing the UI on the screen. Without windows or controls, that meant drawing, boxes, buttons, input fields, etc on the screen. The View can also monitor the model and display any data in it or update itself if the data changes.      &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Controller&lt;/strong&gt;      &lt;br /&gt;The controller is responsible for handling the User Input and then updating the Model or the View. So if the user is interacts with the application, IE: presses a button on the keyboard, moves the mouse, the controller is notified of that user gesture and decides what to do with it. Maybe it should update the view, maybe it should update the model. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I whipped up the following example to illustrate what a Controller would look like in a ‘pure’ MVC implementation. I happened to implement it in normal asp.net (not asp.net Mvc), but without relying on any of the controls. So it’s more traditional asp style. (&lt;em&gt;&lt;span style="font-size:78%;"&gt;Ok, I know this is not a pretty example, but I hope it gets the point across of what a controller was meant to do.)&lt;/span&gt; &lt;/em&gt;&lt;/p&gt;  &lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Controller&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; IView _view;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Controller(IView view)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         _view = view;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;         HttpRequest request = HttpContext.Current.Request;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (request.Form[&lt;span style="color: rgb(0, 96, 128);"&gt;"ShowPerson"&lt;/span&gt;] == &lt;span style="color: rgb(0, 96, 128);"&gt;"1"&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;         {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.IsNullOrEmpty(request.Form[&lt;span style="color: rgb(0, 96, 128);"&gt;"Id"&lt;/span&gt;]))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;             {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;                 ShowError(&lt;span style="color: rgb(0, 96, 128);"&gt;"The ID was missing"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;             }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;             ShowPerson(Convert.ToInt32(request.Form[&lt;span style="color: rgb(0, 96, 128);"&gt;"Id"&lt;/span&gt;]));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; ShowError(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; s)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;         _view.ShowError(s);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; ShowPerson(&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; Id)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  28:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  29:&lt;/span&gt;         var model = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Repository().GetModel(Id);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  30:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  31:&lt;/span&gt;         _view.ShowPerson(model);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  32:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  33:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After many years, the programming paradigm changed somewhat. The concept of a &lt;a title="Control, aka GUI Widget" href="http://en.wikipedia.org/wiki/Widget_%28computing%29"&gt;control&lt;/a&gt; emerged. A Control encapsulates both the visualization (It draws itself), but also the user interaction. A button knows what to do if you click it. A textbox knows what to do if you type text in it. This reduces the need for a controller, so the Model View Controller pattern became less relevant. However, since there was still a need for separating out the logic of the application from the Controls and the data, an other pattern called Model View Presenter became more popular. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Most examples of the MVC pattern focus on very small components, such as building a text box or building a button. With a bit more modern UI technologies (Visual basic 3 is modern compared to 1979 smalltalk), you typically don’t need to apply this pattern. Unless you are developing your own control using very low level API’s. For example, if you want to build a completely custom control using Direct X, then you might be interested in this pattern. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The last couple of years MVC pattern became very relevant again, but for a different reason, with the advent of the &lt;a href="http://www.asp.net/mvc/"&gt;ASP.Net MVC&lt;/a&gt; framework. The ASP.Net MVC framework does not use the concept of controls in the same way as the normal ASP.NET framework does. In the ASP.Net MVC framework, a View is an ASPX control that renders HTML. And the controller again handles the user gestures, because it receives the HTTP requests. Based on the http request, it determines what to do (update a model or display a particular view). &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Model View Presenter pattern&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So after the rise of visual programming environments and the introduction of controls that encapsulated both the Visualization and the User Interaction code, the need for creating a separate controller class became less. But people still found the need for a form separated presentation, only this time at a higher abstraction level.  Because it turned out that if you create a form that is composed out of several controls and also contains the UI logic and the data, The Model View Presenter pattern describes a way to separate out the visual elements (Controls) from the Logic (What happens when you interact with the controls) and the Data (what data is displayed in the view).&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_4.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_thumb_1.png" border="0" height="505" width="651" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt; &lt;li&gt;&lt;strong&gt;Model&lt;br /&gt;    &lt;br /&gt;&lt;/strong&gt;The model typically is the data of your application and the logic to retrieve and persist that data. Often, this is a domain model that can be based on a database or the results from web services. In some cases, that domain model maps perfectly to what you see on the screen, but in other cases it has to be adapted, aggregated or extended to be usable. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;&lt;strong&gt;View&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;The View is typically a user control or form that combines several (smaller grained controls) into a (part of a) user interface. The user can interact with the controls in the View, but when some logic needs to be started, the view will delegate this to the presenter. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;&lt;strong&gt;Presenter&lt;br /&gt;    &lt;br /&gt;&lt;/strong&gt;The presenter holds all the logic for the view and is responsible for synchronizing the model and the View. When the view notifies the presenter that the user has done something (for example, clicked a button), the presenter will then update the model and synchronize any changes between the Model and the View. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;One important thing to mention is that the Presenter doesn’t communicate directly to the view. In stead, it communicates through an interface. This way, the presenter and the model can be tested in isolation. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;There are two variations of this pattern, Passive View and Supervising Controller. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;&lt;strong&gt;Passive View&lt;/strong&gt;&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the passive view, the view knows nothing about the model, but instead exposes simple properties for all the information it wants to display on the screen.  The presenter will read information from the Model and update the properties from the model.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This would be an example of a passive view:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; PersonalDataView : UserControl, IPersonalDataView&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     TextBox _firstNameTextBox;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; FirstName&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         get&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;         {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _firstNameTextBox.Value;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;         set &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;         {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;             _firstNameTextBox.Value = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;         }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As you can see, this requires quite a lot of coding, both for the View but also for the Presenter. However, it will make the interaction between the View and the Presenter more testable. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Supervising Controller&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In supervising controller, the View DOES know about the Model and is responsible for databinding the model to the view. This makes the interaction between the Presenter and the View a lot less chatty, but at the expense of testability of the View-Presenter interaction. Personally i hate the fact that this pattern is called “Controller”. Because the controller is again not the same thing as the controller in the MVC pattern and also not the same as an “Application Controller”. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This would be an example of a view in the Supervising Controller. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; PersonalDataView : UserControl, IPersonalDataView&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; TextBox _firstNameTextBox;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; SetPersonalData(PersonalData data)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         _firstNameTextBox.Value = data.FirstName;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; UpdatePersonalData(PersonalData data)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;         data.FirstName = _firstNameTextBox.Value;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As you can see, this interface is less granular and puts more responsibilities in the View. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Presentation Model&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Martin Fowler describes a different approach on achieving separation of concerns on his site, that’s called &lt;a title="Presentation Model" href="http://martinfowler.com/eaaDev/PresentationModel.html"&gt;Presentation Model&lt;/a&gt;. The Presentation Model is a logical representation of the User Interface, without relying on any visual elements. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_7.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_thumb_2.png" border="0" height="251" width="534" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The presentation model has several responsibilities:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt; &lt;li&gt;&lt;strong&gt;Hold the logic of the UI:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Same as the Presenter, the Presentation Model holds the logic of the UI. When you click a button, that click is forwarded to the Presentation Model, which then decides what to do with it.&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;&lt;strong&gt;Massage the data from the model to be displayed on the screen:&lt;br /&gt;    &lt;br /&gt;&lt;/strong&gt;The presentation model can convert the data in the model so it can more easily be displayed on the screen. Often, the information contained in the model cannot directly be used on the screen. You might need to alter the information (IE: convert data types),  enrich the information (IE: summations) or aggregate information from several sources. This is especially likely if you don’t have full control over the model. For example, you get information from an 3rd party web service, or from a database of an existing application.&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;&lt;strong&gt;Store the state of the UI:&lt;br /&gt;    &lt;br /&gt;&lt;/strong&gt;Often, the UI needs to store additional information that has nothing to do with the domain model. For example, which item is currently selected on the screen? What validation errors have occurred? The presentation model can store this information in properties.  &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The View can then easily read the information from the Presentation Model and get all the information it needs to display the view. One advantage of this approach is that you can create a logical and fully unit testable representation of your UI, without relying on testing visual elements. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The Presentation Model pattern doesn’t really describe how the view then uses the data in the Presentation Model. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Model View ViewModel&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;And then there is Model View ViewModel, also known as MVVM or just the ViewModel pattern. It looks surprisingly similar to the Presentation Model pattern:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_11.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/1thedifferencebetweenmodelviewviewmodela_EC9E/image_thumb_3.png" border="0" height="433" width="669" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In fact, the pretty much the only difference is the explicit use of the databinding capabilities of WPF and Silverlight. Not surprising, because &lt;a href="http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx"&gt;John Gossman&lt;/a&gt; was one of the first persons to mention this pattern on his blog. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The ViewModel doesn’t communicate directly with the View. Instead it exposes easily bindable properties and methods (in the form of &lt;a title="The ICommand interface" href="http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.aspx"&gt;Commands&lt;/a&gt;). The View can databinding those properties and commands to query information from the ViewModel and call methods on the ViewModel. It’s also not required that the View knows about the ViewModel. XAML Databinding uses a form of reflection to bind properties of the ViewModel, so theoretically you can use any ViewModel with the View that exposes the right properties. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Some of the things I really like about this pattern when applied to Silverlight or WPF are:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt; &lt;li&gt;You get a fully testable logical model of your application. I’ll talk more about this in further posts.&lt;br /&gt;  &lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;Because the View Model offers everything the view needs in easily consumed format, the view itself can be fairly simple. In fact, a designer can play with the look and feel in Expression Blend and change it without affecting the UI.&lt;br /&gt;  &lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;Lastly, you can avoid using code behind. In a later blog post, I’ll describe how to do this in more detail. Now this is a point of debate amongst View Model fans. I personally feel that you often don’t need code behind and that there are often better ways of solving it. Ok, sometimes you’ll need to do some tricks (like create attached behaviors) but they offer really nice and reusable solution. However, I also recognize that not everybody likes XAML markup and the XAML way of expressing databinding. The ViewModel pattern doesn’t force you to use or avoid code behind. Do what feels right to you. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Conclusion&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I hope this description of the most common Separated Presentation patterns helps you in understanding their differences. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9870544" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-8313127067117867713?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/8313127067117867713/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/difference-between-model-view-viewmodel.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8313127067117867713'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8313127067117867713'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/difference-between-model-view-viewmodel.html' title='the difference between model-view-viewmodel and other separated presentation patterns'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-3575775084595989776</id><published>2010-06-01T10:01:00.001-07:00</published><updated>2010-06-04T21:55:55.056-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVVM'/><title type='text'>Implementing the Model View ViewModel pattern</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/erwinvandervalk/archive/2009/08/18/implementing-the-model-view-viewmodel-pattern.aspx"&gt;Implementing the Model View ViewModel pattern&lt;/a&gt;: "&lt;blockquote&gt;   &lt;p&gt;In this third part of my series of blog posts on the ViewModel pattern, I’m going to demonstrate how to implement a simple example of the ViewModel pattern. Not to worry, we’ll dive into more exiting examples later. &lt;/p&gt;    &lt;p&gt;&lt;a title="How do I do ... with the ViewModel pattern" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/12/how-do-i-do-with-the-model-view-viewmodel-pattern.aspx"&gt;&amp;lt;Back to intro&amp;gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a title="The difference between MVVM and other separated presentation patterns." href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/14/the-difference-between-model-view-viewmodel-and-other-separated-presentation-patterns.aspx"&gt;&amp;lt;Back to: The difference between MVVM and other Separated presentation patterns&amp;gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a title="Adapting a simple vs complex model." href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/31/how-do-i-adapt-a-simple-vs-complex-model.aspx"&gt;&amp;lt;Next: Adapting a simple vs complex model&amp;gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;     &lt;/p&gt;&lt;p&gt;&lt;a title="MVVM demo app" href="http://cid-be4acdc9251c75df.skydrive.live.com/self.aspx/Public/MVVMDemoApp%20-%20blog%2020090917.zip"&gt;&lt;/a&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;&lt;/blockquote&gt;  &lt;h1&gt;The ViewModel &lt;/h1&gt;  &lt;blockquote&gt;   &lt;p&gt;So what is a ViewModel? And how does it differ from a View or the Model. Consider the following example. Suppose you would build Paint using WPF or Silverlight, using the MVVM pattern:&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/ImplementingtheModelViewViewModelpattern_D996/image_12.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/ImplementingtheModelViewViewModelpattern_D996/image_thumb_5.png" border="0" height="338" width="465" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;The View obviously determines what is displayed on the Screen. And the Model, well that will likely be the Image. But the application works with more data than ‘just’ the Document. This extra data is mostly the State of the UI. What brush is currently selected? What is the ‘zoom’ percentage? While it is possible to store this information in the View itself, this is usually a bad practice. For example, the zoom slider bar could be the place where you would store the zoom percentage. However, when more elements on the screen need to use the Zoom percentage, this value quickly becomes very hard to manage. &lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Model for the View&lt;/h2&gt;  &lt;blockquote&gt;   &lt;p&gt;The ViewModel is a model for the view. Therefore, it hold’s all the state of the view as well as the logic that operates on the state. The ViewModel exposes this data and logic in such a way that the View can very easily access it. However, the ViewModel should not expose or interact directly with UI elements.  &lt;/p&gt;    &lt;p&gt;Another responsibility of the ViewModel is to adapt the Model to the View. Typically the Model is a domain model (we’ll dive into that more in a later blog post). If you have full control over the model, then typically you can build it so that the model itself is very easily databindable. However, if you don’t have control over the model, for example, you are getting it from an external system, then the ViewModel might need to adapt the model to the view. For example, by adding aggregations, combining information from different models or simply by implementing INotifyPropertyChanged to enable the ViewModel notifying the View that properties have changed. &lt;/p&gt; &lt;/blockquote&gt;  &lt;h1&gt;The MVVM pattern&lt;/h1&gt;  &lt;blockquote&gt;   &lt;p&gt;So the following picture shows the MVVM pattern as how you would typically implement it in WPF or Silverlight:&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/ImplementingtheModelViewViewModelpattern_D996/image_14.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/ImplementingtheModelViewViewModelpattern_D996/image_thumb_6.png" border="0" height="312" width="494" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;The View is typically implemented as a UserControl or DataTemplate (in WPF). It uses Databinding to read and update information on the ViewModel. For example, the ViewModel can expose a public property Name that can be bound to a textbox. &lt;/p&gt;    &lt;p&gt;If the view needs to communicate to the ViewModel, there are several options: &lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;&lt;strong&gt;Commands&lt;/strong&gt;&lt;/h2&gt;  &lt;blockquote&gt;   &lt;p&gt;To route the Click event from a button to a ViewModel, the easiest way is to implement a Command. The &lt;a title="The Command pattern on wikipedia" href="http://en.wikipedia.org/wiki/Command_pattern"&gt;Command pattern&lt;/a&gt; describes an object that can invoke functionality at a later point in time. In this case, when the user clicks a button. We’ll dive into commands later in this post. &lt;/p&gt;    &lt;p&gt;This defines the Commands in XAML:&lt;/p&gt;    &lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;     &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;       &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Define the Commands&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; ICommand ShowCalorieKingInfoCommand { get; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; ICommand ShowIngredientInfoCommand { get; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Initialize the commands in the constructor with a delegate command.&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; MealDetailsViewModel(IDialogService dialogService)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.ShowCalorieKingInfoCommand = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DelegateCommand&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&amp;gt;(ShowMealCalorieKing);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.ShowIngredientInfoCommand = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DelegateCommand&amp;lt;Ingredient&amp;gt;(ShowIngredientInfo, CanShowIngredientInfo);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; } &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// The methods called when the commands are invoked&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; ShowMealCalorieKing(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; notUsed) {..}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanShowIngredientInfo(Ingredient selectedIngredient) {..}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; ShowIngredientInfo(Ingredient selectedIngredient) {..}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt; &lt;/div&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;This snippet shows an example how to bind a command to a button in XAML&lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;div&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Button&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Margin&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="10, 10, 10, 10"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Content&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Show information on CalorieKing.Com"&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(255, 0, 0);"&gt;Commands:Click&lt;/span&gt;.&lt;span style="color: rgb(255, 0, 0);"&gt;Command&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="{Binding ShowCalorieKingInfoCommand}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;Pretty much only buttons allow you to use Commands out of the box. Now it’s possible (and not too hard) to create your own commands using &lt;a href="http://blogs.msdn.com/johngossman/archive/2008/05/07/the-attached-behavior-pattern.aspx"&gt;attached behaviors&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;&lt;strong&gt;2 way bindable properties&lt;/strong&gt; &lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;p&gt;You can also use TwoWay databinding to notify the ViewModel that something has changed. For example, the following codesnippet shows how the DataGrid Control has a SelectedItem property. If you TwoWay databind this property to a property on the ViewModel. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;Here’s the property in C#:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;   &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Ingredient SelectedIngredient&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _selectedIngredient; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     set&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_selectedIngredient == &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;         _selectedIngredient = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         OnPropertyChanged(&lt;span style="color: rgb(0, 96, 128);"&gt;"SelectedIngredient"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt; &lt;/div&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;You can see that it also supports the INotifyPropertyChanged event. This means that the View will be notified if this value is changed in the ViewModel. And this is what the XAML would look like:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;div&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;data:DataGrid&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="{Binding Meal.Ingredients}"&lt;/span&gt;&lt;br /&gt;              &lt;span style="color: rgb(255, 0, 0);"&gt;SelectedItem&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="{Binding SelectedIngredient, Mode=TwoWay}"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt; &lt;/div&gt;&lt;br /&gt;&lt;br /&gt; &lt;div&gt; &lt;/div&gt;&lt;br /&gt;&lt;br /&gt; &lt;div&gt;When I first started using the ViewModel pattern, I overlooked this capability. For example, I was looking for a way to attach functionality to the SelectedItemChanged event of the DataGrid. But two way databinding works a lot more directly. Just don’t forget to add the “Mode=TwoWay” tag ;)&lt;/div&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;&lt;strong&gt;Bind ViewModel methods to events from controls&lt;/strong&gt;&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;p&gt;The &lt;a href="http://caliburn.codeplex.com/"&gt;Caliburn&lt;/a&gt; framework allows you to bind public methods on the ViewModel directly to your controls in XAML. While this is a really cool technology, I also believe it makes your XAML more complex, because effectively, you are now programming (calling methods) in XAML. So I would personally try to either use commands, use two way databinding or implement an &lt;a href="http://blogs.msdn.com/johngossman/archive/2008/05/07/the-attached-behavior-pattern.aspx"&gt;attached behavior&lt;/a&gt; (more on this subject later).  &lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Code behind&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;p&gt;It is always possible to use Code Behind to communicate between the View and the ViewModel. Whether this is a good idea is a topic of hot debate. I personally am of the opinion that there are better ways to solve this problem than to use code behind. In a later blog post, I’ll go into details why i think this is a bad idea and how you can avoid this.  But there are people who think differently.&lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;ICommand interface&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;p&gt;A common way to expose functionality from your ViewModel that your Views can interact with is by exposing &lt;a title="Commands, as described in the Composite Application Library" href="http://msdn.microsoft.com/en-us/library/cc707894.aspx"&gt;Command&lt;/a&gt; objects. A command object implements the &lt;a title="The ICommand interface on MSDN" href="http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.aspx"&gt;ICommand&lt;/a&gt; interface. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;The ICommand interface has two methods:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;ul&gt;&lt;br /&gt;   &lt;li&gt;&lt;strong&gt;Execute&lt;/strong&gt;, which will fire the logic encapsulated by the command &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;   &lt;li&gt;&lt;strong&gt;CanExecute&lt;/strong&gt;, which determines if the command can actually execute. &lt;/li&gt;&lt;br /&gt; &lt;/ul&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;The CanExecute is interesting. It’s a common scenario that you might wish to disable certain functionality, based on the state of your UI. This can easily be accomplished with a command. Because, when you bind a button to a command and CanExecute returns false, then the button will automatically become disabled. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;Commands also have another advantage: They decouple the invocation from the actual logic. This allows for interesting scenario’s:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;ul&gt;&lt;br /&gt;   &lt;li&gt;&lt;strong&gt;Binding multiple ui elements to a command&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;Consider for example a SaveCommand. Often you don’t just have a Save Button, but also a Save menu item, and perhaps a save keyboard shortcut that will fire the same functionality. All these user gestures can be bound to the same command. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;   &lt;li&gt;&lt;strong&gt;Chaining commands together&lt;br /&gt;      &lt;br /&gt;&lt;/strong&gt;You might also wish to bind several commands to a single UI element. For example, a certain type of ViewModel can expose a Save Command. However, you can have several instances of that ViewModel (with the corresponding view) open at any given time. A Save All button can be bound to all SaveCommands on all those ViewModels. &lt;/li&gt;&lt;br /&gt; &lt;/ul&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;Silverlight doesn’t have Commanding support built in. Fortunately, it does support the ICommand interface, so there are several libraries available that provide Silverlight implementations of the ICommand interface. For example Prism (aka the Composite Application Guidance for WPF and Silverlight) and the MVVM Toolkit both provide a DelegateCommand implementation. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;In my demo application, I’m also demonstrating the use of the DelegateCommand. &lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;The INotifyPropertyChanged interface&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;p&gt;One thing that you’ll find yourself implementing on your ViewModels the time is the INotifyPropertyChanged interface. This interface allows your ViewModel to notify the View of changes to properties. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;This code snippet shows how to implement this pattern:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt;   &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Public event (for the interface)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Protected method for invoking the event from code&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;virtual&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; property)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     var handler = PropertyChanged;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (handler != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         handler(&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; PropertyChangedEventArgs(property));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Example property that triggers the property. &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Ingredient SelectedIngredient&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;  {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;      get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _selectedIngredient; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;      set&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;      {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;          &lt;span style="color: rgb(0, 128, 0);"&gt;// IMPORTANT: only trigger the event if someting actually changes!&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_selectedIngredient == &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;              &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;          _selectedIngredient = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt;          OnPropertyChanged(&lt;span style="color: rgb(0, 96, 128);"&gt;"SelectedIngredient"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt;      }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt;  }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt; &lt;/div&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;One important thing: before invoking the event in the property, check if the value has actually changed. This helps preventing never ending loops when properties are chained together. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;If you don’t like the repeating code you’ll get when implementing properties with INotifyPropertyChagned, you can also use ObservableObjects as properties, as I’m describing (among other things) in this blog post:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;p&gt;&lt;a title="http://blogs.msdn.com/erwinvandervalk/archive/2009/04/29/how-to-build-an-outlook-style-application-with-prism-v2-part-2.aspx" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/04/29/how-to-build-an-outlook-style-application-with-prism-v2-part-2.aspx"&gt;http://blogs.msdn.com/erwinvandervalk/archive/2009/04/29/how-to-build-an-outlook-style-application-with-prism-v2-part-2.aspx&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;What not to do in a ViewModel&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;p&gt;There are a couple of things you shouldn’t do in your ViewModels:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;ul&gt;&lt;br /&gt;   &lt;li&gt;&lt;strong&gt;Expose or interact with visual elements in your ViewModel&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;Don’t try to expose Visual Elements, such as Buttons or other views from your ViewModel. This ties your UI to Visual Elements and makes it hard to test in isolation. Now you might run into the situation where your ViewModel needs to determine which view to display. In a later blogpost, i’ll describe how your ViewModel can be responsible for the logical ViewModel selection and use a DataTemplate to create the Visualization.&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;   &lt;li&gt;&lt;strong&gt;Try to control the View too directly from your ViewModel&lt;br /&gt;      &lt;br /&gt;&lt;/strong&gt;You should try to keep your ViewModel logical, rather than Visual. For example, if you want to color a control red in error situations, you could expose an “IsControlRed” property, or expose a brush in the red color. It’s usually better to expose the logical property, such as “HasError”. Then the UI designer can decide if the color of the control should be red or purple in an error situation. &lt;/li&gt;&lt;br /&gt; &lt;/ul&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Summary&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt; &lt;p&gt;This blog post describes the basics about implementing the MVVM pattern. In later blog posts, we’ll dive into more interesting scenario’s. &lt;/p&gt;&lt;/blockquote&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9874681" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-3575775084595989776?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/3575775084595989776/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/implementing-model-view-viewmodel.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/3575775084595989776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/3575775084595989776'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/implementing-model-view-viewmodel.html' title='Implementing the Model View ViewModel pattern'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-2204804855896885444</id><published>2010-06-01T10:01:00.000-07:00</published><updated>2010-06-04T21:56:22.732-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVVM'/><title type='text'>how to apply a viewmodel to new windows</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/erwinvandervalk/archive/2009/09/18/how-to-apply-a-viewmodel-to-new-windows.aspx"&gt;how to apply a viewmodel to new windows&lt;/a&gt;: "&lt;p&gt;A colleague asked me a question today. How do you apply the Model View ViewModel pattern to new Windows and Popups. To illustrate that, i wrote a small sample app, which I wanted to share with you.&lt;/p&gt;  &lt;p&gt;This post is part of a series:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/12/how-do-i-do-with-the-model-view-viewmodel-pattern.aspx"&gt;&amp;lt;Back to intro&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/31/how-do-i-adapt-a-simple-vs-complex-model.aspx"&gt;&amp;lt;Back to ‘How do I adapt a simple vs complex viewModel’&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="Forward to: How do I trigger animations from your ViewModel" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/10/12/how-to-work-with-animations-in-silverlight-in-the-mvvm-pattern.aspx"&gt;&amp;lt;Forward to ‘How to trigger animations from your ViewModel’&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;   &lt;/p&gt;&lt;p&gt;&lt;a title="MVVM sample code" href="http://cid-be4acdc9251c75df.skydrive.live.com/self.aspx/Public/mvvm%20-%20Windows%20-%2020090918.zip"&gt;&lt;/a&gt;&lt;/p&gt; There are usually two types of windows you might want to open. Modal windows, where the current window is no longer accessible until the modal window is closed, and non modal popups, where both the current window and the popup are opened and usable at the same time. &lt;p&gt;&lt;/p&gt;  &lt;h1&gt;&lt;/h1&gt;  &lt;h1&gt;Modal windows&lt;/h1&gt;  &lt;p&gt;From the perspective of the ViewModel, opening another viewmodel in a popup is just like a very slow synchronous service. Take for example opening a confirmation dialog. The viewmodel doesn’t care if you ask the confirmation from a user, or from an external service. All it knows is that it needs the confirmation and has to wait until it get’s it. &lt;/p&gt;  &lt;p&gt;The following codesnippet shows this:&lt;/p&gt;  &lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; MainWindowViewModel : INotifyPropertyChanged&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;//...&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// At a certain point in time, the MainViewModel want's to open a modal window&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// pass it the number of the window and know the number of the window that was closed last. &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; OpenDialogWindow()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create the viewmodel for the child window. This allows us to communicate&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// with the window in the popup&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;         var viewModel = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ChildViewModel();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// pass the viewmodel some data: in this case, the number of the current window&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;         viewModel.WindowNumber = ++WindowCount;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;     &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// opening a modal dialog is like a synchronous service&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;         _windowService.ShowViewModelInDialog&amp;lt;ChildView&amp;gt;(viewModel);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// After the window is closed, get the number of the window that was just closed&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;         LastWindowToBeClosed = viewModel.WindowNumber;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can see how the viewmodel askes a service (The WindowService) to show a particular viewmodel. To keep the implementation of the WindowService, i’m also passing the Template (ChildView) to use to visualize the View. But there are many different ways of solving this, for example the one I’ve demonstrated in my &lt;a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/09/18/how-to-build-an-outlook-style-application-part-1.aspx"&gt;Outlook style sample&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The code for the WindowService is very simple:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; WindowService : IWindowService&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt;? ShowViewModelInDialog&amp;lt;TViewType&amp;gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; viewModel)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;where&lt;/span&gt; TViewType : Control, &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         Window w = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Window();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         TViewType view = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; TViewType();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;         view.DataContext = viewModel;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;         w.Content = view;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; w.ShowDialog();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is simply a generic way of showing a viewmodel in a window, by using a View to visualize the ViewModel and show the window as a dialog. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Non modal popups&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now in the case of a normal popup, it’s more like an asynchronous service. The code in the ViewModel can continue to execute, but the opened window can raise events to signal status changes. This is very similar to, for example, an asynchronous webservice, that raises events for progress changes or completion. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The following code snippet shows this:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; OpenPopupWindow()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Create the ViewModel to communicate with the service&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     var viewModel = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ChildViewModel();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Pass the ViewModel some information&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     viewModel.WindowNumber = ++WindowCount;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Opening a popup is like an asynchronous service. You can listen to change notification events&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// such as the Closed Event i've implemented&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     _windowService.ShowViewModelInPopup&amp;lt;ChildView&amp;gt;(viewModel);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Listen for a change notification, when the window is closed&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;     viewModel.Closed += viewModel_Closed;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// This method is called when the window is closed again&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; viewModel_Closed(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Get the information from the viewmodel&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;     var viewModel = (sender &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; ChildViewModel);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.LastWindowToBeClosed = viewModel.WindowNumber;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Unsubscribe from the event to prevent memory leaks&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt;     viewModel.Closed -= viewModel_Closed;   &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As you can see, the code is similar to the Modal example. The only difference is, that you have to sign up for an event to get the required information. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The WindowService is slightly more complicated in this case:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; ShowViewModelInPopup&amp;lt;TViewType&amp;gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; viewModel)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;where&lt;/span&gt; TViewType : Control, &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     Window window = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Window();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     TViewType view = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; TViewType();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     view.DataContext = viewModel;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     window.Content = view;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// If the viewmodel knows about window closing events (IClosedAware) &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// then forward closing notifications to the viewModel;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;     SubScribeToClosedEvent(window, viewModel &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; IClosedAware);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;     window.Show();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; SubScribeToClosedEvent(Window window, IClosedAware view)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (view == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;     window.Closed += (sender, args) =&amp;gt; view.OnClosed();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I wanted a generic way for the WindowService to notify a viewmodel if the window is closed. So I created the IClosedAware interface, and implemented that on the ViewModel. The WindowService will, if the viewModel implements the IClosedAware, sign up for the ClosedEvent of the window and notify the ViewModel if that event occurs. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Hopefully this explains the way you can work with several Windows when using MVVM. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9896920" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-2204804855896885444?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/2204804855896885444/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-to-apply-viewmodel-to-new-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/2204804855896885444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/2204804855896885444'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-to-apply-viewmodel-to-new-windows.html' title='how to apply a viewmodel to new windows'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-926843474648021143</id><published>2010-06-01T10:00:00.000-07:00</published><updated>2010-06-04T21:56:50.411-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PRISM'/><category scheme='http://www.blogger.com/atom/ns#' term='MVVM'/><title type='text'>how to build an outlook style application – part 1</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/erwinvandervalk/archive/2009/09/18/how-to-build-an-outlook-style-application-part-1.aspx"&gt;how to build an outlook style application – part 1&lt;/a&gt;: "&lt;p&gt;[Update] This is part 1 of this post. Read the &lt;a title="Part 2 of &amp;quot;how to build an outlook style application&amp;quot;" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/04/29/how-to-build-an-outlook-style-application-with-prism-v2-part-2.aspx"&gt;second post&lt;/a&gt; here. &lt;/p&gt;  &lt;p&gt;At the end of building prism V2, we have played around with different application styles to see how easy it is to consume our own libraries. In this blog post, I’m going to describe my attempt at creating an outlook style application. My implementation shows the following aspects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;How to create application parts that can be activated and deactivated, can be put in a list, and are very lightweight. &lt;/li&gt;    &lt;li&gt;How to use an Application Model? &lt;/li&gt;    &lt;li&gt;How to do pure ViewModel first development. In WPF, you can apply implicit Data Templates to visualize objects, but in silverlight that doesn’t work. So I’ll demonstrate two ways to do this. &lt;/li&gt;    &lt;li&gt;How to handle RegionContext in a more direct way. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You can download the Source Code here:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://cid-be4acdc9251c75df.skydrive.live.com/self.aspx/Public/OutlookStyleApp%20-%20Blog%2020090918.zip"&gt;&amp;lt;Outlook style app&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You will need the following references to make the solution work:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.codeplex.com/CompositeWPF"&gt;Prism&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=unity"&gt;Unity&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Download prism, compile it, and place the binaries in the lib folder. Also, place the Unity binaries in the lib folder. &lt;/p&gt;  &lt;h1&gt;Requirements&lt;/h1&gt;  &lt;p&gt;So what are my requirements for the outlook style app. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Be able to show a list of buttons that can activate parts of an application (like the outlook buttons for Mail, calendar, contacts, etc.) &lt;/li&gt;    &lt;li&gt;It should be possible to activate and deactivate ‘Application parts’. If an application part becomes active, It’s initial view should show up in the main area. &lt;/li&gt;    &lt;li&gt;Only one ‘application part’ can be active at any point in time. &lt;/li&gt;    &lt;li&gt;When a view or an application part becomes active or inactive, other views might also have to be added or removed, such as toolbars. &lt;/li&gt;    &lt;li&gt;Show a list of available ‘application parts’, without really instantiating all their views immediately. Only instantiate the views the first time you show them. &lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Solution&lt;/h1&gt;  &lt;p&gt;So this is my Outlook style app:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplication_8D33/image_4.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplication_8D33/image_thumb_1.png" border="0" height="269" width="407" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With a little bit of imagination, I hope you can see how this app could resemble outlook ;)&lt;/p&gt;  &lt;p&gt;The following diagram shows the overall structure of the application and the most important pieces. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplication_8D33/image_2.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtobuildanoutlookstyleapplication_8D33/image_thumb.png" border="0" height="448" width="670" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;My shell has several regions, each brightly colored to make it clear where they are. &lt;/p&gt;  &lt;p&gt;The &lt;b&gt;ApplicationModel&lt;/b&gt; defines that the application has a list of UseCases. The ButtonBar (in red) is bound to the list of use cases. Each use case is represented as a button. When you click that button, the ActivateUseCase command is fired which will activate the selected UseCase. &lt;/p&gt;  &lt;p&gt;An UseCase (like the &lt;b&gt;MainEmailUseCase&lt;/b&gt;) implements the &lt;b&gt;IActiveAwareUseCaseController&lt;/b&gt; and likely inherits from &lt;b&gt;ActiveAwareUseCaseController&lt;/b&gt;. This makes it activatable (I know, it’s not a word). Lastly, the EmailUseCase itself defines which views it needs and where those views should go. &lt;/p&gt;  &lt;p&gt;In the following paragraphs, i’m going to describe some of the moving pieces of this design.&lt;/p&gt;  &lt;h1&gt;Application model&lt;/h1&gt;  &lt;p&gt;The approach I took when creating the OutlookStyle app is to have a central ‘application model’ that knows how the application is structured. The modules also know a bit about this application model, through the IApplicationModel interface. &lt;/p&gt;  &lt;p&gt;The ApplicationModel has a list of Main Usecases (more on usecases later), that I could bind my list of buttons to. It also has a command that can activate a UseCase when one of the buttons is clicked. &lt;/p&gt;  &lt;p&gt;Using an ApplicationModel is kind of a double edged sword. It ties you somewhat down to a specific style of application. This makes your modules less portable, but it also makes the interaction between your modules and your shell more explicit and thus easier to understand. Using an application model is only one approach to creating an outlook style application and there are many others. But I thought it was an elegant solution and since we weren’t showing how to create an ApplicationModel in the Prism RI or the Quickstarts I thought it would be nice to show it here. &lt;/p&gt;  &lt;p&gt;Internally, the application model uses a SingleActiveRegion to store the UseCases. This might seem strange, but a Region is nothing more than a model that can store a collection of objects that can be added, removed and activated. The SingleActiveRegion is ideal for this purpose, because it will make sure only one usecase is active at a given time. I choose not to add the region to a regionmanager, because I want the ApplicationModel to control access to this region. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h1&gt;Showing application parts: UseCaseControllers. &lt;/h1&gt;  &lt;p&gt;My implementation for the ‘application parts’ that can be activated and deactivated are called ‘UseCaseControllers’. This were my requirements for them: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;I want to be able to put it in a list bind a collection of buttons to &lt;/li&gt;    &lt;li&gt;I want to be able to activate and deactivate it. &lt;/li&gt;    &lt;li&gt;It should be very lightweight, because all available controllers will be activated at once. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Motivations for naming the ‘application parts’&lt;/h3&gt;  &lt;p&gt;It was quite hard to find a right name for the ‘application parts’:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It’s not a module, because a module will likely contain many application parts. Also, a module should be viewed as a unit of deployment. &lt;/li&gt;    &lt;li&gt;It’s not a view, because it’s more likely a set of views, working together to fulfill a single use case. These views, can be main views, tool bars, etc.. &lt;/li&gt;    &lt;li&gt;I considered the term ‘feature’ for a while. However, if you have ever built installers, you’ll know that a feature is also an overloaded term. It also refers more to a unit of deployment than what we’re looking for here. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So called my ‘Application parts’ &lt;strong&gt;UseCaseControllers&lt;/strong&gt;. In my example, the main buttons on the outlook app kind of map to the ‘main’ or initial UseCases in my application. &lt;/p&gt;  &lt;p&gt;Why call it controller? Controller is quite an overloaded term, because of the Model View Controller pattern. However, controllers are also commonly used to coordinate some kind of process and couple several pieces together to form a single unit. So because the controller hooks several controls together to perform a single use case, I called it a UseCaseController. &lt;/p&gt;  &lt;h3&gt;ActiveAwareUseCaseController&lt;/h3&gt;  &lt;p&gt;The ActiveAwareUseCaseController is a handy base class that you can use to fulfill the IActiveAwareUseCaseController interface. It does the following things for you:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;BeforeFirstActivation Method. &lt;/b&gt;Have a handy place for the first time you activate this controller. In this method (BeforeFirstActivation), you can create all your Views or ViewModels and perform any eventwiring. For example, tie any toolbar commands to your ViewModels. The ObjectFactory also helps with this. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;ViewToRegionBinder.&lt;/b&gt; One of the things you are very likely to do is to add views to some regions when the UseCase becomes active, and remove them again when it becomes inactive. Instead of having to put region.Add(view) and matching region.Remove(view) calls in the activate and deactivate methods, I figured it would be handy to create one registration method that takes care of this. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Using the ViewToRegionBinder to add and remove views to and from regions&lt;/h3&gt;  &lt;p&gt;Adding and removing views from a region whenever something becomes active or inactive can be quite tedious. Whenever a view or usecase (or anything else that implements IActiveAware) becomes active, you probably have to find the right regions, add the views to the regions. And the same if the usecase is deactivated (but then remove the views)&lt;/p&gt;  &lt;p&gt;To make this a bit easier, I have created the ViewToRegionBinder. This object can monitor an IActiveAware object (such as a IActiveAwareUseCaseController or a view or a ViewModel). You can register a list of objects (views or viewmodels) against names of regions so that, when the object you are monitoring becomes active, the views will be added to the right regions and removed when the object becomes inactive. &lt;/p&gt;  &lt;div&gt;   &lt;div    style="border-style: none; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Make sure the Toolbar and the mainregion get displayed when this use case is activated&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// and removed again when it becomes inactive. &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.ViewToRegionBinder.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;"ToolbarRegion"&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.emailToolBarViewModel);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.ViewToRegionBinder.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;"MainRegion"&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.emailViewModel);&lt;/pre&gt;&lt;br /&gt; &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Using the ObjectFactory to delay creation of your views until you actually need them&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Another interesting challenge I ran into was:I wanted to shows a list of buttons for each usecase in my system. But only when I click one of these buttons do I want my views to be created and initialized. You can imagine, if you have 20 of these ‘main’ usecases and each creates a bunch of views when the application starts, application load time would be dramatic. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This was one of the motivations for creating the UseCaseControllers in the first place. They are very lightweight and I could create the views I needed in the Activate() method. But then I faced an other issue. I really like to create my views and my viewmodels using Constructor Injection. However, since the objects injected the constructor would be created &lt;strong&gt;before &lt;/strong&gt;the usecase would be created, not after, i had to put in some level of indirection.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is what the ObjectFactory&amp;lt;Type&amp;gt; solves. You can express the dependency on an object in the constructor, and create the object when you need it, by calling the ObjectFactory.CreateInstance() method. You can access the instance created by the objectfactory using the ObjectFactory.Value property. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now I didn’t want to create member variables for the ObjectFactories, because that would mean that every time I needed to access the view, i would have to go through the ObjectFactory.Value property. I really wanted to have variables of the type of the views. So I created the &lt;strong&gt;AddInitializationMethod, &lt;/strong&gt;where you can add a lambda expression that will set the member variable for the views. The ActiveAwareUseCaseController will call these lambda’s just before the UseCase becomes active for the first time. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The following code snippet shows how this works in the MainEmailUseCase&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; max-height: 200px;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// The references to these viewmodels will be filled when the app is initialized for the first time. &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; EmailMainViewModel emailViewModel;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; EmailToolBarViewModel emailToolBarViewModel;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; EmailMainUseCase(&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Get the ViewToRegionBinder that the baseclass needs&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     IViewToRegionBinder viewtoToRegionBinder&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Get the factories that can create the viewmodels&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     , ObjectFactory&amp;lt;EmailMainViewModel&amp;gt; emailViewFactory&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;     , ObjectFactory&amp;lt;EmailToolBarViewModel&amp;gt; emailToolBarFactory) : &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;(viewtoToRegionBinder)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Just before the view is initialized for the first time&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.AddInitializationMethods(&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Create the emailViewModel and assign it to this variable&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;         () =&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.emailViewModel = emailViewFactory.CreateInstance()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Create the toolbarViewModel and assign it to this variable&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;         , () =&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.emailToolBarViewModel = emailToolBarFactory.CreateInstance());&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt; &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Why do I like Constructor Injection? It expresses very clearly what the dependencies of my object are, in a single place.  Take the previous code snippet. You can clearly see that the EmailUseCase has a dependency on the IViewToRegionBinder, the EmailMainViewModel and the EmailToolBarViewModel. Those are the only objects this class interacts with. Sure, in some cases it might seem easier to get a reference to the service locator and resolve types when you need them, but that makes it very unclear what other types your class depends on and also makes unit testing a lot harder. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Bootstrapper&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As usual, the bootstrapper is the glue for all the individual pieces. In the bootstrapper, all the infrastructure pieces are registered in the right way, so the application can use them. You can see that I’m registering the types i need to the container and some of the default regionbehaviors to the RegionBehaviorFactory&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;What’s next?&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the Outlook style application, i’m also showing a bunch of other things:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt; &lt;li&gt;How to do ViewModel First development in an elegant way. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;How to use RegionContext in a bit easier way &lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;li&gt;How to show views in a popup in a robust way. Note, in the current version, this is still work in progress. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Since I’ve already spent way to much time on this blogpost, i’m going to address these things in future posts. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As always, I really appreciate your feedback. Any comments or questions are more than welcome. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Happy coding!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;_Erwin&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;[Update: Also read &lt;a title="Part 2 of this blog post." href="http://blogs.msdn.com/erwinvandervalk/archive/2009/04/29/how-to-build-an-outlook-style-application-with-prism-v2-part-2.aspx"&gt;part 2&lt;/a&gt; of this post. ]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9896893" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-926843474648021143?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/926843474648021143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-to-build-outlook-style-application.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/926843474648021143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/926843474648021143'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-to-build-outlook-style-application.html' title='how to build an outlook style application – part 1'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-4800193304981948599</id><published>2010-06-01T09:59:00.000-07:00</published><updated>2010-06-04T22:44:36.620-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><title type='text'>how to work with animations in Silverlight in the mvvm pattern</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/erwinvandervalk/archive/2009/10/12/how-to-work-with-animations-in-silverlight-in-the-mvvm-pattern.aspx"&gt;how to work with animations in Silverlight in the mvvm pattern&lt;/a&gt;: "&lt;p&gt;One of the things I found a bit more challenging than it should have been is working with animations in Silverlight. Often people will resort to code behind and triggering animations from code. However, I don’t really like that approach, because animations are a form of visualization. Visualizations should be created by designers. And I don’t think designers should have to be able to write code. So I’m going to show a pure XAML – databinding based way to trigger animation, by using a very simple attached property. &lt;/p&gt;  &lt;p&gt;This post is part of my series on MVVM. &lt;/p&gt;  &lt;p&gt;&lt;a title="Back to 'How do I do .. with the ViewModel pattern'" href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/12/how-do-i-do-with-the-model-view-viewmodel-pattern.aspx"&gt;&amp;lt;Back to intro&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="Previous Post: How to apply ViewModel pattern to new windows." href="http://blogs.msdn.com/erwinvandervalk/archive/2009/09/18/how-to-apply-a-viewmodel-to-new-windows.aspx"&gt;&amp;lt;Back to ‘How to apply the ViewModel pattern to new windows’&amp;gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h1&gt;Why use animations?&lt;/h1&gt;  &lt;p&gt;Using animations is a double edged sword. On the one hand, when abused, they can create a very flashy, but totally unusable UI’s. For example, moving advertising banners on websites can make that website much less usable. They distract from the actual content and make it harder for users to find. On the other hand, when you use animations properly, it can really enhance the user experience. For example, in Windows, if you minimize a window, it doesn’t just vanish. You see it quickly shrink and move to the position on the taskbar where it was minimized to. That makes it easy to see what happened, and where to find your window when you want to get it back. &lt;/p&gt;  &lt;p&gt;I typically use the following rules to judge if an animation is valuable:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Animations should call the attention of the users that something has happened and make it very clear what is happening.&lt;/li&gt;    &lt;li&gt;Animations should never get in the way of the user:&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Animations should not be distracting from what’s important.&lt;/li&gt;      &lt;li&gt;Animations should not slow down the user. If the user has to wait until an animation is done, then the animation is hindering. &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;h1&gt; &lt;/h1&gt;  &lt;h1&gt;Who is responsible for animations?&lt;/h1&gt;  &lt;p&gt;Animations can be an important part of your application. Often animations should be triggered by Business Logic. For example, if your application has network connectivity and you detect that the internet connection is lost, you might wish to start an animation to get the attention of the users and notify them of this state change. In this case, you might argue that the logic (your VieowModel) should trigger the animation. However, animations are also a form of visualization. Often, they are closely tied to visual elements (because they will be animated). So that means the animations should live in the View. &lt;/p&gt;  &lt;p&gt;If you start your animations in directly from your ViewModel, you are directly interacting with visual elements from your ViewModel. That means you are breaking the separation of concerns between the Visualization and the Logic of your UI. Basically, you are undoing the benefits of the ViewModel pattern.&lt;/p&gt;  &lt;p&gt;When it comes to triggering animations from your ViewModel, I try to split the responsibility between the logical event and the visualization of the animation: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Logical Event that should trigger the animation:      &lt;br /&gt;&lt;/strong&gt;Your ViewModel should raise an event to notify a logical state change. This can either be a pure ‘event’, but it’s typically easier create an observable property (by implementing INotifyPropertyChanged on your VM). If the logical event occurs, you can change the value of that property on your ViewModel. This is something you can test in your Unit Test. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Animated visualization of the event:&lt;/strong&gt;     &lt;br /&gt;The View should define the animation, for example by defining a storyboard. This animation can easily be changed by a designer. Then to visualize the event and start the animation, the view should listen to the event or monitor the property for changes. When the property changes, the animation should be triggered.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You could use the Code-Behind of your views to do this wireup. However, I don’t really like that approach, because there are much simpler ways to do that. I’ll show you how to trigger animations purely from XAML using databinding. &lt;/p&gt;  &lt;h1&gt;Triggering animations from your ViewModel&lt;/h1&gt;  &lt;p&gt;First of all, you have to create a logical property on your ViewModel, that will change when the animation should be triggered. &lt;/p&gt;  &lt;p&gt;I’m also demonstrating animations in several places in my sample application:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtoworkwithanimationsinSilverlightinth_C0CF/image_2.png"&gt;&lt;img style="border: 0px none ; display: inline;" title="image" alt="image" src="http://blogs.msdn.com/blogfiles/erwinvandervalk/WindowsLiveWriter/howtoworkwithanimationsinSilverlightinth_C0CF/image_thumb.png" border="0" height="181" width="577" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You can see 4 buttons, that demonstrate different aspects of working with ViewModels. When you click a button, the UI for that particular demo should come into View. However, because some of the UI pieces are used for different parts of the demo, I used animations to make it very clear what UI elements are added and removed when you enter a particular demo.&lt;/p&gt;  &lt;p&gt;To enable these animations I followed the following steps:&lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h2&gt;Define a bindable property on your ViewModel&lt;/h2&gt;  &lt;p&gt;In my sample, I’ve defined a bindable property on my ViewModel, called “State” and a Command that can update the state. Clicking one of the buttons on my app should change the state and trigger an animation. &lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;     &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Public property that will change&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; State&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _state; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     set&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (_state == &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;         _state = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;         OnPropertyChanged(&lt;span style="color: rgb(0, 96, 128);"&gt;"State"&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// In my case, the command that will trigger the state change:&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; ICommand GoToStateCommand { get; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; GoToState(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; newState)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.State = newState;   &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create the command object that can trigger the state change&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt; GoToStateCommand = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DelegateCommand&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt;(GoToState);&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Define animation in my view&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The actual animations are defined in the view itself. I decided to use the &lt;a title="Visual State Manager on MSDN" href="http://msdn.microsoft.com/en-us/library/system.windows.visualstatemanager%28VS.95%29.aspx"&gt;VisualStateManager&lt;/a&gt; for this, but there are other options. Then I’ve created 4 visual states, each corresponding to one of the buttons. Here you can see one example of that:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;VisualState&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x:Name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="SimpleViewModel"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Storyboard&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;DoubleAnimationUsingKeyFrames&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;BeginTime&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="00:00:00"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Storyboard&lt;/span&gt;.&lt;span style="color: rgb(255, 0, 0);"&gt;TargetName&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="mealDetailsView"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Storyboard&lt;/span&gt;.&lt;span style="color: rgb(255, 0, 0);"&gt;TargetProperty&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EasingDoubleKeyFrame&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;KeyTime&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="00:00:00.2000000"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="592.667"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;DoubleAnimationUsingKeyFrames&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;DoubleAnimationUsingKeyFrames&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;BeginTime&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="00:00:00"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Storyboard&lt;/span&gt;.&lt;span style="color: rgb(255, 0, 0);"&gt;TargetName&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="mealDetailsView"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Storyboard&lt;/span&gt;.&lt;span style="color: rgb(255, 0, 0);"&gt;TargetProperty&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;EasingDoubleKeyFrame&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;KeyTime&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="00:00:00.2000000"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="1022"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;DoubleAnimationUsingKeyFrames&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Storyboard&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;VisualState&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Trigger the animation when the state changes&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now that i have a property on my ViewModel that raises an INotifyPropertyChanged.PropertyChanged event and I have a storyboard in place, now I have to tie the two together. In WPF this is fairly simple, because you can use a &lt;a title="DataTriggers on MSDN" href="http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx"&gt;DataTrigger&lt;/a&gt; to trigger the animation. However, in Silverlight, this does not work with ViewModels. So I’ve written a small class that allows you to use databinding to trigger animations. This is just an example of how you could accomplish this. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The VisualStateSetter has a bindable dependency property. When you set it to a certain string value, it will access the Visual State Manager and set the state to that string value. And because it’s a implemented as an attached property, you can apply it to any type of control. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; VisualStateSetter&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; DependencyProperty StateProperty =&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;         DependencyProperty.RegisterAttached(&lt;span style="color: rgb(0, 96, 128);"&gt;"State"&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;), &lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;(VisualStateSetter), &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; PropertyMetadata(StateChanged));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; SetState(DependencyObject target, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; state)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;         target.GetValue(StateProperty);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; GetState(DependencyObject target)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; target.GetValue(StateProperty) &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; StateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;     {&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;         Control host = d &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; Control;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (host == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;  &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;         VisualStateManager.GoToState(host, e.NewValue &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;So this is what using the VisualStateSetter class looks like:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px;font-family:'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;br /&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;UserControl&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;UI:VisualStateSetter&lt;/span&gt;.&lt;span style="color: rgb(255, 0, 0);"&gt;State&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="{Binding State}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;&amp;lt;!-- The content of the control --&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;UserControl&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here you see me binding the State property of the ViewModel to the Visual States that are defined in my View. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now it would have been cleaner to have a more logical property on my ViewModel, for example an Enum and implement a converter that converts the Enum values to the Visual States in my View. But that’s not very difficult to do, so I’ll leave that up to you ;)&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Hope this helps you to trigger animations in your views from your ViewModels.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;_Erwin&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9906326" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-4800193304981948599?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/4800193304981948599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-to-work-with-animations-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/4800193304981948599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/4800193304981948599'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/how-to-work-with-animations-in.html' title='how to work with animations in Silverlight in the mvvm pattern'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-8576111034066740984</id><published>2010-06-01T09:19:00.000-07:00</published><updated>2010-06-04T22:44:43.181-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PRISM'/><title type='text'>Learning Prism (Composite Application Guidance for WPF &amp; Silverlight). How do I start?</title><content type='html'>&lt;a href="http://feeds.southworks.net/%7Er/dschenkelman/%7E3/rLPX1PQMWLg/"&gt;Learning Prism (Composite Application Guidance for WPF &amp;amp; Silverlight). How do I start?&lt;/a&gt;: "&lt;p&gt;A question we get asked frequently is: “How do I start learning Prism? Is there a particular order for the Quickstarts? What other web resources do you recommend to start learning?”. If you are in this situation, or just want to have some more insight on a particular Prism topic, this is the post for you (I always wanted to say that, just like TV announcements :))&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;The basic question: “How do I start learning Prism?”&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;The first thing you should do to start learning Prism (assuming you know WPF/Silverlight), is begin with the &lt;a href="http://msdn.microsoft.com/en-us/library/dd458809.aspx"&gt;documentation&lt;/a&gt;.  It is really clear in what it tries to explain, provides great samples and explains a lot of the common doubts when starting to develop applications with Prism. There is not a particular order to learn Prism, so you should tackle it in the way you feel comfortable. Pay special attention to the &lt;a href="http://msdn.microsoft.com/en-us/library/dd458876.aspx"&gt;Technical Concepts&lt;/a&gt; section, as it really helps understand how things come together.&lt;/p&gt;&lt;br /&gt;&lt;table align="center" border="2" cellpadding="2" cellspacing="0" width="223"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td valign="top" width="221"&gt;&lt;strong&gt;Tip 1&lt;/strong&gt;: Read the &lt;a href="http://msdn.microsoft.com/en-us/library/dd458809.aspx"&gt;Prism documentation&lt;/a&gt;.&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;If while reading the documentation you have any doubts, or want to dig deeper into any particular topic you have many different options (and search queries in your favorite search engine). However, there are some things I believe you should take a look at:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://compositewpf.codeplex.com/wikipage?title=Knowledge%20Base&amp;amp;referringTitle=Home"&gt;Prism KB&lt;/a&gt;. There you will find links on many different topics (you can find a picture of them below), that could be videos, sample applications or blog post which will help you better understand some of Prism concepts.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Watch videos. There are lots of video tutorials going around, but these two collections are particularly good. &lt;a href="http://compositewpf.codeplex.com/wikipage?title=Learn%20Prism&amp;amp;ProjectName=compositewpf"&gt;Videos from P&amp;amp;P team&lt;/a&gt; &amp;amp; &lt;a href="http://www.sparklingclient.com/prism-silverlight/"&gt;10 Things to Know About Silverlight Prism&lt;/a&gt;.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;table align="center" border="2" cellpadding="2" cellspacing="0" width="416"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td valign="top" width="414"&gt;&lt;strong&gt;Tip 2: &lt;/strong&gt;Use the &lt;a href="http://compositewpf.codeplex.com/wikipage?title=Knowledge%20Base&amp;amp;referringTitle=Home"&gt;Prism KB&lt;/a&gt; and watch videos (&lt;a href="http://compositewpf.codeplex.com/wikipage?title=Learn%20Prism&amp;amp;ProjectName=compositewpf"&gt;these&lt;/a&gt; and &lt;a href="http://www.sparklingclient.com/prism-silverlight/"&gt;also these&lt;/a&gt; particularly).&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;h3&gt;&lt;a href="http://blogs.southworks.net/dschenkelman/files/2009/10/image.png"&gt;&lt;img src="http://blogs.southworks.net/dschenkelman/files/2009/10/image-thumb.png" alt="image" border="0" height="387" width="728" /&gt;&lt;/a&gt;&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(0, 64, 128);font-family:Calibri;" &gt;&lt;em&gt;Prism KB site&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;But, what if I have some doubts while learning?&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;That is why developer communities were created, and as any other p&amp;amp;p asset Prism has its own &lt;a href="http://compositewpf.codeplex.com/Thread/List.aspx"&gt;forum&lt;/a&gt; at Codeplex where you can ask questions about any topic (technical concepts, how do I?, etc). The forum has a really active community, and is also monitored by the p&amp;amp;p Client Sustained Engineering Team (which we are part of). So if you have a question that has been bugging you for some time, and have not found the answer anywhere you can always drop by the forum.&lt;/p&gt;&lt;br /&gt;&lt;table align="center" border="2" cellpadding="2" cellspacing="0" width="400"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td valign="top" width="400"&gt;&lt;strong&gt;Tip 3:&lt;/strong&gt; Ask questions in the &lt;a href="http://compositewpf.codeplex.com/Thread/List.aspx"&gt;Prism Codeplex forum&lt;/a&gt;.&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;h2&gt;Last, but definitely not least…&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;There are some frequent Prism bloggers that you should follow, as they have some really interesting posts about how to use Prism and its insides. Below I will provide the list of those I follow (which is probably really short in comparison to the one I should be following), and for some the most interesting/requested post in my opinion:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://blogs.msdn.com/blaine/"&gt;Blaine’s&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/bobbrum/"&gt;Bob&lt;/a&gt;’s and &lt;a href="http://blogs.msdn.com/dphill/"&gt;David’s&lt;/a&gt; blogs, with the latest news about Prism future.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://blogs.msdn.com/erwinvandervalk/"&gt;Erwin’s&lt;/a&gt; blog. He has a really interesting &lt;a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/12/how-do-i-do-with-the-model-view-viewmodel-pattern.aspx"&gt;series about working with MVVM&lt;/a&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://neverindoubtnet.blogspot.com/"&gt;Ward Bell&lt;/a&gt;. He has some really interesting posts, but the ones I choose are: &lt;a href="http://neverindoubtnet.blogspot.com/2009/05/birth-and-death-of-m-v-vm-triads.html"&gt;Birth and Death of M-V-VM Triads&lt;/a&gt; &amp;amp; &lt;a href="http://neverindoubtnet.blogspot.com/2009/05/prism-event-aggregator-subscription.html"&gt;Prism Event Aggregator Subscription Blues&lt;/a&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Southworks blogs: &lt;a href="http://blogs.southworks.net/jdominguez/"&gt;Julian&lt;/a&gt;, &lt;a href="http://blogs.southworks.net/ejadib/"&gt;Ezequiel&lt;/a&gt;, &lt;a href="http://blogs.southworks.net/mconverti/"&gt;Mariano&lt;/a&gt;, &lt;a href="http://blogs.southworks.net/matiasb/"&gt;Matias&lt;/a&gt;. The post that is a &lt;strong&gt;MUST &lt;/strong&gt;is Julian’s &lt;a title="http://blogs.southworks.net/jdominguez/2008/08/icommand-for-silverlight-with-attached-behaviors/" href="http://blogs.southworks.net/jdominguez/2008/08/icommand-for-silverlight-with-attached-behaviors/"&gt;ICommand For Silverlight with Attached Behaviors.&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://blogs.msdn.com/gblock/"&gt;Glenn’s&lt;/a&gt; post: &lt;a href="http://blogs.msdn.com/gblock/archive/2009/08/03/the-spirit-of-mvvm-viewmodel-it-s-not-a-code-counting-exercise.aspx"&gt;The spirit of MVVM (ViewModel), it’s not a code counting exercise&lt;/a&gt;, as this is something we get asked a lot and I share his thoughts on this topic.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;As an extra, you can also follow the &lt;a href="http://twitter.com/clientdev"&gt;clientdev twitter&lt;/a&gt;, in which we tweet about the latest news about different .Net Client Development technologies (mostly Silverlight &amp;amp; WPF) and can be really useful when learning about Prism.&lt;/p&gt;&lt;br /&gt;&lt;table align="center" border="2" cellpadding="2" cellspacing="0" width="400"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td valign="top" width="400"&gt;&lt;strong&gt;Tip 4: &lt;/strong&gt;Read tons of articles about Prism.&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;I hope this article will help your Prism learning process, and please provide any feedback you might have so I can improve this guidance, like comments on the bloggers.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://dotnetshoutout.com/Learning-Prism-Composite-Application-Guidance-for-WPF-Silverlight-How-do-I-start"&gt;&lt;img src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2009%2F10%2F22%2Flearning-prism-composite-application-guidance-for-wpf-silverlight-how-do-i-start%2F" alt="Shout it" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.southworks.net%2fdschenkelman%2f2009%2f10%2f22%2flearning-prism-composite-application-guidance-for-wpf-silverlight-how-do-i-start%2f"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.southworks.net%2fdschenkelman%2f2009%2f10%2f22%2flearning-prism-composite-application-guidance-for-wpf-silverlight-how-do-i-start%2f" alt="kick it on DotNetKicks.com" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/%7Er/dschenkelman/%7E4/rLPX1PQMWLg" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-8576111034066740984?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/8576111034066740984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/learning-prism-composite-application_01.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8576111034066740984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8576111034066740984'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/learning-prism-composite-application_01.html' title='Learning Prism (Composite Application Guidance for WPF &amp; Silverlight). How do I start?'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-2758482815585601938</id><published>2010-06-01T09:14:00.000-07:00</published><updated>2010-06-04T22:47:48.388-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PRISM'/><title type='text'>Learning Prism (Composite Application Guidance for WPF &amp; Silverlight) MVVM Fundamentals</title><content type='html'>&lt;a href="http://feeds.southworks.net/%7Er/dschenkelman/%7E3/AkrthO2vwOk/"&gt;Learning Prism (Composite Application Guidance for WPF &amp;amp; Silverlight) MVVM Fundamentals&lt;/a&gt;: "&lt;p&gt;On a &lt;a href="http://blogs.southworks.net/dschenkelman/2009/10/22/learning-prism-composite-application-guidance-for-wpf-silverlight-how-do-i-start/"&gt;previous post&lt;/a&gt; in this series I talked about a possible approach to take when starting to learn Prism as a whole (the Tip numbering is resumed from the previous post). In this post I will get more specific and talk about one of the most used (if not the most used) pattern when developing Prism applications (either for WPF &amp;amp; Silverlight): MVVM.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Most people are familiar with this pattern (if you are not great places to read about it are &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;here for WPF&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd458800.aspx"&gt;over here for Silverlight&lt;/a&gt;), so I will not go deep into what is the main idea of it. Instead I will try to go over some core concepts that usually lead to different levels of confusion.&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;What’s the difference between MVVM and PresentationModel?&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;The above question is one asked a lot, as people tend to get confused when they hear all the talk about MVVM and then open some Prism &lt;a href="http://msdn.microsoft.com/en-us/library/dd458858.aspx"&gt;Quickstarts&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/dd458919.aspx"&gt;RI&lt;/a&gt; and find most of them &lt;em&gt;“implement the &lt;strong&gt;PresentationModel&lt;/strong&gt; pattern”&lt;/em&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Well, there is not a certain answer (and if there was I probably wouldn’t be the one who came up with it), but as far as Prism development is concerned they are synonyms. There is no difference between them, except for the coined term. As &lt;a href="http://martinfowler.com/"&gt;Martin Fowler&lt;/a&gt; explains in his &lt;a href="http://martinfowler.com/eaaDev/PresentationModel.html"&gt;PresentationModel article&lt;/a&gt;: &lt;em&gt;“The essence of a Presentation Model is of a fully self-contained class that represents all the data and behavior of the UI window, but without any of the controls used to render that UI on the screen. A view then simply projects the state of the presentation model onto the glass.”&lt;/em&gt;, so if you think about it, the way to “project the state of the PresentationModel (or ViewModel) onto the glass is &lt;strong&gt;WPF/Silverlight&lt;/strong&gt; DataBinding in our case (or as &lt;a href="http://blogs.southworks.net/jdominguez/"&gt;Julian&lt;/a&gt; likes to explain it: &lt;em&gt;“the ViewModel is a bindable Presenter”&lt;/em&gt;).&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Always remember the main objective, testability and decoupling.&lt;/p&gt;&lt;br /&gt;&lt;table align="center" border="1" cellpadding="2" cellspacing="0" width="292"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td valign="top" width="290"&gt;&lt;strong&gt;Tip 5:&lt;/strong&gt; MVVM and Presentation Model are synonyms.&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;h2&gt;How do I do pure MVVM?&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;This is another point of confusion as people tend to relate MVVM with &lt;a href="http://msdn.microsoft.com/en-us/library/ms742521.aspx"&gt;DataTemplates&lt;/a&gt; and no View code behind, so they get the idea that the only way to implement the pattern is that one.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In my opinion there is no pure MVVM, it is a design pattern, so it can have many different implementations which will depend mainly on who implements it and what his requirements are. In this particular topic I would like to “branch you” to &lt;a href="http://blogs.msdn.com/gblock/"&gt;Glenn’s&lt;/a&gt; post “&lt;a href="http://blogs.msdn.com/gblock/archive/2009/08/03/the-spirit-of-mvvm-viewmodel-it-s-not-a-code-counting-exercise.aspx"&gt;The spirit of MVVM (ViewModel), it’s not a code counting exercise.&lt;/a&gt;” as I agree with his point of view in this topic, so there is no point in duplicating the information.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Now that you have finished reading Glenn’s post, I hope you understand what I am trying to explain (not necessarily agree). I for once like the “View First” (you “talk” to the view) implementation to relate the View to its &lt;strong&gt;ViewModel&lt;/strong&gt; in Prism could be the following (using DI):&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;MyView&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;public &lt;/span&gt;MyView(&lt;span style="color: rgb(43, 145, 175);"&gt;IMyViewModel &lt;/span&gt;viewModel)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.DataContext = viewModel;&lt;br /&gt;&lt;br /&gt;InitializeComponent();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In the code above, Unity’s DI provides the decoupling between the View and the ViewModel, so the ViewModel “does not have to know anything about the view” and allows you to test the VM in isolation (of course this is just one of the ways to do it).&lt;/p&gt;&lt;br /&gt;&lt;table align="center" border="1" cellpadding="2" cellspacing="0" width="457"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td valign="top" width="455"&gt;&lt;strong&gt;Tip 6: &lt;/strong&gt;There is no Silver Bullet MVVM implementation. Use the one that you like best.&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;h2&gt;How should I manage my View/ViewModel?&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;This question addresses both creation/destruction of View and ViewModels as well as its interaction with other components in the application. Often it is not “clear” which component should handle a specific action.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Say that when a button is clicked an event should be published. Where should this be done? Well, without information about the application and its patterns it is hard to say. It could be done in the &lt;strong&gt;ViewModel&lt;/strong&gt; or it could be done in a module level controller that manages interaction with other modules, but this depends on how your application is structured.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Instead of expanding on this topic, I would like to branch you (yet again), to these posts from Ward Bell which talk about these common questions and provide some really interesting and thought answers:&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://neverindoubtnet.blogspot.com/2009/05/birth-and-death-of-m-v-vm-triads.html"&gt;Birth and Death of M-V-VM Triads&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://neverindoubtnet.blogspot.com/2009/06/screen-factory.html"&gt;Screen Factory&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h2&gt;Should I always use commands to communicate with the ViewModel?&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;Before using a command, I usually stop and think: “Can this be done in another way?, Can I achieve this same functionality with binding?”. Well, sometimes the answer is yes, and that is when I think commands are not necessary. The most common example is binding a command to execute every time and item in a Listbox is selected. This same behavior can be achieved by binding the SelectedItem property of the Listbox to your ViewModel (most of the times), and executing the required action on the setter.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Having thought of the above, what if I do need a command? Well, my first recommendation would be understanding how do Commands with attached Behaviors work, a topic explained by &lt;a href="http://blogs.southworks.net/jdominguez/"&gt;Julian&lt;/a&gt; in this &lt;a href="http://blogs.southworks.net/jdominguez/2008/08/icommand-for-silverlight-with-attached-behaviors/"&gt;great post&lt;/a&gt;. After that you can use the &lt;a href="http://blogs.southworks.net/dschenkelman/2009/08/13/c-code-snippet-to-create-commands-with-attached-behaviors-using-prism/"&gt;code snippet I created&lt;/a&gt; some time ago to help you with the tedious task of creating the classes required for this to work.&lt;/p&gt;&lt;br /&gt;&lt;table align="center" border="1" cellpadding="2" cellspacing="0" width="400"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td valign="top" width="400"&gt;&lt;strong&gt;Tip 7: &lt;/strong&gt;Before using commands, think if there is another option.&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;h3&gt;Things to add to your reading list&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;To help you comply with Tip 4, you can find below a couple of articles about MVVM and MVVM with Prism that I think might be of use to better understand this topic (the ones mentioned above would be in this list, but there is not need in duplicating them):&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/08/12/how-do-i-do-with-the-model-view-viewmodel-pattern.aspx"&gt;Erwin’s MVVM series&lt;/a&gt; (with some more posts to go)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://blogs.msdn.com/dphill/archive/2009/06/15/prism-quick-start-kit-update.aspx"&gt;David’s Visual Studio templates&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;Hopefully, this post has helped you understand a little more about MVVM and how to use it with Prism. As always, your feedback is appreciated, so if you believe any link should be added or anything of the sort, just drop a comment.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://dotnetshoutout.com/Learning-Prism-Composite-Application-Guidance-for-WPF-Silverlight-MVVM-Fundamentals"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2009%2F11%2F16%2Flearning-prism-composite-application-guidance-for-wpf-silverlight-mvvm-fundamentals%2F" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.southworks.net%2fdschenkelman%2f2009%2f11%2f16%2flearning-prism-composite-application-guidance-for-wpf-silverlight-mvvm-fundamentals%2f"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblogs.southworks.net%2fdschenkelman%2f2009%2f11%2f16%2flearning-prism-composite-application-guidance-for-wpf-silverlight-mvvm-fundamentals%2f" alt="kick it on DotNetKicks.com" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/%7Er/dschenkelman/%7E4/AkrthO2vwOk" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-2758482815585601938?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/2758482815585601938/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/learning-prism-composite-application.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/2758482815585601938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/2758482815585601938'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/learning-prism-composite-application.html' title='Learning Prism (Composite Application Guidance for WPF &amp; Silverlight) MVVM Fundamentals'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-8235105210664269656</id><published>2010-06-01T09:13:00.001-07:00</published><updated>2010-06-04T22:47:51.058-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PRISM'/><title type='text'>Memory Leak removing View with child regions in Prism-v2</title><content type='html'>&lt;a href="http://feeds.southworks.net/%7Er/dschenkelman/%7E3/NEsjSWq74sQ/"&gt;Memory Leak removing View with child regions in Prism-v2&lt;/a&gt;: "&lt;p&gt;About a week ago in the &lt;a href="http://compositewpf.codeplex.com/Thread/List.aspx"&gt;Prism forum&lt;/a&gt; we got a &lt;a href="http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=77847"&gt;question&lt;/a&gt; about an issue in the scenario displayed below.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blogs.southworks.net/dschenkelman/files/2010/01/regions.png"&gt;&lt;img src="http://blogs.southworks.net/dschenkelman/files/2010/01/regions.png" alt="" height="343" width="499" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;The Issue&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;When the &lt;strong&gt;MainView&lt;/strong&gt; was removed from the &lt;strong&gt;MainRegion,&lt;/strong&gt; the &lt;strong&gt;RightOne&lt;/strong&gt; and &lt;strong&gt;RightTwo&lt;/strong&gt; regions were not removed from the &lt;strong&gt;RegionManager&lt;/strong&gt; and the views were still being referenced by the region. We were able to reproduce this issue “successfully”  both using scoped regions and without them so we started thinking on a possible fix for this.&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;The Fix&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;After trying different things out, we took &lt;a href="http://blogs.southworks.net/jdominguez/"&gt;Julian’s&lt;/a&gt; suggestions and created a &lt;strong&gt;RegionBehavior&lt;/strong&gt; that would be in charge of this. You can find the complete code for this class below:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;ClearChildViewsRegionBehavior &lt;/span&gt;: &lt;span style="color: rgb(43, 145, 175);"&gt;RegionBehavior&lt;br /&gt;  &lt;/span&gt;{&lt;br /&gt;      &lt;span style="color:blue;"&gt;public const string &lt;/span&gt;BehaviorKey = &lt;span style="color: rgb(163, 21, 21);"&gt;“ClearChildViews”&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;protected override void &lt;/span&gt;OnAttach()&lt;br /&gt;      {&lt;br /&gt;          &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Region.PropertyChanged +=&lt;br /&gt;              &lt;span style="color:blue;"&gt;new &lt;/span&gt;System.ComponentModel.&lt;span style="color: rgb(43, 145, 175);"&gt;PropertyChangedEventHandler&lt;/span&gt;(Region_PropertyChanged);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;void &lt;/span&gt;Region_PropertyChanged(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, System.ComponentModel.&lt;span style="color: rgb(43, 145, 175);"&gt;PropertyChangedEventArgs &lt;/span&gt;e)&lt;br /&gt;      {&lt;br /&gt;          &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.PropertyName == &lt;span style="color: rgb(163, 21, 21);"&gt;“RegionManager”&lt;/span&gt;)&lt;br /&gt;          {&lt;br /&gt;              &lt;span style="color:blue;"&gt;if &lt;/span&gt;(&lt;span style="color:blue;"&gt;this&lt;/span&gt;.Region.RegionManager == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;              {&lt;br /&gt;                  &lt;span style="color:blue;"&gt;foreach &lt;/span&gt;(&lt;span style="color:blue;"&gt;object &lt;/span&gt;view &lt;span style="color:blue;"&gt;in this&lt;/span&gt;.Region.Views)&lt;br /&gt;                  {&lt;br /&gt;                      &lt;span style="color: rgb(43, 145, 175);"&gt;DependencyObject &lt;/span&gt;dependencyObject = view &lt;span style="color:blue;"&gt;as &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;DependencyObject&lt;/span&gt;;&lt;br /&gt;                      &lt;span style="color:blue;"&gt;if &lt;/span&gt;(dependencyObject != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)&lt;br /&gt;                      {&lt;br /&gt;                          dependencyObject.ClearValue(&lt;span style="color: rgb(43, 145, 175);"&gt;RegionManager&lt;/span&gt;.RegionManagerProperty);&lt;br /&gt;                      }&lt;br /&gt;                  }&lt;br /&gt;              }&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;  }&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;When the &lt;strong&gt;RegionManager&lt;/strong&gt; property of a &lt;strong&gt;Region&lt;/strong&gt; changes to null, the behavior removes the view’s &lt;strong&gt;RegionManager&lt;/strong&gt; attached property of all views in the region. Adding this behavior by overriding the bootstrapper’s &lt;strong&gt;ConfigureDefaultRegionBehaviors&lt;/strong&gt; will enable this behavior for all regions:&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:blue;"&gt;protected override &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IRegionBehaviorFactory &lt;/span&gt;ConfigureDefaultRegionBehaviors()&lt;br /&gt;       {&lt;br /&gt;           &lt;span style="color:blue;"&gt;var &lt;/span&gt;regionBehaviorTypesDictionary = &lt;span style="color:blue;"&gt;base&lt;/span&gt;.ConfigureDefaultRegionBehaviors();&lt;br /&gt;           regionBehaviorTypesDictionary.AddIfMissing&lt;br /&gt;               (&lt;span style="color: rgb(43, 145, 175);"&gt;ClearChildViewsRegionBehavior&lt;/span&gt;.BehaviorKey, &lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;ClearChildViewsRegionBehavior&lt;/span&gt;));&lt;br /&gt;           &lt;span style="color:blue;"&gt;return &lt;/span&gt;regionBehaviorTypesDictionary;&lt;br /&gt;       }&lt;/pre&gt;&lt;br /&gt;&lt;h2&gt;The Outcome&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;I have created a sample application showing how the fix works. You can download it from &lt;a href="http://cid-09f63fc7ac065e5e.skydrive.live.com/self.aspx/p%5E0p%20Samples/RemovingViewWithTwoSubregionsLevels.zip"&gt;here&lt;/a&gt;. The code is provided “AS IS” with no warranties and confers no rights. I hope you can find this behavior useful if you have a similar kind of situation in your application.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;As I probably won’t blog anymore until after the holidays, have a merry Christmas and a happy new year &lt;img src="http://blogs.southworks.net/dschenkelman/wp-includes/images/smilies/icon_smile.gif" alt=":)" /&gt; .&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://dotnetshoutout.com/Memory-Leak-removing-View-with-child-regions-in-Prism-v2"&gt;&lt;img src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2009%2F12%2F23%2Fmemory-leak-removing-view-with-child-regions-in-prism-v2%2F" alt="Shout it" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/%7Er/dschenkelman/%7E4/NEsjSWq74sQ" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-8235105210664269656?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/8235105210664269656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/memory-leak-removing-view-with-child.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8235105210664269656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8235105210664269656'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/memory-leak-removing-view-with-child.html' title='Memory Leak removing View with child regions in Prism-v2'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-1467020137474889736</id><published>2010-06-01T09:13:00.000-07:00</published><updated>2010-06-04T22:48:19.025-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PRISM'/><title type='text'>Creating a multi-shell application in Prism-v2</title><content type='html'>&lt;a href="http://feeds.southworks.net/%7Er/dschenkelman/%7E3/uD9SLkf31K8/"&gt;Creating a multi-shell application in Prism-v2&lt;/a&gt;: "&lt;p&gt;&lt;a href="http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=25938"&gt;This thread&lt;/a&gt; from the &lt;a href="http://compositewpf.codeplex.com/Thread/List.aspx"&gt;Prism forum&lt;/a&gt; presents the following question (this is not an actual quote but a summary): &lt;em&gt;Are there any examples with multiple Shell windows, as the Prism documentation mentions?&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;First I re-read &lt;a href="http://msdn.microsoft.com/en-us/library/dd490829.aspx"&gt;this article&lt;/a&gt; from the Prism documentation so I could get in the same page as the user. I’m not going to quote it here, but the &lt;strong&gt;“Implementing a Shell” &lt;/strong&gt; section is the one where it is explained. Once I read that, the popular Popup Region from the &lt;a href="http://msdn.microsoft.com/en-us/library/dd458919.aspx"&gt;Prism-v2 RI&lt;/a&gt; was out of the table so with &lt;a href="http://blogs.southworks.net/ejadib/"&gt;Ezequiel Jadib&lt;/a&gt; we decided to create a small spike to see what changes needed to be done.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Creating Multiple Shells&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;As in a regular Prism application, using the &lt;strong&gt;CreateShell&lt;/strong&gt; method to create the new Shell seemed like a good approach. However, as the &lt;strong&gt;RegionManager&lt;/strong&gt; is set to the &lt;strong&gt;DependencyObject&lt;/strong&gt; returned by this method, this had to be done manually for any other Shell window.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:blue;"&gt;protected override &lt;/span&gt;DependencyObject CreateShell()&lt;br /&gt;     {&lt;br /&gt;         &lt;span style="color: rgb(43, 145, 175);"&gt;Shell1 &lt;/span&gt;shell = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Shell1&lt;/span&gt;();&lt;br /&gt;         &lt;span style="color: rgb(43, 145, 175);"&gt;Shell2 &lt;/span&gt;shell2 = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Shell2&lt;/span&gt;();&lt;br /&gt;         shell.Show();&lt;br /&gt;         shell2.Show();&lt;br /&gt;         shell.Activate();&lt;br /&gt;&lt;br /&gt;         &lt;span style="color: rgb(43, 145, 175);"&gt;RegionManager&lt;/span&gt;.SetRegionManager(shell2, &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Container.Resolve&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;IRegionManager&lt;/span&gt;&amp;gt;());&lt;br /&gt;         &lt;span style="color: rgb(43, 145, 175);"&gt;RegionManager&lt;/span&gt;.UpdateRegions();&lt;br /&gt;&lt;br /&gt;         &lt;span style="color:blue;"&gt;return &lt;/span&gt;shell;&lt;br /&gt;     }&lt;/pre&gt;&lt;br /&gt;&lt;h3&gt;When to close the application?&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Another thing to determine is when to close the application. This is not something &lt;em&gt;“Prism specific” &lt;/em&gt; as &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.application.shutdownmode.aspx"&gt;WPF provides this option for any application&lt;/a&gt;. Since there are multiple Shell Windows, choosing the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shutdownmode.aspx"&gt;ShutdownMode&lt;/a&gt;=”OnLastWindowClose” seemed like the best approach.&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Application &lt;/span&gt;&lt;span style="color:red;"&gt;x:Class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;“&lt;span style="color:blue;"&gt;HelloWorld.App&lt;/span&gt;”&lt;br /&gt;   &lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;“&lt;span style="color:blue;"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/span&gt;”&lt;br /&gt;   &lt;span style="color:red;"&gt;xmlns:x&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;“&lt;span style="color:blue;"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/span&gt;” &lt;span style="color:red;"&gt;ShutdownMode&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;“&lt;span style="color:blue;"&gt;OnLastWindowClose&lt;/span&gt;“&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;h3&gt;Sample Application&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;I created a small sample application which publishes an event in one of the Shell views and subscribes to it in the other. You can download it from &lt;a href="http://cid-09f63fc7ac065e5e.skydrive.live.com/self.aspx/p%5E0p%20Samples/TwoShells.zip"&gt;here&lt;/a&gt;. The code is provided “AS IS”  with no warranties and confers no rights.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blogs.southworks.net/dschenkelman/files/2010/01/image.png"&gt;&lt;img src="http://blogs.southworks.net/dschenkelman/files/2010/01/image-thumb.png" alt="image" border="0" height="249" width="494" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://dotnetshoutout.com/Creating-a-multi-shell-application-in-Prism-v2"&gt;&lt;img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2010%2F01%2F26%2Fcreating-a-multi-shell-application-in-prism-v2%2F" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/%7Er/dschenkelman/%7E4/uD9SLkf31K8" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-1467020137474889736?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/1467020137474889736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/creating-multi-shell-application-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/1467020137474889736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/1467020137474889736'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/06/creating-multi-shell-application-in.html' title='Creating a multi-shell application in Prism-v2'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-5566419502489896820</id><published>2010-05-29T23:06:00.000-07:00</published><updated>2010-06-04T22:48:40.840-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PRISM'/><title type='text'>Prism Template Pack for Visual Studio 2010</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/dphill/archive/2010/03/25/prism-template-pack-for-visual-studio-2010.aspx"&gt;Prism Template Pack for Visual Studio 2010&lt;/a&gt;: "&lt;p&gt;Now that we have Release Candidate versions of Visual Studio 2010, as well as WPF and Silverlight 4.0, I’ve updated the Prism Templates so that you can more easily develop Prism applications that target these latest releases.&lt;/p&gt;  &lt;p&gt;The templates themselves are similar to those I released a while back – there are templates for Shell and Module projects, as well as ‘QuickStart Solution’ templates that provide a complete, pre-configured, multi-module solution that you can use as a starting point for a complete Prism application. All templates are available for both WPF and Silverlight. They are all in C# at the moment. I’ll work on VB.NET versions soon…&lt;/p&gt;  &lt;p&gt;I’ve modified the templates a little to use some of the features that have been introduced since Silverlight 2.0. In particular, I updated the QuickStart Solution to use the Silverlight PagedCollectionView class so that the ViewModel can keep track of the current selection automatically.&lt;/p&gt;  &lt;p&gt;The biggest change, though, is that the templates now come in a VSIX package and use the Visual Studio 2010 Extension Manager. This dramatically simplifies the installation and management of the templates!! You can download the VSIX package &lt;a href="http://dphill.members.winisp.net/Download/Prism.TemplatePack.RC.zip"&gt;here&lt;/a&gt; – &lt;strong&gt;&lt;em&gt;note that you will have to change the file extension from .zip to .vsix in order to install it&lt;/em&gt;&lt;/strong&gt; – or you can find it in the Visual Studio Code Gallery. You can also read the Getting Started release notes &lt;a href="http://dphill.members.winisp.net/Templates.html"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You can install the VSIX package by simply double-clicking it (once you’ve changed the file extension to .vsix). You’ll be prompted to accept the license but two clicks is pretty much all it takes. When you run Visual Studio 2010 and open the Extension Manager (from the Tools menu) you’ll see the Prism Template Pack is installed. You can uninstall it or disable it from here too.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismTemplatePackforVisualStudio2010_A42A/ExtensionManager_2.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="ExtensionManager" alt="ExtensionManager" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismTemplatePackforVisualStudio2010_A42A/ExtensionManager_thumb.png" border="0" height="286" width="504" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The templates show up in the Visual Studio 2010 New Project dialog under the Prism category. There are Shell and Module project templates, as well as the QuickStart Solution templates, for Silverlight and WPF.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismTemplatePackforVisualStudio2010_A42A/NewProject_2.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="NewProject" alt="NewProject" src="http://blogs.msdn.com/blogfiles/dphill/WindowsLiveWriter/PrismTemplatePackforVisualStudio2010_A42A/NewProject_thumb.png" border="0" height="350" width="504" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Once you’ve created a project using the templates, a ReadMe file will be shown that details the remaining steps you will need to take before the solution will compile and run. This mainly involves updating the project’s references to point to the Prism assemblies on your system. In some cases, you might also have to add Silverlight App References to the Web project so that the projects are linked together properly. I haven’t yet figured out how to do this automatically without requiring some kind of complicated Visual Studio automation but I’m still working on it…&lt;/p&gt;  &lt;p&gt;These templates target the Release Candidate versions of Visual Studio 2010, and WPF and Silverlight 4.0. Once they are fully released, I will update the templates with any changes that are required. I’m also hoping that templates like these will be included ‘in the box’ for Prism 4.0.&lt;/p&gt;  &lt;p&gt;In the meantime, I hope you find them useful. Let me know what you think!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9985306" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-5566419502489896820?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/5566419502489896820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/prism-template-pack-for-visual-studio.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/5566419502489896820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/5566419502489896820'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/prism-template-pack-for-visual-studio.html' title='Prism Template Pack for Visual Studio 2010'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-2302044085487645654</id><published>2010-05-29T23:03:00.000-07:00</published><updated>2010-06-04T22:45:17.036-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Silverlight'/><title type='text'>Silverlight 4 + RIA Services - Ready for Business: Authentication and Personalization</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/brada/archive/2010/03/26/silverlight-4-ria-services-ready-for-business-authentication-and-personalization.aspx"&gt;Silverlight 4 + RIA Services - Ready for Business: Authentication and Personalization&lt;/a&gt;: "&lt;p&gt;&lt;/p&gt;  &lt;p&gt;To &lt;a title="continue our series" href="http://blogs.msdn.com/brada/archive/2010/03/15/silverlight-4-ria-services-ready-for-business-index.aspx"&gt;continue our series&lt;/a&gt;,  In real business applications our data is often very valuable and as such we need to know who is accessing what data and control certain data access to only users with privilege.  Luckily this is very easy to do with RIA Services.  For example, say we want to let only authenticated users access our data in this example.   That is as easy to accomplish as adding an attribute, see line 2 below.  &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  1:     [EnableClientAccess]&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  2:     [RequiresAuthentication]&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  3:     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; DishViewDomainService : LinqToEntitiesDomainService&amp;lt;DishViewEntities&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  4:     {&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  5: &lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When we run the application, we now get an error.  Clearly you can do a bit better from a user experience angle… but the message is clear enough.  &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;  &lt;a href="javascript:void(0);"&gt;&lt;img style="border-width: 0px; display: inline;" title="image_thumb[93]" alt="image_thumb[93]" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/Silverlight4RIAServicesReadyforBusinessA_A121/image_thumb93.png" border="0" height="429" width="506" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Notice there is a login option, so we can log in… &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="javascript:void(0);"&gt;&lt;img style="border-width: 0px; display: inline;" title="image_thumb[107]" alt="image_thumb[107]" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/Silverlight4RIAServicesReadyforBusinessA_A121/image_thumb%5B107%5D_a6deb126-f34d-4781-acc9-a9407463b59a.png" border="0" height="198" width="244" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;and even create a new user.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="javascript:void(0);"&gt;&lt;img style="border-width: 0px; display: inline;" title="image_thumb[108]" alt="image_thumb[108]" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/Silverlight4RIAServicesReadyforBusinessA_A121/image_thumb%5B108%5D_654b429a-9929-48ca-ab63-c3ec2f795770.png" border="0" height="214" width="244" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;and with a refresh we now get our data&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="javascript:void(0);"&gt;&lt;img style="border-width: 0px; display: inline;" title="image_thumb[97]" alt="image_thumb[97]" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/Silverlight4RIAServicesReadyforBusinessA_A121/image_thumb97.png" border="0" height="112" width="279" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;And the application knows who i am on the client and gives me a way to log out.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now you can also easily interact with the current user on the server.  So for example, only return records that they have edited, or, in this case, log every access:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  1:         &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; IQueryable&amp;lt;Restaurant&amp;gt; GetRestaurants()&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  2:         {&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  3:             File.AppendAllLines(@"&lt;span style="color: rgb(139, 0, 0);"&gt;C:\Users\brada\Desktop\log.txt&lt;/span&gt;", &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] {&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  4:                 String.Format("&lt;span style="color: rgb(139, 0, 0);"&gt;{0}:{1}&lt;/span&gt;", DateTime.Now,&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:12px;"&gt;  5:                 &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.ServiceContext.User.Identity.Name)});&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt;  6:             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;.ObjectContext.Restaurants&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt;  7:                 .Where (r=&amp;gt;r.Region != "&lt;span style="color: rgb(139, 0, 0);"&gt;NC&lt;/span&gt;")&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt;  8:                 .OrderBy(r=&amp;gt;r.ID);&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt;  9:         }&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt; 10: &lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Line 5 is the key one.. we are accessing the current users on the server.   This gives us a nice simple log.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:Fixedsys;"&gt;3/7/2010 9:42:57 PM:darb&lt;br /&gt;  &lt;br /&gt;3/7/2010 9:43:05 PM:darb&lt;/span&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now we can also personalize this a bit.  Say we want our users to be able to give us a favorite color and we keep track of that on the server and the client, so it works seamlessly from any machine.  &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;First we need to add BackgroundColor to our backing store.  I this case I am using ASP.NET profile storage, so I add the right stuff to web.config&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="javascript:void(0);"&gt;&lt;img style="border-width: 0px; display: inline;" title="image_thumb[103]" alt="image_thumb[103]" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/Silverlight4RIAServicesReadyforBusinessA_A121/image_thumb%5B103%5D_8d717f35-bb83-4042-b02f-1d4df9b40328.png" border="0" height="66" width="244" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Then I need to access this from the Silverlight client, so I add a property to the User instance in the Models\User.cs &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; partial &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; User : UserBase&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt;    {&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; FriendlyName { &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt;; }&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="12px" style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; BackgroundColor { &lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt;; }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Finally, we need to access  it on the client.   In main.xaml add lines 2 and 3.. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  1:   &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Grid&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x&lt;/span&gt;:&lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"LayoutRoot"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Style&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"{StaticResource LayoutRootGridStyle}"&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  2:         &lt;span style="color: rgb(255, 0, 0);"&gt;Background&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"{Binding Path=User.BackgroundColor}"&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  3:         &lt;span style="color: rgb(255, 0, 0);"&gt;DataContext&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"{StaticResource WebContext}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  4:&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  5: &lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Run it and we get our great default background color!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="javascript:void(0);"&gt;&lt;img style="border-width: 0px; display: inline;" title="image_thumb[104]" alt="image_thumb[104]" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/Silverlight4RIAServicesReadyforBusinessA_A121/image_thumb%5B104%5D_6d3da1de-00e1-4cd8-90c9-a0ff423f1e2e.png" border="0" height="208" width="244" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now, that is nice, but it would be even better to give the user a chance to actually edit their settings.  So in About.xaml, we use a very similar model as above.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Grid&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;x&lt;/span&gt;:&lt;span style="color: rgb(255, 0, 0);"&gt;Name&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"LayoutRoot"&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: rgb(255, 0, 0);"&gt;DataContext&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"{StaticResource WebContext}"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;and&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(199, 21, 133);"&gt;sdk&lt;/span&gt;:&lt;span style="color: rgb(128, 0, 0);"&gt;Label&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Content&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"Background Color:"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;TextBox&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Text&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"{Binding Path=User.BackgroundColor, Mode=TwoWay}"&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;Height&lt;/span&gt;=&lt;span style="color: rgb(0, 0, 255);"&gt;"23"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Then wire up a save button&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; button1_Click(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, System.Windows.RoutedEventArgs e)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;            WebContext.Current.Authentication.SaveUser(&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: rgb(255, 255, 255); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;        }&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;And it works! &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="javascript:void(0);"&gt;&lt;img style="border-width: 0px; display: inline;" title="image_thumb[105]" alt="image_thumb[105]" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/Silverlight4RIAServicesReadyforBusinessA_A121/image_thumb%5B105%5D_c3d57467-d7b6-46b7-b793-1d9dee7861fc.png" border="0" height="154" width="244" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;And what’s better is if you run it from another browser, on another machine, once you log in you get the exact same preferences!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="javascript:void(0);"&gt;&lt;img style="border-width: 0px; display: inline;" title="image_thumb[106]" alt="image_thumb[106]" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/Silverlight4RIAServicesReadyforBusinessA_A121/image_thumb%5B106%5D_ff65f469-5bff-4e18-952b-bf7a9cae7e1b.png" border="0" height="161" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9974990" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-2302044085487645654?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/2302044085487645654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/silverlight-4-ria-services-ready-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/2302044085487645654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/2302044085487645654'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/silverlight-4-ria-services-ready-for.html' title='Silverlight 4 + RIA Services - Ready for Business: Authentication and Personalization'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-2134231857752768286</id><published>2010-05-29T23:02:00.000-07:00</published><updated>2010-05-29T23:02:30.275-07:00</updated><title type='text'>On Being a Bad Client</title><content type='html'>&lt;a href="http://visitmix.com/Opinions/On-Being-a-Bad-Client"&gt;On Being a Bad Client&lt;/a&gt;: "&lt;p&gt;  &lt;/p&gt;&lt;center&gt;&lt;a title="Business Guys on Business Trips" href="http://businessguysonbusinesstrips.com/"&gt;&lt;img title="Business Guys on Business Trips" alt="http://businessguysonbusinesstrips.com/" src="http://visitmix.com/Content/Files/clip_image002%5B4%5D_11.jpg" /&gt;&lt;/a&gt;&lt;/center&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;  I love these posts. But the thing is, they always come from the agency or designer's side. Here, I intend to give you a little insight from &lt;b&gt;the bad client's&lt;/b&gt; side. Because even though I think most of my agency partners find me pleasurable to work with, I sometimes see myself in these 'bad clients' posts. I thought maybe I could help bring some perspective to the relationship. &lt;/p&gt; &lt;h2&gt;  Bad Client Behavior #1: They Want a Ton of Changes At the Last Minute &lt;/h2&gt; &lt;p&gt;  You, the designer, probably did exactly what you should do. You went through a business requirements gathering exercise, then talked to some actual users (yes, you were that lucky) and delivered an amazing set of wireframes (on time!). And what did you hear from your client? Crickets. &lt;/p&gt; &lt;p&gt;  So you pressed ahead. You sent over the visual comp of the homepage expecting everything to go smoothly, when BAM! Suddenly Mr. Bad Client's feedback is flowing and he's telling you, 'We're way off track here!' You get more and more frustrated as the delivery date looms heavily and you have to cancel your plans to see the Human Centipede movie this weekend. &lt;/p&gt; &lt;p&gt;  Here's the problem: Most of the time, your bad clients are super busy and just can't wrap their heads around a wireframe. In fact, they probably scanned it for about two minutes and declared it good. The visual comp is the closest thing to a real site in their heads, so that's when they begin providing the feedback you needed earlier in the process. &lt;/p&gt; &lt;p&gt;  The fix? I recommend getting to the visual comp phase as fast as possible, and allowing room in the schedule to deal with feedback on the design. &lt;/p&gt; &lt;h2&gt;  Bad Client Behavior #2: Ugh! They Want You to Build a Site Without Content! &lt;/h2&gt; &lt;p&gt;  Ok, I'll admit it. I'm guilty of this. I've actually read Kristina Halvorson's book, Content Strategy for the Web. But I've been in situations where I was the primary contact with the agency, and my stakeholders just didn't have the content ready before putting together the site. Sorry Kristina! &lt;/p&gt; &lt;p&gt;  After I apologized profusely, the great agency I worked with did the next best thing: They asked what kind of content would go in the various content blocks, and tried to use existing content instead of lorem ipsum. It actually worked out pretty well. &lt;/p&gt; &lt;p&gt;  I was able to give them some guidance and examples of content we used in the past. For example, Microsoft is notorious for using long product names, titles of posts and titles of session for our events. So the typical 'Lorem Ipsum' filler text wouldn't work for us. We were able to plan for that. &lt;/p&gt; &lt;p&gt;  I believe that you should have your content prior to building a site. But sometimes reality sets in, and you have to adjust to the situation. This agency has a special place in my heart for working with me vs. lecturing me. &lt;/p&gt; &lt;h2&gt;  Bad Client Behavior #3: They Want To See 10 Different Comps &lt;/h2&gt; &lt;p&gt;  As a client, I have to admit I like the idea of having choices. And yes, I will always want a Frankenstein of a web site that combines the best of the three you have shown me. Sorry! &lt;/p&gt; &lt;p&gt;  But you have to remember: Most clients are not keeping up-to-date on the &lt;a href="http://www.smashingmagazine.com/2010/05/04/web-design-trends-2010/"&gt;latest design trends&lt;/a&gt;. Helping give them exposure is a good thing. &lt;/p&gt; &lt;p&gt;  Also, remember there are a ton of stakeholders (especially in a large company) that have a say-so in the design (or at least who sign my paycheck). So although you may have created one concept to rule them all, it may be more fruitful in the end to let me choose from different concepts. &lt;/p&gt; &lt;h2&gt;  Bad Client Behavior #4: They're Obsessed With 'Above The Fold' &lt;/h2&gt; &lt;p&gt;  First of all, let me just say: I'm with you on this one. Also in this bucket is: &lt;/p&gt; &lt;ul&gt;  &lt;li&gt;Can you make the logo bigger?  &lt;/li&gt;  &lt;li&gt;It just doesn't 'pop' for me.  &lt;/li&gt;  &lt;li&gt;Can you make it more clean?  &lt;/li&gt;  &lt;li&gt;Hey! You left some empty space! Can we put a blog roll or a puppy picture there to fill it up?  &lt;/li&gt; &lt;/ul&gt; &lt;p&gt;  These are critical moments for educating the client. Explain the 'why'. Another great agency I worked with was really good about explaining what was &lt;b&gt;not&lt;/b&gt; on the page, and why. This made it very easy to go back to the stakeholders and explain why something was done (or NOT done). &lt;/p&gt; &lt;h2&gt;  Bad Client Behavior #5: They're Just Idiots &lt;/h2&gt; &lt;p&gt;  First, your clients are not idiots. They probably know their knowledge space just as much as you know yours. &lt;/p&gt; &lt;p&gt;  That said, I do believe in firing really bad clients. If they don't pay up, if they don't respect you, if they burn you—by all means, you should never do anything for them again. I recommend &lt;a href="http://www.zeldman.com/2008/12/04/20-signs-you-dont-want-that-web-design-project/"&gt;Zeldman's 20 Signs You Don't Want That Web Design Project&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;  But take time when you are frustrated to look at it from the client's side. &lt;/p&gt; &lt;h2&gt;  Now Say You… &lt;/h2&gt; &lt;p&gt;  Do you agree? Do you disagree? Please let me know what you think in the comments below. I would be particularly interested in bad clients you have dealt with. Did you 'fire' them? Did you have a Jedi-trick you used to get over a rough patch? Please tell me about it below! &lt;/p&gt; &lt;p&gt;  Also, &lt;a href="http://twitter.com/tommylee"&gt;follow me&lt;/a&gt; or &lt;a href="http://twitter.com/mixonline"&gt;MIX Online&lt;/a&gt; on Twitter if you like. &lt;/p&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-2134231857752768286?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://visitmix.com/Opinions/On-Being-a-Bad-Client' title='On Being a Bad Client'/><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/2134231857752768286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/on-being-bad-client.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/2134231857752768286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/2134231857752768286'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/on-being-bad-client.html' title='On Being a Bad Client'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-8976074264790617320</id><published>2010-05-29T23:01:00.000-07:00</published><updated>2010-06-04T22:49:08.219-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>MSDN Video: Introduction to ASP.NET 3.5 (Level 200)</title><content type='html'>&lt;a href="http://www.microsoft.com/events/series/msdnnetframework35.aspx?tab=videos&amp;amp;seriesid=124&amp;amp;webcastid=6572"&gt;MSDN Video: Introduction to ASP.NET 3.5 (Level 200)&lt;/a&gt;: "While many developers have enjoyed success with ASP.NET development, and have learned the new capabilities with each successive release, there is a significant group of developers out there who did not get involved with ASP.NET from the beginning, and find it hard to uncover a solid learning path for both current and mature ASP.NET technology. This talk assumes no ASP.NET background, and introduces many of the flagship capabilities of the framework, allowing the vast audience of developers who did not start with ASP.NET 1.0 to get on board. At the end of the talk you will have seen many of the core elements of ASP.NET development, with practical examples to help get you started building solutions with the ASP.NET Framework."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-8976074264790617320?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/8976074264790617320/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/msdn-video-introduction-to-aspnet-35.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8976074264790617320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8976074264790617320'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/msdn-video-introduction-to-aspnet-35.html' title='MSDN Video: Introduction to ASP.NET 3.5 (Level 200)'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-9038662984957438447</id><published>2010-05-29T22:59:00.000-07:00</published><updated>2010-06-04T22:46:07.586-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Entity Framework'/><title type='text'>MSDN Video: Introduction to Entity Framework (Level 100)</title><content type='html'>&lt;a href="http://www.microsoft.com/events/series/msdnnetframework35.aspx?tab=videos&amp;amp;seriesid=124&amp;amp;webcastid=13301"&gt;MSDN Video: Introduction to Entity Framework (Level 100)&lt;/a&gt;: "This is an introduction to the Microsoft &lt;a href="http://ado.net/"&gt;ADO.NET&lt;/a&gt; Entity Framework, it covers the basics that will help you get started. "&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-9038662984957438447?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/9038662984957438447/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/msdn-video-introduction-to-entity.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/9038662984957438447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/9038662984957438447'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/msdn-video-introduction-to-entity.html' title='MSDN Video: Introduction to Entity Framework (Level 100)'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-8359814807762004607</id><published>2010-05-29T00:16:00.000-07:00</published><updated>2010-05-29T00:16:03.411-07:00</updated><title type='text'>Prism V2.2 Posted to Codeplex</title><content type='html'>&lt;a href="http://blogs.msdn.com/b/bobbrum/archive/2010/05/28/prism-v2-2-posted-to-codeplex.aspx"&gt;Prism V2.2 Posted to Codeplex&lt;/a&gt;: "&lt;p&gt;The updates to the Prism source outlined &lt;a href="http://blogs.msdn.com/bobbrum/archive/2010/04/23/prism-source-updated-for-unity-2-0-and-silverlight-4.aspx"&gt;here&lt;/a&gt;, have been &lt;a href="http://prism.codeplex.com/releases/view/46046"&gt;packaged as downloadable release&lt;/a&gt; on Codeplex.&lt;/p&gt;  &lt;p&gt;This is largely the same code, with these additional items:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Added the Quickstarts and Acceptance test projects back in.  These are the same as the ones available in version 2.1. &lt;/li&gt;    &lt;li&gt;A more complete test pass. &lt;/li&gt;    &lt;li&gt;A smoke test when targeting all projects to .Net 4.0 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Additionally, we’ve posted the source to the ProjectLinker that can also work in VS2010.  We plan on shortly posting the ProjectLinker to the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/"&gt;Visual Studio Gallery&lt;/a&gt;, to make it a bit easier to consume.&lt;/p&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10017020" height="1" width="1" /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-8359814807762004607?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://blogs.msdn.com/b/bobbrum/archive/2010/05/28/prism-v2-2-posted-to-codeplex.aspx' title='Prism V2.2 Posted to Codeplex'/><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/8359814807762004607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/prism-v22-posted-to-codeplex_29.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8359814807762004607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/8359814807762004607'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/05/prism-v22-posted-to-codeplex_29.html' title='Prism V2.2 Posted to Codeplex'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-1769616568421357696</id><published>2010-02-14T01:19:00.000-08:00</published><updated>2010-06-04T22:49:35.106-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mansoor'/><title type='text'>My Favorite Quotations</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Mansoor Mehmood's favorite Quotations&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Smile, it makes people wonder what you're thinking.&lt;br /&gt;&lt;br /&gt;There are two theories to arguing with women. Neither one works.&lt;br /&gt;&lt;br /&gt;A bus station is where a bus stops. A train station is where a train stops. On my desk I have a work station.&lt;br /&gt;&lt;br /&gt;When you lose, don't lose the lesson.&lt;br /&gt;&lt;br /&gt;I talk to myself because I like dealing with a better class of people.&lt;br /&gt;&lt;br /&gt;If you're too lazy to start anything, you may get a reputation for patience.&lt;br /&gt;&lt;br /&gt;I am not in competition with anybody but myself.My goal is to beat my last performance.&lt;br /&gt;&lt;br /&gt;Never take a problem to your boss unless you have a solution.&lt;br /&gt;&lt;br /&gt;I feel that the greatest reward for doing is the opportunity to do more.\&lt;br /&gt;&lt;br /&gt;Well done is better than well said&lt;br /&gt;&lt;br /&gt;All easy problems have already been solved&lt;br /&gt;&lt;br /&gt;Anyone can count the seeds in an apple. No one can count the apples in a seed&lt;br /&gt;&lt;br /&gt;Computers are not intelligent. They only think they are.&lt;br /&gt;&lt;br /&gt;Confidence is the feeling you have before you understand the situation&lt;br /&gt;&lt;br /&gt;Foresight is knowing when to shut your mouth before someone suggests it.&lt;br /&gt;&lt;br /&gt;He is truly wise who gains wisdom from another's mishap.&lt;br /&gt;&lt;br /&gt;If all you have is a hammer, everything looks like a nail.&lt;br /&gt;&lt;br /&gt;If everything is coming your way, then you're in the wrong lane&lt;br /&gt;&lt;br /&gt;It's hard to make a program foolproof because fools are so ingenious&lt;br /&gt;&lt;br /&gt;Never appeal to a man's "better nature." he might not have one&lt;br /&gt;&lt;br /&gt;You can discover what your enemy fears most by observing the means he uses to frighten you.&lt;br /&gt;&lt;br /&gt;Sometimes what's right isn't as important as what's profitable.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-1769616568421357696?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/1769616568421357696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/02/my-favorite-quotations.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/1769616568421357696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/1769616568421357696'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/02/my-favorite-quotations.html' title='My Favorite Quotations'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-6484751055159113001</id><published>2010-02-14T01:08:00.000-08:00</published><updated>2010-04-03T23:03:51.124-07:00</updated><title type='text'>SMS Poetry , Funny SMS , Urdu Only</title><content type='html'>&lt;span style="font-weight: bold;"&gt;SMS Poetry&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;MUJH may khusbu basi ussi ki hai&lt;br /&gt;jese ye zingagiussi ki hai&lt;br /&gt;wo kahin aas paas hai mojod,&lt;br /&gt;ho-na-ho ye hansi ussi ki hain ,&lt;br /&gt;dukha rah hon dil is main lekin khushi usi ki hai&lt;br /&gt;yani koi kami nahi mujh main,&lt;br /&gt;yahi mujh main kami usi ki hai,&lt;br /&gt;kya mere khuwab b nahi mare?&lt;br /&gt;kya meri neend b usi ki hai?&lt;br /&gt;&lt;br /&gt;jin se kismat ke sitare root jate hain&lt;br /&gt;badal jati hain dunya magar sahare root jate hai,&lt;br /&gt;wo kashti jis ki kismat main ho doob jana,&lt;br /&gt;agar tofah se bach b nikle to kinare root jate hain&lt;br /&gt;&lt;br /&gt;jab tanha tumhari shaamain hon,&lt;br /&gt;jub moonh morh le duniya tum se&lt;br /&gt;udaas tumhari raatain hon&lt;br /&gt;her khushiroote jaya tum se&lt;br /&gt;pukaar lana tum mujhey&lt;br /&gt;ek muqa dena tum mujhey&lt;br /&gt;tumhare zakum zakum badan ko&lt;br /&gt;apnay kayal ka marham doon ga&lt;br /&gt;jaltay haye daman ko&lt;br /&gt;tamman;on ka sangam doon ga&lt;br /&gt;samhaal loon ga tumhare toote dil ko&lt;br /&gt;main taam loon ga har ek pal ko&lt;br /&gt;ke phir kaheen tum kabhi toott kar bikhro&lt;br /&gt;bikhar ke sulgo&lt;br /&gt;tanha na tumhari zaat ho&lt;br /&gt;tumhare saath main bhi toottoon tooth kar bikharoon&lt;br /&gt;aur bikar ker sulgoon&lt;br /&gt;&lt;br /&gt;mari hatheli tum apne pass rakh loo&lt;br /&gt;jab dua mango tu isse b utta lena&lt;br /&gt;khushi mile to apni hatheli agay karna..&lt;br /&gt;gham milen to meri hatheli main sameet daina&lt;br /&gt;&lt;br /&gt;NA JAANE KYUN DIL KI YE KHWAHISH HA&lt;br /&gt;WO MERI HAR BAAT JAAN JAE BINA KUCH KHE&lt;br /&gt;&lt;br /&gt;AASUON KO BAHOT SAMJHAYA,&lt;br /&gt;KE TANHAIYON MAIN AAYA KARO,&lt;br /&gt;MEHFIL MAIN HUMARA MAZAK MAT URAYA KARO,&lt;br /&gt;IS PER AANSOO TARAP KER BOLE, Copyright www.lovelysms.com&lt;br /&gt;ITNE LOGO MAIN BHI AAPKO TANHA PAATE HAI,&lt;br /&gt;ISILIYE TUMHARA SAATH DENE CHALE AATE HAI..&lt;br /&gt;&lt;br /&gt;Phoolon Say Pyaar Hai....?&lt;br /&gt;Magar Jab Phool Khiltay Hain To Unhain Tehni Say Tor Dalti Ho....&lt;br /&gt;Tum Kehti Ho Mujhay Baarishoon Say Pyaar Hai...?&lt;br /&gt;Magar Jab Baarish Hoti Hai To Chuppti Phirti Ho....&lt;br /&gt;Tum Kehti Ho Mujhay Hawaoon Say Pyaar Hai....?&lt;br /&gt;Magar Jab Hawa Chalti Hai Tu Khirkiyan Band Kar Leti Ho...&lt;br /&gt;Phir Us Waqt&lt;br /&gt;Main Khof Zada Sa Ho Jata Hoon Jab Tum.....&lt;br /&gt;Mujh Se Kehti Ho Mujhay Tum Say Pyar Hai......&lt;br /&gt;&lt;br /&gt;Dil mein basa tha pyaar tera,&lt;br /&gt;Wo dil to kabhi ka tod dia,&lt;br /&gt;Badnaam na hone deinge tujhe,&lt;br /&gt;Tera naam bhi lena chod dia.....!&lt;br /&gt;&lt;br /&gt;Hame maut per bhi hai yaqeen,&lt;br /&gt;Pyaar per bhi hai aetbaar hai,&lt;br /&gt;Dekhte hain pehle kaun aata hai,&lt;br /&gt;Hamein to dono ka intezar hai..........!&lt;br /&gt;&lt;br /&gt;Socha tha us bewakuf ko bhul jaayeinge,&lt;br /&gt;Dekh ker bhi andekha ker jaayeinge,Per&lt;br /&gt;,Jaise hi wo saamne aaye wo hasi chehra,&lt;br /&gt;Socha is baar dekh lein agli baar bhul jaayeinge............!&lt;br /&gt;&lt;br /&gt;palbhar me toot jaye wo kasam nahi,dosto ko bhool jaye wo hum nahi,&lt;br /&gt;hum tumhe bhul jaye is baat me dum nahi,aur tum Hume bhul jaao&lt;br /&gt;itne bure hum nahi.&lt;br /&gt;&lt;br /&gt;Chand utra tha hamare angan me,&lt;br /&gt;yeh sitaro ko gawara na hua,&lt;br /&gt;hum bhi sitaron se kya gila kare,&lt;br /&gt;jab chand hi hamra na hua&lt;br /&gt;&lt;br /&gt;meri ankhien rakh lo mujey kuch khab dey du.&lt;br /&gt;jis mien tumhari jhalak ho aisi sharab de du&lt;br /&gt;chalo choro sari batien ek baat maan jao&lt;br /&gt;meri sari umer ley lo bus ek pal ka saath dey du..&lt;br /&gt;&lt;br /&gt;Na aana usse leke mere janaze mein, Meri Mohabbat ki tauhin hogi, Main 4 logon ke kandhe pe hounga, Aur&lt;br /&gt;meri jaan paidal hogi&lt;br /&gt;&lt;br /&gt;Rah rah kar aapki yad aye to kya karun,&lt;br /&gt;Yaad dil se na jay to kya karun,&lt;br /&gt;Socha tha khawaboo me hogi mulakat,&lt;br /&gt;Par neend hi na aye to main kya karun.&lt;br /&gt;&lt;br /&gt;Apne dil ki suno, jazbat se kam na lo... Muje yad rakho beshak mera naam na lo... Apka vehem hai k hum bhul&lt;br /&gt;gaye AAPKO, Aisa soch k mere pyar ka imtihan na lo&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Funny SMS&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Shaadi karni thi par kismat khuli nahin.......&lt;br /&gt;Tajmahal banana tha par Mumtaz mili nahin....&lt;br /&gt;Ek din... kismat khuli,.....shaadi hui,........&lt;br /&gt;Ab Taj banana hai par yeh Mumtaz marti hi nahin.&lt;br /&gt;&lt;br /&gt;Zara gaur se................&lt;br /&gt;Lohe ko Loha kat ta hai ,&lt;br /&gt;Sone Ko Sona Kat ta hai,&lt;br /&gt;Zaher ko Zaher kat ta hai,&lt;br /&gt;Isliye apko Kutta katega..&lt;br /&gt;&lt;br /&gt;Hamaare Dil ke arman aansuon me beh gaye,&lt;br /&gt;Hum gali me thay gali me reh gaye,,,,,,,,,,,,,,,,,,,,,&lt;br /&gt;Kambakhat light chali gayi,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,&lt;br /&gt;Jo baat unse kehni thi wo unki mummy se keh gaye..&lt;br /&gt;&lt;br /&gt;Ager dum hai tu is sawal ka jawab yes or no me deke batao ... .... ... kya aapko pagalpan ke dure padhne band ho gaye hai?&lt;br /&gt;&lt;br /&gt;Do U know the fullform of COLLEGE- C-Come,O-On,L-Lets, L-Love, E-Each,G-Girl,E-Equally......Thats why boys go to college regularly....&lt;br /&gt;&lt;br /&gt;Who said english is easy???Fill in the blank with YES or No... 1.-----I dont have brain... 2.-----I dont have sence... 3.-----I am stupid....&lt;br /&gt;&lt;br /&gt;Ye Keh Kar India Ne Pakistan Ka Paani Khol Diya Faraz...&lt;br /&gt;K Hum Larki Ki Susraal Ka Pani Nahi Peetay. :-)&lt;br /&gt;&lt;br /&gt;itne to burey na the jitne ilzaam lagaye logon ne faraz&lt;br /&gt;kuch us ne humain badnaam kiya aag lagai apno ne...&lt;br /&gt;&lt;br /&gt;Us ki Zulfon Mai Jab Se Soya Hon&lt;br /&gt;Faraz...&lt;br /&gt;Qasam Se Mujhe To Jooen hi Nahi Chortin!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-6484751055159113001?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/6484751055159113001/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/02/sms-poetry-funny-sms-urdu-only.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/6484751055159113001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/6484751055159113001'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/02/sms-poetry-funny-sms-urdu-only.html' title='SMS Poetry , Funny SMS , Urdu Only'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4757484069882229120.post-6040987565900009217</id><published>2010-02-13T23:49:00.000-08:00</published><updated>2010-06-04T22:09:44.274-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mansoor'/><title type='text'>About Mansoor Mehmood</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_GStOn1vdCFk/TAH65CsnfTI/AAAAAAAAAAU/EJ-2sZ0cSrg/s1600/Full+Team.jpg"&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_GStOn1vdCFk/TAH45fxiigI/AAAAAAAAAAM/iXbbZeQTzoY/s1600/Mansoor+2nd+Prize.jpg"&gt;&lt;br /&gt;&lt;/a&gt;&lt;div id="nameplate"&gt;           &lt;h1 id="name"&gt;&lt;span class="fn n"&gt;&lt;span class="given-name"&gt;Mansoor&lt;/span&gt; &lt;span class="family-name"&gt;Mehmood&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;         &lt;/div&gt;                    &lt;div class="info"&gt;               &lt;div class="image"&gt;&lt;img src="http://media.linkedin.com/mpr/mpr/shrink_80_80/p/2/000/026/3d3/17d53c4.jpg" class="photo" alt="Mansoor Mehmood" /&gt;&lt;/div&gt;               &lt;p class="headline title"&gt;                        Software Engineer at F3                    &lt;/p&gt;             &lt;div class="adr"&gt;               &lt;p class="locality"&gt;                        Pakistan&lt;/p&gt;&lt;span style="font-weight: bold;"&gt;Mansoor Mehmood’s Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I am a software engineer by profession.I am Developing software since 2005.My goal or  aim is to become one of the best dot net specialist around the world. I am very hard working and I am always willing to learn to improve my skills in software development.&lt;br /&gt;&lt;br /&gt;I have been awarded the best employee at MTBC for the month of June 2007. I have secured 1st position in my master degree&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Mansoor Mehmood’s Education&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;I have done master's in computer science from the &lt;a href="http://www.blogger.com/www.uaar.edu.pk"&gt; University of Arid Agriculture&lt;/a&gt;, Rawalpindi in year 2007.I have done BCS from the Newport Institute of communication and economics in year 2004.I have took my initial level studies from the Islamabad model colleges, specifically Islamabad model college for boys G 8/4.I have topped  my university during my masters degree(MCS).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;My Websites/Projects:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I have develop few projects during my studies which are as under.&lt;br /&gt;Website of trading company , Online furniture sale shop&lt;br /&gt;PC Ludo game  (using turbo C language)&lt;br /&gt;Shortest job first algorithm simulation (using turbo C language)&lt;br /&gt;GSM network simulation (using .NET C#)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;My Interests:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I love developing desktop and web applications.I have developed desktop and web application for my employer and keep developing,. I love reading books related to history of Islam . I love playing computer games and watching movies.I have played a lot of cricket during my studies but now a days only watch cricket on TV (because of my very busy professional schedule).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;About My Family&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We are six (6) brothers and I am the eldest . My father (Manzoor Hussain Qureshi)has served in Pakistan government service for thirty (30) years.We belong from Mandra , a town in Tehsil Gujar Khan and district Rawalpindi.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;My Recent Activities&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I am working with a team whose goal is to develop or suggest the suitable software architecture for the next five (5) years. Developing or suggesting an architecture is really a very difficult job as all the new projects are going to follow it in future.We are studying and analyzing few of the best architectures and best practices already  in use, through out the world. We worked in SOA based applications in past, now we are trying to improve current SOA by introducing few new technologies like &lt;a href="http://www.pnpguidance.net/Category/Prism.aspx"&gt;PRISM&lt;/a&gt; , &lt;a href="http://en.wikipedia.org/wiki/Windows_Communication_Foundation"&gt;WCF&lt;/a&gt; and .net frame work 4.&lt;br /&gt;&lt;br /&gt;I am also looking into &lt;a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation"&gt;WPF&lt;/a&gt; and &lt;a href="http://www.silverlight.net/"&gt;Silverlight&lt;/a&gt; technologies.I have studied the Microsoft &lt;a href="http://entlib.codeplex.com/"&gt;Enterprise Library&lt;/a&gt; blocks.I am very impressed with these blocks as they are covering very important crosscutting concern of application.The block are related to logging, exception handling, caching, cryptography, validation and security. I do recommend all .Net developers to study and use the enterprise library.&lt;br /&gt;&lt;br /&gt;Recently I have been awarded the 2nd best software engineer of the year. I am very happy to receive the award, this will encourage me more to work hard and efficiently in future. Here are few  pictures from the ceremony.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_GStOn1vdCFk/TAH45fxiigI/AAAAAAAAAAM/iXbbZeQTzoY/s1600/Mansoor+2nd+Prize.jpg"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 214px;" src="http://3.bp.blogspot.com/_GStOn1vdCFk/TAH45fxiigI/AAAAAAAAAAM/iXbbZeQTzoY/s320/Mansoor+2nd+Prize.jpg" alt="2nd prize for Mansoor" id="BLOGGER_PHOTO_ID_5476932288524749314" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Mansoor receiving 2nd best software engineer prize in above picture. My team also get declared as the best team of the year 2009-2010.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_GStOn1vdCFk/TAH65CsnfTI/AAAAAAAAAAU/EJ-2sZ0cSrg/s1600/Full+Team.jpg"&gt;&lt;img style="display: block; margin: 0px auto 10px; text-align: center; cursor: pointer; width: 320px; height: 214px;" src="http://3.bp.blogspot.com/_GStOn1vdCFk/TAH65CsnfTI/AAAAAAAAAAU/EJ-2sZ0cSrg/s320/Full+Team.jpg" alt="Team of year" id="BLOGGER_PHOTO_ID_5476934479742729522" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;In above picture Mansoor is in group photo with his team.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;           &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4757484069882229120-6040987565900009217?l=mansoormehmood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mansoormehmood.blogspot.com/feeds/6040987565900009217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mansoormehmood.blogspot.com/2010/02/about-mansoor-mehmood.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/6040987565900009217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4757484069882229120/posts/default/6040987565900009217'/><link rel='alternate' type='text/html' href='http://mansoormehmood.blogspot.com/2010/02/about-mansoor-mehmood.html' title='About Mansoor Mehmood'/><author><name>Mansoor Mehmood</name><uri>http://www.blogger.com/profile/04321726423146741975</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_GStOn1vdCFk/TAH45fxiigI/AAAAAAAAAAM/iXbbZeQTzoY/s72-c/Mansoor+2nd+Prize.jpg' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
