<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CEcNR30yfip7ImA9WhBaEEg.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453</id><updated>2013-05-20T17:44:56.396+05:30</updated><category term="ASP.NET 4.0" /><category term="Geolocator" /><category term="DLR" /><category term="MVVM" /><category term="Metro" /><category term="Prism" /><category term="html5" /><category term="debugging" /><category term="free" /><category term="push technology" /><category term="LOH" /><category term="CodeProject" /><category term="gift" /><category term="TPL" /><category term="cookbook" /><category term="windowsclient.net" /><category term="Azure" /><category term="kinect" /><category term="XAML" /><category term="Configuration" /><category term="design pattern" /><category term="Custom Control" /><category term="MEF" /><category term="Developer Conference" /><category term="IDisposable" /><category term=".NET 4.5" /><category term="VS2012" /><category term="tips" /><category term="Unity" /><category term="Teched" /><category term="Finalize" /><category term="dotnetfunda.com" /><category term="async" /><category term="IsolatedStorage" /><category term="C#5.0" /><category term="WinForms" /><category term="giveaways" /><category term=".NET 3.5" /><category term="gesture" /><category term="beyondrelational" /><category term="scripting" /><category term="Threading" /><category term="PDC10" /><category term="silverlight" /><category term="multithreading" /><category term="MVP" /><category term="blogger tips" /><category term="Windows Phone7" /><category term="book" /><category term=".NET infrastructure" /><category term="Online Session" /><category term="ADO.NET" /><category term="C#" /><category term="WinRT" /><category term="jquery" /><category term="Regex" /><category term="Reflection" /><category term="asp.net4.5" /><category term="internals" /><category term="WCF" /><category term=".NET 4.0" /><category term="Database" /><category term="GC" /><category term="Patterns" /><category term=".NET Memory Management" /><category term="Windows8" /><category term="Memory Allocation" /><category term="architecture" /><category term="WeakReference" /><category term="IObservable. Rx" /><category term="WPF" /><category term="SOH" /><category term=".NET" /><category term="TPL Data Flows" /><title>DOT NET TRICKS</title><subtitle type="html">Handy Tricks and Tips to do your .NET code Fast, Efficient and Simple. Some common questions that comes into mind. Please check if you could find them listed or not.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://www.abhisheksur.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>166</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/abhisheksur/WTgI" /><feedburner:info uri="abhisheksur/wtgi" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-sa/2.0/" /><logo>http://creativecommons.org/images/public/somerights20.gif</logo><feedburner:emailServiceId>abhisheksur/WTgI</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;DUUEQHY_fCp7ImA9WhBbF0s.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-3481647213948619953</id><published>2013-05-06T01:37:00.000+05:30</published><updated>2013-05-17T10:36:41.844+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-17T10:36:41.844+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="giveaways" /><category scheme="http://www.blogger.com/atom/ns#" term="free" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.5" /><category scheme="http://www.blogger.com/atom/ns#" term="gift" /><category scheme="http://www.blogger.com/atom/ns#" term="cookbook" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="book" /><title>Want a copy of Visual Studio 2012 and .NET 4.5 Expert Cookbook for free in simple steps?</title><content type="html">&lt;br /&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
Visual Studio 2012 and .NET 4.5 Expert Development cookbook is your ready-made reference to all the problems we face while working with Visual Studio and .NET 4.5. It gives you explicit references to some of the interesting topics that as a developer you always wanted to master or want to collect and store securely so that it is available to you just the time when needed. It has been my honor to put up such important things into one book and make you understand development better.&amp;nbsp;&lt;/div&gt;
&lt;h3 style="background-color: white; border: 0px; color: #222222; font-family: MuseoSans500, Helvetica, Arial, Verdana, Tahoma, sans-serif; font-size: 21px; margin: 0px; outline: 0px; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;"&gt;
To give you some instances :&amp;nbsp;&lt;/h3&gt;
&lt;ul style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin: 15px 0px 15px 20px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Internals of .NET Memory Management and Garbage Collection Techniques.&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Solution to 10 common mistakes made by developers while writing code&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Securing code from reverse engineering using Obfuscation&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Writing Multi-threaded application more quickly and easily.&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Working with Performance boosters in ASP.NET Web Applications.&amp;nbsp;&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;HTML5 and CSS3&amp;nbsp;&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Write enhanced application in MVVM model.&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Building Applications using WinJS and XAML in Windows 8&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Enable Push notification to update Tiles, Toast, Batch notifications of your Windows 8 Applications&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;And many more like this ...&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="background-color: white; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px;"&gt;I am overwhelmed to receive great responses for my articles on&lt;/span&gt;&lt;a href="http://www.abhisheksur.com/2011/03/internals-to-net.html" style="background-color: white; border: 0px; color: #20328e; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;&amp;nbsp;"Internals of .NET"&lt;/a&gt;&lt;span style="background-color: white; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px;"&gt;&amp;nbsp;&amp;nbsp;on my blog but I wrote this book in such a way so that you can take most out of the under the hood items of Language and CLR and use those skills while writing or architecting your own application. &amp;nbsp;This is reference book only for developers and experts with more emphasis given on practicals rather than the theory.&amp;nbsp; To know more about the book you can go to the&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.packtpub.com/visual-studio-11-and-dotnet-4-5-expert-development-cookbook/book" style="background-color: white; border: 0px; color: #20328e; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;publisher site using this link&lt;/a&gt;&lt;span style="background-color: white; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px;"&gt;&amp;nbsp;. Moreover, I remember of putting up a draft&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.abhisheksur.com/2013/04/net-book-visual-studio-2012-and-net-45.html" style="background-color: white; border: 0px; color: #20328e; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;about the book as well on my blog&lt;/a&gt;&lt;span style="background-color: white; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px;"&gt;&amp;nbsp;&amp;nbsp;which you can try for more knowledge. &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #222222; font-family: Helvetica, arial, verdana;"&gt;&lt;span style="font-size: 15px; line-height: 22px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 style="background-color: white; border: 0px; color: #222222; font-family: MuseoSans500, Helvetica, Arial, Verdana, Tahoma, sans-serif; font-size: 23px; margin: 0px; outline: 0px; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;"&gt;
I want to win a free copy!&lt;/h2&gt;
&lt;span style="background-color: white; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px;"&gt;As you know I am very much active in the community and love to share my knowledge with the .NET community, it is my pleasure to announce that you can win a copy of this book for free. There are 3 copies of the book to be won from here. All you have to do is :&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;ol style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin: 15px 0px 15px 20px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Leave a comment down below with the reason why you should be the lucky winner. Write on the topic "why you would like to win this book".&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Share this post on&amp;nbsp;&lt;a href="http://www.facebook.com/sharer.php?u=http://dotnet.dzone.com/articles/want-free-copy-visual-studio&amp;amp;t=Check%20out%20this%20free%20giveaways,%20do%20not%20miss!!" style="border: 0px; color: #20328e; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;Facebook&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="http://twitter.com/intent/tweet?url=http://dotnet.dzone.com/articles/want-free-copy-visual-studio&amp;amp;hashtags=csharp,dotnet,book,giveaways,winrt&amp;amp;text=Win%20a%20free%20Visual%20Studio%202012%20and%20.NET%204.5%20Expert%20Cookbook!&amp;amp;via=abhi2434&amp;amp;related=abhi2434" style="border: 0px; color: #20328e; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;Twitter&lt;/a&gt;&amp;nbsp;with a mention to&amp;nbsp;&lt;a href="http://twitter.com/abhi2434" style="border: 0px; color: #20328e; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target=""&gt;@abhi2434&lt;/a&gt;&amp;nbsp;&amp;nbsp;(my twitter handle) so that I can have a count on them, the more is the count, the more will be your chances.&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Like us on&amp;nbsp;&lt;a href="http://facebook.com/dotnetbook" style="border: 0px; color: #20328e; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;Facebook&amp;nbsp;&lt;/a&gt;&amp;nbsp;to get more updates on the book.&lt;/li&gt;
&lt;/ol&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;b&gt;The best motivation wins&lt;/b&gt;&amp;nbsp;and the winner will be notified through email. So be sure to leave any reference of your contact (like facebook url, twitter or anything you feel safe, so that we can contact you).&amp;nbsp;&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
Thats it ... Good Luck to you all !!!.&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;i&gt;&lt;b&gt;The Contest ends on 1st June 2013 ( 6 AM PST) and winners will be contacted and published within 3 days from that.&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;i&gt;&lt;b&gt;So hurry up!!&amp;nbsp;Don't&amp;nbsp;miss the opportunity.&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;a href="http://www.packtpub.com/visual-studio-11-and-dotnet-4-5-expert-development-cookbook/book" style="border: 0px; color: #20328e; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;"&gt;&lt;img alt="Visual Studio 2012 and .NET 4.5 Expert Development Cookbook" src="http://dotnet.dzone.com/sites/all/files/6709EN.jpg" style="border: 0px; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;" /&gt;&lt;/a&gt;&lt;i&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/i&gt;&lt;/div&gt;
&lt;h2 style="background-color: white; border: 0px; color: #222222; font-family: MuseoSans500, Helvetica, Arial, Verdana, Tahoma, sans-serif; font-size: 23px; margin: 0px; outline: 0px; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;"&gt;
What else to win from the same contest?&amp;nbsp;&lt;/h2&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
Well, as a matter of fact, we have decided to give away some additional things with the Book. Here is some of the additional gifts that we are going to provide to the winners.&amp;nbsp;&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;/div&gt;
&lt;ol style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin: 15px 0px 15px 20px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;&lt;b&gt;One T-Shirt for every winner&lt;/b&gt;&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;&lt;b&gt;One USB Flash drive.&lt;/b&gt;&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;&lt;b&gt;One big poster with .NET architecture printed for reference.&lt;/b&gt;&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;&lt;b&gt;One Pen + Pad which suits your desktop.&lt;/b&gt;&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;&lt;b&gt;Some software and training licences (not yet decided)&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style="background-color: white; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px;"&gt;So Hurry !!! Don't miss this opportunity.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;/div&gt;
&lt;h3 style="background-color: white; border: 0px; color: #222222; font-family: MuseoSans500, Helvetica, Arial, Verdana, Tahoma, sans-serif; font-size: 21px; margin: 0px; outline: 0px; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;"&gt;
Who is this book for ?&amp;nbsp;&lt;/h3&gt;
&lt;div style="background-color: white; border: 0px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;span style="color: #222222; font-family: Helvetica, arial, verdana;"&gt;&lt;span style="font-size: 15px; line-height: 22px;"&gt;This book is aimed at Visual Studio 2012 and .Net developers who want to gain advanced understanding and sharpen their existing&amp;nbsp;skill sets&amp;nbsp;and adapt to new .NET technologies. Basic understanding of .NET and C# is assumed. The purpose of this book is to give under the hood expertise in .NET and help you to face common problems on latest technologies.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
Visual Studio 2012 and .NET 4.5 Expert Development Cookbook&amp;nbsp; is a step-by-step tutorial providing Visual Studio 2012 and .Net developers with useful techniques to develop the latest .NET technologies using Visual Studio 2012.&lt;/div&gt;
&lt;span style="background-color: white; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px;"&gt;This book covers all the essential areas of Visual Studio 2012 IDE and delves into step-by-step instructions that highlights various techniques to build, design, asynchronous better multithreaded applications using recent updates on .NET 4.5 and learn better ways to create secure ASP.NET web based applications in .NET 4.5 using JQuery and HTML5.&lt;/span&gt;&lt;br /&gt;
&lt;h3 style="background-color: white; border: 0px; color: #222222; font-family: MuseoSans500, Helvetica, Arial, Verdana, Tahoma, sans-serif; font-size: 21px; margin: 0px; outline: 0px; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;"&gt;
I can't wait and want to buy a copy now !&lt;/h3&gt;
&lt;div style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin-bottom: 1.2em; margin-top: 0.6em; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
Well, thank you so much for your support. Below are the links that would help you buy this book.&lt;/div&gt;
&lt;ul style="background-color: white; border: 0px; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px; margin: 15px 0px 15px 20px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;&lt;a href="http://www.packtpub.com/visual-studio-11-and-dotnet-4-5-expert-development-cookbook/book" style="border: 0px; color: #20328e; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;Buy from packtpub.com&lt;/a&gt;&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;&lt;a href="http://www.amazon.com/dp/184968670X/?tag=packtpubli-20" style="border: 0px; color: #20328e; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank"&gt;Buy from Amazon.com&lt;/a&gt;&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; margin: 0px 0px 10px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;Buy from&amp;nbsp;&lt;a href="http://www.amazon.co.uk/dp/184968670X/?tag=packtpubli-21" style="border: 0px; color: #20328e; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;"&gt;Amazon.UK&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="background-color: white; color: #222222; font-family: Helvetica, arial, verdana; font-size: 15px; line-height: 22px;"&gt;You can also try Ebook version in PDF, Mobi, EPub formats.&amp;nbsp; Thank you.&amp;nbsp;&lt;/span&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=cz2i6pbFnjY:5Cu-eLfZpZc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=cz2i6pbFnjY:5Cu-eLfZpZc:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=cz2i6pbFnjY:5Cu-eLfZpZc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=cz2i6pbFnjY:5Cu-eLfZpZc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=cz2i6pbFnjY:5Cu-eLfZpZc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/cz2i6pbFnjY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/3481647213948619953/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2013/05/want-copy-of-visual-studio-2012-and-net.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/3481647213948619953?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/3481647213948619953?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/cz2i6pbFnjY/want-copy-of-visual-studio-2012-and-net.html" title="Want a copy of Visual Studio 2012 and .NET 4.5 Expert Cookbook for free in simple steps?" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2013/05/want-copy-of-visual-studio-2012-and-net.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0MBRnwyeip7ImA9WhBUF0U.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-6134463480917742725</id><published>2013-04-21T04:08:00.000+05:30</published><updated>2013-05-06T01:54:17.292+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-06T01:54:17.292+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVVM" /><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="push technology" /><category scheme="http://www.blogger.com/atom/ns#" term="VS2012" /><category scheme="http://www.blogger.com/atom/ns#" term="TPL" /><category scheme="http://www.blogger.com/atom/ns#" term="html5" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="TPL Data Flows" /><category scheme="http://www.blogger.com/atom/ns#" term="async" /><category scheme="http://www.blogger.com/atom/ns#" term="internals" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows8" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET infrastructure" /><category scheme="http://www.blogger.com/atom/ns#" term="jquery" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET Memory Management" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="cookbook" /><category scheme="http://www.blogger.com/atom/ns#" term="multithreading" /><category scheme="http://www.blogger.com/atom/ns#" term="asp.net4.5" /><category scheme="http://www.blogger.com/atom/ns#" term="book" /><title>.NET Book : Visual Studio 2012 and .NET 4.5 Expert Development Cookbook (Must Read)</title><content type="html">Friends,&lt;br /&gt;
&lt;br /&gt;
It is my great honor to tell you that my book has finally been released this week. If you have ever liked any of my blogs or internals, you would like this book for sure. There are lot of things to learn from the book and I can assure you that you wont be upset with this book if you buy it.&lt;br /&gt;
&lt;br /&gt;
The &lt;a href="http://www.packtpub.com/visual-studio-11-and-dotnet-4-5-expert-development-cookbook/book" target="_blank"&gt;"Visual Studio 2012 and .NET 4.5 Expert Development Cookbook"&lt;/a&gt;&amp;nbsp;is a book that guides you through steps to ensure you enrich the best experience with the latest technology in the best amount of time possible. The book focusses to give you under the hood expertise in .NET technologies it tends to cover and adapts you the best to face common problems of these technologies. The book is divided in forms of&amp;nbsp;recipes. Each of these recipes gives you clear insight of the problem and step by step process to solve the issue practically. It also addresses the advanced features associated with each of those recipes that gives you additional advantage on getting precise knowledge about the problem and its associated issues.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-HsI0Z8zVTuQ/UXMJXxpEqfI/AAAAAAAAEdc/OPYQ9ZLSm34/s1600/2-19-2013+11-53-20+AM.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-HsI0Z8zVTuQ/UXMJXxpEqfI/AAAAAAAAEdc/OPYQ9ZLSm34/s320/2-19-2013+11-53-20+AM.png" width="259" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h3&gt;
What you will learn from this book&lt;/h3&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="background-color: white; border: 0px; font-family: sans-serif; font-size: 12px; line-height: 18px; list-style: none; margin: 0px; padding: 0px;"&gt;
&lt;li style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; list-style-image: url(http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/new-design-assets/orange-bullet.png); list-style-type: disc; margin: 0px 0px 0px 2em; padding: 0px;"&gt;Basic usage of Visual Studio 2012 IDE and its various components and better utilization of the tool while writing code&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; list-style-image: url(http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/new-design-assets/orange-bullet.png); list-style-type: disc; margin: 0px 0px 0px 2em; padding: 0px;"&gt;Understand memory management techniques to build better applications&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; list-style-image: url(http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/new-design-assets/orange-bullet.png); list-style-type: disc; margin: 0px 0px 0px 2em; padding: 0px;"&gt;Understand the .NET infrastructure with in-depth analysis of its internals&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; list-style-image: url(http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/new-design-assets/orange-bullet.png); list-style-type: disc; margin: 0px 0px 0px 2em; padding: 0px;"&gt;Architect solutions that leverage the full power of .NET language gems, understanding when to use what&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; list-style-image: url(http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/new-design-assets/orange-bullet.png); list-style-type: disc; margin: 0px 0px 0px 2em; padding: 0px;"&gt;Implement multithreaded / asynchronous applications using recent updates on .NET 4.5 and compare the past approaches&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; list-style-image: url(http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/new-design-assets/orange-bullet.png); list-style-type: disc; margin: 0px 0px 0px 2em; padding: 0px;"&gt;Create secure ASP.NET web based applications in .NET 4.5 with use of JQuery and HTML5 for rapid application development&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; list-style-image: url(http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/new-design-assets/orange-bullet.png); list-style-type: disc; margin: 0px 0px 0px 2em; padding: 0px;"&gt;Architect advanced .NET client applications using MVVM with WPF 4.5&lt;/li&gt;
&lt;li style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; line-height: 1.5em; list-style-image: url(http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/new-design-assets/orange-bullet.png); list-style-type: disc; margin: 0px 0px 0px 2em; padding: 0px;"&gt;Understand touch sensitive devices and leverage skills to develop multi-touch applications inside Windows 8&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
To summarise each chapters :&amp;nbsp;&lt;/h2&gt;
&lt;b&gt;Chapter 1 : Introduction to Visual Studio IDE Features &lt;a href="http://www.packtpub.com/sites/default/files/9781849686709_Chapter_01.pdf?utm_source=packtpub&amp;amp;utm_medium=free&amp;amp;utm_campaign=pdf" target="_blank"&gt;(Download this chapter for free)&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
It starts with a basic introduction to Visual Studio IDE and gives the developer insights into how to increase productivity of development &amp;nbsp;using a common set of tools and features present inside the IDE&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Chapter 2 :&amp;nbsp;Basics of .NET Programs and Memory Management&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This chapter introduces the intersection of a .NET program and its core components. It dives deep in demonstrating the .NET infrastructure with detailed explanation of memory management and related techniques. It also covers the internals of .NET and understand some of the few great features that you might never came across.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Chapter 3 : Asynchronous Programming in .NET&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The chapter focuses on introducing all existing techniques to deal with threading in .NET followed by the newer patterns that takes over the existing working principles with in-depth explanation on their working principles.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Chapter 4 : Enhancements to ASP.NET&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The chapter gives you an introduction to latest enhancements of &amp;nbsp;ASP.NET 4.5 with HTML5 and jQuery. It also introduces some of the performance boosters available in .NET 4.5 and Visual Studio 2012 with ASP.NET.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Chapter 5 : Enhancements to WPF&lt;/b&gt;&lt;br /&gt;
It introduces the enhancements to WPF 4.5 and the major components of WPF. It gives a practical implementation of MVVM based WPF application covering all the facets required to program in WPF environment.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Chapter 6 : Building Touch-sensitive Device Applications in Windows 8&lt;/b&gt;&lt;br /&gt;
The chapter introduces the new programming model for developing Windows 8 style tiles application. It gives a step-by-step introduction in how to program using HTML5 and JavaScript as well as WPF and C# for developing Windows 8 applications.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Chapter 7 : Communication and Sharing Using Windows 8&lt;/b&gt;&lt;br /&gt;
It focuses on how to implement network-enabled applications in Windows 8 with step by step implementation on how sharing and searching works inside the Windows 8 environment.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Appendix : .NET languages and its Construct&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
It focuses on giving insights on how languages work in the .NET framework and C# with details explanation with examples of various features of C# language.&lt;br /&gt;
&lt;br /&gt;
You can download this Appendix from &lt;a href="http://www.packtpub.com/sites/default/%20files/downloads/6709EN_Appendix_NET_Languages_and_its_Construct.pdf" target="_blank"&gt;http://www.packtpub.com/sites/default/&lt;/a&gt;&lt;a href="http://www.packtpub.com/sites/default/%20files/downloads/6709EN_Appendix_NET_Languages_and_its_Construct.pdf" target="_blank"&gt;files/downloads/6709EN_Appendix_NET_Languages_and_its_Construct.pdf&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Working with a varied set of upcoming technologies is a challenge. Visual Studio 2012 is all about enabling you to develop and manage these consumer-focused and business-focused apps. It provides best-in-class tools that propel developers to create new apps or evolve existing ones, and it enables individuals and teams to deliver continuous value and agility. In conjunction, .NET 4.5 provides expansive capabilities for developers to work on all forms of apps and services, from client to mobile to web to cloud, enabling them to get to the market fast. This book shows you exactly how to do this, and much more. It focuses on giving expertise on upcoming technologies through complete architectural insights of .NET infrastructure and hands on examples.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;a href="http://www.packtpub.com/visual-studio-11-and-dotnet-4-5-expert-development-cookbook/book" target="_blank"&gt;"Visual Studio 2012 and .NET 4.5 Expert Development Cookbook"&lt;/a&gt; is a step-by-step practical guide that teaches you how to work with new changes on technology under .NET. It provides in-depth analysis and expert advice on various elements of .NET, applying them in code using detailed practical examples. The book provides solutions to common development problems and helps you adapt to the latest technologies and get to grips with modern app development for the .NET 4.5 platform.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;a href="http://www.packtpub.com/visual-studio-11-and-dotnet-4-5-expert-development-cookbook/book" target="_blank"&gt;This cookbook&lt;/a&gt; gets you started on Visual Studio 2012 IDE and its various tooling capabilities. It provides expert knowledge on .NET infrastructure, internals of assemblies, and a basic introduction of Intermediate language. Common C# concepts and ideas are demonstrated through an example-driven approach.&lt;br /&gt;
&lt;br /&gt;
The recipes provide an overall view of ASP.NET Web applications and introduce the new performance boosters in .NET 4.5. It also gives a basic introduction to HTML 5 and JQuery library to enhance Web applications. It provides a complete introduction to Client applications using WPF and MVVM patterns and looks at some of the major enhancements on WPF 4.5. It shows you how to write applications for Windows 8 and provides expert advice on how to write applications in WinRT, either using XAML and C# or HTML/JavaScript.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.packtpub.com/visual-studio-11-and-dotnet-4-5-expert-development-cookbook/book" target="_blank"&gt;"Visual Studio 2012 and .NET 4.5 Expert Development Cookbook"&lt;/a&gt; gives you better understanding of&amp;nbsp; overall .NET infrastructure using the latest technology updates, providing a broad guide for a basic developer to become an expert on .NET.
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
Finally, I have written this book to give you clear insights on the ongoing problems and changing technologies. People liked me before when I was presenting problems in my blog, I have kept the same approach on this book and I am sure as a reader I can justice your time from this book.&amp;nbsp;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2&gt;
Purchase this book online&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
If you are interested to purchase it online, you can get it from the following links :&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.packtpub.com/visual-studio-11-and-dotnet-4-5-expert-development-cookbook/book" target="_blank"&gt;Buy from packtpub.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/dp/184968670X/?tag=packtpubli-20" target="_blank"&gt;Buy from Amazon.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Buy from&amp;nbsp;&lt;a href="http://www.amazon.co.uk/dp/184968670X/?tag=packtpubli-21"&gt;Amazon.UK&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
I am sure you will like this book. Do let me know your feedback on it. Write to me at contact@abhisheksur.com on any problem you face while reading this book.&amp;nbsp;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
Happy Programming !!!&amp;nbsp;&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=AlcGoRCj4bM:IdCPqqReJBw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=AlcGoRCj4bM:IdCPqqReJBw:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=AlcGoRCj4bM:IdCPqqReJBw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=AlcGoRCj4bM:IdCPqqReJBw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=AlcGoRCj4bM:IdCPqqReJBw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/AlcGoRCj4bM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/6134463480917742725/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2013/04/net-book-visual-studio-2012-and-net-45.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6134463480917742725?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6134463480917742725?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/AlcGoRCj4bM/net-book-visual-studio-2012-and-net-45.html" title=".NET Book : Visual Studio 2012 and .NET 4.5 Expert Development Cookbook (Must Read)" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-HsI0Z8zVTuQ/UXMJXxpEqfI/AAAAAAAAEdc/OPYQ9ZLSm34/s72-c/2-19-2013+11-53-20+AM.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2013/04/net-book-visual-studio-2012-and-net-45.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0EGR3s6eyp7ImA9WhBSEU8.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-4632605116201792960</id><published>2013-02-17T22:50:00.000+05:30</published><updated>2013-02-17T22:50:26.513+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-17T22:50:26.513+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="gesture" /><category scheme="http://www.blogger.com/atom/ns#" term="kinect" /><title>A new book on Kinect by Abhijit Jana - A must read</title><content type="html">Kinect is one of the revolutionary device that were introduced lately in Microsoft ecosystem. The use of Kinect devices has increased in great extend in recent times and people are using it more and more in their day to day life. The use of Kinect is not only limited only with the gaming world, but its use is now widely spread over commercial applications too. Microsoft has released the &lt;b&gt;&lt;a href="http://www.microsoft.com/en-us/kinectforwindows/" target="_blank"&gt;Kinect SDK&lt;/a&gt;&lt;/b&gt; that can interact with the hardware and program on them. It is a kind of Fun working with Kinect and also writing small applications for it.&lt;br /&gt;
&lt;br /&gt;
Recently I have read a book on "&lt;a href="http://www.packtpub.com/kinect-for-windows-software-development-kit-programming-guide/book" target="_blank"&gt;Kinect for Windows SDK Programming Guide&lt;/a&gt;" by &lt;a href="http://abhijitjana.net/" target="_blank"&gt;Abhijit Jana&lt;/a&gt;. It is a book with great details about&lt;b&gt;&lt;a href="http://www.microsoft.com/en-us/kinectforwindows/" target="_blank"&gt; Kinect SDK&lt;/a&gt;&lt;/b&gt; and the Hardware. I enjoyed reading this book and thought of sharing my&amp;nbsp;experiences&amp;nbsp;with you such that if you are new in Kinect and want to write code on it, you might find this review helpful.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a class="lightbox-processed" href="http://www.packtpub.com/sites/default/files/2380OT.jpg" rel="lightbox[images]" style="background-color: white; border: 0px; color: #f68c23; font-family: sans-serif; font-size: 12px; font: inherit; line-height: 18px; margin: 0px auto; padding: 0px; text-align: center; text-decoration: initial;" title="Kinect for Windows SDK Programming Guide"&gt;&lt;img alt="Kinect for Windows SDK Programming Guide" class="bookimage" src="http://dgdsbygo8mp3h.cloudfront.net/sites/default/files/imagecache/productview_larger/2380OT.jpg" style="border: 0px; font-size: 12px; font: inherit; margin: 0px; padding: 0px; vertical-align: bottom;" title="Kinect for Windows SDK Programming Guide" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Kinect for Windows SDK Programming Guide by Abhijit Jana&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 1&lt;/h3&gt;
The book starts with the basic introduction to the evolution of the device, introduction of&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Natural_user_interface" target="_blank"&gt;Natural User Interface&lt;/a&gt;&amp;nbsp;and the differences of the Kinect device and Xbox platform. It then take us further introducing each and every component of the device and makes the hardware introduction ready. It is always good to know about the hardware components before going further with the SDK and programming interfaces. It seems this book has taken care of these details correctly.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 2&amp;nbsp;&lt;/h3&gt;
As we are kind of already get a basic introduction of Hardware, the book goes on to do the same with the software components and the &lt;a href="http://www.microsoft.com/en-us/kinectforwindows/" target="_blank"&gt;Kinect SDK&lt;/a&gt;. In this chapter the author clearly introduces how to use the SDK, what are the&amp;nbsp;components&amp;nbsp;we need to install to correctly communicate windows with the hardware. I should also mention, this chapter also introduces some other software tools which might come handy while doing the development. The chapter also introduces the features of Kinect device in short paragraphs to get things really started.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 3&amp;nbsp;&lt;/h3&gt;
&lt;br /&gt;
The real start of writing something is here. I like this chapter because it introduces the SDK by explaining each and every step correctly, such that if you are a beginner, you can start along to build this Infobox. Even Kinect SDK is so simple laid out, it is really fun and simple to create application using it. BTW, it uses WPF to design the sample, that might sometimes challenging. Well, if you want to learn WPF, &lt;a href="http://www.abhisheksur.com/2010/12/wpf-tutorial.html" target="_blank"&gt;I will encourage to read this&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 4&lt;/h3&gt;
&lt;br /&gt;
This chapter introduces Kinect Camera. It introduces how to retrieve color stream and processing it into a ImageControl. Here you will understand how you can stream the RGB set on the canvas and also save pictures form it. It also introduces how to change the elevation of Camera, putting effects on stream, inverting color and everything about camera elegantly. Overall this chapter will give you a good insight on the Camera API.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 5&lt;/h3&gt;
This chapter is about depth mapping. The Kinect sensor provides Depthstream channels which can be utilized to create responding apps. This chapter gives an insight on how to utilize depth camera to determine the position of an object. The application looks cool to me.&lt;br /&gt;
&lt;br /&gt;
Depth masking is one of the most interesting thing in Kinect. The chapter proves to be good one to introduce the various tricks to handle the depth of an object projected on camera.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 6&lt;/h3&gt;
&lt;br /&gt;
Well, probably now as we know everything in Kinect, it comes with something really constructive. This chapter introduces Skeleton Tracking. I must thank Microsoft to have SkeletonStream inbuilt on the SDK and also the Author to introduce and present it beautifully.&lt;br /&gt;
&lt;br /&gt;
Again, this chapter creates a simple application to detect each section of the skeleton. I really enjoyed to track certain Joints on the skeleton while building this application and playing around with JointCollection in real time with the device.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 7&lt;/h3&gt;
&lt;br /&gt;
Well Chapter 7 is regarding the Microphone present in Kinect device. This is more like basic application development to explore sound API on Kinect device.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 8&lt;/h3&gt;
As Chapter 7 being more on introductory level, I got really excited when I read Chapter 8. This chapter introduces Speech Recognisation. I know I did some speech recognisation applications before, but using Kinect, it is unique and exciting. &amp;nbsp;Speech Recognisation works well with Kinect and built a solid application using this chapter is fun.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 9&lt;/h3&gt;
&lt;br /&gt;
Gesture&amp;nbsp;recognition. Well, Its another interesting chapter where I learnt how to detect various gesture of a man, like clapping, moving hand etc. Funda is quite simple, you need to play around with the distance between joints. The idea will be much more clear if you can read this chapter. The chapter also builds up a gesture detection engine, which is what really interesting here, in this chapter.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 10&lt;/h3&gt;
&lt;br /&gt;
Finally it is time to interact with multiple kinect devices. I am yet to read this chapter, but as per I saw, it detects all the devices connected with a machine and combines the streams of all of them into a single application.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Chapter 11&lt;/h3&gt;
&lt;br /&gt;
Chapter 11 is one of the most interesting chapter where client server interaction is shown. It works with Augmented reality, Face tracking system etc.&lt;br /&gt;
&lt;br /&gt;
That's all. Now after reading the whole book, I am very confident to start writing my own real world application using Kinect device. I will share more of Kinect when I build one myself.&lt;br /&gt;
&lt;br /&gt;
After you read this book, probably you would be more inclined towards utilizing what you have learned from here. The trends currently show we are moving towards more touch/gesture sensitive UI in future. Kinect is the future of modern UI.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
My Review&lt;/h3&gt;
&lt;br /&gt;
The book really kept its promises. It has a lot of examples to deal with so that you could utilize the SDK in real time and also describes every bits and pieces of the API as a whole. I would really recommend this book to all who have interest on Kinect API. The book starts from beginners level and so it does not depend how much experienced you are it would definitely be useful.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.packtpub.com/sites/default/files/9781849692380_Chapter_01.pdf" target="_blank"&gt;Download the Sample Chapter from here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="border: 0px; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 12px; line-height: 19.1875px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
If you are interested to purchase it online, you can get that from the publisher packtpub site as well as from amazon or flipkart too. Here are the links to get quick details of the book and link to purchase it online&amp;nbsp;&lt;/div&gt;
&lt;ul style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 12px; line-height: 19.1875px;"&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.packtpub.com/kinect-for-windows-software-development-kit-programming-guide/book" rel="nofollow" style="border: 0px; color: #6e218a; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial; vertical-align: baseline;" target="_blank"&gt;Buy from packtpub.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/gp/product/B00ATYE418/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;amp;tag=kunsbl-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=B00ATYE418" rel="nofollow" style="border: 0px; color: #6e218a; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial; vertical-align: baseline;" target="_blank"&gt;Buy Kindle Edition from amazon.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/gp/product/1849692386/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;amp;tag=kunsbl-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1849692386" rel="nofollow" style="border: 0px; color: #6e218a; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial; vertical-align: baseline;" target="_blank"&gt;Buy Paper Back Edition from amazon.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.flipkart.com/kinect-windows-sdk-programming-guide-1849692386/p/itmdfkwkgyazpgf4?pid=9781849692380&amp;amp;affid=kunal2383y" rel="nofollow" style="border: 0px; color: #6e218a; font-weight: bold; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial; vertical-align: baseline;" target="_blank"&gt;Buy from flipkart.com&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div style="border: 0px; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 12px; line-height: 19.1875px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="border: 0px; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 12px; line-height: 19.1875px; outline: 0px; padding: 0px; vertical-align: baseline;"&gt;
Hope you will like this book and Happy coding.&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=TiTR7iMwle8:-F-dBaIzLuM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=TiTR7iMwle8:-F-dBaIzLuM:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=TiTR7iMwle8:-F-dBaIzLuM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=TiTR7iMwle8:-F-dBaIzLuM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=TiTR7iMwle8:-F-dBaIzLuM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/TiTR7iMwle8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/4632605116201792960/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2013/02/a-new-book-on-kinect-by-abhijit-jana.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/4632605116201792960?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/4632605116201792960?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/TiTR7iMwle8/a-new-book-on-kinect-by-abhijit-jana.html" title="A new book on Kinect by Abhijit Jana - A must read" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2013/02/a-new-book-on-kinect-by-abhijit-jana.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A04DR3g8fCp7ImA9WhJWFko.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-1139626862318288022</id><published>2012-08-23T05:28:00.002+05:30</published><updated>2012-08-23T05:29:36.674+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-08-23T05:29:36.674+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><title>NotifyIcon with WPF applications</title><content type="html">NotifyIcon is an utility form System.Windows.Forms which can be used by any application to invoke the default notification from the system tray. As per my latest requirement, I have to create an application that runs on system tray and occationally shows notification using the system tray default notifications. While working with it, I have wasted a considerable amount of time, and thought it would be worth mentioning the same in a blog.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Steps :&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
1. Start a WPF Application and add Reference to System.Windows.Forms and System.Drawing to the project.&lt;br /&gt;
2. Create an instance of NotifyIcon on the Code behind of the WPF application.&lt;br /&gt;
3. Specify the Icon property for the NotifyIcon.&lt;br /&gt;
Remember, you should specify the Icon property as it is a mandatory before you can show notifyIcons from the application.&lt;br /&gt;
4. Make the NotifyIcon visible.&lt;br /&gt;
5. Call ShowBallonTip after minimizing the window to System Tray.&lt;br /&gt;
&lt;br /&gt;
In my sample application, I have just created one button on the Window and when it is clicked, I show up a notifyIcon on the system tray.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Window&lt;/span&gt;&lt;span style="color: red;"&gt;&amp;nbsp;x&lt;/span&gt;&lt;span style="color: blue;"&gt;:&lt;/span&gt;&lt;span style="color: red;"&gt;Class&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"NotifyIconSample.MainWindow"&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: red;"&gt;&amp;nbsp;xmlns&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: red;"&gt;&amp;nbsp;xmlns&lt;/span&gt;&lt;span style="color: blue;"&gt;:&lt;/span&gt;&lt;span style="color: red;"&gt;x&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: red;"&gt;&amp;nbsp;Title&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"MainWindow"&lt;/span&gt;&lt;span style="color: red;"&gt;&amp;nbsp;Height&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"350"&lt;/span&gt;&lt;span style="color: red;"&gt;&amp;nbsp;Width&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"525"&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Button&lt;/span&gt;&lt;span style="color: red;"&gt;&amp;nbsp;Click&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Button_Click"&lt;/span&gt;&lt;span style="color: red;"&gt;&amp;nbsp;Content&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;&lt;span style="color: blue;"&gt;"Click&amp;nbsp;to&amp;nbsp;Open"&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #a31515;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;Window&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"&gt;&lt;span style="color: blue;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"&gt;&lt;/pre&gt;
&lt;br /&gt;
Code :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;NotifyIcon&lt;/span&gt;&amp;nbsp;nIcon&amp;nbsp;=&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;NotifyIcon&lt;/span&gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;MainWindow()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InitializeComponent();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style="color: blue;"&gt;void&lt;/span&gt;&amp;nbsp;Button_Click(&lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;nbsp;sender,&amp;nbsp;&lt;span style="color: #2b91af;"&gt;RoutedEventArgs&lt;/span&gt;&amp;nbsp;e)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;this&lt;/span&gt;.WindowState&amp;nbsp;=&amp;nbsp;System.Windows.&lt;span style="color: #2b91af;"&gt;WindowState&lt;/span&gt;.Minimized;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;this&lt;/span&gt;.nIcon.Icon&amp;nbsp;=&amp;nbsp;&lt;span style="color: blue;"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af;"&gt;Icon&lt;/span&gt;(&lt;span style="color: #a31515;"&gt;@"../../Cartman-General.ico"&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: blue;"&gt;this&lt;/span&gt;.nIcon.ShowBalloonTip(5000,&amp;nbsp;&lt;span style="color: #a31515;"&gt;"Hi"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: #a31515;"&gt;"This&amp;nbsp;is&amp;nbsp;a&amp;nbsp;BallonTip&amp;nbsp;from&amp;nbsp;Windows&amp;nbsp;Notification"&lt;/span&gt;,&amp;nbsp;&lt;span style="color: #2b91af;"&gt;ToolTipIcon&lt;/span&gt;.Info);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/pre&gt;
&lt;pre style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"&gt;&lt;/pre&gt;
&lt;br /&gt;
Note : I have wasted lot of time just to ensure that the Icon property is mandatory for the NotifyIcon to work on. So it is important to note that you must specify it before using it.&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=8I-HivWYl50:PrnRZcfyp8I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=8I-HivWYl50:PrnRZcfyp8I:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=8I-HivWYl50:PrnRZcfyp8I:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=8I-HivWYl50:PrnRZcfyp8I:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=8I-HivWYl50:PrnRZcfyp8I:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/8I-HivWYl50" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/1139626862318288022/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2012/08/notifyicon-with-wpf-applications.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1139626862318288022?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1139626862318288022?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/8I-HivWYl50/notifyicon-with-wpf-applications.html" title="NotifyIcon with WPF applications" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2012/08/notifyicon-with-wpf-applications.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkMDSXc8eSp7ImA9WhVREEU.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-8915459665827660660</id><published>2012-03-18T19:51:00.001+05:30</published><updated>2012-03-18T19:51:18.971+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-18T19:51:18.971+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Teched" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Online Session" /><title>Microsoft TechEd 2012 on the Go.. Are you attending?</title><content type="html">Well, &amp;nbsp;Microsoft is going Big with their event TechEd 2012 which will be held just in 2 days from now. Everyone is excited to visit Bangaluru for this awesome event and learn lot of technology. I am going to visit Bangalore soon. If you are going, just text me at contact@abhisheksur.com and come and say hi to me during the event.&lt;br /&gt;
&lt;br /&gt;
Visit the link below to know more about the event&lt;br /&gt;
&lt;a href="https://india.msteched.com/" target="_blank"&gt;Microsoft TechEd India 2012 -&amp;gt; Go Big&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now if you cannot join us in Bangaluru for this event, you can still see the event live. Register yourself immediately.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table border="0" cellpadding="0" cellspacing="0" style="background-color: #f7f7f7; color: #333333; font-family: Helvetica, Arial, sans-serif; font-size: 12px; height: 105px; line-height: 16px; width: 550px;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td align="left" style="padding-left: 40px; padding-right: 40px; padding-top: 40px; width: 743px;" valign="top"&gt;&lt;table border="0" cellpadding="0" cellspacing="0" style="height: 23px; width: 470px;"&gt;&lt;thead style="color: #003366;"&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="width: 337px;"&gt;&lt;a href="http://india.msteched.com/" shape="rect" style="border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #003366; outline-color: initial; outline-style: initial; outline-width: 0px; text-decoration: none;" target="_blank"&gt;&lt;img alt="" height="74" src="http://www.microsoft.com/india/images/teched-live-images/MVP_03.jpg" style="border-bottom-style: solid; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-style: solid; border-left-width: 0px; border-right-style: solid; border-right-width: 0px; border-top-style: solid; border-top-width: 0px; border-width: initial;" width="120" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;td align="right" style="width: 333px;" valign="middle"&gt;&lt;img alt="" height="54" src="http://www.microsoft.com/india/images/teched-live-images/gobig.jpg" style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial;" width="160" /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align="left" style="padding-bottom: 60px; padding-left: 40px; padding-right: 40px; padding-top: 60px;" valign="top"&gt;&lt;table border="0" cellpadding="0" cellspacing="0" style="height: 116px; width: 470px;"&gt;&lt;thead style="color: #003366;"&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td align="left" style="color: #ec5526; font-family: tahoma, verdana; font-size: 50px; font-weight: bold; line-height: 54px; width: 431px;" valign="top"&gt;Catch TechEd Online for FREE!!!&lt;/td&gt;&lt;td align="left" style="width: 274px;" valign="middle"&gt;&lt;a href="http://ctracker.communitiesrus.in/L/Go.aspx?t=C19L134H1" shape="rect" style="border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #003366; outline-color: initial; outline-style: initial; outline-width: 0px; text-decoration: none;" target="_blank"&gt;&lt;img align="absMiddle" alt="" height="116" src="http://www.microsoft.com/india/images/teched-live-images/techedlive-750_03.jpg" style="border-bottom-style: solid; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-style: solid; border-left-width: 0px; border-right-style: solid; border-right-width: 0px; border-top-style: solid; border-top-width: 0px; border-width: initial; vertical-align: middle;" width="184" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;table border="0" cellpadding="0" cellspacing="0" height="34"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td align="left" style="height: 34px; padding-right: 5px; width: 335px;" valign="top"&gt;&lt;table border="0" cellpadding="0" cellspacing="0" height="33"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td align="center" style="background-color: #f36523; color: white; font-family: 'segoe ui', tahoma, verdana; font-size: 13px; font-weight: bold; line-height: 20px; padding-bottom: 7px; padding-top: 7px; width: 331px;" valign="top"&gt;&lt;a href="http://ctracker.communitiesrus.in/L/Go.aspx?t=C19L134H1" shape="rect" style="border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: white; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 7px; padding-top: 7px; text-decoration: none;" target="_blank"&gt;Register for TechEd Live!&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;&lt;td align="center" style="background-color: #f36523; color: white; font-family: 'segoe ui', tahoma, verdana; font-size: 13px; font-weight: bold; line-height: 20px; padding-bottom: 7px; padding-top: 7px; width: 331px;" valign="top"&gt;&lt;a href="http://kolkatageeks.com/Events/TechEd2012.aspx" shape="rect" style="border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: white; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 7px; padding-top: 7px; text-decoration: none;"&gt;Click to Read Details!&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;br /&gt;I hope to see you all around.&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=iLnlMusvt_4:6j3zznGFu34:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=iLnlMusvt_4:6j3zznGFu34:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=iLnlMusvt_4:6j3zznGFu34:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=iLnlMusvt_4:6j3zznGFu34:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=iLnlMusvt_4:6j3zznGFu34:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/iLnlMusvt_4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/8915459665827660660/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2012/03/microsoft-teched-2012-on-go-are-you.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/8915459665827660660?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/8915459665827660660?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/iLnlMusvt_4/microsoft-teched-2012-on-go-are-you.html" title="Microsoft TechEd 2012 on the Go.. Are you attending?" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2012/03/microsoft-teched-2012-on-go-are-you.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8MRX46fSp7ImA9WhVTEkQ.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-5473926769437689405</id><published>2012-02-27T04:58:00.000+05:30</published><updated>2012-02-27T04:58:04.015+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-27T04:58:04.015+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.5" /><category scheme="http://www.blogger.com/atom/ns#" term="design pattern" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET Memory Management" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><category scheme="http://www.blogger.com/atom/ns#" term="Memory Allocation" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Inter-Process Communication using MemoryMappingFile</title><content type="html">In an operating system, a Memory Mapping file are virtual storage place which has direct byte to byte correlation between the Virtual Address Space and the corresponding physical storage. So when we access the Virtual Address space via a memory mapping file we are directly communicating with the kernel space where the file is actually loaded. The portion of calculation between the physical storage and logical storage is hence avoided.&lt;br /&gt;
&lt;br /&gt;
Memory Mapping files allows&amp;nbsp;application&amp;nbsp;to access files in the same way as memory. Generally as address between the physical storage and virtual memory address space, we cannot access the physical address directly. But using Memory Mapping Files, the process loads a specific range of address within the process address space with which the storage of memory into the file can be done by just assigning value to a dereferenced pointers. The IO operation on a MemoryMapping file is so fast that from the programmers point of view it seems to be like accessing the memory rather than actual physical storage. To increase performance memory mapping files are not actually stored to the disk file as well, but rather it will be stored automatically in background when FlushViewOfFile is executed or paging file is written. To Read more about memory mapping files, &lt;a href="http://msdn.microsoft.com/en-us/library/ms810613.aspx" target="_blank"&gt;read here.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: x-large;"&gt;Memory Mapping file inside .NET Framework&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
.NET introduces a separate namespace to handle Memory Mapping files. Previously, we needed to do this using unmanaged Api's but with the introduction of managed API into the .NET framework library, it becomes very easy to handle MemoryMapping file directly from .NET library.&lt;br /&gt;
&lt;br /&gt;
As memory mapping files are loaded into memory on a separate range of address space, two process can easily share the same page file instance and thus interprocess communication can be made with fast access to memory. It is recommended to back data with an actual disk file when large data is loaded into memory, so that there is no memory leak on the system when there is large memory pressure.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;MemoryMapping with backup Paging file (For large data communication)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We generally use backed up memory file in the hard disk when the memory that needs to be shared between the process goes out of physical memory available on the pc or when you think that the data that needs to be loaded can be very expensive and sensitive to remain only in memory.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; FILENAME = &lt;span class="str"&gt;"LargeFile.dat"&lt;/span&gt;;
&lt;span class="kwrd"&gt;private&lt;/span&gt; MemoryMappedFile GetMemoryMapFile(FileMode mode)
{
   &lt;span class="kwrd"&gt;string&lt;/span&gt; path = Path.Combine(defaultPath, FILENAME);
   &lt;span class="kwrd"&gt;var&lt;/span&gt; mmf = MemoryMappedFile.CreateFromFile(path, mode, &lt;span class="str"&gt;"INTERPROC"&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;.length, MemoryMappedFileAccess.ReadWriteExecute);
  &lt;span class="kwrd"&gt;return&lt;/span&gt; mmf;
}&lt;/pre&gt;
&lt;br /&gt;
The code above gets the reference of MemoryMappedFile using a disk backup paging file. The CreateFromFile static method of MemoryMappedFile exposes an option to specify path of the actual file location where the memory mapping file content needs to be mapped. By opening the file you can load the views of memory mapping file as you are accessing the file content from memory. You can also use OpenExisting or CreateNew methods if you are sure of the specific requirement of usage.&lt;br /&gt;
&lt;br /&gt;
In the above code, you can see I have specified the length of the file as well as a fixed name "INTERPROC" which indicates the name of the shared memory location which other process can call to access. The length of the file needs to be a multiple of 1024 always, hence if you are not using the content of the file, the paging location will still be occupied with null content. This ensures the mapping file always remains in same context as the loaded memory. The file based Memory Mapping files are not loaded totally when you try to access, but rather it provides views in terms of what data you are currently accessing.&lt;br /&gt;
&lt;br /&gt;
Once the file is opened, you can read the content of it using :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;var&lt;/span&gt; mf = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetMemoryMapFile(FileMode.OpenOrCreate);
   &lt;span class="kwrd"&gt;using&lt;/span&gt;(mf)
   {
        &lt;span class="kwrd"&gt;int&lt;/span&gt; dsize = Marshal.SizeOf(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T));
        T dData;
        &lt;span class="kwrd"&gt;int&lt;/span&gt; offset = dsize * index;
        &lt;span class="kwrd"&gt;using&lt;/span&gt; (&lt;span class="kwrd"&gt;var&lt;/span&gt; accessor = mf.CreateViewAccessor(0, length))
         {
             accessor.Read(offset, &lt;span class="kwrd"&gt;out&lt;/span&gt; dData);
             &lt;span class="kwrd"&gt;return&lt;/span&gt; dData;
         }
  }
