<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:a10="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>outcoldman</title>
    <link>http://outcoldman.com/en</link>
    <description>Denis Gladkikh Personal Web</description>
    <lastBuildDate>Sun, 19 May 2013 22:39:46 Z</lastBuildDate>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/outcoldman_en" /><feedburner:info uri="outcoldman_en" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/wsDLsOeRfA8/332</link>
      <category>TDD</category>
      <category>nUnit</category>
      <category>Moq</category>
      <category>Windows Runtime</category>
      <category>WinRT</category>
      <category>.NET Core</category>
      <category>Unit Tests</category>
      <title>How to use Moq and nUnit to write Unit Tests for Windows Runtime libraries</title>
      <description>&lt;p&gt;I love to use Moq library, it is the best mocking framework for me. Visual Studio provides Fakes framework, but my opinion is that it is for slightly different issues. Fakes is a framework for making fakes, not mokes. For example if you need to change how System.IO.File.Exist handles the path or if for some reason you need to change return value of System.DateTime.Now to test something related to time – this is good job for Fakes framework. If you need to make a Stubs or Mocks I prefer to use Moq, it is just simpler. And don't forget that they work together really well. 
&lt;/p&gt;&lt;p&gt;The problem which I met when I started to write gMusic is that Moq does not exist for Windows Store Apps (WinRT). It is because "&lt;a href="https://groups.google.com/forum/?fromgroups"&gt;winrt doesn't allow dynamic codegen&lt;/a&gt;". But I found a workaround. Instead of creating new Unit Test Class Library for Windows Store Apps I created simple Class Library with Target Framework 4.5 (I will call it Unit Test library). After this I added reference to Windows Runtime using this blog post &lt;a href="http://www.wintellect.com/cs/blogs/jlikness/archive/2013/01/13/referencing-the-windows-runtime-from-desktop-apps.aspx"&gt;Referencing the Windows Runtime from Desktop Apps&lt;/a&gt;. And the latest point is to include my code from Windows Store Apps library to this Unit Test library. I cannot reference it, because my libraries have different runtimes: Windows Store Apps library has runtime .NETCore (or WinRT, or Windows Runtime, so many names for this). And my Unit Test library has runtime .NETFramework 4.5. Visual Studio does not allow you to mix runtimes, except if they are Portable Libraries.  The solution for this is to just include all my code which I want to test from Windows Store Apps library to Unit Test library as links to files &lt;a href="http://msdn.microsoft.com/en-us/library/vstudio/9f4t9t92(v=vs.100).aspx"&gt;Adding an Existing Item as a Link&lt;/a&gt; (you can just use drag'n'drop in Solution Explorer with pressed Shift+Ctrl to move some folder or files from one project to another and make it as links). 
&lt;/p&gt;&lt;p&gt; It is not a perfect solution, but works for me. &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/wsDLsOeRfA8" height="1" width="1"/&gt;</description>
      <a10:updated>2013-04-04T02:28:26Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/332</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/LhSL83iLAlg/331</link>
      <category>.NET</category>
      <category>C#</category>
      <category>Patterns</category>
      <category>IoC</category>
      <category>Unity</category>
      <category>OutcoldSolutions.Framework</category>
      <category>GitHub</category>
      <title>How to improve performance of your own Inversion of Control Framework?</title>
      <description>&lt;p&gt;I enjoy doing anything by myself instead of using well know frameworks. I am not saying that I am using only my own frameworks. It just gives me more knowledge about how these frameworks doing their job. Inversion of Control Framework it is one of these examples. I have a blog post on Russian about simple implementation of IoC container. You can look on it here &lt;a href="http://www.microsofttranslator.com/bv.aspx?from=&amp;amp;to=en&amp;amp;a=http://outcoldman.com/ru/blog/show/276"&gt;Simple IoC Container&lt;/a&gt; (I used Microsoft Translator for this link). Actually right now is more than just one class, I have my own framework, which I use for some my applications, like &lt;a href="http://apps.microsoft.com/windows/en-US/app/gmusic/939f0859-1413-4a52-9ab6-6e50405c8c2e"&gt;gMusic&lt;/a&gt; (you can follow this project on &lt;a href="https://github.com/outcoldman/Framework"&gt;GitHub – Framework&lt;/a&gt;). 
&lt;/p&gt;&lt;p&gt;Couple months ago I met an article &lt;a href="http://www.palmmedia.de/Blog/2011/8/30/ioc-container-benchmark-performance-comparison"&gt;IoC Container Benchmark - Performance comparison&lt;/a&gt;, where this guy compare different IoC containers (when I first time met this article it was only about performance). So I decided to check performance of my simple container. This is result (I have different count of iterations, so do not compare it to the original blog post):
&lt;/p&gt;
&lt;p&gt;&lt;img src="/Library/2013/02/26/022613_0714_1.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;In this list: "Outcold" – this is my current framework, "IoC A" – it is a class which I showed in this blog post &lt;a href="http://www.microsofttranslator.com/bv.aspx?from=&amp;amp;to=en&amp;amp;a=http://outcoldman.com/ru/blog/show/276"&gt;Simple IoC Container&lt;/a&gt; (based on Activator.CreateInstance), "IoC E" – it is a different version of IoC class, but based on Expressions (I showed in in one of my comments &lt;a href="http://outcoldman.com/ru/blog/show/276"&gt;here&lt;/a&gt;). "&lt;a href="http://lightinject.codeplex.com"&gt;LightInject&lt;/a&gt;" – it is one of the faster frameworks from original blog post about IoC performance, "&lt;a href="http://unity.codeplex.com/"&gt;Unity&lt;/a&gt;" – it is one of the famous frameworks. As you can see that, the version of IoC class which is based on Expressions has the worst performance. The funny thing, that I used it everywhere, I really thought that it should be faster than Activator, somebody told me… and I did not verify that…. Anyway, after this article, I spent some time to improve performance of my IoC container, and this is how I did this. 
&lt;/p
&lt;p&gt;The main problem of IoC container which I implemented is that I did not cache the compiled Expression. Each time when I ask IoC to resolve some object – it compiles expression and after this resolve it:
&lt;/p&gt;
&lt;p&gt;&lt;img src="/Library/2013/02/26/022613_0714_2.png" alt=""/&gt;
	&lt;/p&gt;
&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;First optimization is simple. Just need to cache expression after first time somebody will ask to resolve object. However, first I need to change how I invoke constructor, because my expression expects constraints I need to change it to parameters, so each "resolving" can use it is own parameters:
&lt;/p&gt;

&lt;p&gt;&lt;img src="/Library/2013/02/26/022613_0714_3.png" alt=""/&gt;
	&lt;/p&gt;
&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;Now I have Delegate, which can create for me a new object of specific type. The only one problem, that this delegate can have different set of parameters, so I cannot cast it to something like Func&amp;lt;Type1, … , TypeN, Result&amp;gt; and invoke it. I need to call DynamicInvoke, which is slow:
&lt;/p&gt;

&lt;p&gt;&lt;img src="/Library/2013/02/26/022613_0714_4.png" alt=""/&gt;
	&lt;/p&gt;
&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;This is the result of this optimization (as you can see it is very good, but still variant with Activator works better):
&lt;/p&gt;
&lt;p&gt;&lt;img src="/Library/2013/02/26/022613_0714_5.png" alt=""/&gt;
	&lt;/p&gt;
&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;The second step I made – I just changed Expression in such way, so it always takes just one parameter "array of objects". In expression I use this array to cast each item of this array to the parameter in constructor. This is how I do this: 
&lt;/p&gt;
&lt;p&gt;&lt;img src="/Library/2013/02/26/022613_0714_6.png" alt=""/&gt;
	&lt;/p&gt;
&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;This is the result:
&lt;/p&gt;
&lt;p&gt;&lt;img src="/Library/2013/02/26/022613_0714_7.png" alt=""/&gt;
	&lt;/p&gt;
&lt;p&gt;
 &lt;/p&gt;&lt;p&gt;It is faster than version with Activator! But it still slower than LightInject. I guess it is because LightInject used before System.Reflection.Emit instead of Expressions, or maybe they have better idea how to create this expression for type resolving. 
&lt;/p&gt;&lt;p&gt;Anyway, it was a good result for me.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/LhSL83iLAlg" height="1" width="1"/&gt;</description>
      <a10:updated>2013-03-16T20:40:06Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/331</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/qqXlCZpl5Lc/326</link>
      <category>Visual Studio 2010</category>
      <category>Visual Studio 2012</category>
      <category>Visual Studio Extension</category>
      <category>IntelliCommand</category>
      <title>Meet IntelliCommand (Visual Studio 2010/2012 extension)</title>
      <description>&lt;p&gt;How many shortcut keys you know in Visual Studio? Do you want to know all of them? I know how you can learn them very easy. 