&lt;/pre&gt;
&lt;br /&gt;
Here once the MemoryMappedFile is loaded into memory, you can use CreateViewAccessor to create a separate view to see the content of the data. Here I have loaded the entire data at a time, but it is better to create View content as soon as you want to read its content. Once the data is loaded you can use Read method to get data from the memory.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;var&lt;/span&gt; mf = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetMemoryMapFile(FileMode.OpenOrCreate);
&lt;span class="kwrd"&gt;using&lt;/span&gt; (mf)
{
&lt;span class="kwrd"&gt;int&lt;/span&gt; dsize = Marshal.SizeOf(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T));
&lt;span class="kwrd"&gt;int&lt;/span&gt; offset = dsize * index;
&lt;span class="kwrd"&gt;using&lt;/span&gt; (&lt;span class="kwrd"&gt;var&lt;/span&gt; accessor = mf.CreateViewAccessor(0, length))
{
    accessor.Write(offset, &lt;span class="kwrd"&gt;ref&lt;/span&gt; dData);
}
}&lt;/pre&gt;
&lt;br /&gt;
Almost identical to it, you can use write method to write content into the memory.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Remember&lt;/b&gt;&lt;br /&gt;
One thing that you need to remember, when you Dispose the memory content from one process that means all the content that are loaded into view needs to be rewritten to the disk file, such that the other process needs to reopen and recreate the view again. If you want to access some specific view without writing to the page file often after using it, tweak the behavior by not disposing the MemoryMappedFile (removing the using block from here) and the operating system will automatically manage the destruction of View.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;MemoryMapping without backup Paging file (For small data communication)&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
When the load of memory file is small, it would not be always good to have a large paging file created in background and wasting large amount of memory of the system. Sometimes we need to share content only between the process and when no process is accessing the shared memory, the operating system needs to dispose the content. Regards to this requirement, you can use MemoryMappedFiles to be stored only into memory and be called using the name of Memory created.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; MemoryMappedFile GetMemoryMapFile()
{

    &lt;span class="kwrd"&gt;var&lt;/span&gt; security = &lt;span class="kwrd"&gt;new&lt;/span&gt; MemoryMappedFileSecurity();
    security.SetAccessRule(
        &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Security.AccessControl.AccessRule&amp;lt;MemoryMappedFileRights&amp;gt;(&lt;span class="str"&gt;"EVERYONE"&lt;/span&gt;,
            MemoryMappedFileRights.ReadWriteExecute, System.Security.AccessControl.AccessControlType.Allow));

    &lt;span class="kwrd"&gt;var&lt;/span&gt; mmf = MemoryMappedFile.CreateOrOpen(&lt;span class="str"&gt;"InterPROC"&lt;/span&gt;,
                    &lt;span class="kwrd"&gt;this&lt;/span&gt;.length,
                    MemoryMappedFileAccess.ReadWriteExecute,
                    MemoryMappedFileOptions.None,
                    security,
                    HandleInheritability.Inheritable);

    &lt;span class="kwrd"&gt;return&lt;/span&gt; mmf;

}&lt;/pre&gt;
&lt;br /&gt;
In the code above, I have created a MemoryMappedFile using CreateOrOpen and named the actual memory being created as "InterProc". Now this will create a file into the memory without any reference to it into disk file. &amp;nbsp;The HandleInheritability states that the child processes can also access the memory file.&lt;br /&gt;
&lt;br /&gt;
You can also specify security on the memory using MemoryMappedFileSecurity and add Access rule to the security blocks.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; T ReadEntry&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; index) where T : &lt;span class="kwrd"&gt;struct&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;var&lt;/span&gt; mf = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetMemoryMapFile();

    &lt;span class="kwrd"&gt;int&lt;/span&gt; dsize = Marshal.SizeOf(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T));
    T dData;
    &lt;span class="kwrd"&gt;int&lt;/span&gt; offset = dsize * index;
    &lt;span class="kwrd"&gt;using&lt;/span&gt; (&lt;span class="kwrd"&gt;var&lt;/span&gt; accessor = mf.CreateViewAccessor(0, length))
    {
        accessor.Read(offset, &lt;span class="kwrd"&gt;out&lt;/span&gt; dData);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; dData;
    }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WriteEntry&amp;lt;T&amp;gt;(T dData, &lt;span class="kwrd"&gt;int&lt;/span&gt; index) where T : &lt;span class="kwrd"&gt;struct&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;var&lt;/span&gt; mf = &lt;span class="kwrd"&gt;this&lt;/span&gt;.GetMemoryMapFile();
    &lt;span class="kwrd"&gt;int&lt;/span&gt; dsize = Marshal.SizeOf(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T));
    &lt;span class="kwrd"&gt;int&lt;/span&gt; offset = dsize * index;
    &lt;span class="kwrd"&gt;using&lt;/span&gt; (&lt;span class="kwrd"&gt;var&lt;/span&gt; accessor = mf.CreateViewAccessor(0, &lt;span class="kwrd"&gt;this&lt;/span&gt;.length))
    {
        accessor.Write(offset, &lt;span class="kwrd"&gt;ref&lt;/span&gt; dData);
    }
}&lt;/pre&gt;
&lt;br /&gt;
You can read from and write to the file in the same way as you did for the file based shared memory, but one thing you need to remember again, you cannot close/dispose the MemoryMappedFile as this will &amp;nbsp;erase all the content that you write into the View.&lt;br /&gt;
&lt;br /&gt;
Here you can see, I didnt use using block or even wrote the Dispose of MemoryMappedFile as it is important.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="https://skydrive.live.com/embed?cid=BAFA39A62A57009C&amp;amp;resid=BAFA39A62A57009C%21857&amp;amp;authkey=AIBgo38S6AZl_UI" target="_blank"&gt;Download the Source code&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Using the code&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In the sample application that I have provided with this article, there is an interface that you can use to handle both Large and small Communicators. Ideally these classes needs to be used based on the requirement on real world .&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ICommunicator
    {
        T ReadEntry&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; index) where T : &lt;span class="kwrd"&gt;struct&lt;/span&gt;;
        &lt;span class="kwrd"&gt;void&lt;/span&gt; WriteEntry&amp;lt;T&amp;gt;(T dData, &lt;span class="kwrd"&gt;int&lt;/span&gt; index) where T : &lt;span class="kwrd"&gt;struct&lt;/span&gt;;
    }&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; index = 0;
ICommunicator lcom = &lt;span class="kwrd"&gt;new&lt;/span&gt; SmallCommunicator();&lt;span class="rem"&gt;//new LargeCommunicator("D:\\");&lt;/span&gt;

&lt;span class="rem"&gt;// My Try&lt;/span&gt;
while (&lt;span class="kwrd"&gt;true&lt;/span&gt;)
{
    DummyData dData = lcom.ReadEntry&amp;lt;DummyData&amp;gt;(index);
    Console.WriteLine(&lt;span class="str"&gt;"Existing Data at 0 position : {0}"&lt;/span&gt;, dData);

    Console.WriteLine(&lt;span class="str"&gt;"Write Data Id"&lt;/span&gt;);
    dData.Id = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine(&lt;span class="str"&gt;"Write new Data"&lt;/span&gt;);
    dData.Data = Convert.ToInt32(Console.ReadLine());

    lcom.WriteEntry&amp;lt;DummyData&amp;gt;(dData, index);

    Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);
}&lt;/pre&gt;
Thus it will open a SmallCommunicator (or LargeCommunicator) and read/Write data into it.

&lt;br /&gt;
&lt;br /&gt;
Hope that helps!&lt;br /&gt;
&lt;br /&gt;
Happy Coding.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=H-4mXudKtJY:V7XjkOFEi-E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=H-4mXudKtJY:V7XjkOFEi-E:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=H-4mXudKtJY:V7XjkOFEi-E:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=H-4mXudKtJY:V7XjkOFEi-E:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=H-4mXudKtJY:V7XjkOFEi-E:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/H-4mXudKtJY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/5473926769437689405/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2012/02/inter-process-communication-using.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/5473926769437689405?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/5473926769437689405?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/H-4mXudKtJY/inter-process-communication-using.html" title="Inter-Process Communication using MemoryMappingFile" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2012/02/inter-process-communication-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUQBSH47cSp7ImA9WhRbE0w.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-350497784722476311</id><published>2012-02-04T05:25:00.000+05:30</published><updated>2012-02-04T05:25:59.009+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-04T05:25:59.009+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="GC" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="WeakReference" /><category scheme="http://www.blogger.com/atom/ns#" term="design pattern" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET Memory Management" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><category scheme="http://www.blogger.com/atom/ns#" term="Memory Allocation" /><title>Optimizing INPC Objects against memory leaks using WeakEvents</title><content type="html">Working with WPF has always been a fun. Dealing with animation and richness in UI to its optimum  level often gives you an edge to present something to your client and to ensure that your client shouts with a "WOW!". The Wow factor of applications can give you high rank in the first place, but increases expectation from the software. It is practically very hard to maintain with this expectation as time progresses. The survival of the fittest chooses one which best suits to the problem.&lt;br /&gt;
&lt;br /&gt;
One of the major problems that developers face today is the memory leaks in an applications. Often the software that is built looks great but does not follow basic guidelines to ensure that the application is not memory hungry or even there are no existing memory leaks.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Note : By memory leak we mean, some portion of memory is not reclaimed by the garbage collector even though the object is not in use.&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
By this way, the memory usage of the application increases at a certain extent and finally crashes with the OutOfMemoryException. To detect a memory leak there exists a large number of tools of which some are free while others are used as commercial purposes. Most of these problems can be &lt;a href="http://www.codeproject.com/Articles/38068/Best-Practices-of-Memory-Usage" target="_blank"&gt;fixed by either using Disposable pattern&lt;/a&gt; ( IDisposable interface) or manually de - referencing each and every object that are not in use. Sometimes, this can be also done in destructor / finalizers in .net too (but remember using destructors lose GC cycle).&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
GC algorithm actually tries to find all reachable objects in the entire heap and creates a map. It then puts the reachable objects one by one into the heap releasing memory of all unreachable objects. This is called Heap Compaction. By reachable objects we mean those objects to which the application still has strong reference, and the items which can be called in future. Thus it is important to release any strong reference of a memory when it is not in use, so that GC can collect it.&lt;br /&gt;
&lt;br /&gt;
Even though Garbage Collector separates all the reachable objects with non-reachables, there is one exception to this. .NET framework exposes WeakReference as a special type in the system, which can hold objects that are reachable but still it will be collected by the garbage collector. You can look into it in detail in my post :&amp;nbsp;&lt;a href="http://www.abhisheksur.com/2010/07/garbage-collection-algorithm-with-use.html"&gt;Garbage Collection Algorithm with the use of WeakReference&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;The Problem&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now coming back to the application, sometimes it is even difficult to identify a memory leak when it exists inside of its framework. One of such scenario is when a large portion of memory is held by the EventHandler where the source has an EventHandler which is connected with a strong reference of the target which has the event. Let me explain it more :&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-hNC10m6cMi0/TyxaQsF-m3I/AAAAAAAAD8E/cJQBAKRGB94/s1600/StrongReference.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-hNC10m6cMi0/TyxaQsF-m3I/AAAAAAAAD8E/cJQBAKRGB94/s1600/StrongReference.png" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Object A holding strong reference of Object B through the use of EventHandler&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
In the above figure, let say Object A is an object that exposes one Event. Suppose Object A is an INPC container and exposes PropertyChanged Event from it. Object B on the other hand consumes Object A and adds an EventHandler inside B. Now it invokes statement to add this handler to the Object A using the code below :&lt;br /&gt;
&lt;pre class="csharpcode"&gt;A a1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; A();
a1.PropertyChanged += &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangedEventHandler(&lt;span class="kwrd"&gt;this&lt;/span&gt;.A_PropertyChanged);&lt;/pre&gt;
&lt;br /&gt;
So now object A can call A_PropertyChanged event handler defined inside Object B directly.&lt;br /&gt;
At a certain point, lets say Object A is no longer in use and is de-referenced from B by doing :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;a1 = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;br /&gt;
Here the de-referencing works good, but you are missing the fact that a1 still holds reference of B through the Event PropertyChanged, and will not be GCed until B is de-referenced as well. Here is the problem of memory leak. If B is a Static object and creates lots of A throughout the program, this problem can really leak lots of memory and eventually can load the process to crash.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;The Solution&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To deal with such a problem, we need a Co-ordinator for the Event such that the event raised by the object does not go directly to the Object B, rather it calls an intermediate listener which routes the event to the handler of Object B.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-qjqGz2Xx4cs/TyxcD48t5tI/AAAAAAAAD8Q/ELgAs8ehDpY/s1600/WeakListener.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-qjqGz2Xx4cs/TyxcD48t5tI/AAAAAAAAD8Q/ELgAs8ehDpY/s1600/WeakListener.png" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;The Object A is not communicating directly with Object B, rather it connects with a WeakListener which exposes one WeakReference object to hold B&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
In the above figure, we can see, the Listener co-ordinates the event with the EventHandler thus de-referencing Object A and Listener from Object B will remove all the references from it. Lets implement this approach using code.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;interface&lt;/span&gt; IPropertyChanged
    {
        &lt;span class="kwrd"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, PropertyChangedEventArgs e);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; WeakEventListener : IDisposable
    {
        &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; locker = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;();
        WeakReference weakListener;
        INotifyPropertyChanged target;
        IPropertyChanged source;

        &lt;span class="kwrd"&gt;public&lt;/span&gt; WeakEventListener(IPropertyChanged source, INotifyPropertyChanged target)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.source = source;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.target = target;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.target != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.target.PropertyChanged += &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangedEventHandler(target_PropertyChanged);
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.weakListener = &lt;span class="kwrd"&gt;new&lt;/span&gt; WeakReference(source);
        }

        &lt;span class="kwrd"&gt;void&lt;/span&gt; target_PropertyChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, PropertyChangedEventArgs e)
        {
            &lt;span class="kwrd"&gt;object&lt;/span&gt; source = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            &lt;span class="kwrd"&gt;lock&lt;/span&gt; (locker)
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (weakListener != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    source = weakListener.Target;
                }
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (source == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    ReleaseListener();
                    &lt;span class="kwrd"&gt;return&lt;/span&gt;;
                }
            }
            IPropertyChanged notifier = source &lt;span class="kwrd"&gt;as&lt;/span&gt; IPropertyChanged;
            notifier.OnPropertyChanged(sender, e);

        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ReleaseListener()
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (target != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                target.PropertyChanged -= &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangedEventHandler(target_PropertyChanged);
                target = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
                weakListener = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            }
        }
        &lt;span class="preproc"&gt;#region&lt;/span&gt; IDisposable Members

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Dispose()
        {
            &lt;span class="kwrd"&gt;lock&lt;/span&gt; (locker)
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.ReleaseListener();
            }
        }

        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }&lt;/pre&gt;
So here I have implemented one dummy implementation of WeakEventListener. Here the IPropertyChanged &amp;nbsp;interface is used to reference the object inside the Listener for simplicity.&lt;br /&gt;
&lt;br /&gt;
In the above implementation, you can see, I have used two object.&amp;nbsp;Preferably&amp;nbsp;consider object A in figure with INotifyPropertyChanged object target and IPropertyChanged as object B such that object B creates reference to both INotifyPropertyChanged as well as WeakEventListener. Now if B is derived from interface IPropertyChanged and define the eventhandler inside it, the WeakEventListener can invoke it without holding a strong reference of it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; A : INotifyPropertyChanged
{
    &lt;span class="kwrd"&gt;string&lt;/span&gt; myProperty;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; MyProperty
    {
        &lt;span class="kwrd"&gt;get&lt;/span&gt; { &lt;span class="kwrd"&gt;return&lt;/span&gt; myProperty; }
        &lt;span class="kwrd"&gt;set&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.myProperty = value;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.PropertyChanged != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.PropertyChanged(&lt;span class="kwrd"&gt;this&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangedEventArgs(&lt;span class="str"&gt;"MyProperty"&lt;/span&gt;));
        }
    }

    &lt;span class="preproc"&gt;#region&lt;/span&gt; INotifyPropertyChanged Members

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;

    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; B : IPropertyChanged
{
    A a1;
    WeakEventListener wlistener;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; B(A a1)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.a1 = a1;
        wlistener = &lt;span class="kwrd"&gt;new&lt;/span&gt; WeakEventListener(&lt;span class="kwrd"&gt;this&lt;/span&gt;, a1);
    }

    &lt;span class="preproc"&gt;#region&lt;/span&gt; IPropertyChanged Members

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, PropertyChangedEventArgs e)
    {
        MessageBox.Show(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Property {0}, has been changed"&lt;/span&gt;, e.PropertyName));
    }

    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;


    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ReleaseA()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.wlistener != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.wlistener.Dispose();
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.wlistener = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.a1 = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }

}&lt;/pre&gt;
&lt;br /&gt;
Now here class A implements INotifyPropertyChanged and invokes it when any of its property is changed. Class B, on the other hand implements IPropertyChanged and provides a eventhandler of PropertyChanged. But as it is using WeakEventListener you can call ReleaseA to release any strong reference of a1 from it and also dispose the listener object. Therefore you can keep on using the object B irrespective of any memory leak been created.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Alternatives inside Framework&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
WPF has a framework alternative to do the same thing. A number of class are available on the framework which help in implementing the same thing. Lets see how to do this using framework interfaces :&lt;br /&gt;
&lt;br /&gt;
1. Create a class and derive it from WeakEventManager.&lt;br /&gt;
2. Implement IWeakEventListener interface to define listener.&lt;br /&gt;
3. Use AddListener and RemoveListener to add and remove the objects.&lt;br /&gt;
&lt;br /&gt;
Lets see how I implement the same thing.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; A : INotifyPropertyChanged
{
       
    &lt;span class="kwrd"&gt;string&lt;/span&gt; myProperty;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; MyProperty
    {
        &lt;span class="kwrd"&gt;get&lt;/span&gt; { &lt;span class="kwrd"&gt;return&lt;/span&gt; myProperty; }
        &lt;span class="kwrd"&gt;set&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.myProperty = value;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.PropertyChanged != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.PropertyChanged(&lt;span class="kwrd"&gt;this&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangedEventArgs(&lt;span class="str"&gt;"MyProperty"&lt;/span&gt;));
        }
    }
    &lt;span class="rem"&gt;//code to raise the event&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;
}
&lt;span class="kwrd"&gt;class&lt;/span&gt; B : IWeakEventListener
{
    A a1;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; B(A a1)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.a1 = a1;
        PropertyChangedEventManager.AddListener(a1, &lt;span class="kwrd"&gt;this&lt;/span&gt;, &lt;span class="str"&gt;"MyProperty"&lt;/span&gt;);
            
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ReceiveWeakEvent(Type managerType, &lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        PropertyChangedEventArgs pe = e &lt;span class="kwrd"&gt;as&lt;/span&gt; PropertyChangedEventArgs;

        MessageBox.Show(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Property {0}, has been changed"&lt;/span&gt;, pe.PropertyName));

        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ReleaseA()
    {
        PropertyChangedEventManager.RemoveListener(&lt;span class="kwrd"&gt;this&lt;/span&gt;.a1, &lt;span class="kwrd"&gt;this&lt;/span&gt;, &lt;span class="str"&gt;"MyProperty"&lt;/span&gt;);
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.a1 = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }

}&lt;/pre&gt;
&lt;br /&gt;
Here the PropertyChangedEventManager is a special class derived from Dispatcher object deals with INPC objects by holding a collection of all those INPC in the whole process and calling appropriate objects when event is raised. Thus ReceiveWeakEvent will be called, just like what we did earlier in B when A raises the event provided you implement IWeakEventListener interface on it.&lt;br /&gt;
&lt;br /&gt;
The ReleaseA is used to release the object A from memory without any strong reference been held.&lt;br /&gt;
&lt;br /&gt;
There is also a CollectionChangedEventManager to deal with ObservableCollection events or even you can build your own by deriving from WeakEventManager.&lt;br /&gt;
&lt;br /&gt;
I hope the post will help you. Please let me know your thoughts.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading.&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=H5YLeE899yg:L1tg4FNtXLQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=H5YLeE899yg:L1tg4FNtXLQ:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=H5YLeE899yg:L1tg4FNtXLQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=H5YLeE899yg:L1tg4FNtXLQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=H5YLeE899yg:L1tg4FNtXLQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/H5YLeE899yg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/350497784722476311/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2012/02/optimizing-inpc-objects-against-memory.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/350497784722476311?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/350497784722476311?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/H5YLeE899yg/optimizing-inpc-objects-against-memory.html" title="Optimizing INPC Objects against memory leaks using WeakEvents" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-hNC10m6cMi0/TyxaQsF-m3I/AAAAAAAAD8E/cJQBAKRGB94/s72-c/StrongReference.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2012/02/optimizing-inpc-objects-against-memory.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0QAR308eCp7ImA9WhRWFkw.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-1173288162753909344</id><published>2012-01-04T01:05:00.003+05:30</published><updated>2012-01-04T01:05:46.370+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-04T01:05:46.370+05:30</app:edited><title>I am reviewing Microsoft's 70-515 C# exam PrepKit from UCertify</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-t7bPvXkAMEE/TwNYXyktPUI/AAAAAAAAD7s/3P94u_TVSe0/s1600/logo.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-t7bPvXkAMEE/TwNYXyktPUI/AAAAAAAAD7s/3P94u_TVSe0/s1600/logo.gif" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;I have got a offer from uCertify to review their PrepKit and I have accepted that challenge and now I am reviewing&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: red; font-family: arial, sans-serif; font-size: 13px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: red; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;b&gt;&lt;a href="http://www.ucertify.com/exams/Microsoft/70-515-CSHARP.html" style="color: #1155cc;" target="_blank"&gt;70-515 Exam .NET 4.0&lt;/a&gt;&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;PrepKit&amp;nbsp;from uCertify. Initially it looks like a simple tool that has a number of practice sets listed on the initial screen to try out few tests. The home screen also contains few links that points to Study Materials related to the exam that you are registered for. Lets take a look how the initial screen looks like : &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-zBd_VBhCEXQ/TwNWp8wgwVI/AAAAAAAAD7g/mVjNJZKPc0Q/s1600/ucertify.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="544" src="http://2.bp.blogspot.com/-zBd_VBhCEXQ/TwNWp8wgwVI/AAAAAAAAD7g/mVjNJZKPc0Q/s640/ucertify.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222;"&gt;&lt;span style="font-family: arial, sans-serif; font-size: x-small;"&gt;The menu contains different links to Tests, Quiz, Notes, Articles, Reports etc for easy&amp;nbsp;navigation.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;As soon as I am done with the full review I will post it for you all.&lt;/span&gt;
&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif; font-size: 13px;"&gt;If you are looking for a Certification, you can buy it from them :&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;a href="http://www.ucertify.com/"&gt;http://www.ucertify.com/&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
Thanks and stay tune.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=cJPGBb08MJA:Qm8BfqYoJiM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=cJPGBb08MJA:Qm8BfqYoJiM:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=cJPGBb08MJA:Qm8BfqYoJiM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=cJPGBb08MJA:Qm8BfqYoJiM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=cJPGBb08MJA:Qm8BfqYoJiM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/cJPGBb08MJA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/1173288162753909344/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2012/01/i-am-reviewing-microsofts-70-515-c-exam.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1173288162753909344?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1173288162753909344?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/cJPGBb08MJA/i-am-reviewing-microsofts-70-515-c-exam.html" title="I am reviewing Microsoft's 70-515 C# exam PrepKit from UCertify" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-t7bPvXkAMEE/TwNYXyktPUI/AAAAAAAAD7s/3P94u_TVSe0/s72-c/logo.gif" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2012/01/i-am-reviewing-microsofts-70-515-c-exam.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UNQXw6eSp7ImA9WhRWFEg.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-447698324613444450</id><published>2012-01-02T02:24:00.002+05:30</published><updated>2012-01-02T02:24:50.211+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-02T02:24:50.211+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVP" /><title>Awarded Microsoft MVP in a row</title><content type="html">Its new years eve. I was struck in&amp;nbsp;traffic&amp;nbsp;to join a Birthday party of one of my friend. Its all of a sudden I realized that it is my MVP&amp;nbsp;renewal&amp;nbsp;date too. I forgot it totally.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-Y069Z1JPzUM/TwDGwKYts6I/AAAAAAAAD7M/646OpBbiuj8/s1600/Ive-Been-Awarded-Microsoft-MVP-For-Second-Time-600x242.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="129" src="http://2.bp.blogspot.com/-Y069Z1JPzUM/TwDGwKYts6I/AAAAAAAAD7M/646OpBbiuj8/s320/Ive-Been-Awarded-Microsoft-MVP-For-Second-Time-600x242.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I opened my Mobile, browsed to my account and saw, I have got a mail from MVP Award Team.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;"&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;"&gt;Dear Abhishek Sur,&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;" /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;"&gt;Congratulations! We are pleased to present you with the 2012 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in Client App Dev technical communities during the past year.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;" /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;"&gt;The Microsoft MVP Award provides us the unique opportunity to celebrate and honor your significant contributions and say "Thank you for your technical leadership."&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;" /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;"&gt;Nestor Portillo&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;"&gt;Director&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;"&gt;&lt;b&gt;Community &amp;amp; Online Support"&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: Calibri; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #222222; font-family: Calibri; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
I am really passionate about this award and I am really happy to receive this award for yet another time in Client App Dev category. This came to me as a New Years Gift. Thank you so much Microsoft for considering my activities and I want to personally thank &lt;a href="http://www.abhishekkant.net/" target="_blank"&gt;Mr. Abhishek Kant&lt;/a&gt;, as my MVP Lead, &amp;nbsp;&lt;a href="http://abhijitjana.net/" target="_blank"&gt;Abhijit Jana&lt;/a&gt;, &lt;a href="http://www.kunal-chowdhury.com/" target="_blank"&gt;Kunal Chowdhury&lt;/a&gt;, &lt;a href="http://amitbansal.net/" target="_blank"&gt;Amit Bansal&lt;/a&gt;, &lt;a href="http://debugmode.net/" target="_blank"&gt;Dhananjay Kumar&lt;/a&gt;, &lt;a href="http://blog.sqlauthority.com/" target="_blank"&gt;Pinal Dave&lt;/a&gt;, &lt;a href="http://www.amazedsaint.com/" target="_blank"&gt;Anoop Madhusudanan&lt;/a&gt; and last but not the least my own &lt;a href="http://www.kolkatageeks.com/" target="_blank"&gt;Community KolkataGeeks&lt;/a&gt; all of whom inspired me so much on my community activities. I would also like to thank the whole Microsoft Team for providing us such an opportunity to be in touch with this elite group.&lt;br /&gt;
&lt;br /&gt;
And finally thank you to all my blog readers. I feel&amp;nbsp;truly&amp;nbsp;honored&amp;nbsp;to receive such an award.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-M3Jnal2OAIc/TwDHUr78UnI/AAAAAAAAD7U/AFNiAcKtUMY/s1600/New-Year-2012-4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://2.bp.blogspot.com/-M3Jnal2OAIc/TwDHUr78UnI/AAAAAAAAD7U/AFNiAcKtUMY/s320/New-Year-2012-4.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Happy New Year to all of you. Its time to party..... .&lt;br /&gt;
&lt;br /&gt;
:)&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=e62-tQ9Y8xI:sJp_mQ4H0r4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=e62-tQ9Y8xI:sJp_mQ4H0r4:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=e62-tQ9Y8xI:sJp_mQ4H0r4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=e62-tQ9Y8xI:sJp_mQ4H0r4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=e62-tQ9Y8xI:sJp_mQ4H0r4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/e62-tQ9Y8xI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/447698324613444450/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2012/01/awarded-microsoft-mvp-in-row.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/447698324613444450?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/447698324613444450?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/e62-tQ9Y8xI/awarded-microsoft-mvp-in-row.html" title="Awarded Microsoft MVP in a row" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-Y069Z1JPzUM/TwDGwKYts6I/AAAAAAAAD7M/646OpBbiuj8/s72-c/Ive-Been-Awarded-Microsoft-MVP-For-Second-Time-600x242.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2012/01/awarded-microsoft-mvp-in-row.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYMSXc8eip7ImA9WhRXGUg.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-6953338459218754226</id><published>2011-12-27T08:53:00.000+05:30</published><updated>2011-12-27T08:53:08.972+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-27T08:53:08.972+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="tips" /><title>Daily DotNet Tips 1 year and onwards</title><content type="html">Friends,&lt;br /&gt;
&lt;br /&gt;
We are excited to celebrate 1st&amp;nbsp;Anniversary&amp;nbsp;of our site &lt;a href="http://dailydotnettips.com/" target="_blank"&gt;DailyDotnetTips &lt;/a&gt;today. It aims to share useful programming tips for .net developers.This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Here is some of the statistics :&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Founded : 27th December 2010&lt;/li&gt;
&lt;li&gt;No of Posts : 250&lt;/li&gt;
&lt;li&gt;No &lt;a href="http://www.facebook.com/DailyDotNetTips" target="_blank"&gt;facebook likes&lt;/a&gt; : 502&lt;/li&gt;
&lt;li&gt;No of participants : 7&lt;/li&gt;
&lt;li&gt;No of &lt;a href="http://twitter.com/dailydotnettips" target="_blank"&gt;Twitter &lt;/a&gt;followers : 348&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-0-AhllL0P_A/Tvk5TooJGEI/AAAAAAAAD64/lNLVsMCUi2w/s1600/402700_287720581280834_149132408472986_876037_898308886_n.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="466" src="http://2.bp.blogspot.com/-0-AhllL0P_A/Tvk5TooJGEI/AAAAAAAAD64/lNLVsMCUi2w/s640/402700_287720581280834_149132408472986_876037_898308886_n.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We are still a long way to go. Follow us and be a part of it.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href="http://dailydotnettips.com/" target="_blank"&gt;www.dailydotnettips.com&amp;nbsp;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=ERwlBIjbNto:IasnyvdtXPs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=ERwlBIjbNto:IasnyvdtXPs:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=ERwlBIjbNto:IasnyvdtXPs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=ERwlBIjbNto:IasnyvdtXPs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=ERwlBIjbNto:IasnyvdtXPs:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/ERwlBIjbNto" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/6953338459218754226/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/12/daily-dotnet-tips-1-year-and-onwards.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6953338459218754226?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6953338459218754226?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/ERwlBIjbNto/daily-dotnet-tips-1-year-and-onwards.html" title="Daily DotNet Tips 1 year and onwards" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-0-AhllL0P_A/Tvk5TooJGEI/AAAAAAAAD64/lNLVsMCUi2w/s72-c/402700_287720581280834_149132408472986_876037_898308886_n.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/12/daily-dotnet-tips-1-year-and-onwards.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0cHSHk_fyp7ImA9WhRTGUk.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-3473036252261382377</id><published>2011-11-10T21:31:00.001+05:30</published><updated>2011-11-10T21:33:59.747+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-10T21:33:59.747+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Metro" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows8" /><category scheme="http://www.blogger.com/atom/ns#" term="Developer Conference" /><category scheme="http://www.blogger.com/atom/ns#" term="Online Session" /><title>DEVCON – Kolkata, A New Beginning on 12th November, 2011</title><content type="html">&lt;br /&gt;
&lt;div style="background-color: white; font-family: verdana; font-size: 12px; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"&gt;
November 12th , we are getting together for a big event&amp;nbsp;&lt;a href="http://kolkatageeks.com/DevCon2011.aspx" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Developer Conference 2011&lt;/a&gt;&amp;nbsp;Organized by&amp;nbsp;&lt;a href="http://kolkatageeks.com/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Microsoft User Group Kolkata (KolkataGeeks)&lt;/a&gt;&amp;nbsp;.&amp;nbsp; Developer Conference is the premier technical event for technology professionals at Kolkata interested in learning, connecting and exploring latest Microsoft technologies.&amp;nbsp; This is also going to be community Launch event for&amp;nbsp;&lt;em style="font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Office 365&lt;/em&gt;. So be there and enjoy the flavor of cutting edge Microsoft technologies.&lt;/div&gt;
&lt;div style="background-color: white; font-family: verdana; font-size: 12px; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"&gt;
&lt;span id="more-3353" style="font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="background-color: white; font-family: verdana; font-size: 12px; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"&gt;
This is a full day event and you can attend this&amp;nbsp; event in person at&amp;nbsp;&lt;a href="http://www.bing.com/mapindia/default.aspx?v=2&amp;amp;FORM=LMLTCP&amp;amp;cp=22.544695%7E88.357726&amp;amp;style=r&amp;amp;lvl=17&amp;amp;tilt=-90&amp;amp;dir=0&amp;amp;alt=-1000&amp;amp;phx=0&amp;amp;phy=0&amp;amp;phscl=1&amp;amp;cid=BAFA39A62A57009C%21762&amp;amp;encType=1" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;Bharatiya Bhasha Parisad&amp;nbsp;&lt;/a&gt;36A, Shakespeare Sarani, 4th Floor&amp;nbsp; Kolkata – 700017.&amp;nbsp; Overall there are 7 different sessions which primarily focused on latest Microsoft Technologies.&amp;nbsp; .&amp;nbsp; Check the&amp;nbsp;&lt;a href="http://kolkatageeks.com/DevCon2011.aspx" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Dev Con&lt;/a&gt;&amp;nbsp;Web Site for more information.&lt;/div&gt;
&lt;div style="background-color: white; font-family: verdana; font-size: 12px; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"&gt;
I’ll be presenting on “&lt;em style="font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Windows 8 Metro Style Application&lt;/em&gt;“.&amp;nbsp; In this session I will talk about latest Windows release and how you can get best out of it through your Metro Style applications. There will be lots of demo in this session.&amp;nbsp;&lt;/div&gt;
&lt;div style="background-color: white; font-family: verdana; font-size: 12px; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"&gt;
Check out session details and agenda from here&amp;nbsp;&lt;a href="http://kolkatageeks.com/DevCon2011.aspx" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" title="http://kolkatageeks.com/DevCon2011.aspx"&gt;http://kolkatageeks.com/DevCon2011.aspx&lt;/a&gt;&amp;nbsp;.&amp;nbsp; You can register for this event over here&amp;nbsp;&amp;nbsp;&lt;a href="http://kolkatageeks.com/DevCon2011/Register.aspx" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" title="http://kolkatageeks.com/DevCon2011/Register.aspx"&gt;http://kolkatageeks.com/DevCon2011/Register.aspx&lt;/a&gt;&lt;/div&gt;
&lt;div style="background-color: white; font-family: verdana; font-size: 12px; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"&gt;
See you there !&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=eXd_qrug-tI:Vw-hfeg_6uE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=eXd_qrug-tI:Vw-hfeg_6uE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=eXd_qrug-tI:Vw-hfeg_6uE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=eXd_qrug-tI:Vw-hfeg_6uE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=eXd_qrug-tI:Vw-hfeg_6uE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/eXd_qrug-tI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/3473036252261382377/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/11/devcon-kolkata-new-beginning-on-12th.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/3473036252261382377?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/3473036252261382377?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/eXd_qrug-tI/devcon-kolkata-new-beginning-on-12th.html" title="DEVCON – Kolkata, A New Beginning on 12th November, 2011" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/11/devcon-kolkata-new-beginning-on-12th.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QNSX0-fSp7ImA9WhRTEE8.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-701057140440559889</id><published>2011-10-31T06:06:00.001+05:30</published><updated>2011-10-31T06:06:38.355+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-31T06:06:38.355+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Metro" /><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="WinRT" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows8" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.5" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><title>Layout adjustments Snapping and OrientationChanges in Metro Applications</title><content type="html">If you have read &lt;a href="http://www.abhisheksur.com/2011/10/understanding-basic-winrt-metro.html"&gt;my first article on Windows 8 metro styled application&lt;/a&gt;, you might already know about the working principle of it. I have talked about the capabilities for an application and settings which end user can configure for an application. In this post I will take a look at the basic layout structure that one needs to follow while creating an application in WinRT Metro styles so that it is best suited to perform well.&lt;br /&gt;
&lt;br /&gt;
Layout is the most important part of any application. The best design for an application gets more credit and love from the users than applications that are designed bad. Metro style applications runs in full screen. Your application does not include a &amp;nbsp;Title Bar, status bar or anything. Microsoft gave us some of the basic layout guidelines that one needs to follow. Lets talk about them here to make you understand how you should layout your application in Metro Applications to utilize maximum flexibility of it.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
Lets start defining a layout and explain each section.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="LayoutSample.MainPage"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:d&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/expression/blend/2008"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:mc&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;/span&gt;
    &lt;span class="attr"&gt;mc:Ignorable&lt;/span&gt;&lt;span class="kwrd"&gt;="d"&lt;/span&gt;
    &lt;span class="attr"&gt;Loaded&lt;/span&gt;&lt;span class="kwrd"&gt;="UserControl_Loaded"&lt;/span&gt;
    &lt;span class="attr"&gt;d:DesignHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="768"&lt;/span&gt; &lt;span class="attr"&gt;d:DesignWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="1366"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="LayoutRoot"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF0C0C0C"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="Auto"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="320"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="Auto"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Rectangle&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="rctSpacerLeft"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="120"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="brdHeader"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="140"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Left"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="My Basic Layout"&lt;/span&gt;
                       &lt;span class="attr"&gt;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;="40"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ListBox&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="lstBasicItems"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;
                 &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ListBox.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt; &lt;span class="attr"&gt;Orientation&lt;/span&gt;&lt;span class="kwrd"&gt;="Vertical"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Name}"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Description}"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Left"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;DataTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ListBox.ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ListBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="grdLayoutRight"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;DataContext&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding ElementName=lstBasicItems, Path=SelectedItem}"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="Auto"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="Auto"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;="14"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBox&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Name}"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Description"&lt;/span&gt; &lt;span class="attr"&gt;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;="14"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBox&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding Description}"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