&lt;/p&gt;&lt;p&gt;I'd like to introduce you a cool extension for Visual Studio 2010/2012 which I wrote with help of my colleagues Drake Campbell and &lt;a href="https://twitter.com/Mandaleeka"&gt;Aditya Mandaleeka&lt;/a&gt;. Let me just copy-paste description from &lt;a href="http://visualstudiogallery.msdn.microsoft.com/83f59659-abc1-4bfa-9779-42f687af0481"&gt;Visual Studio Gallery&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;IntelliCommand - an extension for Visual Studio 2010 and 2012 which helps to find the short keys. It shows the help windows with all possible combinations when you press Ctrl or Shift or Alt or their combinations (hold it for about 2 seconds to see this window). Also it shows the list of possible combination when you press first combination of chord shortcut keys, like Ctrl+K, Ctrl+C (this combination comments selected text in editor).
&lt;/p&gt;&lt;h2&gt;Couple screenshots:
&lt;/h2&gt;&lt;p&gt;IntelliCommand shows all available shortcut keys for combination of Control + Shift after couple seconds:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012/10/31/103112_0622_MeetIntelli1.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;Ctrl+K was pressed. Visual Studio waits for second combination:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012/10/31/103112_0622_MeetIntelli2.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;Available options for Intelli Command. The delay of showing Intelli Command window. Customization of Intelli Command window look:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012/10/31/103112_0622_MeetIntelli3.png" alt=""/&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/83f59659-abc1-4bfa-9779-42f687af0481"&gt;Download IntelliCommand from Visual Studio Gallery.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Feedback is welcome!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/qqXlCZpl5Lc" height="1" width="1"/&gt;</description>
      <a10:updated>2012-10-31T06:22:20Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/326</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/94nL_KmEXKs/325</link>
      <category>outcoldman</category>
      <category>outcoldman.ru</category>
      <category>outcoldman.com</category>
      <category>Azure</category>
      <category>ASP.NET MVC</category>
      <category>Mobile Devices</category>
      <title>Moving site to the Windows Azure Web Sites</title>
      <description>&lt;p&gt;It was a year and half when last time I updated my web site. Sadly this is just one project I have where I can have some experience with web development. And because I really missed it, so I've put three things on my agenda:
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Move domain from ru to com, so now my site is available on &lt;a href="http://outcoldman.com"&gt;http://outcoldman.com&lt;/a&gt;. 
&lt;/li&gt;&lt;li&gt;Add support for mobile devices and make some minor changes.
&lt;/li&gt;&lt;li&gt;Move site from masterhost to orcsweb. I have both of them for free, but second one gives better conditions, like more storage and better network bandwidth. And I like orcsweb, because these guys update their servers on next days after new .NET Framework ships. 
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;But how you can understand from the topic I failed last task. Because orcsweb sets medium trust for shared sites – this is a huge pain for developers. For example I met problems with using &lt;a href="http://nuget.org/packages/AntiXSS"&gt;AntiXSS&lt;/a&gt;. 
&lt;/p&gt;&lt;h2&gt;Windows Azure Web Sites
&lt;/h2&gt;&lt;p&gt;Azure Web Sites is still in preview. Azure gives you up to 10 Shared Web Instances for free. But if you want to use custom domains you need move instance to Paid Shared Instance Model, which will cost you about 10-15$ per month. I'm not sure about this, I still cannot understand how this will work if my instance will use CPU only for 1 minute in an hour. I will need to pay for whole hour or just for one minute? 
&lt;/p&gt;&lt;p&gt;Couple days ago also I saw an information that &lt;a href="http://weblogs.asp.net/scottgu/archive/2012/10/25/net-4-5-now-supported-with-windows-azure-web-sites.aspx"&gt;Web Sites now support .NET Framework 4.5&lt;/a&gt;. And this was the latest argument for Web Sites instead of orcsweb. Particularly I dreamed also about to try cloud. 
&lt;/p&gt;&lt;p&gt;I don't want to tell you how it was easy for me to create a Web Site Instance in Azure. Azure portal has really good documentation and a lot of videos about how to do this. I just want to say – try it. If you don't have an account in Azure – you can try &lt;a href="http://weblogs.asp.net/scottgu/archive/2012/09/17/announcing-great-improvements-to-windows-azure-web-sites.aspx"&gt;free trial&lt;/a&gt;, which will ask you about credit card, but don't worry. You can set limit to 0$, so you will not need to worry about what will be when trial period will come to end or what if you will use more resources than Azure gives you for free. Each free shared web instance on Web Sites has domain name like x.azurewebsites.net, so it is very easy to use them to try something or show your project to world. 
&lt;/p&gt;&lt;p&gt;And this is really cool that you don't need to think a lot about settings. I just downloaded Publish Profile, which I imported to the ASP.NET MVC 4 project in Visual Studio (right click on project in solution explorer and choose Publish…). And that is it. 
&lt;/p&gt;&lt;h2&gt;Mobile Devices support
&lt;/h2&gt;&lt;p&gt;I thought that this requires a huge amount of work. Because I remembered from ASP.NET – you need to render your pages on server for mobile devices in special way if you want to support them. I was so surprised when I found that to do this you just need to add two things. Set viewport for mobile devices:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012/10/27/102712_0632_1.png" alt=""/&gt;
 &lt;/p&gt;&lt;p&gt;And set special css classes for case when width is less than some defined value:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012/10/27/102712_0632_2.png" alt=""/&gt;
 &lt;/p&gt;&lt;p&gt;The easiest way is to take a look how ASP.NET MVC 4.0 defines its classes for mobile devices. This is really good example.