This is a basic layout of an application which shows a list of data in the left hand side in a ListBox and the Right hand side shows few textboxes to edit the data.&amp;nbsp;Following the convension, each application should have a left margin of 120 px. In this layout the First Column of the LayoutRoot grid is specified Auto. Auto indicates that the portion of the screen will be sized to content. In this section I specified a Rectangle with width 120px.&lt;br /&gt;
Again the Application needs to have a Heading. I have specified the heading in the First Row of the Grid. The ListBox is taken as 320px, this is because when the application is snapped, it takes 320px of size based on the design resolution. The Grid is *(star) Sized, hence it will adjust the size based on the available space.&lt;br /&gt;
&lt;br /&gt;
Now if you run this code, you will see something like this :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-iIy2K9rNUwE/Tq3j0EhpOzI/AAAAAAAAD50/gwpbZP32UYo/s1600/Fill.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-iIy2K9rNUwE/Tq3j0EhpOzI/AAAAAAAAD50/gwpbZP32UYo/s1600/Fill.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Here the ListBox takes 320 px of size and the Grid takes the rest of the available space. Now if you snap the application with another application, it will not adjust the size automatically. Lets write code so that it does.&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; MainPage()
{
    InitializeComponent();
    var currentView = ApplicationLayout.GetForCurrentView();
    currentView.LayoutChanged += &lt;span class="kwrd"&gt;new&lt;/span&gt; TypedEventHandler&amp;lt;ApplicationLayout, ApplicationLayoutChangedEventArgs&amp;gt;(currentView_LayoutChanged);
}

&lt;span class="kwrd"&gt;void&lt;/span&gt; currentView_LayoutChanged(ApplicationLayout sender, ApplicationLayoutChangedEventArgs args)
{
    &lt;span class="kwrd"&gt;switch&lt;/span&gt; (args.Layout)
    {
        &lt;span class="kwrd"&gt;case&lt;/span&gt; ApplicationLayoutState.Filled:
        &lt;span class="kwrd"&gt;case&lt;/span&gt; ApplicationLayoutState.FullScreen:
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.rctSpacerLeft.Visibility = Windows.UI.Xaml.Visibility.Visible;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.brdHeader.Visibility = Windows.UI.Xaml.Visibility.Visible;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
        &lt;span class="kwrd"&gt;case&lt;/span&gt; ApplicationLayoutState.Snapped:
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.rctSpacerLeft.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.brdHeader.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            &lt;span class="kwrd"&gt;break&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;br /&gt;
So here you can see I have made the rctSpacerLeft and brdHeader visible only when the state of the application is Filled (that means when some other application is snapped with the application) or when the application is FullScreen (that means when the whole application is showed up). But these elements need to be Collapsed whenever the application is in Snapped mode(when the current application is snapped).&lt;br /&gt;
&lt;br /&gt;
You should already know, basically applications has 3 states. One when the size of the application is 320px long (called snapped ), when the application is filled most of the space just leaving 320px of the entire screen for some other application or when the application is full screen.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-PI0Pod8U6oA/Tq3lI7Enp0I/AAAAAAAAD58/7CX2INchrSE/s1600/filled.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-PI0Pod8U6oA/Tq3lI7Enp0I/AAAAAAAAD58/7CX2INchrSE/s1600/filled.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
In the above image, I have just snapped the Tweet@rama that comes preinstalled with Windows 8. You can see the Grid is sized smaller than the previous one sharing the the 320 px of the entire screen to the other application. &amp;nbsp;Here the Margin is kept intact.&lt;br /&gt;
&lt;br /&gt;
But when the current application is snapped state, we need to show the entire thing in 320px. So the application needs to adjust itself to be meaningful to the User.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-UA3bG5i0vKk/Tq3lwxUWDcI/AAAAAAAAD6E/fycQEOCd2cs/s1600/snapped.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-UA3bG5i0vKk/Tq3lwxUWDcI/AAAAAAAAD6E/fycQEOCd2cs/s1600/snapped.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
When I snap the current application with Tweet@rama, you can see, it removes the header, the spacer margin and the Grid that is auto sized.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Responding to Rotation&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Responding to Ration of the device is another important consideration that you should always keep in mind while designing a Metro styled application. To know the Native Orientation of the device when the application gets started, you can use the DisplayProperties.CurrentOrientation property.&lt;br /&gt;
&lt;br /&gt;
Lets modify the code to show the Orientation of current device in header. By default the orientation is Landscape.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-FR0HmQloVr8/Tq3pVxqdabI/AAAAAAAAD6M/pDL9s1YAvpw/s1600/orientation.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-FR0HmQloVr8/Tq3pVxqdabI/AAAAAAAAD6M/pDL9s1YAvpw/s1600/orientation.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The above image shows up the current Orientation of the device. Lets edit the xaml a bit to introduce it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="brdHeader"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="140"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Left"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt;
                 &lt;span class="attr"&gt;FontSize&lt;/span&gt;&lt;span class="kwrd"&gt;="40"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Run&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="My Basic Layout"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Run&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="runOrientation"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
I have added a couple of Run statement to allow changing the Orientation text in one particular Run block inside the TextBlock. Now lets handle the OrientationChanged Event of DisplayProperties to get the current Orientation. To do this lets add this code : 
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; MainPage()
{
    InitializeComponent();
    var currentView = ApplicationLayout.GetForCurrentView();

    currentView.LayoutChanged += &lt;span class="kwrd"&gt;new&lt;/span&gt; TypedEventHandler&amp;lt;ApplicationLayout, ApplicationLayoutChangedEventArgs&amp;gt;(currentView_LayoutChanged);

    DisplayProperties.OrientationChanged += &lt;span class="kwrd"&gt;new&lt;/span&gt; DisplayPropertiesEventHandler(DisplayProperties_OrientationChanged);
}

&lt;span class="kwrd"&gt;void&lt;/span&gt; DisplayProperties_OrientationChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender)
{
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.WriteOrientation();
}
&lt;span class="kwrd"&gt;void&lt;/span&gt; WriteOrientation()
{
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.runOrientation.Text = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;" ({0})"&lt;/span&gt;, DisplayProperties.CurrentOrientation);
}&lt;/pre&gt;
Here we initialize the new event handler for &lt;b&gt;OrientationChanged &lt;/b&gt;in constructor of MainPage, which will call the event whenever the orientation of the device is changed. &lt;b&gt;DisplayProperties &lt;/b&gt;also lists many other display related properties like &lt;b&gt;ColorProfileChanged&lt;/b&gt;, &lt;b&gt;LogicalDpiChanged &lt;/b&gt;etc but they are rarely needed. You can read&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.display.displayproperties"&gt; them from here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="https://skydrive.live.com/embedicon.aspx/.Public/LayoutSample.zip?cid=bafa39a62a57009c&amp;amp;sc=documents"&gt;Download Sample Project&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To write a general purpose application, it is very important that your application maintains proper layout when the device changes its size or shape. The objective of the post is to get you through understanding how you could form a good layout for your application. I hope you have already got the basics of how to layout the application in Metro Environments.&lt;br /&gt;
&lt;br /&gt;
I hope this post helped you.&lt;br /&gt;
&lt;br /&gt;
Thank you for reading.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=n2QhYadnCh0:xneUICFQodU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=n2QhYadnCh0:xneUICFQodU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=n2QhYadnCh0:xneUICFQodU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=n2QhYadnCh0:xneUICFQodU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=n2QhYadnCh0:xneUICFQodU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/n2QhYadnCh0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/701057140440559889/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/10/layout-adjustments-snapping-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/701057140440559889?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/701057140440559889?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/n2QhYadnCh0/layout-adjustments-snapping-and.html" title="Layout adjustments Snapping and OrientationChanges in Metro Applications" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-iIy2K9rNUwE/Tq3j0EhpOzI/AAAAAAAAD50/gwpbZP32UYo/s72-c/Fill.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/10/layout-adjustments-snapping-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQFSHc_cCp7ImA9WhdaGUg.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-7249585573269021996</id><published>2011-10-30T06:47:00.000+05:30</published><updated>2011-10-30T12:01:59.948+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-30T12:01:59.948+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Metro" /><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="WinRT" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows8" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.5" /><category scheme="http://www.blogger.com/atom/ns#" term="Geolocator" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><title>Understanding basic WinRT Metro Applications and Application Capabilities</title><content type="html">Just about a month ago, WinRT was introduced with all new style of application development that can work better with Multi Touch Enabled devices. We call it as Metro Applications. In this post, I will discuss how to develop your first metro applications and how to work with its layout changes.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;How to Start&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Before we start talking directly about Metro Style application, let us see how to install it first. I refer to use OracleVM which you can find for &lt;a href="http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html"&gt;free from this link&lt;/a&gt;, and install. &amp;nbsp;This will install a Virtual Machine in which you can install the Developer Preview of Windows 8.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
After your Virtual Machine is ready download &lt;a href="http://wdp.dlws.microsoft.com/WDPDL/9B8DFDFF736C5B1DBF956B89D8A9D4FD925DACD2/WindowsDeveloperPreview-64bit-English-Developer.iso"&gt;Windows 8 Developer Preview from this link&lt;/a&gt;. Remember you need to install Windows Developer Preview with Developer Tools 64 Bit which is 4.8GB in size if you are willing to develop Metro Style Application. If you have something else, you do not have option than install it again. ( I have lost several hours trying on other windows previews). If you are having problems while installing Windows 8 in your Virtual Box, please follow the steps mentioned here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After you install Windows 8 in your virtual machine please make sure you change the resolution to something above 1152. It is important because anything below this will turn of certain things. You cannot open Metro Apps or you cannot apply Partial fill settings of your application when the resolution is below this range. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Another Important consideration&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
You must remember, Metro application does not support closing the application, at least now. Hence if you start a new application the other application will keep on running in background. &amp;nbsp;You can switch back to that by hovering the left hand side of the screen and dragging back to the working area. Shortcut to do this is Windows + Tab. &amp;nbsp;The only way to close is either using an explicit close button from the application itself, or using Alt + F4 &amp;nbsp;key from the keyboard.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;The Desktop Tile&lt;/span&gt;&lt;br /&gt;
Metro application is designed in such a way that the tiles are capable of update itself and it is easier to work with them using your hand. But like me most of the people might want the desktop on which we are all familiar of in windows. Yes Metro has a Tile called Desktop Tile that can present you with the very old Desktop with applications that are meant to run in desktop. &amp;nbsp;You can move back and forth to this Desktop tile when you want.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-chrvy2fsTMQ/TqyQpKl68CI/AAAAAAAAD5E/9f8_KldrnsQ/s1600/winrt.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="304" src="http://1.bp.blogspot.com/-chrvy2fsTMQ/TqyQpKl68CI/AAAAAAAAD5E/9f8_KldrnsQ/s640/winrt.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
So the one that is marked represents the Desktop Tile. You can also see Visual Studio and other developer tools appear in the same picture as Tile. The Visual Studio Express will help you build your first metro applications.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Application Store&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Application store is another important point to note for Metro style application. After you package a metro style application you need to publish it and upload it to Application Store with all the important information of it clearly. The user that needs the application should connect to the application store and download the same. This way the user is always aware of what he is downloading and what the application does.&lt;br /&gt;
&lt;br /&gt;
Now as you know much about Metro applications, lets start writing one metro application.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;What are Capabilities?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Just like Silverlight or Windows Phone, Metro applications run in a very constrained mode. That means when you install the metro application you should provide the entire rules which the application should follow. That is to say if you do not specify that the application needs internet access to run the application, you would not get it from the application either. Hence Capabilities are defined set of rules that govern the application to access certain functionalities that application needs. &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-JkmL_yHlLIs/TqyS81DfNlI/AAAAAAAAD5M/qeyQp8gbuc8/s1600/capabilities.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="450" src="http://1.bp.blogspot.com/-JkmL_yHlLIs/TqyS81DfNlI/AAAAAAAAD5M/qeyQp8gbuc8/s640/capabilities.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
When you create a blank application in Visual Studio, you will see a appmanifest file that exists for each application. It is nothing but an XML file where you need to specify capabilities, Application related metadata etc. You can easily open that file in XML editor and add Capabilities like below :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Capabilities&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Capability&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="internetClient"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Capabilities&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
But you dont need to. If you double click on the File Package.appmanifest, you can edit to add Capabilities from a list of Capabilities that are commonly used. For instance Internet is checked by default. Lets add Location in this list. Location will allow you to get Latitude/Longitude information of the device.&lt;br /&gt;
&lt;br /&gt;
When you run an application, it deploys the application automatically to metro application without the need of Application store. Hence you dont need to wait until the application store approves your application to run. &amp;nbsp;This is called as side loading which the end user cannot do as it is&amp;nbsp;explicitly&amp;nbsp;restricted to Visual Studio. Now if you run your application, you will see a blank black screen appear after the initial flash screen.&lt;br /&gt;
&lt;br /&gt;
Lets run the project and swipe the application by hand to see some settings. You can also hover over the left hand bottom of your application to open the same settings or use Windows + I.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-GY2XhAKbCd4/TqyXs9BKsfI/AAAAAAAAD5U/cJojEZfhSkk/s1600/settings.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="490" src="http://1.bp.blogspot.com/-GY2XhAKbCd4/TqyXs9BKsfI/AAAAAAAAD5U/cJojEZfhSkk/s640/settings.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Here you can see some standard settings that appear on the bottom of the sidebar. The Application information is also specified in the top of the side bar. And a special link which indicates the application capabilities. &amp;nbsp;Lets click on it to see which capabilities are there for me.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-LiJFe3NkqkE/TqyYOJKhBKI/AAAAAAAAD5c/TTd-h731j4g/s1600/capabilities1.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-LiJFe3NkqkE/TqyYOJKhBKI/AAAAAAAAD5c/TTd-h731j4g/s1600/capabilities1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
I have asked for Location, Proximity and Internet access, and hence it shows up in this list. &amp;nbsp;You can see there is one additional settings called Location listed as Off above the list.&lt;br /&gt;
&lt;br /&gt;
Certain features needs explicit access by the user when the application request it. Location is taken as sensitive capability, and hence it will again ask the user to enable it when you first call it and the user has the option to block this too.&lt;br /&gt;
&lt;br /&gt;
Now lets write some code to access the Location and see what happens to the application.&lt;br /&gt;
&lt;br /&gt;
We add some basic XAML to the application which adds one TextBlock and one Button. So when the Button is clicked the Textblock updates the current location of the device.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lets see how xaml looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="Metro1SimpleApp.MainPage"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:d&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/expression/blend/2008"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:mc&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;/span&gt;
    &lt;span class="attr"&gt;mc:Ignorable&lt;/span&gt;&lt;span class="kwrd"&gt;="d"&lt;/span&gt;
    &lt;span class="attr"&gt;Loaded&lt;/span&gt;&lt;span class="kwrd"&gt;="UserControl_Loaded"&lt;/span&gt;
    &lt;span class="attr"&gt;d:DesignHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="768"&lt;/span&gt; &lt;span class="attr"&gt;d:DesignWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="1366"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="LayoutRoot"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="#FF0C0C0C"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="120"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="120"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt; &lt;span class="attr"&gt;Orientation&lt;/span&gt;&lt;span class="kwrd"&gt;="Vertical"&lt;/span&gt;  &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="txtLocation"&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Your Current Location is : "&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;="Button_Click"&lt;/span&gt; &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;="Update Location"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;StackPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
Here the code adds one TextBlock and a Button that acts just like regular controls. If you try to know from inside these controls are wrappers to WinRT controls. &amp;nbsp;Now the Button has a Click Handler defined and the UserControl also defines the Loaded event handler.&lt;br /&gt;
&lt;br /&gt;
Now lets write code for those handlers :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; async &lt;span class="kwrd"&gt;void&lt;/span&gt; Button_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
{
    await UpdateGeoLocationAsync();
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; async &lt;span class="kwrd"&gt;void&lt;/span&gt; UserControl_Loaded(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
{
    await UpdateGeoLocationAsync();
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; async Task UpdateGeoLocationAsync()
{
    Geolocator location = &lt;span class="kwrd"&gt;new&lt;/span&gt; Geolocator();
    Geoposition position = await location.GetGeopositionAsync();

    &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtLocation.Text = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Your current position is :({0}, {1} "&lt;/span&gt;, position.Coordinate.Latitude, position.Coordinate.Longitude);
}&lt;/pre&gt;
&lt;br /&gt;
Geolocator is an WinRT API that calls for a GeoPosition either by using&amp;nbsp;satellite&amp;nbsp;position (if appropriate sensor is found in the device) or using internet address of the IP. Now this is slow API and hence WinRT allows you to only invoke asynchoronous call to this api. We use the new async support here to call the API.&lt;br /&gt;
&lt;br /&gt;
If you dont know about async, &lt;a href="http://www.codeproject.com/KB/cs/async.aspx"&gt;please read my article&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
We add the contextual await to call from both the UserControl.Loaded and Button.Click event handlers.&lt;br /&gt;
&lt;br /&gt;
When I run the application, it will first ask to unblock the Location API. I have already told you, the location API is taken as sensitive and hence you as an user for the application have the settings to block and unblock. &amp;nbsp;You will see something like below :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-JTFeOJmaYZY/TqyiQBi94RI/AAAAAAAAD5k/5F1LPve5aJo/s1600/allowcapability.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="382" src="http://2.bp.blogspot.com/-JTFeOJmaYZY/TqyiQBi94RI/AAAAAAAAD5k/5F1LPve5aJo/s640/allowcapability.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Thus it asks to turn on location service. If you allow then only the application can get Location data. Lets allow it, you will see the location is updated.&lt;br /&gt;
&lt;br /&gt;
If you are moving, you can click on the Button on the application to update your location when needed.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-apIvBVa6Mn4/Tqyi1i97S2I/AAAAAAAAD5s/ne6_ctmK9R8/s1600/capability3.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-apIvBVa6Mn4/Tqyi1i97S2I/AAAAAAAAD5s/ne6_ctmK9R8/s1600/capability3.PNG" /&gt;&lt;/a&gt;Now after you unblock the location API for the first time, if you go to settings, you will see the Location capability is now enabled for you. You can turn on or off whenever you want.&lt;br /&gt;
&lt;br /&gt;
To run on or off, you can drag the button to the right or left.&lt;br /&gt;
&lt;br /&gt;
You can &lt;a href="https://skydrive.live.com/embedicon.aspx/.Public?cid=bafa39a62a57009c&amp;amp;sc=documents"&gt;download the sample from here.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Even though for a developer coming from normal Windows application it may seem to you as weird to have such kind of security enabled for your application, but world is moving towards it and this will benefit the end user to have clear knowledge about what the application is capable of. Hence it adds up security to the whole system. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
This is still very early stage of WinRT to talk about. There may be some amount of changes in final release of it. But yet it is good to learn about it. I hope you like my post. I will update with more posts on WinRT metro application in near future.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=jgmZs1x_nC8:sBL6MCT6ZxU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=jgmZs1x_nC8:sBL6MCT6ZxU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=jgmZs1x_nC8:sBL6MCT6ZxU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=jgmZs1x_nC8:sBL6MCT6ZxU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=jgmZs1x_nC8:sBL6MCT6ZxU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/jgmZs1x_nC8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/7249585573269021996/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/10/understanding-basic-winrt-metro.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/7249585573269021996?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/7249585573269021996?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/jgmZs1x_nC8/understanding-basic-winrt-metro.html" title="Understanding basic WinRT Metro Applications and Application Capabilities" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-chrvy2fsTMQ/TqyQpKl68CI/AAAAAAAAD5E/9f8_KldrnsQ/s72-c/winrt.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/10/understanding-basic-winrt-metro.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8DRH47eSp7ImA9WhdaEUg.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-4682476537647830506</id><published>2011-10-21T06:31:00.000+05:30</published><updated>2011-10-21T06:31:15.001+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-21T06:31:15.001+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.5" /><category scheme="http://www.blogger.com/atom/ns#" term="Patterns" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Regex" /><title>Regular Expressions with Timeout in .NET 4.5</title><content type="html">.NET 4.5 Developer preview is out with Visual Studio 2011. I was already thinking to try &lt;a href="http://msdn.microsoft.com/en-us/library/ms171868%28v=VS.110%29.aspx"&gt;out what's new in .NET 4.5 myself&lt;/a&gt; and share what exactly been changed.&lt;br /&gt;
&lt;br /&gt;
Lets start by the new Regex Api introduced with the framework. The improvement that has been made is minor yet handy at certain cases. The Regex class of .NET 4.5 supports Timeout. Lets take a look how to work with it.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&amp;nbsp;Lets try to write a simplest RegEx validator to look into it. 

&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;
{
    Regex regexpr = &lt;span class="kwrd"&gt;new&lt;/span&gt; Regex(&lt;span class="str"&gt;"[A-Z ]{10}"&lt;/span&gt;, RegexOptions.Singleline, TimeSpan.FromMilliseconds(1));
    Match mch = regexpr.Match(&lt;span class="str"&gt;"ABHISHEK SUR"&lt;/span&gt;);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (mch.Success)
        Console.WriteLine(&lt;span class="str"&gt;"Match found"&lt;/span&gt;);
    &lt;span class="kwrd"&gt;else&lt;/span&gt;
        Console.WriteLine(&lt;span class="str"&gt;"Not matched"&lt;/span&gt;);

}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (RegexMatchTimeoutException ex)
{
    Console.WriteLine(&lt;span class="str"&gt;"Regex Timeout for {1} after {2} elapsed. Tried pattern {0}"&lt;/span&gt;, ex.Pattern, ex.Message, ex.MatchTimeout);
}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (ArgumentOutOfRangeException ex)
{
    Console.WriteLine(ex.ToString());
}
&lt;span class="kwrd"&gt;finally&lt;/span&gt;
{
    Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);
}&lt;/pre&gt;
&lt;br /&gt;
Here in the code you can see I simply check a string with a Regular expression. It eventually finds success as Pattern matches the string. Now this code is little different than what we have been doing for last few years. The constructor overload of Regex now supports a Timespan seed, which indicates the timeout value after which the Regular expression validator would automatically generate a RegexMatchTimeoutException. The Match defined within the Regex class can generate timeout after a certain time exceeds.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;You can specify &lt;b&gt;Regex.InfiniteMatchTimeout&lt;/b&gt; to specify that the timeout does not occur. The value of &lt;b&gt;InfiniteMatchTimeout &lt;/b&gt;is -1ms internally and you can also use Timespan.Frommilliseconds(-1) as value for timespan which will indicate that the Regular expression will never timeout which being the default behavior of our normal Regex class.

Regex also supports AppDomain to get default value of the Timeout. You can set timeout value for &lt;b&gt;"REGEX_DEFAULT_MATCH_TIMEOUT"&lt;/b&gt; in AppDomain to set it all the way through the Regular expressions being used in the same &lt;b&gt;AppDomain&lt;/b&gt;. 

Lets take a look how it works.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;
{
    AppDomain.CurrentDomain.SetData(&lt;span class="str"&gt;"REGEX_DEFAULT_MATCH_TIMEOUT"&lt;/span&gt;, TimeSpan.FromMilliseconds(2));

    Regex regexpr = &lt;span class="kwrd"&gt;new&lt;/span&gt; Regex(&lt;span class="str"&gt;"[A-Z ]{10}"&lt;/span&gt;, RegexOptions.Singleline);
    Match mch = regexpr.Match(&lt;span class="str"&gt;"ABHISHEK SUR"&lt;/span&gt;);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (mch.Success)
        Console.WriteLine(&lt;span class="str"&gt;"Match found"&lt;/span&gt;);
    &lt;span class="kwrd"&gt;else&lt;/span&gt;
        Console.WriteLine(&lt;span class="str"&gt;"Not matched"&lt;/span&gt;);

}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (RegexMatchTimeoutException ex)
{
    Console.WriteLine(&lt;span class="str"&gt;"Regex Timeout for {1} after {2} elapsed. Tried pattern {0}"&lt;/span&gt;, ex.Pattern, ex.Message, ex.MatchTimeout);
}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (ArgumentOutOfRangeException ex)
{
    Console.WriteLine(ex.ToString());
}
&lt;span class="kwrd"&gt;finally&lt;/span&gt;
{
    Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);
}&lt;/pre&gt;
Now this works exactly the same as the previous one. Here the Regex constructor automatically checks the AppDomain value and applies it as default. If it is not present, it will take -1 as default which is Infinite TImeout and also if explicitely timeout is specified after the default value from AppDomain, the Regex class is smart enough to use the explicitly set value only to itself for which it is specified. 

The Regex Constructor generates a TypeInitializationException if appdomain value of Timespan is invalid. 

Lets check the internal structure. 

&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-7CG8JM_N3bY/TqDB9x3zo7I/AAAAAAAAD4c/wWqiDn4ky64/s1600/timeoutregex.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-7CG8JM_N3bY/TqDB9x3zo7I/AAAAAAAAD4c/wWqiDn4ky64/s1600/timeoutregex.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
This is the actual code that runs in background and generates the timeouts. Infact while scanning the string with the pattern, there is a call to CheckTimeout which checks whether the time specified is elapsed for the object. The CheckTimeout throws the exception from itself.&lt;br /&gt;
&lt;br /&gt;
The Constructor sets DefaultMatchTimeout when the object is created taking it from AppDomain data elements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you read MSDN thoroughly, it suggests to use Timeouts when specifying the Regular expressions. If the pattern is supplied from external or you are not sure about the pattern that needs to be applied to the string, it is always recommended to use Timeouts. Basically you should also specify a rational limit of AppDomain regex default to ensure no regular expression can ever hang your application.&lt;br /&gt;
&lt;br /&gt;
This is a small tip on the new Regex enhancements introduced with .NET 4.5 recently. &amp;nbsp;I hope you like it. More to come shortly, stay tune.&lt;br /&gt;
&lt;br /&gt;
Thank you for reading&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=3gMfZcUvc5o:TbCUw55hQdU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=3gMfZcUvc5o:TbCUw55hQdU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=3gMfZcUvc5o:TbCUw55hQdU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=3gMfZcUvc5o:TbCUw55hQdU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=3gMfZcUvc5o:TbCUw55hQdU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/3gMfZcUvc5o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/4682476537647830506/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/10/regular-expressions-with-timeout-in-net.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/4682476537647830506?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/4682476537647830506?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/3gMfZcUvc5o/regular-expressions-with-timeout-in-net.html" title="Regular Expressions with Timeout in .NET 4.5" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-7CG8JM_N3bY/TqDB9x3zo7I/AAAAAAAAD4c/wWqiDn4ky64/s72-c/timeoutregex.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/10/regular-expressions-with-timeout-in-net.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D08NQ3s8eSp7ImA9WhdUGUk.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-1202276433845520074</id><published>2011-10-07T05:34:00.001+05:30</published><updated>2011-10-07T05:34:52.571+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-07T05:34:52.571+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="tips" /><category scheme="http://www.blogger.com/atom/ns#" term="Reflection" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><title>Generic Types and Static Members</title><content type="html">One of my friend recently asked me a question that I think I should share with you. Say you have a Static Implementation of a Type T which you pass as Open Type in your Generic Class. Now the problem is how to get reference to the Static Members or invoke a method that is Static to the Type from the Open Type T. &amp;nbsp;In this post, I will demonstrate few implementations that help you getting the Static implementation.&lt;br /&gt;
&lt;br /&gt;
First of all, According to C# documentation, any type allocates its static members once per Type rather than once per Open Type. Now lets define this using the code below :&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyType&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Counter;
    &lt;span class="kwrd"&gt;static&lt;/span&gt; MyType()
    {
        Counter = 0;
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; MyType()
    {
        Counter++;
    }
}&lt;/pre&gt;
&lt;br /&gt;
Here this is actually a Generic Type that keeps track &amp;nbsp;of the count of objects that per type creates. The Type instance here MyType&amp;lt;T&amp;gt; is called Open Type and can take form of any Type. &amp;nbsp;Now lets create object of MyType.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;MyType&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; ss = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyType&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();
ss = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyType&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();
ss = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyType&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();
MyType&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; oo = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyType&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;();
oo = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyType&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;();
oo = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyType&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;();

Console.WriteLine(MyType&amp;lt;string&amp;gt;.Counter);

Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
Now we create 3 instance of string and 3 of Object. Thus the Console.WriteLine should show 6, right? .... Wrong.. Actually we here create two types using Generic Type MyType, one is MyType&amp;lt;string&amp;gt; and another is MyType&amp;lt;object&amp;gt;. So here MyType generates its own closed type and each of the type creates its Type interface when first instance of the object is called for, or rather when the Static constructor is called.&lt;br /&gt;
&lt;br /&gt;
Thus if I call MyType&amp;lt;X&amp;gt;.Counter it will show 0 and will create a new Type and call the Static constructor immediately.&lt;br /&gt;
&lt;br /&gt;
Now this is very easy here to call static members of a Generic type, but what if we want to call Static member of the Type we pass into as Generic Argument. Lets see...&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyType
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Try2CalMe()
    {
        Console.WriteLine(&lt;span class="str"&gt;"Wow. You finally called me!"&lt;/span&gt;);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallMe()
    {
        Console.WriteLine(&lt;span class="str"&gt;"Called CallMe"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;br /&gt;
Lets say I have a class defined with one static method and one instance method. As I have already told you that Generic Static members create its memory when it creates it first object, the same is true for non generic types. Hence when an instance of MyType is passed within  a Generic Type as Type argument, you would already have the memory allocated for the Type. Now let us consider using this Type for our Generic Class. 
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyGenericClass&amp;lt;T&amp;gt; 
{
    T MyTObject { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InstanceMethod()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.MyTObject != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.MyTObject.CallMe();
    }
}&lt;/pre&gt;
&lt;br /&gt;
Well the line which calls CallMe leads to a problem, because the Generic Type does not have any idea about what Type it is going to take.  Say for instance if I pass int variable as T it will take  that also. Well to fix this problem we can put a constraint to Type T with a Where clause. But that doesnt solve our problem either. Even though we can call CallMe we cannot call Try2CallMe. 

There are few approaches that you can take to solve this problem.

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Working with your friend Reflection :&lt;br /&gt;&lt;br /&gt;Reflection API can call any method from a Type. You can check whether the static Method is there in the type that is passed during Runtime and if exists you can call it. Lets try to call the method using Reflection :&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyGenericClass&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : MyType
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; T MyTObject { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InstanceMethod()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.MyTObject != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.MyTObject.CallMe();

            &lt;span class="rem"&gt;//Calling static member using Reflection&lt;/span&gt;

            Type currentType = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T);
            var method = currentType.GetMethod(&lt;span class="str"&gt;"Try2CalMe"&lt;/span&gt;, BindingFlags.Static | BindingFlags.Public);
            &lt;span class="kwrd"&gt;if&lt;/span&gt;(method != &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="rem"&gt;// Method exists&lt;/span&gt;
                method.Invoke(&lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;); &lt;span class="rem"&gt;//We pass null as object for static member&lt;/span&gt;

        }
    }
}&lt;/pre&gt;
&lt;br /&gt;
So here we first pass MyType as constraint (even though it makes the type strict to inherited members of MyType) and calling the member using Reflection. Yes, it can call it absolutely.&lt;/li&gt;
&lt;li&gt;Putting it in intermediate Abstract base class:

&lt;br /&gt;&lt;br /&gt;Another option, or probably better approach is to create an intermediate abstract base class for all your types and call it. &amp;nbsp;It is another option for you and probably a better one but remember, all of your members share the same static member here.&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyAType
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Try2CalMe()
    {
        Console.WriteLine(&lt;span class="str"&gt;"Wow. You finally called me!"&lt;/span&gt;);
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallMe()
    {
        Console.WriteLine(&lt;span class="str"&gt;"Called CallMe"&lt;/span&gt;);
    }
}
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyGenericClass&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : MyAType
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; T MyTObject { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InstanceMethod()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.MyTObject != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.MyTObject.CallMe();

            &lt;span class="rem"&gt;//Calling static member Directly here&lt;/span&gt;
            MyAType.Try2CalMe();
               

        }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Here we create an abstract base class for MyType and we pass it as generic constraint. So any class that inherits from this base class can go as a Type for the class MyGenericClass and which in turn can call its static member directly. &lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
There might be some other option available and known to you. I would like you to share that with me.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I hope you like this post.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thanks.&amp;nbsp;&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=m-qEIQYKICg:C77qiKwAv5c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=m-qEIQYKICg:C77qiKwAv5c:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=m-qEIQYKICg:C77qiKwAv5c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=m-qEIQYKICg:C77qiKwAv5c:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=m-qEIQYKICg:C77qiKwAv5c:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/m-qEIQYKICg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/1202276433845520074/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/10/generic-types-and-static-members.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1202276433845520074?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1202276433845520074?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/m-qEIQYKICg/generic-types-and-static-members.html" title="Generic Types and Static Members" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/10/generic-types-and-static-members.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEQCQX09fCp7ImA9WhdUEEs.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-6070026622596817533</id><published>2011-09-26T14:53:00.000+05:30</published><updated>2011-09-27T00:09:20.364+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-27T00:09:20.364+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="internals" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Finalize" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="Patterns" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET Memory Management" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 3.5" /><category scheme="http://www.blogger.com/atom/ns#" term="Memory Allocation" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Internals of .NET Objects and Use of SOS</title><content type="html">Well, now getting deeper into the facts, lets talk about how objects are created in .NET and how type system is laid out in memory for this post in my &lt;a href="http://www.abhisheksur.com/2011/03/internals-to-net.html"&gt;Internals Series&lt;/a&gt;. &amp;nbsp;As this is going to be very deep dive post, I would recommend to read this only if you want to kill your time to know the internal details of .NET runtime and also you have considerable working experience with the CLR types and type system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Recently I have been talking with somebody regarding the actual difference between the C++ type system and managed C# type system. I fact the CLR Type system is different from the former as any object (not a value type) is in memory contains a baggage of information when laid out in memory. This makes CLR objects considerable different from traditional C++ programs.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Classification of Types&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In .NET there are mainly two kind of Types.&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Value Types (derived from System.ValueType)&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Reference &amp;nbsp;Type (derived directly from System.Object)&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Even though ValueTypes are internally inherited from System.Object in its core, but CLR treats them very differently. &amp;nbsp;Indeed from your own perception the &lt;a href="http://www.abhisheksur.com/2011/07/valuetypes-and-referencetypes-under.html"&gt;Value Types are actually allocated in stacks (occationally)&lt;/a&gt; while reference types are allocated in Heaps. This is to reduce the additional contension of GC heaps for Heap allocation, GC cycles,&amp;nbsp;occasional&amp;nbsp;call to OS for additional memory needs etc. The object that is allocated in managed Heap is called Managed Object and the pointer that is allocated in stack to refer to the actual object in heap is called &lt;b&gt;Object Reference &lt;/b&gt;(which is sometimes called as Managed Pointer).&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Additional&amp;nbsp;to this basic difference a Value Type is treated completely different from CLR point of view. CLR treats any object that is derived from System.ValueType differently in respect of any other object derived from System.Object directly. The memory of a ValueType contains just the value of its fields and the size of the Value Type is just the addition to its content, while for reference types the size is completely different. Let us consider looking at the memory layout of both the types.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-9VdXeR3S4Jw/Tn9hd19YYsI/AAAAAAAAD3o/wZoPLHrymUk/s1600/stack.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-9VdXeR3S4Jw/Tn9hd19YYsI/AAAAAAAAD3o/wZoPLHrymUk/s1600/stack.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In case of Value Types, the Managed Pointer holds reference to the initial location of the actual Memory.Thus in this case, the Managed pointer holds reference to 0x0000 which is the address location of Field 1. Hence CLR needs to do pointer arithmetic to find Fields ... N. &amp;nbsp;Thus we can easily use Sizeof operator on ValueTypes to get the actual size of the object.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The reference Types on the other hand holds some complex informations in its header.Lets define the individual blocks that comprises one object using a diagram.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-U_Akn6oAw1Q/Tn9kRz-gkDI/AAAAAAAAD3w/i4oKj_FJClc/s1600/reference1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-U_Akn6oAw1Q/Tn9kRz-gkDI/AAAAAAAAD3w/i4oKj_FJClc/s1600/reference1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In the diagram, I have depicted the entire layout of memory for a reference type. The initial Managed Pointer here for reference types holds the address of Reference to RTTI address (Run Time Type Information). The initial 4 bytes of the memory is allocated for Synchronization Block. In CLR every object holds its own lock information by itself using this storage. There is another important consideration that you need to think of, is every CLR object holds its Type&amp;nbsp;information&amp;nbsp;inside it. This ensures that every object can explain its own type from itself without any dependency from outside. Hence the reference types are Self&amp;nbsp;Explanatory&amp;nbsp;types and programs can use these&amp;nbsp;information&amp;nbsp;while casting, polymorphism, dynamic binding, reflection etc. &amp;nbsp;Even though the Method Table structure reside outside the actual object, the RTTI Address holds the initial address of the Method Table runtime object which holds all the informations regarding the Type of the object. We query the information of the Runtime Type using the GetType method from any reference Type. The .NET runtime creates a special object of Type which helps to find out the actual type information.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
On the other hand, the ValueTypes are simply a chunk of memory without any clue of what it acutally contains. This is the major difference between the two types.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
During instantiation, a valuetype automatically calls its default constructor when it is declared. You cannot define &lt;a href="http://www.abhisheksur.com/2010/10/hidden-facts-on-c-constructor-in.html"&gt;default constructor for a ValueType&lt;/a&gt;. But language (like C#) puts additional restriction to ensure that the valuetype is initialized before it is used to save additional constructor calls.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
ReferenceType on the other hand must have an object assigned to it using new operator. The new operator first allocates memory of its fields with default values and then calls the constructor.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Caveats of CLR Variables&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Value Type variable directly represents memory of a Stack.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Reference Type represents a pointer (or probably we should call it as Reference) that refer to the start location of the object produced in Heap. The reference points to RTTI address location.&lt;/li&gt;
&lt;li&gt;CPU registers can hold managed pointers as well as managed objects. Hence in certain cases, you can either store your value type or a reference to a Object in CPU registers depending on your need.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;AppDomain wide managed Table contains all the references pointing to the managed object references that are marked by GC. It also holds static ValueTypes and static Reference Types.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Implicit Object Reference (this)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
There is nothing new with "this". Any instance member have access to this pointer even though they are Value Type or a Reference. The method generally pass the object from which it is called as "this" as first argument of the call. Hence it is available inside any method. "this" pointer for ValueType points to the first instance field address location while the "this" pointer for the Reference Type points to the address of Method Table information.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;How CLR Methods are called ?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
There are two types of method being called in CLR. One with invoking &lt;b&gt;call&lt;/b&gt; IL instruction which needs the current object to be loaded in stack before any other argument passed as parameters; and other by using &lt;b&gt;CallVirt &lt;/b&gt;which is almost similar to call, but produces an additional instruction to validate the object reference. &amp;nbsp;The call statement does not produce NullReferenceException to a call to the method, but passes null as "this" pointer. But eventually if there is any instruction that requires access to its field or any other method call, it will produce NullReferenceException. CallVirt directly produces NullReferenceException prior to the call to the method when the object does not assign anything.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
When using Interface based methods, the ValueType generally needs to be boxed to produce Method Table &amp;nbsp;information so that the Virtual Methods could be called by CLR. &amp;nbsp;The Reference type does not bother to invoke callvirt which actually translates it based on the type of the runtime object rather than the original type it is called from (interface&amp;nbsp;reference).&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Delegates on the other hand is a special type that holds reference of methods. MSIL has two opcodes to deal with them, ldvirtftn that load virtually a method, and ldftn. The ldftn loads the method address into stack. &amp;nbsp;The type of the method token loaded by this IL instruction can be searched to MethodTable of the type to get the actual address of the method. Delegates generally pass the object on which the member needs to be executed as Target and the method address stored in delegate instance to invoke the method. In case of Static method call the target is apssed as null. The process of retrieving an storing address to a delegate is expensive and is called delegate binding.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Delegates are derived from a special type called System.Delegate in .NET CLR. A delegate can hold multiple methods in a chain. You can add more methods of same signature to a delegate which will be invoked sequentially by calling the last method added to it first and thereby calling the first method that is added as the final method in delegate chain. The return statement of the final method call is actually passed to the caller.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Trying out some basic debugging with Son of Strike(SOS)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Before we start SOS debugging with Visual Studio, you should recollect that there are three important data structure that you need to keep in mind.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;MethodTable &lt;/b&gt;: Stores all&amp;nbsp;information&amp;nbsp;about a Type. Holds information regarding static data, table of method descriptors, pointers to EEClass, pointers to other Methods from other VTable and pointers to Constructors.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;EEClass &lt;/b&gt;: This is almost same structure as of Method Table, but holds more static data information.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;MethodDesc &lt;/b&gt;: Information regarding a particular method such as IL or JIT'ed informations.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Now let us consider a dummy class to start debugging.&lt;/div&gt;
&lt;/div&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyClass
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; RefCounter;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; age;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; MyClass(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, &lt;span class="kwrd"&gt;int&lt;/span&gt; age)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Name = name;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Age = age;
        MyClass.RefCounter++;
    }
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; name;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; name;
        }
        set
        {
            name = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
        }
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Age
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; age;
        }
        set
        {
            age = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
        }
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GetNext(&lt;span class="kwrd"&gt;int&lt;/span&gt; age)
    {
        Console.WriteLine(&lt;span class="str"&gt;"Getting next at age"&lt;/span&gt; + age);
    }
}&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;
Here I have defined one static field, two member fields, a parameterized constructor and one instance method to start testing. We will use SOS to test instance of this code.&lt;br /&gt;
&lt;br /&gt;
So as we know already when an object is created, the memory contains an object reference to the actual object placed in heap. Hence lets create an object of it in Main.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
{
    MyClass obj = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyClass(&lt;span class="str"&gt;"Abhishek"&lt;/span&gt;, 28);
    obj.GetNext(20);
}&lt;/pre&gt;
&lt;br /&gt;
To start debugging you need to enable native debugging. To do this, Right Click on project =&amp;gt; Debug =&amp;gt; Enable unmanaged code debugging. Now put a breakpoint on the first line and step into the constructor. Lets say I go until one instance field is loaded. Now open &lt;b&gt;Intermediate Window &lt;/b&gt;and type&lt;b&gt;&amp;nbsp;.load C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\sos.dll. &lt;/b&gt;Please replace the exact location if folder structure differs.&lt;br /&gt;
&lt;br /&gt;
Now once the extension is loaded we can examine the instance of &lt;b&gt;MyClass&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
We call &amp;nbsp;!&lt;b&gt;DumpStackObjects &lt;/b&gt;to dump the object that is loaded in memory. We see something like below :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-7UOtRfJ5oQM/Tn-zjWS3WnI/AAAAAAAAD30/DZgXzQwfl0g/s1600/dumpobject.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-7UOtRfJ5oQM/Tn-zjWS3WnI/AAAAAAAAD30/DZgXzQwfl0g/s1600/dumpobject.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
These are the managed objects that are loaded into memory. Our concern is to see instance of &lt;b&gt;MyClass&lt;/b&gt;. So copy the object reference handle of the corresponding Object &amp;nbsp;of &lt;b&gt;MyClass &lt;/b&gt;( in our &amp;nbsp;case it is&amp;nbsp;00c2c1d0). Now lets use !&lt;b&gt;DumpObj&amp;nbsp;&lt;/b&gt;00c2c1d0&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-jOBVwnL-CiU/Tn-0vT12udI/AAAAAAAAD34/4B1Ry3y5ma0/s1600/dumpobj.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-jOBVwnL-CiU/Tn-0vT12udI/AAAAAAAAD34/4B1Ry3y5ma0/s1600/dumpobj.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The instruction actually dumped the entire object with the address to MethodTable, EEClass and size of the object in bytes. &amp;nbsp;You can see the size of the object in heap is 16 bytes. This is because the Objects in CLR holds more than the fields and members (like sync headers, method pointers etc.) &amp;nbsp;It also lists the fields currently in memory. You can see Value for name has an address as we execute this after the instruction line name in constructor but before age. &amp;nbsp;Now if I pass through all the lines of constructor it will show the memory address of all the members. You can use !DumpObject to play around the addresses of Name (00c2c1b0) or age or any instance member from here onwards.&lt;br /&gt;
&lt;br /&gt;
Now lets try few more commands to get interesting behaviors. There are few commands that you can try. !CLRSTACK dumps the managed code on the stack on the CurrentThread. !DumpStack on the other hand dumps both managed and native stack. Lets try !CLRStack now, the output will be like this :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-hHqiESe_kGk/Tn-4NOyf7FI/AAAAAAAAD4A/92-_nA75Wvg/s1600/clrstack2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-hHqiESe_kGk/Tn-4NOyf7FI/AAAAAAAAD4A/92-_nA75Wvg/s1600/clrstack2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
Here I have moved to the call to &lt;b&gt;GetNext &lt;/b&gt;method. Hence you can see the &lt;b&gt;GetNext &lt;/b&gt;and &lt;b&gt;Main &lt;/b&gt;in stack for the command&lt;b&gt; !CLRStack&lt;/b&gt;. With additional argument like -p -l produces the result with better output listing all the parameters passes to the method. You can see this represents the first parameter for the method &lt;b&gt;GetNext&lt;/b&gt;, as I have told you which holds the object obj (in our case).&lt;br /&gt;
&lt;br /&gt;
Similarly you can use&lt;b&gt; &lt;/b&gt;&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;b&gt;!DumpStack&lt;/b&gt; to dump both the native and managed objects and&lt;b&gt; !EEStack&lt;/b&gt; to execute &lt;b&gt;!DumpStack&lt;/b&gt; on all threads.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;To conclude,&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;This post is just the starting point of your understanding. There are lots of depth in this topic. You can try an&amp;nbsp;excellent&amp;nbsp;article on &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163791.aspx"&gt;MSDN magazine here&lt;/a&gt;, which talks more on CLR object creation. If you want to know more on internals of .NET, you can also try my &lt;a href="http://www.abhisheksur.com/2011/03/internals-to-net.html"&gt;Internal Series here&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;Thank you for reading, give your feedback.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;Stay tune for more.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=o5njP7FmoIw:mB_gI0ksllY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=o5njP7FmoIw:mB_gI0ksllY:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=o5njP7FmoIw:mB_gI0ksllY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=o5njP7FmoIw:mB_gI0ksllY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=o5njP7FmoIw:mB_gI0ksllY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/o5njP7FmoIw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/6070026622596817533/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/09/internals-of-net-objects-and-use-of-sos.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6070026622596817533?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6070026622596817533?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/o5njP7FmoIw/internals-of-net-objects-and-use-of-sos.html" title="Internals of .NET Objects and Use of SOS" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-9VdXeR3S4Jw/Tn9hd19YYsI/AAAAAAAAD3o/wZoPLHrymUk/s72-c/stack.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/09/internals-of-net-objects-and-use-of-sos.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8NQX88fip7ImA9WhdVGEg.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-5912551752591387581</id><published>2011-09-24T14:14:00.000+05:30</published><updated>2011-09-24T14:14:50.176+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-24T14:14:50.176+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="internals" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Internals of Interface and its Implementation</title><content type="html">As many of my followers requested me to write few things that I missed out from the &lt;a href="http://www.abhisheksur.com/2011/03/internals-to-net.html"&gt;Internals Series&lt;/a&gt;, I should continue with it. In this post, I will cover the internals of Interface implementation and mostly talk about explicit interface implementation, as most of the developers seems to be in confusion with it. I hope you will like the post.&lt;br /&gt;
&lt;br /&gt;
Beginning from the basics, Interfaces are the most important part of any application. Interfaces are language construct that does not implement anything but declares a few members upfront. Generally we use interfaces to create a contract between the two or more communication agents. Another important thing that everyone would be knowing already, Interfaces are meant to be implemented. That means whenever you are creating a class, all the members that were there in the interface are meant to be implemented completely. .NET (or probable any other standard language) disallows the creation of objects on types that are not fully defined. Hence abstract classes also coming into play here. They are classes that have few members undefined or abstract. Once you&amp;nbsp;don't&amp;nbsp;have concrete implementation, you cannot create an instance of a type. Notably, you can say&lt;b&gt; "Interface is a types that does not belong to the System.Object or implement it when it reside inside an assembly"&lt;/b&gt;. But ironically you could also says that once the type is implemented, it would probably inherit from System.object by default.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
Another important OOPS feature is that you can hold reference of any concrete type to any of its base implementations. By this what I mean, if say class X derived from Y and implements Z (where Z is an interface) you can say either&lt;i&gt; Y y1 = new X()&lt;/i&gt; or &lt;i&gt;Z z1 = new X().&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Now lets define an interface and start some tweaks some of its behaviors.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IA
{
    &lt;span class="kwrd"&gt;void&lt;/span&gt; GetX();
}&lt;/pre&gt;
&lt;br /&gt;
Let us suppose we have an interface IA which has a method GetX(). Now you should remember, it is not allowed to use access specifier for members of an interface as that mean the implementers of this interface needs to specify access specifiers for its members and it would appear to all implemtors that these members are public. &amp;nbsp;Now lets see one implementation of it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; A : IA
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GetX()
    {
        Console.WriteLine(&lt;span class="str"&gt;"Here is X: Normal"&lt;/span&gt;);
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; IA.GetX()
    {
        Console.WriteLine(&lt;span class="str"&gt;"Here is X: Explicitely"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;br /&gt;
A is a class which implements IA, and hence need to declare one member GetX. Now you can see here we have defined two implementation of the same method GetX. The other one is Explicit implementation of IA. &amp;nbsp;The explicit declaration of a method can only be done for Interfaces (not allowed for normal classes) and allows you to differentiate the calls to GetX to its explicit implementation when interface is used rather than a normal derived reference is used. &amp;nbsp;Hence if I call :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;A a1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; A();
a1.GetX(); &lt;span class="rem"&gt;// prints Here is X: Normal&lt;/span&gt;

IA a2 = a1;
a2.GetX(); &lt;span class="rem"&gt;//Prints Here is X: Explicitely&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
You can see here compiler replaces the call to some explicit implementation based on the reference itself.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;There are few &lt;b&gt;basic characteristics of Explictely implemented methods&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;They are not overridable and cannot be made virtual.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;They can only be called with appropriate interface name, as the methods in Vtable is not&amp;nbsp;determined&amp;nbsp;by its name but by the reference it calls for.&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;You cannot specify any access specifier for the implementation of Explicit method.}&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;They remain private and does not belong to a member of actual concrete class. For instance, if I remove the normal implementation of GetX and try calling the code below :&lt;br /&gt;
&lt;pre class="csharpcode"&gt;dynamic a1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; A();
a1.GetX();&lt;/pre&gt;
&lt;br /&gt;
It produces an exception, as A does not contain the member GetX().&lt;br /&gt;Now if we see the IL for the implementation :&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-iORNcRyLxqg/TnZxAjFnqAI/AAAAAAAAD3M/mXRQFCRhjk4/s1600/explicit.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-iORNcRyLxqg/TnZxAjFnqAI/AAAAAAAAD3M/mXRQFCRhjk4/s1600/explicit.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
So here you can see the explicit declaration defines two important attributes, viz, newslot, virtual and final.&lt;br /&gt;
&lt;br /&gt;
newslot defines a new pointer in the VTable. Thus it is a completely new method created in vtable that can only be called by reference of the interface explicitely.&lt;br /&gt;
&lt;br /&gt;
virtual : you must already know virtual means the object could be overridable at runtime.&lt;br /&gt;
final : means sealed.&lt;br /&gt;
&lt;br /&gt;
Hence it is a sealed method with a new entry in VTable.&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;They are privately inherited and can be implemented only in the class where the Interface is actually implemented, not in any of its parent. For instance :&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IA
{
    &lt;span class="kwrd"&gt;void&lt;/span&gt; GetX();
}
&lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; A : IA
{
}
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; B : A
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GetX()
    {
        ((IA)&lt;span class="kwrd"&gt;this&lt;/span&gt;).GetX();
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; IA.GetX()
    {
        Console.WriteLine(&lt;span class="str"&gt;"New Impleentation"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;br /&gt;
The above code produces an exception&lt;br /&gt;
&lt;b&gt;"Inconsistent accessibility: base class 'TestInterfaceApplication.A' is less accessible than class 'TestInterfaceApplication.B'"&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Which means the GetX() method is private to B and cannot be implemented there. &lt;br /&gt;&lt;/li&gt;
&lt;li&gt;But remember, interface inheritence is supported. Thus the code below compiles fine :&lt;br /&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IA
{
    &lt;span class="kwrd"&gt;void&lt;/span&gt; GetX();
}
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IB : IA
{
}
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; B : IB
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GetX()
    {
        ((IA)&lt;span class="kwrd"&gt;this&lt;/span&gt;).GetX();
    }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; IA.GetX()
    {
        Console.WriteLine(&lt;span class="str"&gt;"New Impleentation"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;br /&gt;This is because interface implementation is not actually possible in CLR without marking both of them in concrete class so that the Types can be cast to any of the parent interfaces. So when you specify an Interface implementation, the two interfaces remains as individual types and when you implement the derived interface, it will actually implement the two interfaces for you. Its just a compiler trick. &amp;nbsp;Lets see the IL.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-wtxrT60ck7Q/Tn2VkcMEnrI/AAAAAAAAD3k/mYFv5Hp6j00/s1600/interfaceimplementation.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-wtxrT60ck7Q/Tn2VkcMEnrI/AAAAAAAAD3k/mYFv5Hp6j00/s1600/interfaceimplementation.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
So here you can see, if I implement a Derived interface IB from IA, the actual class actually implements both the interface explicitly.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Practical uses&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Explicit interfaces are generally used when you need two implementation of same method or property to co-exist. We generally create Explicit interfaces to specify default behaviour of a class. As explicit methods are actually attached to the interface itself, so at any level of Inherited member, it can be cast easily to get the default implementation (which is in fact not overridable).&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Even though there might be some further cases where it comes really handy, I would like to leave them for you. Post your comments regarding some other practical implementation or something you would like to address to me.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thanks, I hope you find it interesting.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Happy programming.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=RHKiXdlWCF4:3Y9i44Kq9eU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=RHKiXdlWCF4:3Y9i44Kq9eU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=RHKiXdlWCF4:3Y9i44Kq9eU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=RHKiXdlWCF4:3Y9i44Kq9eU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=RHKiXdlWCF4:3Y9i44Kq9eU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/RHKiXdlWCF4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/5912551752591387581/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/09/internals-of-interface-and-its.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/5912551752591387581?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/5912551752591387581?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/RHKiXdlWCF4/internals-of-interface-and-its.html" title="Internals of Interface and its Implementation" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-iORNcRyLxqg/TnZxAjFnqAI/AAAAAAAAD3M/mXRQFCRhjk4/s72-c/explicit.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/09/internals-of-interface-and-its.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcNQ38zeip7ImA9WhdWF0U.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-6009748124979915923</id><published>2011-09-12T05:04:00.001+05:30</published><updated>2011-09-12T05:04:52.182+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-12T05:04:52.182+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Configuration" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Writing a Custom ConfigurationSection to handle a Collection</title><content type="html">Configuration is one of the major thing that you need to keep in mind while building any application. Either its an Windows Forms application or a Web site, configuration file is always needed. We write all the configuration that are needed to be changed after it is being deployed in confugration files. It is an XML File which lists all the configuration blocks itself and also allows you to define your own custom configuration sections yourself. Today I am building my own custom configuration section and show how easily you can build yourself.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
While dealing with Configurations, there are two things that you need to address&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;ConfigurationSection&lt;/li&gt;
&lt;li&gt;ConfigurationElement&lt;/li&gt;
&lt;li&gt;ConfigurationElementCollection&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;
For most of the simple configurations, it is pretty much common to use these two classes, but when you need more complex configuration block, like appsettings which actually puts a Collection of ConfigurationElements, you might need to use ConfigurationElementCollection to hold the collection of ConfigurationElement.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here in the article I will build one Configuration similar to appsettings so that it would be easier to build one for your own application.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-8O1BOMChjqs/Tm1Ba6QMSQI/AAAAAAAAD3I/5UfYipTZK_4/s1600/configsection.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-8O1BOMChjqs/Tm1Ba6QMSQI/AAAAAAAAD3I/5UfYipTZK_4/s1600/configsection.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;ConfgurationSection &lt;/b&gt;maps to the whole configuration, reading through the whole configuration you define in your config file. It has its own serialization and deserialization technique internally to open and close one specific ConfigurationSection when you want. For each Configuration file, it searches the Type of the ConfigSection, (in out case it is ConnectionSection which is within the assembly Configurationsettings). The name of the section indicates the Tag which you use for your ConfigurationSection.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ConfigurationElement &lt;/b&gt;maps with the individual element of the Section. It generally points to the entire XML configuration Tag that we use for the configuration. It is the serialized object with all the information about your configuration. When used as a Collection (as in our case) the ConfigurationElement maps to individual configuration blocks (in our case it is Element).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ConfigurationElementCollection &lt;/b&gt;: Each ConfigurationSection can have a collection of ConfigurationElement. In our case Servers represents the collection of Element.&lt;br /&gt;
&lt;br /&gt;
Now lets see how we code to retrieve data from this Configuration.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Implementation of ConfigurationElement&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
On the lowest level, each Configuration block in the collection represents one .NET object. Lets think that the enter tag here is converted to a .NET object and vice-versa. So how your .NET object would look like ?&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Element : ConfigurationElement
{
    [ConfigurationProperty(&lt;span class="str"&gt;"name"&lt;/span&gt;, DefaultValue = &lt;span class="str"&gt;""&lt;/span&gt;, IsKey = &lt;span class="kwrd"&gt;true&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; name
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"name"&lt;/span&gt;]; }
        set { &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"name"&lt;/span&gt;] = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }
    }
    [ConfigurationProperty(&lt;span class="str"&gt;"servername"&lt;/span&gt;, DefaultValue = &lt;span class="str"&gt;""&lt;/span&gt;, IsKey = &lt;span class="kwrd"&gt;false&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; servername
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"servername"&lt;/span&gt;]; }
        set { &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"servername"&lt;/span&gt;] = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }
    }

    [ConfigurationProperty(&lt;span class="str"&gt;"isactive"&lt;/span&gt;, DefaultValue = &lt;span class="str"&gt;"true"&lt;/span&gt;, IsKey = &lt;span class="kwrd"&gt;false&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; isactive
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;bool&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"isactive"&lt;/span&gt;]; }
        set { &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"isactive"&lt;/span&gt;] = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }
    }

    [ConfigurationProperty(&lt;span class="str"&gt;"userid"&lt;/span&gt;, DefaultValue = &lt;span class="str"&gt;"abhi"&lt;/span&gt;, IsKey = &lt;span class="kwrd"&gt;false&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; userid
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"userid"&lt;/span&gt;]; }
        set { &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"userid"&lt;/span&gt;] = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }
    }

    [ConfigurationProperty(&lt;span class="str"&gt;"password"&lt;/span&gt;, DefaultValue = &lt;span class="str"&gt;"password"&lt;/span&gt;, IsKey = &lt;span class="kwrd"&gt;false&lt;/span&gt;, IsRequired = &lt;span class="kwrd"&gt;false&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; password
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;)&lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"password"&lt;/span&gt;]; }
        set { &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"password"&lt;/span&gt;] = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Here the class Element represents exactly as we define our Configuration element in the collection. Our Element in configuration looks like :&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Element&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="RemoteServer"&lt;/span&gt;
                    &lt;span class="attr"&gt;servername&lt;/span&gt;&lt;span class="kwrd"&gt;="68.240.22.19"&lt;/span&gt;
                    &lt;span class="attr"&gt;userid&lt;/span&gt;&lt;span class="kwrd"&gt;="abhijit"&lt;/span&gt;
                    &lt;span class="attr"&gt;password&lt;/span&gt;&lt;span class="kwrd"&gt;="passcode"&lt;/span&gt;
                    &lt;span class="attr"&gt;isactive&lt;/span&gt;&lt;span class="kwrd"&gt;="true"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So our idea to create a type that maps to this. &amp;nbsp;Remember XML is case - sensitive.&lt;br /&gt;