&lt;/p&gt;&lt;h2&gt;Moving domain
&lt;/h2&gt;&lt;p&gt;At first I specified for both of my domains that they should redirect to azure web site instance. After this I set two special rules for Url Rewriter in web.config. Url Rewriter is installed on Web Sites by default. 
&lt;/p&gt;
&lt;p&gt;&lt;img src="/Library/2012/10/27/102712_0632_3.png" alt=""/&gt;&lt;/p&gt;
&lt;p&gt;After this I found that it is really easy to change domain in Google Web Master and Google Analytics services. As I understand to do the moving right – I will need also to find main referral pages in internet (Google Analytics can help me to do this) and change links on it (or ask owners to change them). And after this I can say good bye to my old domain.
&lt;/p&gt;&lt;h2&gt;What is next?
&lt;/h2&gt;&lt;p&gt;As I said I really missed web-development. So I have some plans to continue improving my web site. At first I want to refactor couple places in source code and publish it to GitHub. When I tried some new features, like Entity Framework and SQL Server CE I didn't try to do it well, I just tried it. And when I saw that it works – I published it with thoughts that I will refactor this code in future. Very common situation, right? 
&lt;/p&gt;&lt;p&gt;One thing which I still cannot understand – is how to analyzer log files from 0:/LogFiles/http/RawLogs/*.log. They have next format:
&lt;/p&gt;&lt;blockquote&gt;# date time s-sitename cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken 
&lt;/blockquote&gt;&lt;p&gt;The best option which I found is to import them to excel.  &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/94nL_KmEXKs" height="1" width="1"/&gt;</description>
      <a10:updated>2012-10-27T07:50:04Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/325</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/6O2gKkg6osM/322</link>
      <category>.NET</category>
      <category>Bug</category>
      <category>Sample</category>
      <category>nuget</category>
      <category>ObjectReleaseVerification</category>
      <category>memory leak</category>
      <title>Object Release Verification Framework</title>
      <description>&lt;p&gt;Computer Software can have bugs and some of these bugs are Memory Leaks. It is usual case that if your software is a Multi-Document application you need to pay more attention on memory leaks. The main question in these applications is how I can be sure that when user will close document I will release all instances and resources related to this document? What if you already found a Memory Leak and fixed it? How you can protect yourself to be sure that after some changes you will not have this memory leak again?
&lt;/p&gt;&lt;p&gt;I had the same thought after one of my Memory Leak fix. Do we have any software or tools which can validate that after some interaction with my application all instances are released, which I want to be released? In native world there are should be a lot of different instruments / practices to do this (I'm not an expert, but pretty sure that this is true). In managed world there are a lot of tools with names Memory Profiler, but to make them work you need to run them separately, analyze your application and after that analyze the report to find memory leaks. This can work, but I'd like to have some instrument in my application which can in runtime check my application and find memory leaks. The solution which I found is pretty simple. I store the list of &lt;a href="http://msdn.microsoft.com/en-us/library/system.weakreference.aspx"&gt;WeakReferences&lt;/a&gt; to objects which I want to check after some interaction that they are released. Based on this I wrote &lt;a href="https://nuget.org/packages/ObjectReleaseVerification"&gt;Object Release Verification Framework&lt;/a&gt; with couple classes and interfaces. This framework is published on nuget.org as a portable library. 
&lt;/p&gt;&lt;p&gt;Let's take a look on example. At first – we need to create a new WPF Application project (I will use Visual Studio 2012), after this we need to include nuget package ObjectReleaseVerification by invoking next command in Package Managed Console (or with help of NuGet UI):
&lt;/p&gt;&lt;p style="margin-left: 36pt"&gt;&lt;span style="color:#f79646; font-size:12pt"&gt;PM&amp;gt; Install-Package ObjectReleaseVerification
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;After this we need to add some code to initialize Verification Framework. It is turned off by default, and it doesn't have any notifications about memory leaks by default. The cause of the latest: some restrictions of using portable library – it is hard to find something which will work on Windows Phone, Web and Desktop platforms at the same time. The initialization code can be next:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\09\13/091312_0738_ObjectRelea1.png" alt=""/&gt;&lt;/p&gt;&lt;p&gt;This code turns on Object Release Verification framework only when we compile bits in Debug configuration. Also we add one Handler for verification events, which actually is a part of verification framework TextOutputVefiricationHandler. This class expects just one parameter in constructor. The value of this parameter is a function which can write strings. In my case it is debug output window. 
&lt;/p&gt;&lt;p&gt;After this I will add some logic to the application. I will emulate work of multi-document application:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\09\13/091312_0738_ObjectRelea2.png" alt=""/&gt;
&lt;/p&gt;&lt;p&gt;This code adds simple table control and couple buttons which can add and remove tabs to this control. The code behind:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\09\13/091312_0738_ObjectRelea3.png" alt=""/&gt;
&lt;/p&gt;&lt;p&gt;Method AddTab creates and adds new tab item to the tab control, it uses DateTime.Now as a name for the tab, we will use as a "document name" (just want to remind that I'm going to emulate a multi-document application). Our window also contains the list of all tab items. We use it just to emulate memory leaks in future. The last code line adds the new tab item to the verification framework, so it can start to track it. We use "document name" as a context. Context is a unique name, which allows us to group instances in different lists, so we can just validate instances in special list, by special context.
&lt;/p&gt;&lt;p&gt;Method RemoveTab removes active tab from the list of all tabs and from control. Last line of code in this method validates that all instances in current context are released. The context is a document name (tab header), which we generates in AddTab. In method Verify we use delay for 1 second to be sure that Verifier will do verification when runtime will go away from the RemoveTab method. We need to be sure that all variable instances like tabItem will be out of scope, so there are will be no references to these instances. Method Verify will invoke Collect method of Garbage Collection and after that do verification, like which objects are released and which of them not.
&lt;/p&gt;&lt;p&gt;This is how it looks:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\09\13/091312_0738_ObjectRelea4.png" alt=""/&gt;
&lt;/p&gt;&lt;p&gt;On this screenshot I added couple tabs and after this removed one of them. As you can see in output window – verification framework shows me which objects are released. 
&lt;/p&gt;&lt;p&gt;You can implement your own verification handler. For example verification handler in next sample just shows assert when verification fails (application has memory leaks):
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\09\13/091312_0738_ObjectRelea5.png" alt=""/&gt;
&lt;/p&gt;&lt;p&gt;After this we can also add it to the collection of verification handlers:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\09\13/091312_0738_ObjectRelea6.png" alt=""/&gt;
&lt;/p&gt;&lt;p&gt;After this let's try to comment one line in RemoveTab, so with this line we will simulate memory leak:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\09\13/091312_0738_ObjectRelea7.png" alt=""/&gt;
&lt;/p&gt;&lt;p&gt;After we will try the same steps which we made in previous run (add couple tabs and remove one of them) we will see assert and detail information in output window:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\09\13/091312_0738_ObjectRelea8.png" alt=""/&gt;
&lt;/p&gt;&lt;p&gt;You can take a look on this sample at &lt;a href="https://github.com/outcoldman/OutcoldSolutions-ObjectReleaseVerification-Sample"&gt;https://github.com/outcoldman/OutcoldSolutions-ObjectReleaseVerification-Sample&lt;/a&gt;. If you will have any suggestions or comments about this framework – I'd like to hear them. 
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/6O2gKkg6osM" height="1" width="1"/&gt;</description>
      <a10:updated>2012-09-17T03:42:00Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/322</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/a7FwwJo80M8/318</link>
      <category>Silverlight</category>
      <category>Windows Phone 7</category>
      <category>Windows Phone</category>
      <category>Tasks</category>
      <title>Windows Phone: Safe work with tasks</title>
      <description>&lt;p&gt;When developers use task from namespace &lt;a href="http://msdn.microsoft.com/en-us/library/ff428753(v=vs.92).aspx"&gt;Microsoft.Phone.Tasks&lt;/a&gt; they can do two mistakes: a) do not put some logic about that application can go to the tombstone mode, it is when phone will save all states off pages and application somewhere and when user will come back to application – phone will restore these states to application and pages; b) developers don't known that method Show can throw exception InvalidOperationException, this can happends when application is in progress of navigation, which potentially can kill your application if you do not have some exception handler, and this means that when user will go back from task to application he will see the main page of phone instead of the application's page. 
&lt;/p&gt;&lt;p&gt;Ok, so let's look at simple example, my Windows Phone page will do next task: it will have some image control and button which can choose the image from library:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\07\04/070412_0634_WindowsPhon1.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;I have next code behind:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\07\04/070412_0634_WindowsPhon2.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;So, how much problems you see in this code? 
&lt;/p&gt;&lt;h2&gt;Problem #1. Tombstone mode.
&lt;/h2&gt;&lt;p&gt;If you will have closer look on MSDN documentation, for example on &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.photochoosertask(v=VS.92).aspx"&gt;PhotoChooserTask&lt;/a&gt; – you will see the Important Note which tells us about Tombstone Mode. This is big mistake to think that your application is not really huge and there are a little chance that phone can send your application to Tombsone Mode (especially when we got users with just 512Mb devices). It is very simple to test your application on how it can handle Tombstone Mode, you just need to set the checkbox in Debug setting of your project properties:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\07\04/070412_0634_WindowsPhon3.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;If you will try to use my example you will see that after you will choose the image – the application will do nothing. You will see this behavior because phone will kill all instances of pages and instance of application when task will be launched. And after user will come back to your application – the phone will recreate all instances of pages and instance of application. If you need to store some data between the time when it kills and restores the instances of the application and pages you can use the States of pages and application to store some data. Be careful, because all objects in states will be serialized and deserialized, so if you will try to save a very huge graph of objects – phone can throws exception. Also phone knows what task you've invoked on your page and when phone will navigate back to your page from tombstone mode it will also invokes the event of the task like Completed. So this is how we can solve problem with tombstone mode in my example:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\07\04/070412_0634_WindowsPhon4.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;Of course in most cases you will need to have some association between the image and data in your application model. For example you want to store the icon for some contact in application. So we need to get knowledge how to work with States: &lt;a href="How%20to:%20Preserve%20and%20Restore%20Page%20State%20for%20Windows%20Phone."&gt;How to: Preserve and Restore Page State for Windows Phone&lt;/a&gt;. Actually the solution will be pretty simple: a) we need to save data in method OnNavigatedFrom b) and in method OnNavigatedTo we need to read from State this data and after that subscribe to Completed event of the task. You will need to have subscription exactly in an OnNavigatedTo method, because if you will still have a subscription in constructor – phone will invokes the handler when State will not be loaded yet. You can use State only after OnNavigatedTo will be invoked. So, I will need to change my example to this:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\07\04/070412_0634_WindowsPhon5.png" alt=""/&gt;
	&lt;/p&gt;&lt;h2&gt;Problem #2. Method Show can throw exceptions.
&lt;/h2&gt;&lt;p&gt;The method Show can throw exception. It is very easy to reproduce this. Just double click on button from previous example. After you will do this – after you will choose the image the phone will show you main screen instead of your application's pages. This is because your application will not catch exception on second button's click, so on first click you will launch the task, and on second click method Show will throw exception "&lt;em&gt;System.InvalidOperationException: Not allowed to call Show() multiple times before a Chooser returns&lt;/em&gt;". So you need always to have a try-catch blocks on top of Show invokes. I solved this problem for me very easy: I just wrote couple wrappers which do all work like catch exception. You can look on the code in my &lt;a href="http://www.assembla.com/code/outcoldman_p/subversion/nodes/BlogProjects/TaskProblems/TaskProblems/TaskWrapper.cs"&gt;repository&lt;/a&gt;. 
&lt;/p&gt;&lt;p&gt;So, the previous example will be next (if we will not need the States to store something when Task will be launched):
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\07\04/070412_0634_WindowsPhon6.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;And to invoke tasks which don't have ChooserTask as a base class (which just shows something and you do not expect to get some data from them) you will need to write the next code:
&lt;/p&gt;&lt;p&gt;&lt;img src="/Library/2012\07\04/070412_0634_WindowsPhon7.png" alt=""/&gt;
	&lt;/p&gt;&lt;p&gt;Let's do our windows phone application more stable! Example with my wrappers and all other my source code you can find at my &lt;a href="http://www.assembla.com/code/outcoldman_p/subversion/nodes/BlogProjects/TaskProblems/TaskProblems/TaskWrapper.cs"&gt;repository&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/a7FwwJo80M8" height="1" width="1"/&gt;</description>
      <a10:updated>2012-07-04T06:34:00Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/318</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/_jwqWJnyLTQ/308</link>
      <category>Silverlight</category>
      <category>XAML</category>
      <category>Expression Blend</category>
      <category>Binding</category>
      <category>Windows Phone 7</category>
      <category>Behavior</category>
      <category>Blend</category>
      <category>Interactivity</category>
      <title>Windows Phone 7 Silverlight: Behaviors for TextBox</title>
      <description>&lt;p&gt;I’ve submitted my first application for Windows Phone! It is very simple app. Marketplace has a good amount of similar apps: &lt;a href="http://www.windowsphone.com/en-US/apps/f5cf9254-ab40-44be-a042-01a76091076c"&gt;Planning Poker&lt;/a&gt;. Anyway, I’ve wrote couple own behaviors for TextBox and want to share this code with you.&lt;/p&gt;  &lt;p&gt;If you are Silverlight/WPF developer and have already used Blend than you should know what are Behaviors and Interactions. If not or if you forget what it is I will remind you. You can find these libraries in directory “c:\Program Files (x86)\Microsoft SDKs\Expression\Blend\” (in case if you have Windows x86 than you should remove from path (x86)). And of course these libraries exist only in case if Blend has been installed. In this directory you can find packs of libraries for WPF/Silverlight and WindowsPhone. If you don’t know what are Behaviors and Interaction I suggest you to read &lt;a href="http://msdn.microsoft.com/en-us/library/dd440765.aspx"&gt;Expression Blend SDK for Windows Phone&lt;/a&gt; on MSDN. In few words: this is approach to extend default control’s features, more than! this approach allows you to use MVVM pattern. &lt;/p&gt;  &lt;p&gt;Let’s extend some features of default TextBox control.&lt;/p&gt;    &lt;h2&gt;FocusOnLoadedBehavior&lt;/h2&gt;  &lt;p&gt;If you will try to open phone contact’s item to edit on your device you’ll see that device will set focus on first TextBox. This is very good user experience: if you open something for edit than most likely you will put focus on TextBox to edit data in this TextBox. Otherwise it is good question what if this page will have more than one TextBox, should we place focus on first of them or not? Windows Phone does it, it places focus on first TextBox if you will open edit page of contact’s name. &lt;/p&gt;  &lt;p&gt;I found that it will be good to do the same in some of my pages, so I wrote next behavior:&lt;/p&gt;  &lt;div class="codeSnippetWrapper" style="cursor: text; font-size: 9pt; border-top: silver 1px solid; font-family: tahoma, verdana, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; color: black; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 10pt; padding-right: 4px; background-color: #f4f4f4"&gt;   &lt;div class="codeSnippet" style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px"&gt;     &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #008000"&gt;/// UI Behavior to set focus to &amp;lt;see cref=&amp;quot;AssociatedObject&amp;quot;/&amp;gt; on loaded event.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; FocusOnLoadedBehavior : Behavior&amp;lt;Control&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; DependencyProperty SetFocusOnLoadedProperty =&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        DependencyProperty.Register(&lt;span style="color: #006080"&gt;&amp;quot;SetFocusOnLoaded&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;), &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(FocusOnLoadedBehavior), &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyMetadata(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #008000"&gt;/// Set focus to &amp;lt;see cref=&amp;quot;AssociatedObject&amp;quot;/&amp;gt; on loaded event. By default &amp;lt;value&amp;gt;true&amp;lt;/value&amp;gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; SetFocusOnLoaded&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;)GetValue(SetFocusOnLoadedProperty); }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        set { SetValue(SetFocusOnLoadedProperty, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnAttached()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnAttached();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AssociatedObject.Loaded += AssociatedObject_Loaded;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnDetaching()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnDetaching();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        AssociatedObject.Loaded -= AssociatedObject_Loaded;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AssociatedObject_Loaded(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AssociatedObject.Loaded -= AssociatedObject_Loaded;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (SetFocusOnLoaded)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            AssociatedObject.Focus();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;It is easy to use it. Just place it for one of your TextBox like I will show below and this behavior will set focus on Loaded event (in most cases it will be the moment when user opens page with this control):&lt;/p&gt;

&lt;div class="codeSnippetWrapper" style="cursor: text; font-size: 9pt; border-top: silver 1px solid; font-family: tahoma, verdana, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; color: black; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 10pt; padding-right: 4px; background-color: #f4f4f4"&gt;
  &lt;div class="codeSnippet" style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px"&gt;
    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MaxLength&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;255&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Path=DisplayName, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;     &lt;span style="color: #ff0000"&gt;xmlns:interactivity&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;     &lt;span style="color: #ff0000"&gt;xmlns:oBehaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;clr-namespace:outcold.Phone.Behaviors;assembly=outcold.Phone&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;interactivity:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;oBehaviors:FocusOnLoadedBehavior&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;interactivity:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;I’ve put namespace definitions “interactivity” and “oBehavior” to TextBox attributes just for example, you can move it on top level, for example you can add it to your page attributes.&lt;/p&gt;

&lt;p&gt;This behavior has property SetFocusOnLoad. If you will need to manage when you need set this focus and when not – you can use this property. For example it can be the case when you have two TextBoxes and you need to decide which of them should get focus on page load.&lt;/p&gt;

&lt;h2&gt;TextBoxSelectOnFocusBehavior&lt;/h2&gt;

&lt;p&gt;This is second must have behavior. If user (or you) set focus to TextBox than in different cases user can expect different default position of cursor. For example if it is TextBox for edit some word than most likely user don’t want to add some letters to this word, in most cases he will delete this word to write new one (for example it can be dictionary), so it is good UX to select whole word on focus set event. To do so you can use next behavior:&lt;/p&gt;

&lt;div class="codeSnippetWrapper" style="cursor: text; font-size: 9pt; border-top: silver 1px solid; font-family: tahoma, verdana, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; color: black; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 10pt; padding-right: 4px; background-color: #f4f4f4"&gt;
  &lt;div class="codeSnippet" style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px"&gt;
    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;enum&lt;/span&gt; TextBoxFocusSelectType&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    None = 0, &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    SelectAll = 1,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    SetCursorToTheEnd = 2&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #008000"&gt;/// UI Behavior to set how to select text in TextBox on Focused.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; TextBoxSelectOnFocusBehavior : Behavior&amp;lt;TextBox&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; TextBoxSelectOnFocusBehavior()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        Type = TextBoxFocusSelectType.None;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #008000"&gt;/// Set behavior of how to select text in &amp;lt;see cref=&amp;quot;AssociatedObject&amp;quot;/&amp;gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #008000"&gt;/// By default &amp;lt;value&amp;gt;TextBoxFocusSelectType.None&amp;lt;/value&amp;gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; TextBoxFocusSelectType Type&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        get;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        set;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnAttached()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnAttached();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AssociatedObject.GotFocus += AssociatedObject_GotFocus;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnDetaching()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnDetaching();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        AssociatedObject.GotFocus -= AssociatedObject_GotFocus;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AssociatedObject_GotFocus(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Type == TextBoxFocusSelectType.SelectAll)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            AssociatedObject.SelectAll();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Type == TextBoxFocusSelectType.SetCursorToTheEnd)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            AssociatedObject.Select(AssociatedObject.Text.Length, 0);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;To use it just add it to TextBox:&lt;/p&gt;

&lt;div class="codeSnippetWrapper" style="cursor: text; font-size: 9pt; border-top: silver 1px solid; font-family: tahoma, verdana, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; color: black; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 10pt; padding-right: 4px; background-color: #f4f4f4"&gt;
  &lt;div class="codeSnippet" style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px"&gt;
    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MaxLength&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;255&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Path=DisplayName, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;     &lt;span style="color: #ff0000"&gt;xmlns:interactivity&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;     &lt;span style="color: #ff0000"&gt;xmlns:oBehaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;clr-namespace:outcold.Phone.Behaviors;assembly=outcold.Phone&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;interactivity:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;oBehaviors:FocusOnLoadedBehavior&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;oBehaviors:TextBoxSelectOnFocusBehavior&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SetCursorToTheEnd&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;interactivity:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h2&gt;TextBoxInputRegexFilterBehavior&lt;/h2&gt;

&lt;p&gt;The last behavior for today TextBoxInputRegexFilterBehavior, which allows you to filter input text. Actually this behavior can add some unobviousness behavior to your application: user sees some button, but when he presses it he doesn’t see any changes. So you should use it very careful. One place where I used it: I need to get integer values from user, but TextBox has minimum InputScope=”Number” which has digits and dot (or comma, it depends on your device language). I saw in one of the apps that one developer created his own keyboard to get rid of this problem. I didn’t like it, and of course I don’t want to use validators for Windows Phone applications, we have very small screen for validators. So I’ve wrote next behavior:&lt;/p&gt;

&lt;div class="codeSnippetWrapper" style="cursor: text; font-size: 9pt; border-top: silver 1px solid; font-family: tahoma, verdana, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; color: black; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 10pt; padding-right: 4px; background-color: #f4f4f4"&gt;
  &lt;div class="codeSnippet" style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px"&gt;
    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #008000"&gt;/// UI behavior for &amp;lt;see cref=&amp;quot;TextBox&amp;quot;/&amp;gt; to filter input text with special RegularExpression&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; TextBoxInputRegexFilterBehavior : Behavior&amp;lt;TextBox&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Regex _regex;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _originalText;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _originalSelectionStart;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _originalSelectionLength;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; RegularExpression &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _regex.ToString(); } &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        set &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;                _regex = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;                _regex = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Regex(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        } &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnAttached()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnAttached();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AssociatedObject.TextInputStart += AssociatedObject_TextInputStart;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        AssociatedObject.TextChanged += AssociatedObject_TextChanged;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnDetaching()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnDetaching();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AssociatedObject.TextInputStart -= AssociatedObject_TextInputStart;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        AssociatedObject.TextChanged -= AssociatedObject_TextChanged;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AssociatedObject_TextInputStart(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, TextCompositionEventArgs e)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_regex != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; e.Text != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; !(e.Text.Length == 1 &amp;amp;&amp;amp; Char.IsControl(e.Text[0])))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!_regex.IsMatch(e.Text))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;            {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                _originalText = AssociatedObject.Text;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;                _originalSelectionStart = AssociatedObject.SelectionStart;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                _originalSelectionLength = AssociatedObject.SelectionLength;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;            }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AssociatedObject_TextChanged(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, TextChangedEventArgs e)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_originalText != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; text = _originalText;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            _originalText = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;            AssociatedObject.Text = text;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            AssociatedObject.Select(_originalSelectionStart, _originalSelectionLength);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;To use it:&lt;/p&gt;

&lt;div class="codeSnippetWrapper" style="cursor: text; font-size: 9pt; border-top: silver 1px solid; font-family: tahoma, verdana, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; color: black; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 10pt; padding-right: 4px; background-color: #f4f4f4"&gt;
  &lt;div class="codeSnippet" style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px"&gt;
    &lt;pre style="margin: 0em; background-color: white"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Path=Value, Mode=TwoWay}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;MaxLength&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;3&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;100&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;InputScope&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Number&amp;quot;&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #ff0000"&gt;xmlns:interactivity&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        &lt;span style="color: #ff0000"&gt;xmlns:oBehaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;clr-namespace:outcold.Phone.Behaviors;assembly=outcold.Phone&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;interactivity:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;oBehaviors:TextBoxSelectOnFocusBehavior&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SelectAll&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;oBehaviors:TextBoxInputRegexFilterBehavior&lt;/span&gt; &lt;span style="color: #ff0000"&gt;RegularExpression&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[0-9]+&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; background-color: white"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;interactivity:Interaction.Behaviors&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBox&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In next topics I will show you some other behaviors which I use for my Windows Phone applications. And don’t forget to read section &lt;a href="http://msdn.microsoft.com/en-us/library/dd440765.aspx"&gt;Expression Blend SDK for Windows Phone&lt;/a&gt; on MSDN!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/_jwqWJnyLTQ" height="1" width="1"/&gt;</description>
      <a10:updated>2012-01-05T05:21:00Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/308</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/hvnWUXl0kb8/271</link>
      <category>Silverlight</category>
      <category>Silverlight 4</category>
      <category>Book Review</category>
      <title>Silverlight 4 in Action</title>
      <description>&lt;p&gt;&lt;a href="http://www.manning.com/pbrown/"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 20px 20px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="pbrown_cover150" border="0" alt="pbrown_cover150" align="left" src="/Library/2010/12/20/pbrown_cover150_63EEB2C3.jpg" width="150" height="186" /&gt;&lt;/a&gt;&lt;a href="http://www.manning.com/pbrown/"&gt;Silverlight 4 in Action&lt;/a&gt; (Manning, Pete Brown) – this is second book, which I read about Silverlight. First was &lt;a href="http://apress.com/book/view/9781430223818"&gt;Pro Silverlight 3 in C#&lt;/a&gt; (Apress, Matthew MacDonald), which helped me when I was need to very quickly know more about Silverlight after WPF. After reading &lt;strong&gt;Silverlight 4 in Action&lt;/strong&gt; I think that this is best book about Silverlight. But maybe I should compare this book with Pro Business Applications with Silverlight.&lt;/p&gt;  &lt;p&gt;I think that most of Silverlight and WPF developers know book’s author’s &lt;a href="http://10rem.net"&gt;blog&lt;/a&gt; Pete Brown. Since 2009 author is Microsoft employee, since 2007 Silverlight became the main technology of development for him. You can think that &lt;strong&gt;Silverlight 4 in Action&lt;/strong&gt; is second edition, because Manning has also &lt;a href="http://www.manning.com/campbell/"&gt;Silverlight 2 in Action&lt;/a&gt;, which I didn’t read. But Silverlight 2 in Action has different authors than SL4 in Action. So talk about what’s new in &lt;strong&gt;Silverlight 4 in Action&lt;/strong&gt; is no good, it is different book, written by another author. Looks like this is first book of Pete Brown, and it is written very good.&lt;/p&gt;  &lt;p&gt;After buying paper book you will get also free e-book version (pdf), which you can read with Kindle device for example (&lt;a href="/Library/2010/11/05/P1010363_7C318EA7.jpg"&gt;only in album rotation&lt;/a&gt;). The book has about 800 pages, has 3 parts and 25 chapters.&lt;/p&gt;    &lt;p&gt;First what was strange for me it was order of chapters. Chapters about creating own panels, custom controls (not UserControls), and about styles and resources located at the end of the book (with comparing with Pro Silverlight 3). Maybe for beginners it will be a problem, but for me all was very consecutive. And I think it is very logical that stuff which you will use not really often showed at the end of the book, like: Writable Bitmap, making own panels and controls. Most of us are developing applications for enterprise, so for us making animation not is usual stuff. About own controls and panels, really I remember only a few cases for 2-3 years of my WPF/Silverlight developing career, when I was designing panels and controls for Silverlight or WPF. By the way, it was really cool that in book author design OrbitPanel instead of WrapPanel (this is first example in each book of creating own panels, like Hello World). &lt;/p&gt;  &lt;p&gt;Nearly the end of the book I really liked example of creating own MediaStreanSource, which generate video and audio noise instead of video and audio streams at client side with Silverlight code. Most of examples are really useful, most of them are usual problems which you need solve when you are developing own application, like when author write about printing he show the example about creating reports from list with paging support. This is ready to use code, really.&lt;/p&gt;  &lt;p&gt;And of course the book has chapter about which every book reader write: “Structuring and testing with the MVVM/ViewModel pattern”. With chapter “WCF RIA Services”, which going after MVVM chapter – they are on 100 pages in details show how to develop Silverlight business applications, architecture specifics, etc. I think this is the best topic explanation which I saw.&lt;/p&gt;  &lt;p&gt;I recommend this book for developers, who want to or already design business applications on Silverlight, I think this is main auditory for who Pete Brown had wrote this book.&lt;/p&gt;  &lt;p&gt;One thought which I can’t understand, what is notice on 492 page:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;If you’re really and truly bored and need a break from reading, check out &lt;a href="http://cornify.com/"&gt;http://cornify.com/&lt;/a&gt; to add unicorns and rainbows to any web site or photo. Warning: 5th grade girls’ Trapper Keeper graphics overload. &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Humor? :) &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/hvnWUXl0kb8" height="1" width="1"/&gt;</description>
      <a10:updated>2011-01-26T18:05:46Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/271</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/-3wbmD9rKB0/267</link>
      <category>.NET</category>
      <category>TDD</category>
      <category>Mock</category>
      <category>nUnit</category>
      <category>Book Review</category>
      <category>Manning</category>
      <category>Moq</category>
      <title>The art of Unit Testing with Examples in .NET</title>
      <description>&lt;p&gt;&lt;a href="http://www.manning.com/osherove/"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 10px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="osherove_cover" border="0" alt="osherove_cover" align="left" src="/Library/2010/11/07/osherove_cover_095490E3.jpg" width="160" height="196" /&gt;&lt;/a&gt;First time when I familiarized with unit testing was 5 or 6 years ago. It was start of my developing career. I remember that somebody told me about code coverage. At that time I didn’t write any Unit tests. Guy, who was my team lead, told me “Do you see operator if with three conditions? You should check all of these conditions”. So, after that I had written some code, I should go to interface and try to invoke all code which I wrote from user interface. Nice? At current time I know little more about tests and unit testing. I have not participated in projects, designed by &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank"&gt;Test Driven Development (TDD)&lt;/a&gt;. Basics of my knowledge are a spying code of my colleagues, some articles and screencasts. I had decide that I should know much more, and became a real professional of unit testing, this is why I had start to read book &lt;a href="http://www.manning.com/osherove/" target="_blank"&gt;The art of Unit Testing with Examples in .NET&lt;/a&gt;. More than, in my current job place looks like I’m just one who writing unit tests for my code. I should show good examples of my tests.&lt;/p&gt;    &lt;p&gt;The book was written about half year ago. Most of samples was written with C#. I saw a lot of recommendation for reading this book. &lt;/p&gt;  &lt;p&gt;Author of this book is &lt;a href="http://osherove.com/"&gt;Roy Osherove&lt;/a&gt;. He is famous &lt;a href="http://weblogs.asp.net/rosherove/"&gt;blogger&lt;/a&gt;, also he is lecturing TDD master classes, sometimes he is working consultant for IT companies, if they want to implement TDD in their projects (he wrote not one time about this, bring successful and unsuccessful cases). He is working as a main architect in company Typemock. Typemock developing paid instruments for tests/unit testing and code analysis. &lt;/p&gt;  &lt;p&gt;The book will be useful for developers of any platforms. Like I said before most of examples was written with C# (some of examples with Java). In book author use &lt;a href="http://www.nunit.org/"&gt;NUnit&lt;/a&gt; framework for unit tests, &lt;a href="http://ayende.com/projects/rhino-mocks.aspx"&gt;Rhino Mocks&lt;/a&gt; for Mock and Stub objects in Unit tests (before that I didn’t know that Stub and Mock are different, I knew only about Mocks). &lt;/p&gt;  &lt;p&gt;So, what you will find in the book? You can download a few chapters from &lt;a href="http://www.manning.com/osherove/"&gt;official book’s site&lt;/a&gt;, so before buy the book you can read first is it good for you or not. First chapter of book is “Hello world!”. It is about what you need to write tests, what kind of frameworks, tools, and of course first test is there. Next chapter about frameworks which author use in his book: NUnit and Rhino Mocks. He used Rhino Mocks at book as I understand because he got statistic that Rhino Mocks is frequently used framework for creating Mocks and Stubs. I think that today situation little different, I like &lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt;. And NUnit today is still most used unit testing framework. One time I used MbUnit, because it has more features, but NUnit today has the same features.&lt;/p&gt;  &lt;p&gt;It the book you will find information about how to write tests, how you should design them. And also you will find antipatterns: I found out all of them, I had used them in my code. :( &lt;/p&gt;  &lt;p&gt;Also I found answer for my old question. I wrote some article about testing applications with NHibernate, and I got comment about why you are testing ORM? I thought that this man know more than me in unit testing, so really maybe I shouldn’t test ORM Repositories. At that time I had really specific case, so I said that I need it, and said why I need these tests. I didn’t know why this guy asked me this question. Really this is my integration test. With this test I check that database schema is equal to xml-mapping, mapping is equal to classes, and if I use special queries I check them too with my tests. It is really helpful. In the book I found answer for my question – tests for ORM is really helpful, author if this book always write tests for his Data Access Layer, and he said why.&lt;/p&gt;  &lt;p&gt;Also in the book you will find how to introduce TDD in your company, how to work with Legacy code (this is really important when you introduce TDD in exist project, not new). Also a lot of questions and answers for guy, who want to introduce TDD in his group/company, he will get a lot of questions for his colleagues (money, time, knowledge, etc).&amp;#160; &lt;/p&gt;  &lt;p&gt;At the end of book author made an inventory of frameworks, which you can use for testing. Of course in his list you will find paid frameworks, which was written by &lt;a href="http://typemock.com/"&gt;Typemock&lt;/a&gt;, where author are working.&lt;/p&gt;  &lt;p&gt;Really I recommend this book for all companies, which use TDD in their practice and which write unit tests, so for all companies. My recommendation for team leads and managers, don’t say “You must write tests”, read book first, or ask your colleagues to read the book, make a lectures, trainings, and you will see the result.&amp;#160; &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/-3wbmD9rKB0" height="1" width="1"/&gt;</description>
      <a10:updated>2011-01-16T21:13:55Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/267</feedburner:origLink></item>
    <item>
      <link>http://feedproxy.google.com/~r/outcoldman_en/~3/muxVpnPzmaE/260</link>
      <category>Silverlight</category>
      <category>XAML</category>
      <category>Validation</category>
      <title>Silverlight basics. Validation. Part 2. IDataErrorInfo &amp; INotifyDataErrorInfo</title>
      <description>&lt;p&gt;At &lt;a href="/en/blog/show/259"&gt;previous my blog post&lt;/a&gt; I wrote about how to implement validation with DataAnnotations. I this part of my article I will describe interfaces &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo(VS.95).aspx"&gt;IDataErrorInfo&lt;/a&gt;and &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(VS.95).aspx"&gt;INotifyDataErrorInfo&lt;/a&gt;. I recommend you to read &lt;a href="/en/blog/show/259"&gt;first part&lt;/a&gt; before read this part. Because I use example from previous part.&lt;/p&gt;    &lt;h2&gt;Few words about ValidationOnExceptions&lt;/h2&gt;  &lt;p&gt;Forgot to tell you, if you want implement validation with exceptions, you may not use DataAnnotations, you can throw your own exceptions from set methods. For example, you can implement check of password confirmation like this:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;     &lt;pre style="background-color: white; margin: 0em"&gt;[Display(Name = &lt;span style="color: #006080"&gt;&amp;quot;New password confirmation&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPasswordConfirmation&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPasswordConfirmation; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    set&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        _newPasswordConfirmation = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        OnPropertyChanged(&lt;span style="color: #006080"&gt;&amp;quot;NewPasswordConfirmation&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        ChangePasswordCommand.RaiseCanExecuteChanged();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.CompareOrdinal(_newPassword, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;) != 0)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Exception(&lt;span style="color: #006080"&gt;&amp;quot;Password confirmation not equal to password.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Looks better than CustomValidationAttribute.&lt;/p&gt;

&lt;h2&gt;IDataErrorInfo&lt;/h2&gt;

&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo(VS.95).aspx"&gt;IDataErrorInfo&lt;/a&gt; interface came with Silverlight 4. If we want implement validation with this interface we should implement it in our ViewModel (one property and one method). Usually developers write &lt;a href="http://johnpapa.net/silverlight/enabling-validation-in-silverlight-4-with-idataerrorinfo/"&gt;own class handler&lt;/a&gt;, which store validation errors)&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ValidationHandler&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; BrokenRules { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ValidationHandler()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        BrokenRules = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;[&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; property]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; BrokenRules[property]; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; BrokenRuleExists(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; property)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; BrokenRules.ContainsKey(property);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ValidateRule(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; property, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; message, Func&amp;lt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt; ruleCheck)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; check = ruleCheck();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!check)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (BrokenRuleExists(property))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                RemoveBrokenRule(property);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            BrokenRules.Add(property, message);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            RemoveBrokenRule(property);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; check;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RemoveBrokenRule(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; property)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (BrokenRules.ContainsKey(property))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            BrokenRules.Remove(property);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Clear()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        BrokenRules.Clear();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now let’s rewrite our BindingModel class, we will inherit it from interface IDataErrorInfo and will implement it:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BindingModel : INotifyPropertyChanged, IDataErrorInfo&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _newPassword;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _newPasswordConfirmation;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; ValidationHandler _validationHandler = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ValidationHandler();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; INotifyPropertyChanged&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged = &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt; { };&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        PropertyChanged(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedEventArgs(propertyName));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; IDataErrorInfo&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;[&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; columnName]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        get&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_validationHandler.BrokenRuleExists(columnName))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _validationHandler[columnName];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Error&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NotImplementedException(); }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The main properties for our BindingModel will look like this:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;[Display(Name = &lt;span style="color: #006080"&gt;&amp;quot;New password&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPassword&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPassword; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    set&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        _newPassword = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        OnPropertyChanged(&lt;span style="color: #006080"&gt;&amp;quot;NewPassword&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_validationHandler.ValidateRule(&lt;span style="color: #006080"&gt;&amp;quot;NewPassword&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;New password required&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;                                    () =&amp;gt; !&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;)))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            _validationHandler.ValidateRule(&lt;span style="color: #006080"&gt;&amp;quot;NewPassword&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Max length of password is 80 symbols.&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                                    () =&amp;gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;.Length &amp;lt; 80);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        ChangePasswordCommand.RaiseCanExecuteChanged();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;[Display(Name = &lt;span style="color: #006080"&gt;&amp;quot;New password confirmation&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPasswordConfirmation&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPasswordConfirmation; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    set&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        _newPasswordConfirmation = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        OnPropertyChanged(&lt;span style="color: #006080"&gt;&amp;quot;NewPasswordConfirmation&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        _validationHandler.ValidateRule(&lt;span style="color: #006080"&gt;&amp;quot;NewPasswordConfirmation&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Password confirmation not equal to password.&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;                                        () =&amp;gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.CompareOrdinal(_newPassword, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;) == 0);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        ChangePasswordCommand.RaiseCanExecuteChanged();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Each call of VaidationRule checks some condition, and if it not true, then write info about this validation error in errors collection. After binding Silverlight infrastructure will call get method of indexing property this[string columnName] and it will return error information for this property (columnName). We should set property &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.validatesondataerrors(VS.95).aspx"&gt;ValidatesOnDataErrors&lt;/a&gt; in our binding to true if we want to use this kind of validation. Property Error throw NotImplementedException because Silverlight doesn’t use it. Quotation from &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo(VS.95).aspx"&gt;MSDN&lt;/a&gt;: “&lt;em&gt;Note that the binding engine never uses the Error property, although you can use it in custom error reporting to display object-level errors&lt;/em&gt;.” &lt;/p&gt;

&lt;p&gt;In end we should implement again methods for command:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; BindingModel()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    ChangePasswordCommand = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DelegateCommand(ChangePassword, CanChangePassword);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DelegateCommand ChangePasswordCommand { get; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; CanChangePassword(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; arg)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; !&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(_newPassword) &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &amp;amp;&amp;amp; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.CompareOrdinal(_newPassword, _newPasswordConfirmation) == 0;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ChangePassword(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; obj)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (ChangePasswordCommand.CanExecute(obj))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        MessageBox.Show(&lt;span style="color: #006080"&gt;&amp;quot;Bingo!&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We again should use &lt;em&gt;CanChangePassword&lt;/em&gt; method, because we need to set button to disabled state when object is invalid. We can’t check valid state of whole object before binding happened. Another problem with this realization: we should write validation rules twice: in property set methods and at CanChangePassword method. But this is problem of this realization; you can solve it with another realization: you can write some class &lt;em&gt;ValidationHandler&lt;/em&gt;, which will store not only validation errors, but validation rules, so you can raise validation check in CanChangePassword method. But we still have a problem, we can’t tell to ValidationSummary or some other control at our interface that some validation errors happened or disappeared without binging. &lt;/p&gt;

&lt;p&gt;Also you can use DataAnnotation for this approach, but you should write some helper method for that, I will tell you how in next example. &lt;/p&gt;

&lt;p&gt;Result of IDataErrorInfo realization (Silverlight sample):&lt;/p&gt;
&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="150px"&gt;
		  &lt;param name="source" value="http://outcoldman.com/library/content/03/SLValidation/SilverlightValidation2.xap" /&gt;
		  &lt;param name="background" value="white" /&gt;
		  &lt;param name="minRuntimeVersion" value="4.0.50826.0" /&gt;
		  &lt;param name="autoUpgrade" value="true" /&gt;
		  &lt;a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;amp;v=4.0.50826.0" style="text-decoration:none"&gt;
 			  &lt;img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none" /&gt;
		  &lt;/a&gt;
	    &lt;/object&gt;

&lt;p&gt;I think that behavior of this sample the same like in previous part. I want to say that this sample has bug, if user will input &lt;em&gt;Password Confirmation&lt;/em&gt; first and then &lt;em&gt;New Password&lt;/em&gt;, he will see validation error about password confirmation not equal, because this check happened only on &lt;em&gt;NewPasswordConfirmation&lt;/em&gt; binding.&amp;#160; &lt;/p&gt;

&lt;h2&gt;INotifyDataErrorInfo&lt;/h2&gt;

&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(VS.95).aspx"&gt;INotifyDataErrorInfo&lt;/a&gt;interface came with Silverlight 4 too. The main advantage of this interface you can do synchronous (like in previous samples) and asynchronous validation too. You can wait validation from server, and only after that tell to interface that all ok or some validation error occurred. I like this way of validation more than other. I will use some classes and realization from articles of &lt;a href="http://davybrion.com"&gt;Davy Brion&lt;/a&gt; about “&lt;a href="http://davybrion.com/blog/2010/08/mvp-in-silverlightwpf-series/"&gt;MVP In Silverlight/WPF Series&lt;/a&gt;”.&lt;/p&gt;

&lt;p&gt;First I got class &lt;em&gt;PropertyValidation&lt;/em&gt;, with it we will store validation rule for properties and message which should be showed when validation error occurred. &lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; PropertyValidation&amp;lt;TBindingModel&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; TBindingModel : BindingModelBase&amp;lt;TBindingModel&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Func&amp;lt;TBindingModel, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt; _validationCriteria;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _errorMessage;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _propertyName;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; PropertyValidation(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        _propertyName = propertyName;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; PropertyValidation&amp;lt;TBindingModel&amp;gt; When(Func&amp;lt;TBindingModel, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt;&amp;gt; validationCriteria)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_validationCriteria != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color: #006080"&gt;&amp;quot;You can only set the validation criteria once.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        _validationCriteria = validationCriteria;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; PropertyValidation&amp;lt;TBindingModel&amp;gt; Show(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; errorMessage)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_errorMessage != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color: #006080"&gt;&amp;quot;You can only set the message once.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        _errorMessage = errorMessage;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; IsInvalid(TBindingModel presentationModel)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_validationCriteria == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; InvalidOperationException(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;                &lt;span style="color: #006080"&gt;&amp;quot;No criteria have been provided for this validation. (Use the 'When(..)' method.)&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _validationCriteria(presentationModel);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetErrorMessage()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_errorMessage == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; InvalidOperationException(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                &lt;span style="color: #006080"&gt;&amp;quot;No error message has been set for this validation. (Use the 'Show(..)' method.)&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _errorMessage;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; PropertyName&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _propertyName; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You will understand how it works when we will start implement validation rules in our example. This class has generic parameter with base class &lt;em&gt;BindingModelBase&amp;lt;T&amp;gt;,&lt;/em&gt; from which we will inherit our main &lt;em&gt;BindingModel&lt;/em&gt; class.&lt;/p&gt;

&lt;p&gt;Let’s implement &lt;em&gt;BindingModelBase&lt;/em&gt; class, we will inherit it from &lt;em&gt;INotifyPropertyChanged&lt;/em&gt; and &lt;em&gt;INotifyDataErrorInfo&lt;/em&gt; interfaces, and will add two fields, one for store validation rules and one for store validation errors:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BindingModelBase&amp;lt;TBindingModel&amp;gt; : INotifyPropertyChanged, INotifyDataErrorInfo&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; TBindingModel : BindingModelBase&amp;lt;TBindingModel&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; List&amp;lt;PropertyValidation&amp;lt;TBindingModel&amp;gt;&amp;gt; _validations = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;PropertyValidation&amp;lt;TBindingModel&amp;gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;&amp;gt; _errorMessages = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; INotifyDataErrorInfo&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IEnumerable GetErrors(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_errorMessages.ContainsKey(propertyName)) &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _errorMessages[propertyName];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[0];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; HasErrors&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _errorMessages.Count &amp;gt; 0; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; EventHandler&amp;lt;DataErrorsChangedEventArgs&amp;gt; ErrorsChanged = &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt; { };&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnErrorsChanged(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        ErrorsChanged(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataErrorsChangedEventArgs(propertyName));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; INotifyPropertyChanged&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged = &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt; { };&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        PropertyChanged(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyChangedEventArgs(propertyName));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Also I want to add one helper method additional to OnPropertyChanged, it will be method which has Expression in parameters and will let us to use it like this:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPassword&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPassword; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    set { _newPassword = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; OnCurrentPropertyChanged(); }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This method is very useful. Implementation of this method:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPassword&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPassword; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    set { _newPassword = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;; OnPropertyChanged(() =&amp;gt; NewPassword); }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Implementation:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPropertyChanged(Expression&amp;lt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt;&amp;gt; expression)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    OnPropertyChanged(GetPropertyName(expression));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetPropertyName(Expression&amp;lt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt;&amp;gt; expression)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (expression == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span style="color: #006080"&gt;&amp;quot;expression&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    MemberExpression memberExpression;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (expression.Body &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; UnaryExpression)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        memberExpression = ((UnaryExpression)expression.Body).Operand &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; MemberExpression;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        memberExpression = expression.Body &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; MemberExpression;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (memberExpression == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentException(&lt;span style="color: #006080"&gt;&amp;quot;The expression is not a member access expression&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;expression&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    var property = memberExpression.Member &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; PropertyInfo;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (property == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentException(&lt;span style="color: #006080"&gt;&amp;quot;The member access expression does not access a property&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;expression&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    var getMethod = property.GetGetMethod(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (getMethod.IsStatic)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ArgumentException(&lt;span style="color: #006080"&gt;&amp;quot;The referenced property is a static property&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;expression&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; memberExpression.Member.Name;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Method get property name from expression. Next, let’s add some methods which will perform validation:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ValidateProperty(Expression&amp;lt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt;&amp;gt; expression)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    ValidateProperty(GetPropertyName(expression));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ValidateProperty(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    _errorMessages.Remove(propertyName);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    _validations.Where(v =&amp;gt; v.PropertyName == propertyName).ToList().ForEach(PerformValidation);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    OnErrorsChanged(propertyName);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    OnPropertyChanged(() =&amp;gt; HasErrors);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; PerformValidation(PropertyValidation&amp;lt;TBindingModel&amp;gt; validation)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (validation.IsInvalid((TBindingModel) &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        AddErrorMessageForProperty(validation.PropertyName, validation.GetErrorMessage());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddErrorMessageForProperty(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; errorMessage)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_errorMessages.ContainsKey(propertyName))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        _errorMessages[propertyName].Add(errorMessage);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        _errorMessages.Add(propertyName, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; {errorMessage});&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Method &lt;em&gt;ValidateProperty&lt;/em&gt; delete information about all validation errors which was happened with current property, then check each rule for current property, and if some rule is false it will add error to errors collection. Also we can raise validation check for each property auto with PropertyChanged event:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; BindingModelBase()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    PropertyChanged += (s, e) =&amp;gt; { &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (e.PropertyName != &lt;span style="color: #006080"&gt;&amp;quot;HasErrors&amp;quot;&lt;/span&gt;) ValidateProperty(e.PropertyName); };&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;For easy add validation rules to our collection we will add next method:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; PropertyValidation&amp;lt;TBindingModel&amp;gt; AddValidationFor(Expression&amp;lt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt;&amp;gt; expression)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    var validation = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyValidation&amp;lt;TBindingModel&amp;gt;(GetPropertyName(expression));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    _validations.Add(validation);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; validation;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now we can implement &lt;em&gt;BindingModel&lt;/em&gt; class, which we will use in our last example. If we want to implement validation with &lt;em&gt;INotifyDataErrorInfo&lt;/em&gt; interface we should set to true property &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.validatesonnotifydataerrors(VS.95).aspx"&gt;ValidatesOnNotifyDataErrors&lt;/a&gt;in bindings.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;BindingModel&lt;/em&gt; implementation:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BindingModel : BindingModelBase&amp;lt;BindingModel&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _newPassword;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _newPasswordConfirmation;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DelegateCommand ChangePasswordCommand { get; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; BindingModel()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        ChangePasswordCommand = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DelegateCommand(ChangePassword);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AddValidationFor(() =&amp;gt; NewPassword)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            .When(x =&amp;gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(x._newPassword))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            .Show(&lt;span style="color: #006080"&gt;&amp;quot;New password required field.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AddValidationFor(() =&amp;gt; NewPassword)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            .When(x =&amp;gt; !&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(x._newPassword) &amp;amp;&amp;amp; x._newPassword.Length &amp;gt; 80)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            .Show(&lt;span style="color: #006080"&gt;&amp;quot;New password must be a string with maximum length of 80.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AddValidationFor(() =&amp;gt; NewPasswordConfirmation)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            .When(x =&amp;gt; !&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(x._newPassword) &amp;amp;&amp;amp; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.CompareOrdinal(x._newPassword, x._newPasswordConfirmation) != 0)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            .Show(&lt;span style="color: #006080"&gt;&amp;quot;Password confirmation not equal to password.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    [Display(Name = &lt;span style="color: #006080"&gt;&amp;quot;New password&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPassword&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPassword; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        set&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            _newPassword = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            OnPropertyChanged(() =&amp;gt; NewPassword);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    [Display(Name = &lt;span style="color: #006080"&gt;&amp;quot;New password confirmation&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPasswordConfirmation&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPasswordConfirmation; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        set&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            _newPasswordConfirmation = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            OnPropertyChanged(() =&amp;gt; NewPasswordConfirmation);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ChangePassword(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; obj)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In ctor we describe all three validation rules for properties. Look’s very good (Thanks Davy Brion!). I told you that I don’t like to set disabled button, so from now it will be always enabled. For realization command’s method &lt;em&gt;ChangePassword&lt;/em&gt; I need some method which will check all validation rules of current object, it will be &lt;em&gt;ValidateAll&lt;/em&gt; method, which I will implement in &lt;em&gt;BindingModelBase&lt;/em&gt; class:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ValidateAll()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    var propertyNamesWithValidationErrors = _errorMessages.Keys;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    _errorMessages = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    _validations.ForEach(PerformValidation);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    var propertyNamesThatMightHaveChangedValidation =&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        _errorMessages.Keys.Union(propertyNamesWithValidationErrors).ToList();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    propertyNamesThatMightHaveChangedValidation.ForEach(OnErrorsChanged);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    OnPropertyChanged(() =&amp;gt; HasErrors);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This method deletes all validation errors in collection. Then check validation rules, write errors if rule is false, and then raise &lt;em&gt;OnErrorsChanged&lt;/em&gt; event for each property which has changed validation state.&lt;/p&gt;

&lt;p&gt;Implementation of method &lt;em&gt;ChangePassword&lt;/em&gt;:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ChangePassword(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; obj)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    ValidateAll();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!HasErrors)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        MessageBox.Show(&lt;span style="color: #006080"&gt;&amp;quot;Bingo!&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Result (Silverlight application):&lt;/p&gt;
&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="150px"&gt;
		  &lt;param name="source" value="http://outcoldman.com/library/content/03/SLValidation/SilverlightValidation3.xap" /&gt;
		  &lt;param name="background" value="white" /&gt;
		  &lt;param name="minRuntimeVersion" value="4.0.50826.0" /&gt;
		  &lt;param name="autoUpgrade" value="true" /&gt;
		  &lt;a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;amp;v=4.0.50826.0" style="text-decoration:none"&gt;
 			  &lt;img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none" /&gt;
		  &lt;/a&gt;
	    &lt;/object&gt;

&lt;p&gt;I like this realization. It much more flexible and it can use all advantages of previous variants. What about DataAnnotation? If you like to describe validation rules with data annotation attributes I can give you one more help method for that. This method will get all rules from attributes and convert them to &lt;em&gt;PropertyValidation&lt;/em&gt;:&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; PropertyValidation&amp;lt;TBindingModel&amp;gt; AddValidationFor(Expression&amp;lt;Func&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt;&amp;gt; expression)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; AddValidationFor(GetPropertyName(expression));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; PropertyValidation&amp;lt;TBindingModel&amp;gt; AddValidationFor(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; propertyName)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    var validation = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyValidation&amp;lt;TBindingModel&amp;gt;(propertyName);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    _validations.Add(validation);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; validation;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddAllAttributeValidators()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    PropertyInfo[] propertyInfos = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (PropertyInfo propertyInfo &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; propertyInfos)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        Attribute[] custom = Attribute.GetCustomAttributes(propertyInfo, &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(ValidationAttribute), &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (var attribute &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; custom)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            var property = propertyInfo;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            var validationAttribute = attribute &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; ValidationAttribute;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (validationAttribute == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;                &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; NotSupportedException(&lt;span style="color: #006080"&gt;&amp;quot;validationAttribute variable should be inherited from ValidationAttribute type&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; name = property.Name;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            var displayAttribute = Attribute.GetCustomAttributes(propertyInfo, &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(DisplayAttribute)).FirstOrDefault() &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; DisplayAttribute;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (displayAttribute != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                name = displayAttribute.GetName();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            var message = validationAttribute.FormatErrorMessage(name);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            AddValidationFor(propertyInfo.Name)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                .When(x =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;                {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                    var &lt;span style="color: #0000ff"&gt;value&lt;/span&gt; = property.GetGetMethod().Invoke(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[] { });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;                    var result = validationAttribute.GetValidationResult(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                                                            &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ValidationContext(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) { MemberName = property.Name });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result != ValidationResult.Success;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;                })&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;                .Show(message);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And the last &lt;em&gt;BindingModel&lt;/em&gt; variant:&lt;/p&gt;
 

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; color: black; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="padding-left: 0px; padding-right: 0px; padding-top: 0px; adding-bottom: 0px" id="codeSnippet"&gt;
    &lt;pre style="background-color: white; margin: 0em"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; BindingModel : BindingModelBase&amp;lt;BindingModel&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _newPassword;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _newPasswordConfirmation;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DelegateCommand ChangePasswordCommand { get; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; BindingModel()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        ChangePasswordCommand = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DelegateCommand(ChangePassword);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AddAllAttributeValidators();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        AddValidationFor(() =&amp;gt; NewPasswordConfirmation)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            .When(x =&amp;gt; !&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(x._newPassword) &amp;amp;&amp;amp; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.CompareOrdinal(x._newPassword, x._newPasswordConfirmation) != 0)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            .Show(&lt;span style="color: #006080"&gt;&amp;quot;Password confirmation not equal to password.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    [Display(Name = &lt;span style="color: #006080"&gt;&amp;quot;New password&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    [Required]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    [StringLength(80, ErrorMessage = &lt;span style="color: #006080"&gt;&amp;quot;New password must be a string with maximum length of 80.&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPassword&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPassword; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        set&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            _newPassword = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            OnPropertyChanged(() =&amp;gt; NewPassword);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    [Display(Name = &lt;span style="color: #006080"&gt;&amp;quot;New password confirmation&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; NewPasswordConfirmation&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _newPasswordConfirmation; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        set&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;            _newPasswordConfirmation = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            OnPropertyChanged(() =&amp;gt; NewPasswordConfirmation);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ChangePassword(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; obj)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        ValidateAll();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!HasErrors)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;            MessageBox.Show(&lt;span style="color: #006080"&gt;&amp;quot;Bingo!&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="background-color: white; margin: 0em"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Source code of these samples you can download from my &lt;a href="https://www.assembla.com/code/outcoldman_p/subversion/nodes/BlogProjects/SilverlightValidation"&gt;assembla.com&lt;/a&gt; repository.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/outcoldman_en/~4/muxVpnPzmaE" height="1" width="1"/&gt;</description>
      <a10:updated>2010-11-24T21:18:00Z</a10:updated>
    <feedburner:origLink>http://outcoldman.com/en/blog/show/260</feedburner:origLink></item>
  </channel>
</rss>