Hence we create a class. We map the individual Properties with ConfigurationProperty. You can see each individual property has few attributes that you can define. Such as, &amp;nbsp;DefaultValue would be used whenever the attribute is not present in actual configuration; IsRequired indicate that the property is mandatory etc.&lt;br /&gt;
&lt;br /&gt;
You should always consider one of the property of the &lt;b&gt;ConfigurationElement &lt;/b&gt;as Key field. Key field represents the unique identifier for the object.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Implementation of ConfigurationElementCollection&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now as we have a collection of Element in our configuration block, we need to wrap the individual Element inside a ConfigurationElementCollection. This class is an abstract implementation of a ConfigCollection. It has few members that we need to address. Lets see how do we implement it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;[ConfigurationCollection(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Element))]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ServerAppearanceCollection : ConfigurationElementCollection
{
    &lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; PropertyName = &lt;span class="str"&gt;"Element"&lt;/span&gt;;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; ConfigurationElementCollectionType CollectionType
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; ConfigurationElementCollectionType.BasicMapAlternate;
        }
    }
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ElementName
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; PropertyName;
        }
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsElementName(&lt;span class="kwrd"&gt;string&lt;/span&gt; elementName)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; elementName.Equals(PropertyName, StringComparison.InvariantCultureIgnoreCase);
    }


    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsReadOnly()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
    }


    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; ConfigurationElement CreateNewElement()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Element();
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; GetElementKey(ConfigurationElement element)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; ((Element)(element)).name;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Element &lt;span class="kwrd"&gt;this&lt;/span&gt;[&lt;span class="kwrd"&gt;int&lt;/span&gt; idx]
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; (Element)BaseGet(idx);
        }
    }
}&lt;/pre&gt;
&lt;br /&gt;
First and foremost, we need to annotate the class using ConfigurationCollection attribute. Generally, each configurationSection is read by the .NET configuration reader using Reflection. It chooses appropriate classes based on the Attribute. Hence it is important to define this for each configuration.&lt;br /&gt;
&lt;br /&gt;
Here the first thing that you notice is we define an Indexer for the class and return BaseGet(index). The BaseGet actually reads the configuration collection and use Reflection to create object of the ConfigurationElement.&lt;br /&gt;
&lt;br /&gt;
Another important thing that you need to address in this implementation is CreateNewElement. You need to return the actual implementation of your ConfigurationElement here. The ElementName represents the name of the Tag that you use in Config file.&lt;br /&gt;
&lt;br /&gt;
Implementation of ConfigurationSection&lt;br /&gt;
&lt;br /&gt;
Finally we need to actually map the collection to a single ConfigurationSection. Lets see the implementation first :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ConnectionSection  : ConfigurationSection
{
    [ConfigurationProperty(&lt;span class="str"&gt;"Servers"&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ServerAppearanceCollection ServerElement
    {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; ((ServerAppearanceCollection)(&lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"Servers"&lt;/span&gt;])); }
        set { &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="str"&gt;"Servers"&lt;/span&gt;] = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Here basically we create an object of our Collection and return the whole XML block using base["name of the block"]. You must notice that we wrapped the whole configuration inside one XML tag called Servers. We use this to indicate the whole collection.&lt;br /&gt;
&lt;br /&gt;
As a Side Note&lt;br /&gt;
&lt;br /&gt;
Yes, of course you can read configuration directly without using existing APIs available. This article demonstrates how to handle complex configuration blocks for your application.&lt;br /&gt;
&lt;br /&gt;
If you are looking for something simplier than this, check the following links :&lt;br /&gt;
&lt;a href="http://haacked.com/archive/2007/03/12/custom-configuration-sections-in-3-easy-steps.aspx"&gt;3 Easy steps to create Configuration&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In much simple scenario you dont need to use ConfigurationSectionCollection rather you can simply use ConfigurationSection itself to handle your entire configuration.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;To Get information about Configuration&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To &amp;nbsp;retrieve the information of the configuration lets define a class and enumerate all the Element objects that can be found from Configuration.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ConfigSettings
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ConnectionSection ServerAppearanceConfiguration
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; (ConnectionSection)ConfigurationManager.GetSection(&lt;span class="str"&gt;"serverSection"&lt;/span&gt;);
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; ServerAppearanceCollection ServerApperances
    {
        get
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.ServerAppearanceConfiguration.ServerElement;
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;Element&amp;gt; ServerElements
    {
        get
        {
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Element selement &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.ServerApperances)
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (selement != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                    &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; selement;
            }
        }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Here we use GetSection to get the specific section that we have created, and we can easily cast the object returned by GetSection to ConnectionSection. The GetSection automatically creates the instance of the class (if everything is alright) . Now as our section also contains a Collection of custom settings, we have yield the elements from ServerAppearanceCollection.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="https://skydrive.live.com/embedicon.aspx/.Public?cid=bafa39a62a57009c&amp;amp;sc=documents"&gt;Download Source application&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Use of Custom Section for app.config is generally very handy. The System.Configuration api exposes a number of good classes that can handle configuration for you. Here I have shown how to create a section that might act similar to AppSettings or any collection oriented settings.&lt;br /&gt;
&lt;br /&gt;
I hope this will come handy.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading.&lt;/div&gt;
&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=bF6eBXqTs-o:EkxIn2TzSzM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=bF6eBXqTs-o:EkxIn2TzSzM:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=bF6eBXqTs-o:EkxIn2TzSzM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=bF6eBXqTs-o:EkxIn2TzSzM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=bF6eBXqTs-o:EkxIn2TzSzM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/bF6eBXqTs-o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/6009748124979915923/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/09/writing-custom-configurationsection-to.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6009748124979915923?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6009748124979915923?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/bF6eBXqTs-o/writing-custom-configurationsection-to.html" title="Writing a Custom ConfigurationSection to handle a Collection" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-8O1BOMChjqs/Tm1Ba6QMSQI/AAAAAAAAD3I/5UfYipTZK_4/s72-c/configsection.PNG" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/09/writing-custom-configurationsection-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C04BSX09fip7ImA9WhdXGE8.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-6788197985270515283</id><published>2011-09-01T01:49:00.000+05:30</published><updated>2011-09-01T01:49:18.366+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-01T01:49:18.366+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="MEF" /><category scheme="http://www.blogger.com/atom/ns#" term="Threading" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="tips" /><category scheme="http://www.blogger.com/atom/ns#" term="Patterns" /><category scheme="http://www.blogger.com/atom/ns#" term="Reflection" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><title>31 Tips for the month on Threading, WPF, MEF, ASP.NET</title><content type="html">&lt;span class="Apple-style-span" style="background-color: white; font-family: verdana; font-size: 12px;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="color: black; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;
&lt;a href="http://dailydotnettips.com/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;Daily .NET Tips&amp;nbsp;&lt;/a&gt;is aiming to sharing useful coding tips and tricks for .NET Developers. This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET.&amp;nbsp;&amp;nbsp; This month we have wide range of tips including Threading, MEF, WPF and MVC. In this post I am quickly listing down all the tips which are published over the month August 2011. And the most important point to mention, &lt;u&gt;among those 31 tips that has been posted on DailyDotnettips this month 22 is coming from me.&amp;nbsp;&lt;/u&gt;&lt;/div&gt;
&lt;div style="color: black; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="color: black; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;
&lt;span id="more-3014" style="font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ol style="font: normal normal normal 1.01em/normal verdana; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 12px; padding-bottom: 0px; padding-left: 40px; padding-right: 0px; padding-top: 0px;"&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/31/working-with-aggregatecatalog-in-mef/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Working with AggregateCatalog in MEF&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&amp;nbsp;&lt;a href="http://dailydotnettips.com/2011/08/31/working-with-directorycatalog-in-mef/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Working with DirectoryCatalog in MEF&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/30/working-with-assemblycatalog-in-mef/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Working with AssemblyCatalog in MEF&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/29/working-with-typecatalog-in-mef/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Working with TypeCatalog in MEF&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/28/how-to-use-debuggertypeproxy-while-debugging-your-sensitive-type/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;How to use DebuggerTypeProxy while debugging your sensitive Type&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/28/asp-net-calendar-control-as-outlook-calendar/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;ASP.NET Calendar Control as Outlook Calendar&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/27/initialize-assemblies-using-preapplicationstartmethodattribute-aspnet4-app/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Initialize assemblies using PreApplicationStartMethod for ASP.NET 4.0 Application&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/26/async-lambda-expression/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Async Lambda Expression&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/25/playing-with-list-controls-using-jquery/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Playing with ASP.NET List Controls using jQuery&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/24/how-to-allow-user-to-input-html-in-asp-net-mvc/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;How to allow user to input html in ASP.NET MVC?&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/22/using-mutex-to-avoid-deadlocks/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Using Mutex to avoid deadlocks&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/21/writing-inline-code-in-wpf/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;Writing inline Code in WPF&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/20/what-is-synchronizationcontext-all-about/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;What is SynchronizationContext all about&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/19/threadlocal-storage-a-lazy-implementation/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;ThreadLocal storage in .NET&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/18/barrier-in-net-4-0/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Barrier in .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/17/use-of-interlocked-in-race-condition/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Use of Interlocked in Race Condition&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/16/call-asp-net-page-methods-using-ajax/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Call ASP.NET Page Methods using your own AJAX&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/15/use-of-spinlock-for-threadlocking/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Use of SpinLock for ThreadLocking&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/14/using-readerwriterlock-over-monitor-for-thread-locking/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;Using ReaderWriterLock over Monitor for Thread Locking&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/11/1538/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;What is the use of IsBackground property of Thread?&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/10/enable-address-level-debugging-in-visual-studio/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Enable Address Level Debugging in Visual Studio&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/09/get-list-of-all-control-types-in-wpf/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;Get List of all Control Types in WPF&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/08/how-to-create-simple-faded-transparent-controls-in-wpf/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;How to apply simple faded transparent effects on WPF controls ?&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&amp;nbsp;&lt;a href="http://dailydotnettips.com/2011/08/07/use-visual-studio-server-explorer-to-add-new-or-existing-sql-server-ce-database/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Use Visual Studio Server Explorer to Add New or Existing SQL Server CE Database&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/06/co-ordinated-thread-shutdown-with-and-without-using-cancellationtokensource/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Co-Ordinated Thread Shutdown with and without using CancellationTokenSource&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/05/generate-thousand-of-request/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Generate thousand of request&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/05/writing-a-stretchable-contentcontrol-in-wpf/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Writing a Stretchable ContentControl in WPF&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/04/how-to-retrieve-wpf-visual-tree-programmatically/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;How to Retrieve WPF Visual Tree Programmatically ?&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/03/what-is-visual-tree-and-logical-tree-in-wpf/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;What is Visual Tree and Logical Tree in WPF?&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&amp;nbsp;&lt;a href="http://dailydotnettips.com/2011/08/02/dealing-with-hwnd-in-wpf/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Dealing with HWND in WPF&lt;/a&gt;&lt;/li&gt;
&lt;li style="color: black; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;a href="http://dailydotnettips.com/2011/08/01/hosting-a-wpf-control-inside-a-windows-form/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank"&gt;Hosting a WPF control inside a Windows Form&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div style="color: black; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;
To get regular updates visit&amp;nbsp;&lt;a href="http://dailydotnettips.com/" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;http://dailydotnettips.com&lt;/a&gt;&amp;nbsp;and follow&amp;nbsp;&lt;a href="http://twitter.com/dailydotnettips" style="border-bottom-color: rgb(255, 255, 255); border-bottom-style: dashed; border-bottom-width: 1px; color: navy; font: normal normal normal 1.01em/normal verdana; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;@dailydotnettips&lt;/a&gt;&amp;nbsp;at Twitter.&lt;/div&gt;
&lt;div style="color: black; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="color: black; font: normal normal normal 1.01em/normal verdana; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;
I hope you would like the posts. Stay tune for more.&amp;nbsp;&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=dw7_9v_BILI:MK4XtDYyjuw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=dw7_9v_BILI:MK4XtDYyjuw:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=dw7_9v_BILI:MK4XtDYyjuw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=dw7_9v_BILI:MK4XtDYyjuw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=dw7_9v_BILI:MK4XtDYyjuw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/dw7_9v_BILI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/6788197985270515283/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/09/31-tips-for-month-on-threading-wpf-mef.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6788197985270515283?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6788197985270515283?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/dw7_9v_BILI/31-tips-for-month-on-threading-wpf-mef.html" title="31 Tips for the month on Threading, WPF, MEF, ASP.NET" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/09/31-tips-for-month-on-threading-wpf-mef.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MGQXw4fyp7ImA9WhdXFU8.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-2031541982783371304</id><published>2011-08-28T14:20:00.000+05:30</published><updated>2011-08-28T14:20:20.237+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-28T14:20:20.237+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MEF" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><category scheme="http://www.blogger.com/atom/ns#" term="Online Session" /><title>Monday Mornings : Extensibility in .NET 4.0</title><content type="html">It is my great pleasure to speak at Microsoft Moday's last Monday on 22nd August 2011. I have introduced a way to develop a &lt;a href="http://www.abhisheksur.com/2011/08/steps-to-write-plugin-based-application.html"&gt;plugin based application with and without MEF&lt;/a&gt;. I have also touched some of the interfaces which Visual Studio uses for Extensibility. It has been a very good session and I have learned a lot from it.&lt;br /&gt;
&lt;br /&gt;
If you are a part of the session, please get the Power Point Presentation and the updated source code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div id="__ss_9037541" style="width: 425px;"&gt;
&lt;strong style="display: block; margin: 12px 0 4px;"&gt;&lt;a href="http://www.slideshare.net/abhi2434/extensibility-in-application" title="Extensibility in application"&gt;Extensibility in application&lt;/a&gt;&lt;/strong&gt;&lt;object height="355" id="__sse9037541" width="425"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=extensibilityinapplication-110827160911-phpapp01&amp;stripped_title=extensibility-in-application&amp;userName=abhi2434" /&gt;

&lt;param name="allowFullScreen" value="true"/&gt;

&lt;param name="allowScriptAccess" value="always"/&gt;

&lt;embed name="__sse9037541" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=extensibilityinapplication-110827160911-phpapp01&amp;stripped_title=extensibility-in-application&amp;userName=abhi2434" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;
&lt;div style="padding: 5px 0 12px;"&gt;
View more &lt;a href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/abhi2434"&gt;Abhishek Sur&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="https://skydrive.live.com/embedicon.aspx/.Public/MEFPluginHostSample.zip?cid=bafa39a62a57009c&amp;amp;sc=documents"&gt;You can download the source code from here.&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
For further references on MEF you can read :&lt;br /&gt;
&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-style-span" style="font-family: 'Lucida Sans Unicode'; font-size: large;"&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;b&gt;&lt;a href="http://tinyurl.com/MEFWorld"&gt;http://tinyurl.com/MEFWorld&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;b&gt;&lt;a href="http://tinyurl.com/MEFSource"&gt;http://tinyurl.com/MEFSource&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;b&gt;&lt;a href="http://tinyurl.com/MEFGuide"&gt;http://tinyurl.com/MEFGuide&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;b&gt;&lt;a href="http://tinyurl.com/MEFBlogs"&gt;http://tinyurl.com/MEFBlogs&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;b&gt;&lt;a href="http://tinyurl.com/MEFDiscussions"&gt;http://tinyurl.com/MEFDiscussions&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;b&gt;&lt;a href="http://tinyurl.com/PluginMEF"&gt;http://tinyurl.com/PluginMEF&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;Thanks for attending my session.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px;"&gt;Keep in touch.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=pPEn-yEHaxQ:dMyD5VJJ9ME:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=pPEn-yEHaxQ:dMyD5VJJ9ME:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=pPEn-yEHaxQ:dMyD5VJJ9ME:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=pPEn-yEHaxQ:dMyD5VJJ9ME:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=pPEn-yEHaxQ:dMyD5VJJ9ME:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/pPEn-yEHaxQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/2031541982783371304/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/08/monday-mornings-extensibility-in-net-40.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/2031541982783371304?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/2031541982783371304?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/pPEn-yEHaxQ/monday-mornings-extensibility-in-net-40.html" title="Monday Mornings : Extensibility in .NET 4.0" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/08/monday-mornings-extensibility-in-net-40.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ACQXc6eyp7ImA9WhdXFEo.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-5820623058600593831</id><published>2011-08-27T23:38:00.000+05:30</published><updated>2011-08-28T00:32:40.913+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-28T00:32:40.913+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MEF" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="windowsclient.net" /><category scheme="http://www.blogger.com/atom/ns#" term="Patterns" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Steps to write a plugin based application with MEF</title><content type="html">I have already &lt;a href="http://www.abhisheksur.com/2011/07/managed-extensibility-framework-look.html"&gt;written a blog on Managed Extensibility Framework&lt;/a&gt; few days ago, and you must wonder why I am writing again. Well actually today I have been creating an application that could be easily plugged into a host application. In this blog lets show you in steps how you could easily create your own plugin based application and later change itself easily using MEF.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Steps to create a Plugin based application :&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Before we proceed lets look how the User Interface for the application that I am building looks like :&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-AtWID-x9cmY/Tk_jw_Ype_I/AAAAAAAAD2w/bA6FJwc0uBs/s1600/userinterface.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-AtWID-x9cmY/Tk_jw_Ype_I/AAAAAAAAD2w/bA6FJwc0uBs/s320/userinterface.PNG" width="317" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;The UI contains two Panels, one to show the UI loader control, ideally will list a Button, and another container which will load the actual UI for the application. I have used normal windows based application to make you understand better. &amp;nbsp;Initially it will show you a button, and when you click on the button, it will load the actual usercontrol.&lt;/li&gt;
&lt;li&gt;To start creating a plugin based application, we need to create a contract that lies between the Modules and the Host. The contract restricts the Plugins to be loaded on the Host.&lt;/li&gt;
&lt;li&gt;Lets add a Class Library to the project and name it as PluginContract. We add 3 interfaces.&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IProcessRunner
{
    &lt;span class="kwrd"&gt;void&lt;/span&gt; Process();
}

&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;The IProcess interface includes some portion of code that you need to execute when the application is getting loaded. This interface acts as a process which the plugin needs to execute whenever the object is loaded. The idea is to separate the actual process code from the User Interface.&lt;/li&gt;
&lt;li&gt;Next we define IPlugin interface which maps the actual User Interface of the Module. The&amp;nbsp;definition&amp;nbsp;of the IPlugin interface looks like :&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IPlugin
{
    UserControl GreeterControl { get; set; }

    &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsPluginCreated { get; set; }
    &lt;span class="kwrd"&gt;void&lt;/span&gt; CreatePlugin();
    UserControl GetPlugin();

}

&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;The final Interface represents the Interface attacher when connects the plugin with the application and also giving a special interface to run the plugin and run custom code. The interface looks like :&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IInterfaceAttacher
{
    Control InterfaceControl { get; set; }
    IProcessRunner Runner { get; set; }
    Control GetInterfaceObject();
    IPlugin Plugin { get; set; }
    Control Container { get; set; }
}&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Once you are done, you can add a new Class Library and add one UserControl in it. We call it as GreetControl. Add reference to the Contract library and add the implementation of the interfaces.&lt;/li&gt;
&lt;li&gt;IProcess is the most simple interface that I have added to the system. It implements only Process method. The idea is to invoke a sequence of steps in the Process to generate the UserControl. For simplicity we put a messageBox in it.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The IPlugin interface on the other hand actually used to create an object of my plugin and return back the object. The implementation looks like :&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Plugin : IPlugin
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; UserControl GreeterControl { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsPluginCreated { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreatePlugin()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.GreeterControl == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.GreeterControl = &lt;span class="kwrd"&gt;new&lt;/span&gt; ucGreetMessage();

        &lt;span class="rem"&gt;//Initialize&lt;/span&gt;

        &lt;span class="kwrd"&gt;this&lt;/span&gt;.IsPluginCreated = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; UserControl GetPlugin()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;this&lt;/span&gt;.IsPluginCreated)
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.CreatePlugin();

        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.GreeterControl;
    }
}&lt;/pre&gt;
&lt;br /&gt;Here we create the object of GreeterControl and return the object of it when the GetPlugin is called. This contract element should be used from the Host to load the interface.&lt;/li&gt;
&lt;li&gt;InterfaceAttacher is created to aggregate all the elements into a single object. It creates an object of IPlugin, an object of IProcess, so it is the main contract for the whole plugin. Lets see how I implement the interface :&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; InterfaceAttacher : IInterfaceAttacher, IDisposable
{

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize()
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.InterfaceControl.Text = &lt;span class="str"&gt;"Load Greeter"&lt;/span&gt;;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Control InterfaceControl { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; IProcessRunner Runner { get; set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; IPlugin Plugin { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Control Container { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Control GetInterfaceObject()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.InterfaceControl == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.InterfaceControl = &lt;span class="kwrd"&gt;new&lt;/span&gt; Button();
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.InterfaceControl.Click += &lt;span class="kwrd"&gt;new&lt;/span&gt; EventHandler(InterfaceControl_Click);
        }
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Initialize();

        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.InterfaceControl;
    }

    &lt;span class="kwrd"&gt;void&lt;/span&gt; InterfaceControl_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Container == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ApplicationException(&lt;span class="str"&gt;"You cannot load a module without specifying the container"&lt;/span&gt;);

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Runner == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Runner = &lt;span class="kwrd"&gt;new&lt;/span&gt; Processor();

        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Runner.Process();

        &lt;span class="rem"&gt;//Load Plugin&lt;/span&gt;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Plugin == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.Plugin = &lt;span class="kwrd"&gt;new&lt;/span&gt; Plugin();

        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Container.Controls.Add(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Plugin.GetPlugin());
    }

    &lt;span class="preproc"&gt;#region&lt;/span&gt; IDisposable Members

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Dispose()
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.InterfaceControl != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.InterfaceControl.Dispose();
    }

    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
}&lt;/pre&gt;
&lt;br /&gt;Here the InterfaceControl is an individual control which will be loaded on the system and used to invoke a load operation of the Plugin. Here for simplicity I have used a Button to load the plugin, but ideally it should be a menu item. Thus when the object is Clicked, it will invoke certain events to call the Process of IProcess and load the IPlugin to the Container which is provided by the Host.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;i&gt;Certainly, you might be thinking why I am showing this crappy unusable code to you. Actually I have written this code long ago, may be at least 2 years ago when I was actually creating plugin based application for the first time. Here is to show you how I have actually developed the system, and how easy is to modify it to use MEF.&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Creating the Host&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Finally lets create the Host for this Plugin. &amp;nbsp;The plugin host will host two container (in our case) one to load all the buttons that are coming for each individual plugin which loads the actual plugin to the system, and another is to host the actual plugin interface. Lets take two panels in the Form and name it&amp;nbsp;pnlLoadControls &amp;nbsp;for the panel which loads the InterfaceLoader (Button) and&amp;nbsp;pnlContainer which loads the actual UserControl coming from plugin.&lt;br /&gt;
&lt;br /&gt;
Once the interface is created we need to write some code to actually load all the interface elements when form is loaded and upon user interaction, the actual UserInterface is loaded. Hence we write like this :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Form1_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; fpath &lt;span class="kwrd"&gt;in&lt;/span&gt; Directory.GetFiles(&lt;span class="str"&gt;"plugins"&lt;/span&gt;, &lt;span class="str"&gt;"*.dll"&lt;/span&gt;))
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.LoadAssembly(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fpath));
    }
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; LoadAssembly(&lt;span class="kwrd"&gt;string&lt;/span&gt; filepath)
{
    Assembly asm = Assembly.LoadFile(filepath);
    var items = asm.GetTypes().Where(t =&amp;gt; &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IInterfaceAttacher).IsAssignableFrom(t));

            

    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var item &lt;span class="kwrd"&gt;in&lt;/span&gt; items)
    {
        IInterfaceAttacher attacher = Activator.CreateInstance(item) &lt;span class="kwrd"&gt;as&lt;/span&gt; IInterfaceAttacher;
        attacher.Container = &lt;span class="kwrd"&gt;this&lt;/span&gt;.pnlContainer;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.pnlLoadControls.Controls.Add(attacher.GetInterfaceObject());
    }
}&lt;/pre&gt;
&lt;br /&gt;
Hmm, looks quite complex to you, isnt it ? Its just a code that loads the assemblies from the plugins directory and GetInterfaceObject from all the IInterfaceAttacher type that is found within the plugin. Hence the code will place the button called Load in the interface. You can see, that we pass the Container to load the actual interface when the InterfaceControl is clicked.&lt;br /&gt;
&lt;br /&gt;
So this is all we need to create our first plugin based application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Limitations of this approach:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;This approach is very tightly coupled with the host. The Plugin needs to follow exactly what the rules that is created by the Host.&lt;/li&gt;
&lt;li&gt;The plugins are not flexible enough to create interdependencies. That means, you cannot have interdependent plugins so that one plugin can easily host a component coming from another plugin.&lt;/li&gt;
&lt;li&gt;The approach requires some sort of standardization so that once a plugin is created it can be re used in another host.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The approach forms a strict rule that a Plugin cannot spread itself in multiple dlls. I mean the IPlugin should always reside within the Plugin attacher.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To address these situations we use MEF.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Lets introduce MEF to the System&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
If you are new to MEF, please feel free to read my &lt;a href="http://www.abhisheksur.com/2011/07/managed-extensibility-framework-look.html"&gt;previous blog about MEF&lt;/a&gt; to get the idea. MEF is actually a IOC container that relate each Exports with Imports. The idea of MEF is to mark an interface with &amp;nbsp;Export when it needs to be plugged in to a system, and Mark as Import when we need to host some sort of plugin that might be present in the system.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Export:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We mark all methods, properties, types as Export when we want to export the&amp;nbsp;functionality&amp;nbsp;to the external world.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Import&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If you are a host of Plugin you need to Import the plugin. Hence Import is used to import a functionality to the system.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Compose&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The CompositionContainer is a IOC container that maps individual Export with its appropriate Import.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
You can read about them from my&lt;a href="http://www.abhisheksur.com/2011/07/managed-extensibility-framework-look.html"&gt; article here&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Steps to change the existing application to use MEF&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li&gt;Add System.CompositionModel.Composition to your Plugins and add Export attribute to the IInterfaceAttacher.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-UiUdH2AZ5M4/TlkkDVwbCVI/AAAAAAAAD20/d2nzH-XKvfo/s1600/item1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-UiUdH2AZ5M4/TlkkDVwbCVI/AAAAAAAAD20/d2nzH-XKvfo/s1600/item1.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
Adding Export(typeofIInterfaceAttacher) will enable that the Interface object will be viable to export from the system to some external agent which wants to import it.&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;In the Actual Host we add a new class which creates a property of IInterfaceAttacher and Import the object. &amp;nbsp;The class looks like :&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; InterfaceBuilder
{
    [ImportMany(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IInterfaceAttacher))]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;IInterfaceAttacher&amp;gt; Attachers { get; set; }
}&lt;/pre&gt;
We use ImportMany as we can have multiple plugin in the dlls. So the property Attachers will list all the plugins into a single IEnumerable. &lt;/li&gt;
&lt;li&gt;In the Form, lets remove all the code that I have written to invoke the Type from assembly and change it to something like this :&lt;/li&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Form1_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    DirectoryCatalog catalog = &lt;span class="kwrd"&gt;new&lt;/span&gt; DirectoryCatalog(&lt;span class="str"&gt;"plugins"&lt;/span&gt;);
           
    InterfaceBuilder builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; InterfaceBuilder();
    CompositionContainer container = &lt;span class="kwrd"&gt;new&lt;/span&gt; CompositionContainer(catalog);
    container.ComposeParts(builder);


    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (IInterfaceAttacher attacher &lt;span class="kwrd"&gt;in&lt;/span&gt; builder.Attachers)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.pnlLoadControls.Controls.Add(attacher.GetInterfaceObject());
        attacher.Container = &lt;span class="kwrd"&gt;this&lt;/span&gt;.pnlContainer;
    }
}&lt;/pre&gt;
&lt;br /&gt;So here I have just created an object of DirectoryCatalog. DirectoryCatalog actually lists all the Exports and Imports present in the dlls present in a particular directory. In our case the directory is plugins. We create an object of InterfaceBuilder which holds the IEnumerable of IInterfaceAttacher. Next we create an object of CompositionContainer and pass our InterfaceBuilder object to compose its parts.&amp;nbsp;
&lt;li&gt;Now if you run the code, it runs just fine.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Thus you can see that the Exported plugin is actually created automatically using CompositionContainer and works as we have implemented earlier.&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Benefits ?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Yes. There are lots of benefits of using MEF. &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li&gt;As it forms a standard, the same dll can plugin to any system that imports something that the plugin is going to export.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;As we do not create dlls manually and rely completely on CompositionContainer, it is quite capable of handling errors, and reporting critical errors.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Interdependency&amp;nbsp;can also be achieved in this approach. The plugins can spread into multiple dlls easily. Lets look how :&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-MiCUbFDW1uE/TlkxPJjp62I/AAAAAAAAD24/xkmSgy2URUM/s1600/item2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-MiCUbFDW1uE/TlkxPJjp62I/AAAAAAAAD24/xkmSgy2URUM/s1600/item2.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;We made the Runner and Plugin in&amp;nbsp;InterfaceAttacher as Import capable and removed the object creation from InterfaceControl_Click event handler. &amp;nbsp;And Export the actual classes. Even you can do the same for the UserControl too.&lt;br /&gt;&lt;br /&gt;Simple huh ?&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Yes now you can spread the types into assemblies, even your plugins can import types from outside the assemblies, even from the host&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;a href="https://skydrive.live.com/embedicon.aspx/.Public/MEFPluginHostSample.zip?cid=bafa39a62a57009c&amp;amp;sc=documents"&gt;You can download the sample&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
I hope this post comes to you handy. Even though you should change it in your practical plugin based application, but this will help you to start.&lt;br /&gt;
&lt;br /&gt;
Thank you.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=GcjJ9XaFEgI:C4FXXoc4RuE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=GcjJ9XaFEgI:C4FXXoc4RuE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=GcjJ9XaFEgI:C4FXXoc4RuE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=GcjJ9XaFEgI:C4FXXoc4RuE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=GcjJ9XaFEgI:C4FXXoc4RuE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/GcjJ9XaFEgI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/5820623058600593831/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/08/steps-to-write-plugin-based-application.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/5820623058600593831?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/5820623058600593831?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/GcjJ9XaFEgI/steps-to-write-plugin-based-application.html" title="Steps to write a plugin based application with MEF" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-AtWID-x9cmY/Tk_jw_Ype_I/AAAAAAAAD2w/bA6FJwc0uBs/s72-c/userinterface.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/08/steps-to-write-plugin-based-application.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YDRH8-cSp7ImA9WhdQE0g.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-1441842820185799648</id><published>2011-08-15T01:13:00.002+05:30</published><updated>2011-08-15T01:16:15.159+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-15T01:16:15.159+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="C#5.0" /><category scheme="http://www.blogger.com/atom/ns#" term="Threading" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="tips" /><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone7" /><category scheme="http://www.blogger.com/atom/ns#" term="Database" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 3.5" /><title>.NET Tips : List of my short tips</title><content type="html">Hi Friends,&lt;br /&gt;
&lt;br /&gt;
As I have already told you that I have been publishing short tips in&lt;a href="http://www.dailydotnettips.com/" target="_blank"&gt; DailyDotnetTips&lt;/a&gt; regularly, it is time to share the links with you to keep you updated. Please read these short tips from me and give your feedback.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/08/14/using-readerwriterlock-over-monitor-for-thread-locking/" target="_blank"&gt;Using ReaderWriterLock over Monitor for Thread Locking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/08/11/1538/" target="_blank"&gt;What is the use of IsBackground property of Thread?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/08/06/co-ordinated-thread-shutdown-with-and-without-using-cancellationtokensource/" target="_blank"&gt;Co-Ordinated Thread Shutdown with and without using CancellationTokenSource&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/08/05/writing-a-stretchable-contentcontrol-in-wpf/" target="_blank"&gt;Writing a Stretchable ContentControl in WPF&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/08/03/what-is-visual-tree-and-logical-tree-in-wpf/" target="_blank"&gt;What is Visual Tree and Logical Tree in WPF?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/08/02/dealing-with-hwnd-in-wpf/" target="_blank"&gt;Dealing with HWND in WPF&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/08/01/hosting-a-wpf-control-inside-a-windows-form/" target="_blank"&gt;Hosting a WPF control inside a Windows Form&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/07/28/1377/" target="_blank"&gt;Accessing local assemblies in XAML&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/07/27/difference-between-a-usercontrol-and-a-customcontrol/" target="_blank"&gt;Difference between a UserControl and a CustomControl&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/07/26/hosting-a-windows-forms-control-inside-a-wpf/" target="_blank"&gt;Hosting a Windows Forms control inside a WPF&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/07/25/use-xshared-to-write-your-frameworkelements-directly-as-resource/" target="_blank"&gt;Use x:Shared to write your FrameworkElements directly as Resource&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/07/20/use-bitmapscalingmode-to-ensure-your-rendering-of-image-is-perfect/" target="_blank"&gt;Use BitmapScalingMode to ensure your rendering of Image is perfect&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/07/08/object-hierarchy-of-null/" target="_blank"&gt;Object hierarchy of NULL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/06/30/lazy-initializer-to-defer-expensive-object-creation-in-net-4-0/" target="_blank"&gt;Lazy Initializer to defer expensive Object creation in .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/06/29/working-with-co-variance-and-contra-variance-in-net-4-0/" target="_blank"&gt;Working with Co-Variance and Contra-Variance in .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/06/28/using-complex-numbers-in-net-4-0/" target="_blank"&gt;Using Complex Numbers in .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/06/27/working-with-biginteger-in-net-4-0/" target="_blank"&gt;Working with BigInteger in .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/06/26/working-with-sortedset-in-net-4-0/" target="_blank"&gt;Working with SortedSet in .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/06/14/common-table-expressions/" target="_blank"&gt;Common Table Expressions in SQL Server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://dailydotnettips.com/2011/06/05/compiler-directive-pragma-reference/" target="_blank"&gt;Compiler directive #Pragma reference&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So here are my last 20 short tips posted on &lt;a href="http://www.dailydotnettips.com/" target="_blank"&gt;DailyDotnetTips&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I hope you will like these tips. For full list of all the tips and the latest updates,&amp;nbsp;&lt;a href="http://dailydotnettips.com/author/abhishek-sur/" target="_blank"&gt;check this link&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Happy Coding.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thanks.&amp;nbsp;&lt;/div&gt;
&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=egPh__MpFyM:-HOcfs90kig:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=egPh__MpFyM:-HOcfs90kig:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=egPh__MpFyM:-HOcfs90kig:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=egPh__MpFyM:-HOcfs90kig:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=egPh__MpFyM:-HOcfs90kig:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/egPh__MpFyM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/1441842820185799648/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/08/net-tips-list-of-my-short-tips.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1441842820185799648?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1441842820185799648?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/egPh__MpFyM/net-tips-list-of-my-short-tips.html" title=".NET Tips : List of my short tips" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/08/net-tips-list-of-my-short-tips.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkAFQno_fyp7ImA9WhdREEo.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-1732136038451678996</id><published>2011-07-31T05:35:00.000+05:30</published><updated>2011-07-31T05:35:13.447+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-31T05:35:13.447+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="internals" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="Patterns" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 3.5" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Internals of Dependency Property in WPF</title><content type="html">WPF introduces new property system to us. Every WPF objects that is inherited from DependencyObject inherently supports Dependency property containers within it. That means you can define your own dependency property in your code which can take part in some of the interesting features of WPF like Binding, Styles, Triggers, Animation, Property Inheritence etc. Today I will concentrate on how Dependency Property system is actually built and what are the benefits we get instead of using CLR property system.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note :&lt;/b&gt; If you are really new in WPF and don't know about Dependency Property, it would be nice to &lt;a href="http://www.codeproject.com/KB/WPF/wpf5.aspx"&gt;read my post on Dependency Property&lt;/a&gt; or you can also try&lt;a href="http://www.codeproject.com/KB/WPF/wpf1.aspx"&gt; WPF Tutorial series to start on&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-ou6ETubet3A/TjSVygWd1pI/AAAAAAAAD2I/Sf2vdWAZApc/s1600/internalsdp8.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-ou6ETubet3A/TjSVygWd1pI/AAAAAAAAD2I/Sf2vdWAZApc/s1600/internalsdp8.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
So lets start on using the most basic code of creating your own Dependency Property.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty DescriptionProperty = 
    DependencyProperty.Register(&lt;span class="str"&gt;"Description"&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt;), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(DependencyHoster));

&lt;span class="kwrd"&gt;public&lt;/span&gt; string Description
{
    &lt;span class="rem"&gt;// Will not be called each time property is retrieved. Only be called when &lt;/span&gt;
    &lt;span class="rem"&gt;//you explicitely call it through ur code.&lt;/span&gt;
    get
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;)&lt;span class="kwrd"&gt;this&lt;/span&gt;.GetValue(DescriptionProperty); 
    }
    set
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.SetValue(DescriptionProperty, &lt;span class="kwrd"&gt;value&lt;/span&gt;);
    }

}&lt;/pre&gt;
&lt;br /&gt;
So here we define a property called Description to our DependencyObject named DependencyHoster of type string. According to the rule specified on DependencyProperty System, it is stated that you should always create a static reference of DependencyProperty and call Register to register a property to the Property System. It is also to the rule, that you should define a CLR property Stub which will call GetValue and SetValue in its getter and setter which is defined in DependencyObject to get or set the actual value defined for the instance. The Dependency property reference should be named with property name with "property" suffix. (in our case property name is Description and with suffix Property, it is named as DependencyProperty).&lt;br /&gt;
&lt;br /&gt;
Now lets see what exactly happens inside when you Register a DependencyProperty. &amp;nbsp;I would use our&amp;nbsp;favorite&amp;nbsp;tool Reflector to get deep into it.&lt;br /&gt;
&lt;br /&gt;
So if you look into the Register method you will see something like this :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-Yduubbt1AYE/TjRhClTAuhI/AAAAAAAAD1s/KzoarQP9mgg/s1600/internalsdp1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-Yduubbt1AYE/TjRhClTAuhI/AAAAAAAAD1s/KzoarQP9mgg/s1600/internalsdp1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Now lets concentrate on the lines highlighted in the image. The First creates an object of &lt;b&gt;FromNameKey&lt;/b&gt;, which is created with name that we pass in Register and the Type in which the key is associated with. This class is just a repository of a single key element with the type associated with it. &lt;br /&gt;
&lt;br /&gt;
Next, it is checked inside a HashTable named PropertyFromName. Well, I don't know why it is used as HashTable rather than Dictionary&lt;t1,t2&gt;, may be because both Key and Value of the object is Reference Types and does not need boxing/unboxing.&lt;/t1,t2&gt;&lt;br /&gt;
&lt;br /&gt;
Another important line that actually assigns the new object of DependencyProperty to the HashTable.&lt;br /&gt;
&lt;br /&gt;
So basically from the above three lines, you can deduce some of the interesting facts on DependencyProperty System as of now :&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;A DependencyProperty maintains a static reference of all the DependencyProperty you register in WPF object hierarchy. It maintains a HashTable named PropertyFromName which it uses internally to get the DependencyProperty object. So in other word, each dependencyProperty object is registered in a global HashTable.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Now lets check the object DependencyProperty as a whole and what it is capable of. Remember that each DependencyProperty object is created once for every DependencyProperty you define in your property system and not on every instance of object you create. Hence according to what we just seen, all TextBox will have only one TextProperty dependency property that go inside the field PropertyFromName.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-BsvH76T0HlA/TjSBvHMYXII/AAAAAAAAD1w/wy7PY3yYh-w/s1600/internalsdp2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-BsvH76T0HlA/TjSBvHMYXII/AAAAAAAAD1w/wy7PY3yYh-w/s1600/internalsdp2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Therefore the object DependencyProperty just holds the name, ownerType and its metadata. Metadata can be the Callbacks the DependencyPropertyKey element etc.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Where the value gets stored exactly ?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Well this might have come already in your mind. As I have already seen the DependencyProperty and it seems nowhere until now, a provision of value to be stored, yet a DependencyProperty has a method called GetDefaultValue for a specific type which will return the default value, but what if I assign something to a Type, where does it get stored ?&lt;br /&gt;
&lt;br /&gt;
To clear this confusion, lets look into DependencyObject instance a bit and try to see what exactly written inside GetValue, SetValue and ClearValue method.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. GetValue&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
GetValue is used to get the current value of an instance of a control. Remember, DependencyProperty supports a number of levels in which the effective values could be retrieved. Lets look in detail on the source of GetValue.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-mZdsqmL5rMY/TjSFFJcQX6I/AAAAAAAAD10/lJ-7mhfiw58/s1600/internalsdp3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-mZdsqmL5rMY/TjSFFJcQX6I/AAAAAAAAD10/lJ-7mhfiw58/s1600/internalsdp3.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The code snippet that I have specified,clearly says that every DependencyObject instance actually maintains a collection of objects (EffectiveValues) which will be set only when the instance stores / modifies the value of the DependencyProperty. The code gets either from the own collection or gets it from a method GetEffectiveValue based on whether the Request is fully resolved or not. the GetEffectiveValue identifies whether the current value is in animation mode (DependencyProperty supports animation) or is in Expression.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-gBm87nPZ7a8/TjSHhfeXE4I/AAAAAAAAD14/--S4X-MK4bM/s1600/internalsdp4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-gBm87nPZ7a8/TjSHhfeXE4I/AAAAAAAAD14/--S4X-MK4bM/s1600/internalsdp4.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Finally it checks whether the dependencyProperty DefaultValue is changed or not. If it isn't it gets you the default value of the property.&lt;br /&gt;
&lt;br /&gt;
2. SetValue&lt;br /&gt;
&lt;br /&gt;
SetValue on the other hand actually sets a value of &amp;nbsp;a DependencyProperty on the instance from which it is called. As we have already seen every DependencyObject actually maintains a collection of EffectiveValueEntry which holds the value of instance object we specify with some index value.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-DrHjyw_YtQY/TjSJDzXsIMI/AAAAAAAAD18/0emLFIYCSdM/s1600/internalsdp5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-DrHjyw_YtQY/TjSJDzXsIMI/AAAAAAAAD18/0emLFIYCSdM/s1600/internalsdp5.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
So the first thing that you notice is inside the SetValue is actually a feature. If you pass DependencyProperty.UnsetValue as value, it will actually call ClearValue for you. Hence SetValue(DP, DependencyProperty.UnsetValue) equals ClearValue(DP).&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-keE5D8ZfOOQ/TjSJ-ZOFqII/AAAAAAAAD2A/rX85c-qb0TI/s1600/internalsdp6.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-keE5D8ZfOOQ/TjSJ-ZOFqII/AAAAAAAAD2A/rX85c-qb0TI/s1600/internalsdp6.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The rest of the code looks quite simple. It checks whether the entry exists in the current object, if so it resets the value or it create a new EffectiveValueEntry and store it and update the index.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Impact of Styles&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
If you look into styles, it just maintains a collection of Setter. A setter on the other hand maintains a combination of DependencyProperty and the Value of the dependency property. Hence when a style is applied on an instance, it will get the value from it.&lt;br /&gt;
&lt;br /&gt;
The Style is actually a DependencyProperty defined inside FrameworkElement class. So in object hierarchy, it gets the value of the Style. Once the style is set for a control, it first clears all the object instances that the object already applies to and then apply the setters to each of them.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-iA4KJGWFh6w/TjSQpGwyvkI/AAAAAAAAD2E/oixLoAU8hVA/s1600/internalsdp7.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-iA4KJGWFh6w/TjSQpGwyvkI/AAAAAAAAD2E/oixLoAU8hVA/s1600/internalsdp7.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Thus the CreateInstanceData is used to apply a new style for a type.&lt;br /&gt;
&lt;br /&gt;
Remember, styles are overridden by the object values during runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Summary&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To summarize,&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Dependency Property System holds a collection of all DependencyProperty with its corresponding ownerType.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Each instance of a DependencyObject holds a collection of all individual DependencyProperty that has been changed either through animation or programmatically.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Styles produce a separate entity that holds a Key Value collection of a DependencyProperty and its value, once it is applied to a FrameworkElement, it modifies the default DependencyProperties with the ones that is defined inside styles.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Separating DependencyProperty from the object instance saves lots of space, as Reference Types will not create object instances when each instance is created, but will use up the existing instance &amp;nbsp;every time. &amp;nbsp;The separation of property system also allows to have a Property to be used as attached to its children.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Conclusion&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
There are lots of things to be learned and lots of things to be talked about in this regard. It is just the beginning.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Feel free to comment. I would love to see if I missed out something or if anything that you didnt like.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Read more about internals from &lt;a href="http://www.abhisheksur.com/2011/03/internals-to-net.html"&gt;my Internals Series&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thanks for reading.&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=9JWxDhquIIQ:TwU3vG4FadU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=9JWxDhquIIQ:TwU3vG4FadU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=9JWxDhquIIQ:TwU3vG4FadU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=9JWxDhquIIQ:TwU3vG4FadU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=9JWxDhquIIQ:TwU3vG4FadU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/9JWxDhquIIQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/1732136038451678996/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/07/internals-of-dependency-property-in-wpf.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1732136038451678996?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/1732136038451678996?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/9JWxDhquIIQ/internals-of-dependency-property-in-wpf.html" title="Internals of Dependency Property in WPF" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-ou6ETubet3A/TjSVygWd1pI/AAAAAAAAD2I/Sf2vdWAZApc/s72-c/internalsdp8.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/07/internals-of-dependency-property-in-wpf.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcGSHw6fSp7ImA9WhdSFU8.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-8538835298438210166</id><published>2011-07-24T22:19:00.002+05:30</published><updated>2011-07-24T22:33:49.215+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-24T22:33:49.215+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVVM" /><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="windowsclient.net" /><category scheme="http://www.blogger.com/atom/ns#" term="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="Custom Control" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Writing a Reusable Custom Control in WPF</title><content type="html">In &lt;a href="http://www.abhisheksur.com/2011/07/writing-reusable-wpf-control-with.html"&gt;my previous post&lt;/a&gt;, I have already defined how you can inherit from an existing control and define your own reusable chunk. The reusable XAML code that I have defined there is actually a composition of one of more existing elements in a common design surface. But sometimes you must define &amp;nbsp;a new behaviour for your reusable component which does not belong to any of the already existing&amp;nbsp;behaviors. Custom controls can help you in this. You can define a new behaviour for your Custom control which can have a default look and feel defined for it, and obviously which can be changed using Template for the user who is using the control. In this post I am going to provide you step by step approach on defining a Custom Control for your application.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Note&lt;/b&gt;: If you are really new to WPF, please read my &lt;a href="http://www.abhisheksur.com/2010/12/wpf-tutorial.html"&gt;WPF Tutorial&lt;/a&gt; before going further.&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;Steps to Create a new Custom Control&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Creating a custom control is very simple. Just in your project right click and add a new Item. In the dialog box that appears, choose Custom Control template and Name it. I call it here as SimpleControl.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-BnGP_tFFmhg/TixClnBpowI/AAAAAAAAD1g/cR1iSKmlFag/s1600/custom.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-BnGP_tFFmhg/TixClnBpowI/AAAAAAAAD1g/cR1iSKmlFag/s1600/custom.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Once you have added the control, it adds up a new class to your project which inherits from Control. The Template also provides you with some initial help to define your own control. Lets remove all the comments for now and start building a control.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Download Sample Code&lt;/b&gt;&lt;br /&gt;
&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/.Public/CustomControlExample.zip?cid=bafa39a62a57009c&amp;amp;sc=documents" style="background-color: #fcfcfc; height: 115px; padding: 0; width: 98px;" title="Preview"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In this control, I will show you all the components that you need for a Control so that it would help you guide each of the components individually.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Components that comprises a Custom Control&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
There are a number of components that you need to use inside your custom control which represents the behaviour for your control. Lets define each of them one by one before creating a Control.&lt;br /&gt;
&lt;br /&gt;
1. &lt;b&gt;Property &amp;nbsp;:&lt;/b&gt; Properties are one of the most important component for a control. In WPF, we use properties to define certain characteristics of a control. You can use either CLR properties or a Dependency Property. As you must know already a dependency property is a new Property System introduced with WPF, which holds a container of all the properties you define for a single instance of your control and which supports Property Value Inheritence, Animation, Templates, Styles, etc. To&lt;a href="http://www.codeproject.com/KB/WPF/wpf5.aspx"&gt; read more about Dependency Property check my article&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Example :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty ColorProperty = DependencyProperty.Register(&lt;span class="str"&gt;"Color"&lt;/span&gt;, 
    &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Color), 
    &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SimpleControl), 
    &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyMetadata(Colors.Green));

&lt;span class="kwrd"&gt;public&lt;/span&gt; Color Color
{
    get
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (Color)&lt;span class="kwrd"&gt;this&lt;/span&gt;.GetValue(ColorProperty);
    }
    set
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.SetValue(ColorProperty, &lt;span class="kwrd"&gt;value&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;br /&gt;
Here we have defined a new dependency Property called color, which will represent the initial BackColor of the control.  The Default value for the Property is defined as Green. &lt;br /&gt;
&lt;br /&gt;
2. &lt;b&gt;Commands&lt;/b&gt; : It is important to define a command for your Control rather than using a method. Commands lets you use CommandBinding on a control just like your Button Class. The Command generally invoke certain set of action defined using ICommand interface. It also creates an Inversion of Control to invoke some user code as well, during the event.&lt;br /&gt;
&lt;br /&gt;
Example :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; SimpleControl()
        {
            CommandManager.RegisterClassCommandBinding(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SimpleControl), 
                &lt;span class="kwrd"&gt;new&lt;/span&gt; CommandBinding(SimpleControl.CustomCommand, OnCustomCommand));
        }

        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnCustomCommand(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, ExecutedRoutedEventArgs e)
        {
            &lt;span class="rem"&gt;//Need to first retrieve the control&lt;/span&gt;
            SimpleControl invoker = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; SimpleControl;

            &lt;span class="rem"&gt;//Do whatever you need&lt;/span&gt;
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; ICommand CustomCommand = &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedUICommand(&lt;span class="str"&gt;"CustomCommand"&lt;/span&gt;, &lt;span class="str"&gt;"CustomCommand"&lt;/span&gt;,
                                                        &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SimpleControl),
                                                        &lt;span class="kwrd"&gt;new&lt;/span&gt; InputGestureCollection(
                                                            &lt;span class="kwrd"&gt;new&lt;/span&gt; InputGesture[] { 
                                                                &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyGesture(Key.Enter), 
                                                                &lt;span class="kwrd"&gt;new&lt;/span&gt; MouseGesture(MouseAction.LeftClick) }
                                                                )
                                                          );&lt;/pre&gt;
&lt;br /&gt;
Here I have defined a Command called CustomCommand. As you can notice I have used Static Constructor to register my command and static eventHandler so that it is more efficient. You can easily retrieve the actual object easily from sender. &lt;br /&gt;
&lt;br /&gt;
3. &lt;b&gt;RoutedEvents&lt;/b&gt; : Events are another most important thing for a control. You can define your own event for the control, but it should be RoutedEvent to ensure that WPF model supports them internally. RoutedEvent supports event routing, that the event can bubble or tunnel to the complete Visual Tree, when the event is raised. The FrameworkElement has a complete set of methods to use in defining a RoutedEvent.&lt;br /&gt;
&lt;br /&gt;
Example :&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; RoutedEvent InvertCallEvent = EventManager.RegisterRoutedEvent(&lt;span class="str"&gt;"InvertCall"&lt;/span&gt;,
    RoutingStrategy.Bubble, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(RoutedEventHandler), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SimpleControl));

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; RoutedEventHandler InvertCall
{
    add { AddHandler(InvertCallEvent, &lt;span class="kwrd"&gt;value&lt;/span&gt;); }
    remove { RemoveHandler(InvertCallEvent, &lt;span class="kwrd"&gt;value&lt;/span&gt;); }
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnInvertCall()
{
    RoutedEventArgs args = &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedEventArgs(InvertCallEvent);
    RaiseEvent(args);
}&lt;/pre&gt;
&lt;br /&gt;
Just like dependency property system, WPF event system also holds a collection of Events which appropriately raises the event for a particular control when some specific operation is executed.  The WPF event system can take part on EventSetters, Triggers etc. You have noticed that you can use Addhandler and RemoveHandler from the Event Accessor to add or remove an event for a particular control. The RaiseEvent is used to raise an event for a particular control. &lt;br /&gt;
&lt;br /&gt;
4. &lt;b&gt;Handling an Event :&lt;/b&gt; Sometimes your control might require to handle an Event that already comes from Control. For instance, the Button class handles an event called MouseDown to create an event Click to it. In such a scenario you can use RegisterClassHandler method to handle an event. &lt;br /&gt;
&lt;br /&gt;
Example : &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; SimpleControl()
{
    EventManager.RegisterClassHandler(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SimpleControl), Mouse.MouseDownEvent, &lt;span class="kwrd"&gt;new&lt;/span&gt; MouseButtonEventHandler(OnMouseDown));
}

&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnMouseDown(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, MouseButtonEventArgs e)
{
    SimpleControl invoker = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; SimpleControl;
    &lt;span class="rem"&gt;//Do handle event&lt;/span&gt;

    &lt;span class="rem"&gt;//Raise your event&lt;/span&gt;
    invoker.OnInvertCall();

    &lt;span class="rem"&gt;//Do Rest&lt;/span&gt;
}&lt;/pre&gt;
&lt;br /&gt;
Now here I have used RegisterClassHandler to handle the event. This will handle the MouseDown event for the control and invoke InvertCall event defined as RoutedEvent. &lt;br /&gt;
&lt;br /&gt;
5. &lt;b&gt;TemplatePart :&lt;/b&gt; For every control you should specify the rules how the UI for the control should look like. Template allows the user of your control to modify the look and feel, but using TemplatePart you can define the part of a control which you can change behaviour from within the control. Say for instance, if your control has a border, and your control wants to change its color when Mouse is hovered over the control, you can call the part attribute to apply this change which will be shown for any Template your user define later on, provided it should name the same part name.&lt;br /&gt;
&lt;br /&gt;
Note: Currently PartNames are not actually checked for Templates, so you can omit a part&lt;br /&gt;
Example :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;[TemplatePart(Name=&lt;span class="str"&gt;"PART_MainBorder"&lt;/span&gt;, Type=&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Border))]
[TemplatePart(Name=&lt;span class="str"&gt;"PART_body"&lt;/span&gt;, Type= &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ContentControl))]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SimpleControl : Control
{

    Border MainBorder;
    ContentControl Body;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnApplyTemplate()
    {
        &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnApplyTemplate();

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Template != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            Border mainBorder = &lt;span class="kwrd"&gt;this&lt;/span&gt;.Template.FindName(&lt;span class="str"&gt;"PART_MainBorder"&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Border;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (mainBorder != MainBorder)
            {
                &lt;span class="rem"&gt;//First unhook existing handler&lt;/span&gt;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (MainBorder != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    MainBorder.MouseEnter -= &lt;span class="kwrd"&gt;new&lt;/span&gt; MouseEventHandler(MainBorder_MouseEnter);
                    MainBorder.MouseLeave -= &lt;span class="kwrd"&gt;new&lt;/span&gt; MouseEventHandler(MainBorder_MouseLeave);
                }
                MainBorder = mainBorder;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (MainBorder != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    MainBorder.MouseEnter += &lt;span class="kwrd"&gt;new&lt;/span&gt; MouseEventHandler(MainBorder_MouseEnter);
                    MainBorder.MouseLeave += &lt;span class="kwrd"&gt;new&lt;/span&gt; MouseEventHandler(MainBorder_MouseLeave);
                }
            }

            Body = &lt;span class="kwrd"&gt;this&lt;/span&gt;.Template.FindName(&lt;span class="str"&gt;"PART_body"&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; ContentControl;

        }
    }

&lt;span class="kwrd"&gt;void&lt;/span&gt; MainBorder_MouseLeave(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, MouseEventArgs e)
{
    Border thisBorder = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; Border;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (thisBorder != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        thisBorder.Background = &lt;span class="kwrd"&gt;new&lt;/span&gt; SolidColorBrush(Colors.Red);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Body != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            Run r = &lt;span class="kwrd"&gt;new&lt;/span&gt; Run(&lt;span class="str"&gt;"Mouse Left!"&lt;/span&gt;);
            r.Foreground = &lt;span class="kwrd"&gt;new&lt;/span&gt; SolidColorBrush(Colors.White);
            Body.Content = r;
        }
    }
}

&lt;span class="kwrd"&gt;void&lt;/span&gt; MainBorder_MouseEnter(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, MouseEventArgs e)
{
    Border thisBorder = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; Border;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (thisBorder != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        thisBorder.Background = &lt;span class="kwrd"&gt;new&lt;/span&gt; SolidColorBrush(Colors.Blue);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Body != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            Run r = &lt;span class="kwrd"&gt;new&lt;/span&gt; Run(&lt;span class="str"&gt;"Mouse Entered!"&lt;/span&gt;);
            r.Foreground = &lt;span class="kwrd"&gt;new&lt;/span&gt; SolidColorBrush(Colors.White);
            Body.Content = r;
        }
    }
}&lt;/pre&gt;
&lt;br /&gt;
So here I have created two TemplatePart one named PART_MainBorder and another PART_body. In your Generic template you must define this TemplateParts so that the default control acts perfectly. The User can also redefine the template and once the user redefines it, it can also use these Part names to call a specific control inside, so that your control can apply something inside of it. &amp;nbsp;In this example I have used a border, which will change its color to Red when Mouse is entered inside of it, and to Blue when it is left. &amp;nbsp;You should note that I have used Template.FindName and passed the current instance of the control. This is important because Templates are generally shared by more than one instance.&lt;br /&gt;
&lt;br /&gt;
When a Template is applied to a control it calls OnApplyTemplate. Make sure you are tolerant enough to handle bad templates, as you can see, I have checked every time if the object is available before doing anything with it as WPF ignores bad templates and your control might end up with a bad NullReferenceException somewhere if you dont gracefully eliminate the same.&lt;br /&gt;
&lt;br /&gt;
Now in your actual Window, you should declare the template for the Control and define each of the PartNames you specify here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6.&lt;b&gt; Themes &amp;nbsp;:&lt;/b&gt; Yes your control should define a default Theme at least to make sure it at least appears when an object is created. At the basic level, when you add a new Custom Control to your project, you should add a style for Generic.XAML that is added up on the Themes folder. The AseemblyInfo also adds up a assembly level attribute which identifies where the default Theme template resides.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-y7l_VsUKzSk/TixFNhx0iEI/AAAAAAAAD1k/TgvxPSPzeT0/s1600/themefolder.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-y7l_VsUKzSk/TixFNhx0iEI/AAAAAAAAD1k/TgvxPSPzeT0/s1600/themefolder.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The Theme folder will by default hold a Generic.xaml. Lets add a default Style for our control.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Style&lt;/span&gt; &lt;span class="attr"&gt;TargetType&lt;/span&gt;&lt;span class="kwrd"&gt;="{x:Type local:SimpleControl}"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="HorizontalAlignment"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="VerticalAlignment"&lt;/span&gt; &lt;span class="attr"&gt;Value&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt; &lt;span class="attr"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;="Template"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Setter.Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ControlTemplate&lt;/span&gt; &lt;span class="attr"&gt;TargetType&lt;/span&gt;&lt;span class="kwrd"&gt;="local:SimpleControl"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="PART_MainBorder"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="{TemplateBinding Width}"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="{TemplateBinding Height}"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ContentControl&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="PART_body"&lt;/span&gt; 
                                    &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="{TemplateBinding HorizontalAlignment}"&lt;/span&gt; 
                                    &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="{TemplateBinding VerticalAlignment}"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ContentControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ControlTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Setter.Value&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Setter&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
Now as you can see this is a simple Style that will be applied to each control we instantiate in our application.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Creating the Sample&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now as we have already created our control lets add this control in MainWindow.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="CustomControlExample.MainWindow"&lt;/span&gt;
        &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
        &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
        &lt;span class="attr"&gt;xmlns:local&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:CustomControlExample"&lt;/span&gt;
        &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;="MainWindow"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="350"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="525"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:SimpleControl&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="90"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="90"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;local:SimpleControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:SimpleControl&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="90"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="90"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Color&lt;/span&gt;&lt;span class="kwrd"&gt;="Crimson"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:SimpleControl.Template&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ControlTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="PART_MainBorder"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="PART_body"&lt;/span&gt; &lt;span class="attr"&gt;HorizontalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;VerticalAlignment&lt;/span&gt;&lt;span class="kwrd"&gt;="Center"&lt;/span&gt; &lt;span class="attr"&gt;Background&lt;/span&gt;&lt;span class="kwrd"&gt;="Black"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Border&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ControlTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;local:SimpleControl.Template&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;local:SimpleControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
So here basically I add two controls in two rows of a Grid. The first one taking up the Default Template it provides, and the second one creates its own template. You can specify the Template Part in your own template as shown in the declaration which interact with the control itself. &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-Hvrw5Z-UBl0/TixJzO5AbkI/AAAAAAAAD1o/bqVIByxdrGk/s1600/controldemo.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-Hvrw5Z-UBl0/TixJzO5AbkI/AAAAAAAAD1o/bqVIByxdrGk/s1600/controldemo.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now if you run the sample it shows two rectangular box, one with all default values and another with custom template.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Bit Further&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
There are also few things that deals with Design Support of Visual Studio and Expression Blend for a control. You can either build separate dlls for design time support for your control with .design.dll or within the same assembly. The design time support can add custom Adorners which can help in layout the control in Visual Designer or Expression Blend. To build a design time support for a control you need to inherit from IRegisterMetaData and build an AttributeTableMetaData, which will work for the Designer. I will talk about it later in a separate post.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Download the Sample Code&lt;/b&gt;&lt;br /&gt;
&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/.Public/CustomControlExample.zip?cid=bafa39a62a57009c&amp;amp;sc=documents" style="background-color: #fcfcfc; height: 115px; padding: 0; width: 98px;" title="Preview"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
You should remember, creating a Custom control does require a lot of effort. So if you looking for just look and feel, you can get a workaround to this using custom template or &lt;a href="http://www.abhisheksur.com/2011/07/writing-reusable-wpf-control-with.html"&gt;inheriting from other existing Control&lt;/a&gt;s. But if you are building your own Custom behaviour or a library of control, then you should go for Custom Control. Also remember, custom control is Themable, Templatable and also supports inheritence, so you should always consider writing your control gracefully and hitting every possible aspect that your control might come across.&lt;br /&gt;
&lt;br /&gt;
I hope this sample code will help you. If you want, you can read my &lt;a href="http://www.abhisheksur.com/2010/12/wpf-tutorial.html"&gt;WPF Tutorial too from here&lt;/a&gt;&amp;nbsp;and subscribe to my blog too.&lt;br /&gt;
&lt;br /&gt;
Thank you for reading.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=0EVApZZSiwA:ISrIeqTWJIc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=0EVApZZSiwA:ISrIeqTWJIc:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=0EVApZZSiwA:ISrIeqTWJIc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=0EVApZZSiwA:ISrIeqTWJIc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=0EVApZZSiwA:ISrIeqTWJIc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/0EVApZZSiwA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/8538835298438210166/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/07/writing-reusable-custom-control-in-wpf.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/8538835298438210166?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/8538835298438210166?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/0EVApZZSiwA/writing-reusable-custom-control-in-wpf.html" title="Writing a Reusable Custom Control in WPF" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-BnGP_tFFmhg/TixClnBpowI/AAAAAAAAD1g/cR1iSKmlFag/s72-c/custom.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/07/writing-reusable-custom-control-in-wpf.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ADRXYyeyp7ImA9WhdSFUw.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-6147873085626345322</id><published>2011-07-23T22:47:00.002+05:30</published><updated>2011-07-24T18:19:34.893+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-24T18:19:34.893+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVVM" /><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 4.0" /><category scheme="http://www.blogger.com/atom/ns#" term="windowsclient.net" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="architecture" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET 3.5" /><title>Writing a Reusable WPF Control with Design Support</title><content type="html">Code reusablity is one of the major concern to many of us. When dealing with large projects, modularizing your project is one of the primary thing that you should look for. I have talked about many of the approaches that you can use to deal &lt;a href="http://www.abhisheksur.com/2011/06/working-with-prism-40-hello-world.html"&gt;with modularizing your code&lt;/a&gt;, eg, Prism. In this post our intent is not to talk hard on some pattern, rather I will discuss how your WPF application supports code reusability. There are a number of approaches that WPF supports to deal with reusable component. We can use Resources to define a Resource or even use CodeBehind to write our reusable component or even &lt;a href="http://www.abhisheksur.com/2010/10/lazy-load-xaml-content-from-external.html"&gt;load the XAML from a file using XAML Loader&lt;/a&gt;. Each of the approaches has its own pros and cons. Today I will show you another cool technique to write a reusable XAML for your project which will allow you to easily use Visual Studio design surface to design the component.&lt;br /&gt;
&lt;br /&gt;
Note : It is a very basic article, if you want to know about details on WPF, &lt;a href="http://www.abhisheksur.com/2010/12/wpf-tutorial.html"&gt;please read my tutorial&lt;/a&gt; on it.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Steps to Create your Reusable Component&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
Lets create a series of steps to create a reusable component for your application to make it easier for you to write one yourself. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1 :&lt;/b&gt;  Start Visual Studio and Create a new WPF project.&lt;br /&gt;
&lt;b&gt;Step 2 :&lt;/b&gt; Add a new Page to the application and call it as GreetPanel. Just like the figure below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-utNUENJZhEQ/TirLtFvKI3I/AAAAAAAAD1U/Itjxdw09LGk/s1600/loose1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-utNUENJZhEQ/TirLtFvKI3I/AAAAAAAAD1U/Itjxdw09LGk/s1600/loose1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Once you are done lets change the code for the Page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 3 :&lt;/b&gt; Change the root element of the page to Grid to make it a Reusable grid.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-S90pIjAv1Ag/TirM0T1nGFI/AAAAAAAAD1Y/x_TJBXP1Hqc/s1600/loose2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-S90pIjAv1Ag/TirM0T1nGFI/AAAAAAAAD1Y/x_TJBXP1Hqc/s1600/loose2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Note : &lt;/b&gt;Currently there is no Visual Studio File Template for writing a loose XAML component, hence I have used Page to do the same.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 4:&lt;/b&gt; After doing this, you also need to go to the Code -behind for the Page and change it to inherit from Grid. Now you have a complete reusable component (UserControl) which can use the design surface too, to define its components.&lt;br /&gt;
&lt;br /&gt;
Now lets define the control with most basic code :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="WritingLooseXAML.GreetPanel"&lt;/span&gt;
      &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
      &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ColumnDefinition&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.ColumnDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Label&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        Write Name
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBox&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="txtName"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Button&lt;/span&gt; &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;="Greet Me"&lt;/span&gt; &lt;span class="attr"&gt;Click&lt;/span&gt;&lt;span class="kwrd"&gt;="Button_Click"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="tbResult"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Column&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
Here I define a TextBox and a Button which has a click Handler too. You can define the ClickHandler in the codebehind for the GridPanel too. The Button will display a message in a textblock called tbResult. &lt;br /&gt;
&lt;br /&gt;
The Codebehind looks like : &lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; GreetPanel : Grid
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; GreetPanel()
    {
        InitializeComponent();
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Button_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.tbResult.Text = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Hello {0}, Welcome!"&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtName.Text);
    }
}&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Step 5 : &lt;/b&gt;Now once you are done defining your GridPanel, you can use it in any Window. Just use xmlns to declare the namespace for the control, here I used the local namespace, and define the controls. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="WritingLooseXAML.MainWindow"&lt;/span&gt;
        &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
        &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
        &lt;span class="attr"&gt;xmlns:local&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:WritingLooseXAML"&lt;/span&gt;
        &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;="MainWindow"&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="350"&lt;/span&gt; &lt;span class="attr"&gt;Width&lt;/span&gt;&lt;span class="kwrd"&gt;="525"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;WrapPanel&lt;/span&gt; &lt;span class="attr"&gt;Orientation&lt;/span&gt;&lt;span class="kwrd"&gt;="Horizontal"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:GreetPanel&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:GreetPanel&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel2"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:GreetPanel&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel3"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;WrapPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Window&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
You can access each properties of the Grid from your GreetPanel as it is derived from Grid.  Now compile your code and run, you will see your greetpanel working. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Adding a RoutedEvent on the control&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you know RoutedEvent is one of the base for events in WPF application, lets see how you can add one on the panel just declared. Now as you might already know that RoutedEvent can be of three types, one that Bubbles, one Tunnels and one Direct. To declare a RoutedEvent, you need to use EventManager.RegisterRoutedEvent. This command will register the event to the XAML and hence allows you to use Event in EventSetters, styles etc.&lt;br /&gt;
&lt;br /&gt;
In our previous code, lets add an event which will fire when the Result box is altered. To do this, lets add this to the code page of GreetPanel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; RoutedEvent ResutlAlteredEvent = 
    EventManager.RegisterRoutedEvent(&lt;span class="str"&gt;"ResultAltered"&lt;/span&gt;, 
    RoutingStrategy.Bubble, 
    &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(RoutedEventHandler), 
    &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(GreetPanel));

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; RoutedEventHandler ResultAltered
{
    add { AddHandler(ResutlAlteredEvent, &lt;span class="kwrd"&gt;value&lt;/span&gt;); }
    remove { RemoveHandler(ResutlAlteredEvent, &lt;span class="kwrd"&gt;value&lt;/span&gt;); }
}

&lt;span class="rem"&gt;// This method raises the ResultAltered event&lt;/span&gt;
&lt;span class="kwrd"&gt;void&lt;/span&gt; RaiseResultAlteredEvent()
{
    RoutedEventArgs newEventArgs = &lt;span class="kwrd"&gt;new&lt;/span&gt; RoutedEventArgs(GreetPanel.ResutlAlteredEvent);
    RaiseEvent(newEventArgs);
}

&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Button_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
{
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.tbResult.Text = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Hello {0}, Welcome!"&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtName.Text);
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.RaiseResultAlteredEvent();
}&lt;/pre&gt;&lt;br /&gt;
Now from the MainWindow.xaml (where you add this control you can find the ResultAltered event directly. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;WrapPanel&lt;/span&gt; &lt;span class="attr"&gt;Orientation&lt;/span&gt;&lt;span class="kwrd"&gt;="Horizontal"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:GreetPanel&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel1"&lt;/span&gt; &lt;span class="attr"&gt;ResultAltered&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel_ResultAltered"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:GreetPanel&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel2"&lt;/span&gt; &lt;span class="attr"&gt;ResultAltered&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel_ResultAltered"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;local:GreetPanel&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel3"&lt;/span&gt; &lt;span class="attr"&gt;ResultAltered&lt;/span&gt;&lt;span class="kwrd"&gt;="gPanel_ResultAltered"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;WrapPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
And in the code-behind we added the eventhandler as : &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; gPanel_ResultAltered(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs e)
{
    GreetPanel panel = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; GreetPanel;

    MessageBox.Show(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"You have altered result of {0}"&lt;/span&gt;, panel.Name));
}&lt;/pre&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-6cYG511AW-k/TisBPskW9UI/AAAAAAAAD1c/FjNj9FDNjEU/s1600/loose3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-6cYG511AW-k/TisBPskW9UI/AAAAAAAAD1c/FjNj9FDNjEU/s1600/loose3.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Thus when the button is clicked on the Control it shows up a messagebox shows up. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
By this way you can derive any control directly from an existing control. But if you are likely to build a completely new control you can use UserControl as its base, which will ensure that the UI has nothing. This is very easy. In my next post I will talk about Custom Controls.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="https://skydrive.live.com/embedicon.aspx/.Public/WritingLooseXAML.zip?cid=bafa39a62a57009c&amp;sc=documents"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
I hope this tutorial helps you.&lt;br /&gt;
&lt;br /&gt;
Thank you for reading.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=3gC-bAbis8g:Sl9uu9lGcjY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=3gC-bAbis8g:Sl9uu9lGcjY:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=3gC-bAbis8g:Sl9uu9lGcjY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=3gC-bAbis8g:Sl9uu9lGcjY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=3gC-bAbis8g:Sl9uu9lGcjY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/abhisheksur/WTgI/~4/3gC-bAbis8g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/6147873085626345322/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/07/writing-reusable-wpf-control-with.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6147873085626345322?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6147873085626345322?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/3gC-bAbis8g/writing-reusable-wpf-control-with.html" title="Writing a Reusable WPF Control with Design Support" /><author><name>Abhishek Sur</name><uri>https://plus.google.com/117353808377089262292</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh3.googleusercontent.com/-6COXfM91xyM/AAAAAAAAAAI/AAAAAAAAAAA/CW6fzIy03CM/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-utNUENJZhEQ/TirLtFvKI3I/AAAAAAAAD1U/Itjxdw09LGk/s72-c/loose1.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/07/writing-reusable-wpf-control-with.html</feedburner:origLink></entry></feed>
