<?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: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;CEcHQHYycSp7ImA9WhRUEU8.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453</id><updated>2012-01-21T10:30:31.899+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="debugging" /><category term="LOH" /><category term="CodeProject" /><category term="windowsclient.net" /><category term="Azure" /><category term="XAML" /><category term="Configuration" /><category term="design pattern" /><category term="MEF" /><category term="Custom Control" /><category term="Developer Conference" /><category term="IDisposable" /><category term=".NET 4.5" /><category term="tips" /><category term="Unity" /><category term="Finalize" /><category term="dotnetfunda.com" /><category term="async" /><category term="IsolatedStorage" /><category term="C#5.0" /><category term="WinForms" /><category term=".NET 3.5" /><category term="beyondrelational" /><category term="scripting" /><category term="Threading" /><category term="PDC10" /><category term="silverlight" /><category term="MVP" /><category term="blogger tips" /><category term="Windows Phone7" /><category term="Online Session" /><category term="ADO.NET" /><category term="C#" /><category term="WinRT" /><category term="Regex" /><category term="Reflection" /><category term="internals" /><category term="WCF" /><category term=".NET 4.0" /><category term="Database" /><category term="Patterns" /><category term=".NET Memory Management" /><category term="Windows8" /><category term="Memory Allocation" /><category term="architecture" /><category term="IObservable. Rx" /><category term="WPF" /><category term="SOH" /><category term=".NET" /><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://profiles.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>159</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;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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-1173288162753909344?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/aACP2DDJq-FQDNGwSgkA-ON7wDA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/aACP2DDJq-FQDNGwSgkA-ON7wDA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/aACP2DDJq-FQDNGwSgkA-ON7wDA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/aACP2DDJq-FQDNGwSgkA-ON7wDA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-447698324613444450?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZEPkxgbM2atvm7uO2w8zeeXL1Ww/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZEPkxgbM2atvm7uO2w8zeeXL1Ww/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZEPkxgbM2atvm7uO2w8zeeXL1Ww/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZEPkxgbM2atvm7uO2w8zeeXL1Ww/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-6953338459218754226?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/d0I_-BM-fSlOkKpblhYTDLgmTgM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d0I_-BM-fSlOkKpblhYTDLgmTgM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/d0I_-BM-fSlOkKpblhYTDLgmTgM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d0I_-BM-fSlOkKpblhYTDLgmTgM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-3473036252261382377?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ubbzsQylOYdzQhhXpmJyYVdCa3Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ubbzsQylOYdzQhhXpmJyYVdCa3Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ubbzsQylOYdzQhhXpmJyYVdCa3Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ubbzsQylOYdzQhhXpmJyYVdCa3Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-701057140440559889?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Iah6yS4CkfF0jsN_iDXj689hR8I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Iah6yS4CkfF0jsN_iDXj689hR8I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Iah6yS4CkfF0jsN_iDXj689hR8I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Iah6yS4CkfF0jsN_iDXj689hR8I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-7249585573269021996?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zXbzk8D-BtnhA3ZzJUgwu0VG5J0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zXbzk8D-BtnhA3ZzJUgwu0VG5J0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zXbzk8D-BtnhA3ZzJUgwu0VG5J0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zXbzk8D-BtnhA3ZzJUgwu0VG5J0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-4682476537647830506?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ct_-Gf-TcVMNZXCEn9QT0553O08/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ct_-Gf-TcVMNZXCEn9QT0553O08/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ct_-Gf-TcVMNZXCEn9QT0553O08/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ct_-Gf-TcVMNZXCEn9QT0553O08/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-1202276433845520074?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/He8nxp7G9-_eU_3yzE-gKg_cyDE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/He8nxp7G9-_eU_3yzE-gKg_cyDE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/He8nxp7G9-_eU_3yzE-gKg_cyDE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/He8nxp7G9-_eU_3yzE-gKg_cyDE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-6070026622596817533?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/tayHLTAs4ALYQesm2olViWGymvI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tayHLTAs4ALYQesm2olViWGymvI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/tayHLTAs4ALYQesm2olViWGymvI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tayHLTAs4ALYQesm2olViWGymvI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-5912551752591387581?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Plc88e6AYFO90K24IgOVyQKiB-4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Plc88e6AYFO90K24IgOVyQKiB-4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Plc88e6AYFO90K24IgOVyQKiB-4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Plc88e6AYFO90K24IgOVyQKiB-4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-6009748124979915923?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DN92crzZIj_esGA4CG5JmuCkeVk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DN92crzZIj_esGA4CG5JmuCkeVk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DN92crzZIj_esGA4CG5JmuCkeVk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DN92crzZIj_esGA4CG5JmuCkeVk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-6788197985270515283?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vSveJEgNu_Evo7XTjjHgHBnLzuM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vSveJEgNu_Evo7XTjjHgHBnLzuM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vSveJEgNu_Evo7XTjjHgHBnLzuM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vSveJEgNu_Evo7XTjjHgHBnLzuM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-2031541982783371304?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZfWW7YQTe0gNlvhZA26IavRvMQc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZfWW7YQTe0gNlvhZA26IavRvMQc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZfWW7YQTe0gNlvhZA26IavRvMQc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZfWW7YQTe0gNlvhZA26IavRvMQc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-5820623058600593831?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lFNcCfthJ98beZ2GnngVQkiJe84/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lFNcCfthJ98beZ2GnngVQkiJe84/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lFNcCfthJ98beZ2GnngVQkiJe84/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lFNcCfthJ98beZ2GnngVQkiJe84/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-1441842820185799648?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UqFbr04Ws7gl3vKdcYj8Pqh6N8M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UqFbr04Ws7gl3vKdcYj8Pqh6N8M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UqFbr04Ws7gl3vKdcYj8Pqh6N8M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UqFbr04Ws7gl3vKdcYj8Pqh6N8M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-1732136038451678996?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/5zmIGeiLLDQb8TIRse8QvtTAlD0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5zmIGeiLLDQb8TIRse8QvtTAlD0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/5zmIGeiLLDQb8TIRse8QvtTAlD0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/5zmIGeiLLDQb8TIRse8QvtTAlD0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-8538835298438210166?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/djA4Fz9SFuZwIg6q0DX7QqOYLtI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/djA4Fz9SFuZwIg6q0DX7QqOYLtI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/djA4Fz9SFuZwIg6q0DX7QqOYLtI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/djA4Fz9SFuZwIg6q0DX7QqOYLtI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&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://profiles.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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-6147873085626345322?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KZFMyJpky40mM8xI-O5PXXoQSu8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KZFMyJpky40mM8xI-O5PXXoQSu8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KZFMyJpky40mM8xI-O5PXXoQSu8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KZFMyJpky40mM8xI-O5PXXoQSu8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&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://profiles.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><entry gd:etag="W/&quot;D08BRXw5eCp7ImA9WhdTGEk.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-8700392712710635678</id><published>2011-07-17T01:20:00.000+05:30</published><updated>2011-07-17T01:20:54.220+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-17T01:20:54.220+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="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>ValueType and ReferenceType : Under the Hood Part 2</title><content type="html">Well, if you have read &lt;a href="http://www.abhisheksur.com/2011/07/valuetypes-and-referencetypes-under.html"&gt;my previous post&lt;/a&gt;, you should be already clear how memory of ValueTypes and ReferenceTypes are allocated and De-allocated internally in terms of IL. Here in this post, I am going to cover some more concepts behind ValueTypes and ReferenceTypes and what exactly comprises of them.&lt;br /&gt;
&lt;br /&gt;
In my&lt;a href="http://www.abhisheksur.com/2011/07/valuetypes-and-referencetypes-under.html"&gt; previous post on the series&lt;/a&gt;, I have told you that any type that inherits from System.ValueTypes is stored in Stack while any type that is not inherited from System.ValueType is stored in Heap. Well, the statement is not correct totally.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
Lets demonstrate this with an 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;class&lt;/span&gt; MyType
{
    &lt;span class="kwrd"&gt;int&lt;/span&gt; x, y;
}
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;struct&lt;/span&gt; MySType
{
    MyType typ;
}&lt;/pre&gt;
&lt;br /&gt;
In the above code, I have created two types, 1 being MyType which is a Type directly inherits from System.Object and the other being struct MySType which is derived from System.ValueType. As per our previous discussion you can say, MyType will be allocated in Heap (as it uses newobj of IL) and MySType will be created in Stack being a ValueType (as it uses initobj)&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;But what about its members?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Class MyType contains two members x and y which are ValueTypes while on the other hand MySType contains a member of MyType which is not a ValueType. So, &amp;nbsp;Where it is going to be allocated?&lt;br /&gt;
&lt;br /&gt;
Well, don't be so much confused about it. Actually while I talked about initobj in my previous post, I have already specified that it will initialize the struct with all its members with default values. Hence when initobj is initialized the value of typ will be assigned to null. At least default constructor for the ValueType does that automatically. But how does it work when we assign an object on it?&lt;br /&gt;
&lt;br /&gt;
Yes, even though MySType is actually a struct, it creates object using newobj IL statement and hence will be stored in Heap. The constructor for MyType will be called and will store the object in heap and get the reference of it in stack. of MySType itself being stored in stack will hold the Reference to the object of MyType in stack, but the actual object does not.&lt;br /&gt;
&lt;br /&gt;
On the contrary, MyType being a Class, it always store the object in heap. Being x and y the member of the type MyType, they are stored in heap itself. As the members of an object comprises the size of the object each of its members will be stored in Heap together.&lt;br /&gt;
&lt;br /&gt;
Thus the actual statement should be "Only local variables are stored in Stack if it is a value type, any other member is stored in heap". Managed environment prefers Heap than stack even though stack is high performance because stack size is limited.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Impact of new operator over Types&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Even though we all know about new operator when using reference types, "new" Operator has an important impact overValueTypes which most of people I see does have confusion. Lets clear it with an example.&lt;br /&gt;
&lt;br /&gt;
Lets say I write something like :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;MySType s = &lt;span class="kwrd"&gt;default&lt;/span&gt;(MySType);
s = &lt;span class="kwrd"&gt;new&lt;/span&gt; MySType();

Console.WriteLine(s);

Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
So here in the code you can see I have created an object of MyType and initialized to its default value which is also implicitly invoke default constructor. &amp;nbsp;In the second line the object of MySType is again created using new oprator. So what does it mean? Does it mean that the memory s is created twice ? Or new operator does not actually &amp;nbsp;create a memory and use up the existing one?&lt;br /&gt;
&lt;br /&gt;
Lets see the IL now :&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-rNrUggKjX0g/TiHa56YmVhI/AAAAAAAAD1A/i5FAD6R0vGM/s1600/load3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-rNrUggKjX0g/TiHa56YmVhI/AAAAAAAAD1A/i5FAD6R0vGM/s1600/load3.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Basically if you consider the above code, you can see that there is only one reference of local valuetype reference is created, but yet there is two initobj call in the code. So internally there will be two objects been created in your code.&lt;br /&gt;
&lt;br /&gt;
Lets make it more confusing using :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;MySType s = &lt;span class="kwrd"&gt;new&lt;/span&gt; MySType();

Console.WriteLine(s);

Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
And the output to this code is identical to what I showed earlier. Hence in case of ValueTypes you should remember, if you are using any constructor it will first initialize &lt;a href="http://www.abhisheksur.com/2010/10/hidden-facts-on-c-constructor-in.html"&gt;the object using default constructor of struct&lt;/a&gt;&amp;nbsp;and pass the same to the constructor as this. Later it will create another object of S and copy the value of temporary variable to it. This is fact.&lt;br /&gt;
&lt;br /&gt;
Hence if you are using a constructor for your stack, internally IL will create more than 1 object of your struct and assign the initialized object to the local storage in stack. &amp;nbsp;Hence "new" operator on stack always creates a new object even though it is of type Struct.&lt;br /&gt;
&lt;br /&gt;
So you can say all the local variables that you declare inside your own code block which are not member of a class are always allocated in stack? Right ?&lt;br /&gt;
&lt;br /&gt;
Wrong!!! .. It is not always true!!!&lt;br /&gt;
&lt;br /&gt;
If you think of an iterator block, or a lambda expression, or even our new async member function, the local variable here is actually mapped to a class in IL. Hence the local variable that you declare inside an iterator block is actually a member of some type in your compiled assembly. Hence&lt;a href="http://www.abhisheksur.com/2011/01/internals-to-c-iterators.html"&gt; local ValueTypes inside your iterator block is not allocated in Stack&lt;/a&gt; and&lt;a href="http://www.abhisheksur.com/2011/04/internals-of-linq.html"&gt; not for lambda&lt;/a&gt; or &lt;a href="http://www.codeproject.com/KB/cs/async.aspx"&gt;async members&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;
So as to conclude this long talk lets put some points :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Stack and Heap are the primary storage location of any .NET program. (Although it use storage registers too at times).&lt;/li&gt;
&lt;li&gt;Anything that is derived from ValueType and declared locally is sometimes allocated in Stack (with exceptions on iterator block, lambdas, async methods)&lt;/li&gt;
&lt;li&gt;Any type other than ValueType is allocated in Heap and a separate reference variable is created in Stack to use it. The Object will not be deallocated when de-referenced rather will have to rely on GC to collect them.&lt;/li&gt;
&lt;li&gt;Class Members are actually a part of a Type is stored in Heap.&lt;/li&gt;
&lt;li&gt;ValueTypes are not nullable and immutable (with exception to string...) &amp;nbsp;while Reference Types are nullable and generally mutable.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;A Value Type is passed by Value (means will copy itself in new memory) when passed to another method, Reference type will be passed as Reference (while the Reference variable is newly creates which copy the address of the Heap)&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
I hope you have found good time reading this post.&lt;br /&gt;
&lt;br /&gt;
Keep posting your feedbacks.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-8700392712710635678?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/GfOGBeEYK6Yo4lPf9YJQyJaI_eQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/GfOGBeEYK6Yo4lPf9YJQyJaI_eQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/GfOGBeEYK6Yo4lPf9YJQyJaI_eQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/GfOGBeEYK6Yo4lPf9YJQyJaI_eQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=48pYtNAmWw0:FCZKc2Yre7I: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=48pYtNAmWw0:FCZKc2Yre7I: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=48pYtNAmWw0:FCZKc2Yre7I: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=48pYtNAmWw0:FCZKc2Yre7I:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=48pYtNAmWw0:FCZKc2Yre7I: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/48pYtNAmWw0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/8700392712710635678/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/07/valuetype-and-referencetype-under-hood.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/8700392712710635678?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/8700392712710635678?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/48pYtNAmWw0/valuetype-and-referencetype-under-hood.html" title="ValueType and ReferenceType : Under the Hood Part 2" /><author><name>Abhishek Sur</name><uri>https://profiles.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/-rNrUggKjX0g/TiHa56YmVhI/AAAAAAAAD1A/i5FAD6R0vGM/s72-c/load3.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/07/valuetype-and-referencetype-under-hood.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEcHQX87cSp7ImA9WhdTGEk.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-4675077286627637217</id><published>2011-07-16T17:01:00.003+05:30</published><updated>2011-07-17T01:23:50.109+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-17T01:23:50.109+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="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=".NET 3.5" /><category scheme="http://www.blogger.com/atom/ns#" term="Memory Allocation" /><title>ValueTypes and ReferenceTypes : Under the Hood</title><content type="html">In .NET, Value Type and Reference Types are forms an element of confusion between both developers and the students. Many of us take this as granted that Value Types are allocated in Thread Stack ( a 1 MB local stack created per Thread) and on each method calls the local value types are allocated in the Stack such that after the call ends, the object is deallocated. On the contrary, the reference types we know are those which are always allocated in heap (which is not always true, I will discuss later) and even though they are used as locals, and will be deallocated only after an interval by a separate Thread that is running with any .NET process (called finalizer thread) which occationally starts finding the memory blocks on Heap storage and compact and store only the reachable objects called Garbage Collector. Well, in this post, I am not going to cover the details of Garbage Collection, but rather I will focus more on Value Types and Reference Types that I know personally to clear any doubt regarding them in terms of IL constructs. So after reading the post, you will know some of the basics of IL too.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
To tell you the truth, I have been trying to start blogging on this topic long ago, but could not get chance to finish it, but as my buddy &lt;a href="http://twitter.com/#!/zenwalker2008"&gt;@ZenWalker&lt;/a&gt; &amp;nbsp;asked me a couple of questions, which I had to answer, I considered myself writing a blog on the same such that it benefits both him and all other people. His questions sounds like this :&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;If System.ValueType inherits System.object, then all valuetypes are object. right?&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;If so,&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;1) Why do we say c# isnt pure Object Oriented because Value Types are not objects.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;2) Value Types gets created over stack because to save space over heap or may be for performance right because heap creation takes time.&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;3. Why are Value Types struct and not class if they both are objects. To&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&amp;nbsp;avoid complexity for simple types??&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;4. Why we have to do boxing and unboxing if valuetypes are objects too, or just to copy from stack to heap n back on??&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
Well the questions sounds quite interesting to me to answer and lets answer then knowing whats going on under the hood of a normal C# application and lets demonstrate them with code.&lt;br /&gt;
&lt;br /&gt;
Lets start a console application and write a code like below :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; x = 10;

&lt;span class="kwrd"&gt;object&lt;/span&gt; y = 10;

&lt;span class="kwrd"&gt;string&lt;/span&gt; s = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"x :{0}, y : {1}"&lt;/span&gt;, x, y);

Console.WriteLine(s);
Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
This is basically very simple code, where I first created one ValueType (int) an object y which is a reference type and formatted them into a string variable and loaded the string into string variable s.&lt;br /&gt;
&lt;br /&gt;
Now let me see how the IL for the same looks like :&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/-DBTiZ1RRtUs/TiFcD-9PuJI/AAAAAAAAD04/XJ0SZeKo50M/s1600/load1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-DBTiZ1RRtUs/TiFcD-9PuJI/AAAAAAAAD04/XJ0SZeKo50M/s1600/load1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now here lets take a look at the IL. The line says .entrypoint. EntryPoint identifies the start of the program. So if you declare your method as Main in .NET, the entrypoint will automatically be written on it. So it is also a compiler trick which writes the .entrypoint correctly.&lt;br /&gt;
&lt;br /&gt;
The second line says .maxstack 3. Here maxstack will indicate that the method allocates 3 units of stack for the current method. For our code, it will be&lt;br /&gt;
&lt;br /&gt;
1. To store the integer value.&lt;br /&gt;
2. To store reference to the type y while the value is stored in Heap.&lt;br /&gt;
3. To store the&amp;nbsp;reference&amp;nbsp;to the type s while the value is stored in heap.&lt;br /&gt;
&lt;br /&gt;
Hence you should remember, even though you create an object or a memory block that is allocated in Heap, the reference pointer is still allocated inside your stack, which de-reference itself once the code execution ends. When all the references to a memory is de-referenced, it is exposed to the GC for collection.&lt;br /&gt;
&lt;br /&gt;
So the next statement creates three locals for the code block in stack. locals indicates the stack allocation.&lt;br /&gt;
&lt;br /&gt;
Now lets skip the first expression and concentrate only on the lines highlighted.&lt;br /&gt;
stloc.0 : means store the value that is loaded in memory to 0th location of Stack. The line just above it says ldc.i4.s 10, which loads 4 bit integer variable (i4). So the two lines indicates that the value of 4 bit integer will get stored into stack. So without all those complexity, you can say, the two lines will actually initialize the value 10 to the Stack locals 0th location (which infact an integer).&lt;br /&gt;
&lt;br /&gt;
The next highlighted lines indicates a box on Int32. Box means your program will store /convert the loaded value into a reference. Or in other words, the line box will create a storage of 4byte in process Heap and store 10 over it and load the Reference of the Heap to memory. The next line will store the reference to the Heap to the Stack.&lt;br /&gt;
&lt;br /&gt;
Finally, the last three highlighted lines indicates that the locals are loaded into memory again from 0th position and 1st position, where the 0th position holds the value itself, and 1st stored the reference, and box the 0th position to pass in string.Format static method call.&lt;br /&gt;
&lt;br /&gt;
So upto this point you must be clear that "Each valueTypes are actually stored into stack, while Reference Type are stored in some other place (called Process Heap) and the reference is stored inside your stack so as to determine by some other Thread (called Finalizer thread) if the memory is still in use."&lt;br /&gt;
&lt;br /&gt;
Now lets see how our compiler behaves when your own objects are created :&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;struct&lt;/span&gt; MySType
{
}

&lt;span class="rem"&gt;/////////////////////////////////////&lt;/span&gt;

MyType t = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyType();
Console.WriteLine(t);

MySType s = &lt;span class="kwrd"&gt;new&lt;/span&gt; MySType();
Console.WriteLine(s);

Console.ReadKey(&lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
So here, I have created my own type, one as class MyType and another MySType while the former being a class directly inherits from System.Object while the later being a struct inherits from ValueType which in turn inherits from System.Object.&lt;br /&gt;
&lt;br /&gt;
So both of them somehow inherits all the properties of System.Object. &amp;nbsp;Then why this discrimination between the two ?&lt;br /&gt;
&lt;br /&gt;
Yes, actually if you think internally, the language&amp;nbsp;implementers&amp;nbsp;actually implemented this for us. In IL, if you specify an object of ValueType it will indicate the object will be created directly inside your stack and will have a single reference to load the value from Stack. So if you look into the IL it looks like :&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/-h7Awe4Tt1ys/TiFsDqDcRxI/AAAAAAAAD08/aq6eLl4Lhfo/s1600/load2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-h7Awe4Tt1ys/TiFsDqDcRxI/AAAAAAAAD08/aq6eLl4Lhfo/s1600/load2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
So if you see the locals, instead of creating int32 or object, it actually puts a class to hold object reference and valuetype to hold the actual value of the stack. valuetype are immutable object and will be de-referenced as soon as control returns out of scope.&lt;br /&gt;
&lt;br /&gt;
The next line creates an object of MyType by calling its default constructor using newobj. Remember, newobj means it will return the reference to the memory it creates in Heap. Its IL construct, similar to box, which actually creates a newobj internally and gets you the reference to the value you pass on the valuetype. You can see the same happen for our struct too in L_0017 which takes up the already loaded variable and creates a newobj.&lt;br /&gt;
&lt;br /&gt;
initobj on the other hand, initializes all the members to its default value and store in local stack. Yes &lt;a href="http://www.abhisheksur.com/2010/10/hidden-facts-on-c-constructor-in.html"&gt;ValueType does not require a default constructor&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
So, if you think deep into it, according to specification the IL treats a class local as Reference Type which should be constructed using newobj and a valuetype local as a Stack object which is created using initobj. So we have covered one step deep to wipe out the abstraction that is provided by the language.&lt;br /&gt;
&lt;br /&gt;
Hence, we can say, the C# compiler or any other compiler has the logic which indicates that if your type is somehow inherits from System.ValueType, treat it differently (use initobj to create it).&lt;br /&gt;
&lt;br /&gt;
Our C# construct uses Struct to do the same. Hence if you declare a struct, it will write the IL in such a way that it is immutable and stack allocated which itself is high performance memory and does not require extra GC process to de-reference it.&lt;br /&gt;
&lt;br /&gt;
Now as you are clear about it lets answer the question that I mention before :&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Why do we say c# isnt pure Object Oriented because Value Types are not objects?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;In fact, it must be clear it internally a pure object oriented and value type itself are inherited from System.Object, but C# writes the IL for ValueType specially such that the memory it allocates does not involve an extra load to Heap to reference and de-reference objects much quicker. So if your compiler / or Language does not use the facility that is exposed to IL which allow you to create a stack immutable object, it could have allocated all valuetypes into heap. Its an added facility that the language provides to us.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Value Types gets created over stack because to save space over heap or may be for performance right because heap creation takes time.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;ValueType are specially treated objects that are created directly into stack for high performance, as Stack is created on ThreadLocal storage which is limited to 1MB, but can allocate and deallocate very fact because it just moves the Pointer back and forth. Hence it saves processor cycles. &lt;br /&gt;&lt;br /&gt;Actually we dont require to save space on heap, as Heap size is limited to the process not something to the Thread itself. Hence Heap size can be increased too at times. We use stack over heap because it is high performance and cleared more easily than the later.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Why are Value Types struct and not class if they both are objects. To avoid complexity for simple types?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Well, I think the question is already answered. But yes, value types are syntactically defined using struct in C#, but theoritically if you want, you can possibly build your own language which writes IL for types which are marked somehow as valueType probably implementing your class from System.ValueType to ensure it writes initobj rather than newobj for those classes.&lt;br /&gt;&lt;br /&gt;But as we already know struct from C, Language team used this construct to define a valuetype. &amp;nbsp;Yes to make programming&amp;nbsp;simplistic.&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Why we have to do boxing and unboxing if valuetypes are objects too, or just to copy from stack to heap and back on?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;By saying object if you are talking about System.Object type, then yes, ValueTypes are actually a special objects that are created on local stack and referenced and de-referenced quickly. But if you are talking about object in terms of storage, valueTypes are not a normal object, &amp;nbsp;but a special one that are immutable. Hence it needs to be boxed, I mean stored to Heap when it needs to be used as reference type. And Unbox when the object needs to be reallocated to stack.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I hope you enjoyed this post.&lt;br /&gt;
&lt;br /&gt;
By the way, It is not always true that every ValueType is allocated in Stack. You can go for the &lt;a href="http://www.abhisheksur.com/2011/07/valuetype-and-referencetype-under-hood.html"&gt;Second part of the Series from here&lt;/a&gt;. On the other hand if you are eager to &lt;a href="http://www.abhisheksur.com/2011/03/internals-to-net.html"&gt;know more about internals of C# please read my posts&lt;/a&gt; on internals of C# language constructs.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Please put your feedback as comments.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Thank you for reading.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-4675077286627637217?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WlC17pbGGPT8e8leZT21VpbKkAQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WlC17pbGGPT8e8leZT21VpbKkAQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WlC17pbGGPT8e8leZT21VpbKkAQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WlC17pbGGPT8e8leZT21VpbKkAQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=W0K0RkyWGOY:kWfEq3wqMpc: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=W0K0RkyWGOY:kWfEq3wqMpc: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=W0K0RkyWGOY:kWfEq3wqMpc: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=W0K0RkyWGOY:kWfEq3wqMpc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=W0K0RkyWGOY:kWfEq3wqMpc: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/W0K0RkyWGOY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/4675077286627637217/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/07/valuetypes-and-referencetypes-under.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/4675077286627637217?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/4675077286627637217?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/W0K0RkyWGOY/valuetypes-and-referencetypes-under.html" title="ValueTypes and ReferenceTypes : Under the Hood" /><author><name>Abhishek Sur</name><uri>https://profiles.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/-DBTiZ1RRtUs/TiFcD-9PuJI/AAAAAAAAD04/XJ0SZeKo50M/s72-c/load1.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/07/valuetypes-and-referencetypes-under.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D08CRXY-fSp7ImA9WhZaF0w.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-7284182706491797859</id><published>2011-07-03T23:27:00.000+05:30</published><updated>2011-07-03T23:27:44.855+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-03T23:27:44.855+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="Reflection" /><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="DLR" /><category scheme="http://www.blogger.com/atom/ns#" term="Online Session" /><title>Rethinking my Session on TechEd on Road</title><content type="html">Hi Folks,&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Its been a great time together on TechEd on Road event here in Kolkata. I can recollect the fun we had out of the sessions with Pinal Dave, nice to find you here Pinal and with Bijoy Singhal on Windows Phone 7. I would also like to thank Dhanajay Kumar for coming all the way from Pune only for this session, and also for giving a wonderful session to us.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Lets now talk about my session on ".NET Fundamentals that every developers should Know". In this post I will share all the resources and source codes to make your easy way round to understand everything that you didnt understand in the session, &amp;nbsp;of course if any... :)&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;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The Presentation&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div id="__ss_8495432" style="width: 425px;"&gt;&lt;strong style="display: block; margin: 12px 0 4px;"&gt;&lt;a href="http://www.slideshare.net/abhi2434/net-4-features-that-every-developer-should-know" title="Net 4 Features that Every developer should know"&gt;Net 4 Features that Every developer should know&lt;/a&gt;&lt;/strong&gt;&lt;object height="355" id="__sse8495432" width="425"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=net4-110703125335-phpapp02&amp;stripped_title=net-4-features-that-every-developer-should-know&amp;userName=abhi2434" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed name="__sse8495432" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=net4-110703125335-phpapp02&amp;stripped_title=net-4-features-that-every-developer-should-know&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;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;The Resources&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The Session is actually divided into three sections.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;Language Enhancements (mainly C#)&lt;/li&gt;
&lt;li&gt;DateTypes included in .NET 4.0&lt;/li&gt;
&lt;li&gt;Framework Enhancements&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Lets discuss each of them in brief :&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;1. Language Enhancements :&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Named and Optional Parameters&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
One of the First enhancements that were made in the .NET framework 4.0 is Named and Optional Parameters. You can now use Optional Parameters which you can omit during its call so that the default value that you specify in the argument will automatically be initialized with. Please note, that the default value of the parameters must be a constant, as IL manipulates the initialization.&lt;br /&gt;
&lt;br /&gt;
Links :&lt;br /&gt;
&lt;a href="http://www.abhisheksur.com/2010/06/c-40-features.html"&gt;Features of .NET 4.0&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Dynamic Dispatch&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The new dynamic keyword introduced in .NET framework 4.0 allows you to defer the compiler type checking at runtime. You can invoke any method on an object of it and the compiler will ignore the calls strictly yet the type checking will be done during Runtime.&lt;br /&gt;
&lt;br /&gt;
The DLR implementation can also be moved further using IDynamicObject interface that lets you build a truly dynamic object at runtime.&lt;br /&gt;
&lt;br /&gt;
Links :&lt;br /&gt;
&lt;a href="http://www.abhisheksur.com/2010/06/c-40-features.html"&gt;Features of .NET 4.0&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.abhisheksur.com/2010/07/dynamic-behaviour-on-objects-at-runtime.html"&gt;Dynamic Behaviour on Objects at Runtime With Custom ExpandoObject&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Covariance &amp;amp; Contra-Variance&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Generic Type parameters does not follow variance before .NET 4.0. That means the basic rules of OOPS inheritence does not corresponds in case of collection. .NET 4.0 adds a new feature on Co-variance and Contra-variance which allows you to make typesafe conversion of Generic types &amp;nbsp;to its more derived type.&lt;br /&gt;
&lt;br /&gt;
Links :&lt;br /&gt;
&lt;a href="http://dailydotnettips.com/2011/06/29/working-with-co-variance-and-contra-variance-in-net-4-0/"&gt;Working with Co-Variance and ContraVariance&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.abhisheksur.com/2010/06/c-40-features.html"&gt;Features of .NET 4.0&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;2. Data Types included in .NET 4.0&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In this section I have discussed some of the data types that are new to .NET framework 4.0. The data types that I have covered are BigInteger, ComplexNumber, Tuple, Lazy, SortedSet.&lt;br /&gt;
&lt;br /&gt;
Links :&lt;br /&gt;
&lt;a href="http://dailydotnettips.com/2011/06/27/working-with-biginteger-in-net-4-0/"&gt;Working with BigInteger&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://dailydotnettips.com/2011/06/28/using-complex-numbers-in-net-4-0/"&gt;Working with Complex Number&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://dailydotnettips.com/2011/06/26/working-with-sortedset-in-net-4-0/"&gt;Working with SortedSet&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.abhisheksur.com/2010/06/lazy-initializer-to-defer-expensive.html"&gt;Lazy initialization to Defer object creation&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.abhisheksur.com/2010/11/working-with-tuple-in-c-40.html"&gt;Working with Tuple&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;3. Framework Enhancements&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Managed Extensibility Framework&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Managed extensibility framework deals with Extensibility that is most often required in mordern days. In this section I have created an application that supports extensibility and also allows pluggable application.&lt;br /&gt;
&lt;br /&gt;
Links :&lt;br /&gt;
&lt;a href="http://www.abhisheksur.com/2011/07/managed-extensibility-framework-look.html"&gt;Managed Extensibility Framework - A Look&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://mef.codeplex.com/"&gt;MEF - Extensibility&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Parallel Extensions to .NET&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
.NET now wraps around the Threading model into a new framework of classes that allows you to handle Threads more easily than before. The set of classes can use ThreadPool automatically inside it and also can be spread in multi - core platforms.&lt;br /&gt;
&lt;br /&gt;
Links :&lt;br /&gt;
&lt;a href="http://blogs.msdn.com/b/pfxteam/"&gt;Parallel Extension to .NET&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Code - Contract in .NET&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Code contract is another set of classes that allows you to handle your validation easily. I am sorry that I cannot cover this section in the Session, but the article would definitely help you. I have also added one application with the source codes.&lt;br /&gt;
&lt;br /&gt;
Links :&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.abhisheksur.com/2011/02/code-contracts-in-net-40-its-internals.html"&gt;Code Contract and its Internals&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Source Codes Demonstated in the Session :&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/.Public/TechEd-On-Road^5Kolkata^6.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;
I hope you all like my session.&lt;br /&gt;
&lt;br /&gt;
Please write your feedback too.&lt;br /&gt;
&lt;br /&gt;
Thanks, Happy Coding.&amp;nbsp;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-7284182706491797859?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VPGU9uG4if7dCSe8o9igUW8g4Dc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VPGU9uG4if7dCSe8o9igUW8g4Dc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VPGU9uG4if7dCSe8o9igUW8g4Dc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VPGU9uG4if7dCSe8o9igUW8g4Dc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=os1mYhF8b2k:BLr--ibGqVw: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=os1mYhF8b2k:BLr--ibGqVw: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=os1mYhF8b2k:BLr--ibGqVw: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=os1mYhF8b2k:BLr--ibGqVw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=os1mYhF8b2k:BLr--ibGqVw: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/os1mYhF8b2k" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/7284182706491797859/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/07/rethinking-my-session-on-teched-on-road.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/7284182706491797859?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/7284182706491797859?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/os1mYhF8b2k/rethinking-my-session-on-teched-on-road.html" title="Rethinking my Session on TechEd on Road" /><author><name>Abhishek Sur</name><uri>https://profiles.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/07/rethinking-my-session-on-teched-on-road.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUCQHkycSp7ImA9WhZaF0w.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-5107967067225673989</id><published>2011-07-03T22:27:00.001+05:30</published><updated>2011-07-03T22:27:41.799+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-03T22:27:41.799+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="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="DLR" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Managed Extensibility Framework - A Look</title><content type="html">Hi guys,&lt;br /&gt;
&lt;br /&gt;
If you are really new to .NET framework 4.0, this is going to be a quickstart guide to a new framework for extensibility which every developers should know. In this post, I will give you a brief introduction to what Managed Extensibility Framework is all about and also create a sample application on the same. &lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Note: This is the basic stripped version of MEF, if you are looking for something more advanced, stay tune with my blog; its about to follow.&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Why Managed Extensibility Framework?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
You can say MEF is a framework that is built on top of Reflection API, that addresses one special kind of requirement that most of the current developers are in. Modularizing an application is one of &amp;nbsp;the biggest concern for any software giant. Everyone, like me, look for some sort of plugin based modularization for their respective application and ultimately end up doing in their own way like what&lt;a href="http://www.abhisheksur.com/2010/06/pluggable-resource-for-wpf.html"&gt; I did before&lt;/a&gt;, which ultimately does not solve the problem as someone else might end up doing the same thing little differently and eventually "my plugins cannot go into your application" kind of situation. Hence we need some sort of&amp;nbsp;standardization to&amp;nbsp;&amp;nbsp;address this situation such that every plugin based application can work together. MEF addresses this situation by giving you a sleek way of defining your modules as plugins and your application as a Standard host of any plugins.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Lets start this using Code-First approach.&lt;br /&gt;
&lt;br /&gt;
To start with MEF you need .NET framework 4.0 and you need to add an assembly "System.ComponentModel.Composition.dll" to your project. Once you are done with this, lets start writing some simple code here and explain the concept as we go.&lt;br /&gt;
&lt;br /&gt;
Create a console application to host your components. Add a Class Library to the project and add an interface to it.&lt;br /&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;interface&lt;/span&gt; IProcessor
{
    TimeSpan ExecutionTimeSpan { get; set; }
        
    &lt;span class="kwrd"&gt;long&lt;/span&gt; Process();
        
    &lt;span class="kwrd"&gt;string&lt;/span&gt; Message { get; set; }

    Action&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; InvertMe { get; set; }
}&lt;/pre&gt;&lt;br /&gt;
The interface IProcessor is just a contract that both plugin and my application will follow. Even though you can create your application without even having an interface, &amp;nbsp;I will talk about it later, but for the time being, I have made a strict contract between the pluggable modules and the application that hosts the plugins. The interface IProcessor has few &amp;nbsp;methods in it which we need to implement somewhere. But where? Lets see.&lt;br /&gt;
&lt;br /&gt;
Add a Class Library to the Solution and name it as SerialProcessor. This would add a new class to the project. Lets rename that to SerialProcess. Add reference to System.ComponentModel.Composition.dll to the project and also a reference to the Interface library. &amp;nbsp;Once you are done, lets add this code :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;[Export(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IProcessor))]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SerialProcess : IProcessor
{
&lt;span class="preproc"&gt;#region&lt;/span&gt; IProcessor Members

&lt;span class="kwrd"&gt;public&lt;/span&gt; TimeSpan ExecutionTimeSpan
{
get;
set;
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; Process()
{
DateTime startTime = DateTime.Now;

&lt;span class="kwrd"&gt;long&lt;/span&gt; j, rem, result = 0;
&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;long&lt;/span&gt; i = 2; i &amp;lt;= 5000; i++)
{
&lt;span class="kwrd"&gt;for&lt;/span&gt; (j = 2; j &amp;lt; i; j++)
{
rem = i % j;
&lt;span class="kwrd"&gt;if&lt;/span&gt; (rem == 0)
&lt;span class="kwrd"&gt;break&lt;/span&gt;;
}

&lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.InvertMe != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
&lt;span class="kwrd"&gt;this&lt;/span&gt;.InvertMe(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Step [{0}, {1}]"&lt;/span&gt;, i, j));

&lt;span class="kwrd"&gt;if&lt;/span&gt; (i == j)
result = i;
}

&lt;span class="kwrd"&gt;this&lt;/span&gt;.ExecutionTimeSpan = DateTime.Now.Subtract(startTime);

&lt;span class="kwrd"&gt;this&lt;/span&gt;.Message = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Finished processing in {0} ticks"&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;.ExecutionTimeSpan.Ticks);
&lt;span class="kwrd"&gt;return&lt;/span&gt; result;
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Message
{
get;
set;
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; Action&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; InvertMe
{
get;
set;
}

&lt;span class="preproc"&gt;#endregion&lt;/span&gt;
}&lt;/pre&gt;For time being do not concentrate on the logic that is written inside the code, just concentrate on the attribute that I specified on the class. ExportAttribute is a special attribute that comes with MEF which is used to mark a class to be used as Plugin to another application that imports it. Or in other words, you can say, all the code that you want to expose to the application that hosts the plugins should be marked with Export attribute.&lt;br /&gt;
&lt;br /&gt;
Hence you can say, the Types/ Methods/ Properties etc &amp;nbsp;once marked as Export will only be exposed to the Host which consumes the Plugins. I think you got the point clear now. &amp;nbsp;Isnt it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also pass few other MetaData imformations on the Type using&amp;nbsp;&amp;nbsp;[ExportMetadata("Foo", "Name")] attribute that can be associated with the type as well. Say for instance,&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/-pg0IOD0Fu1A/ThCBHUE4AxI/AAAAAAAADxo/ZXOpz6MFv1M/s1600/MEF1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-pg0IOD0Fu1A/ThCBHUE4AxI/AAAAAAAADxo/ZXOpz6MFv1M/s1600/MEF1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
That means you can access the string value Message as KeyValuePair from the Imported Type of IProcessor. As the Value is actually an object type and also it supports Multiple, hence you can send as many information as you want with your type. &lt;br /&gt;
&lt;br /&gt;
Once you are done lets add a new class to the Main Console Application to consume the exported IProcessor class. Lets see how the class looks 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; AssemblyProcessor
    {
        [Import(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(IProcessor)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; IProcessor CurrentProcessor { get; set; }

    }&lt;/pre&gt;&lt;br /&gt;
Once you are done importing the IProcessor interface to the main application you need to determine how the plugin should be attached to the&amp;nbsp;application. For simplicity lets Load the assembly from a certain location and pass it using Assembly.LoadFrom.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;Assembly asm = Assembly.LoadFrom(&lt;span class="str"&gt;"SerialProcessor.dll"&lt;/span&gt;);

var catalog = &lt;span class="kwrd"&gt;new&lt;/span&gt; AssemblyCatalog(asm);
            

var processor = &lt;span class="kwrd"&gt;new&lt;/span&gt; AssemblyProcessor();
var container = &lt;span class="kwrd"&gt;new&lt;/span&gt; CompositionContainer(catalog);

container.ComposeParts(processor);

&lt;span class="kwrd"&gt;if&lt;/span&gt; (processor.CurrentProcessor != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{
     IProcessor currentProcessor = processor.CurrentProcessor;
     currentProcessor.Process();

}&lt;/pre&gt;&lt;br /&gt;
So here &amp;nbsp;few things that you need to understand. First of all, the First line in the code actually Loads the a Dll from file system to an assembly using Reflection Api. Once the assembly is successfully loaded in an assembly instance, we need to create an object of AssemblyCatalog. The assemblyCatalog class enumerates all the types, methods, fields that has Export Attribute in it and create a collection of ComposableParts. Oh wait, wait.. &amp;nbsp;Lets define ComposablePart first.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;ComposablePart&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
A ComposablePart is a composable unit in MEF. That means it holds all the information regarding either Export Unit (in our case IProcessor) or an Import Unit (nothing in our case, as our plugin does not include any Import Attribute). Hence each catalog exposes a property Parts which holds a collection of ExportDefination and ImportDefination where ExportDefination holds each Exports and ImportDefinations holds each Import.&lt;br /&gt;
&lt;br /&gt;
If you loop through all the Parts of a catalog using the code below you can get all the information regarding the Exported type IProcessor.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var part &lt;span class="kwrd"&gt;in&lt;/span&gt; catalog.Parts)
{
    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var exp &lt;span class="kwrd"&gt;in&lt;/span&gt; part.ExportDefinitions)
    {
        Console.WriteLine(&lt;span class="str"&gt;"Export Contract {0}"&lt;/span&gt;, exp.ContractName);

        &lt;span class="rem"&gt;//Write MetaData &lt;/span&gt;
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var metadata &lt;span class="kwrd"&gt;in&lt;/span&gt; exp.Metadata)
            Console.WriteLine(&lt;span class="str"&gt;"Metadata {0} for Part : {1} is {2}"&lt;/span&gt;, metadata.Key, exp.ContractName, metadata.Value);
    }
}&lt;/pre&gt;&lt;br /&gt;
The code will list all the Contracts defined within the assembly which is loaded in the catalog. The MetaData will list all the MetaData informations added to the Type using ExportMetaDataAttribute (which in our case is a message Serial Processor).&lt;br /&gt;
&lt;br /&gt;
Once the Exports are loaded, its time to Map each Export defined in the dll (SerialProcessor.dll) with the corresponding Reference in the application which is defined within the class AssemblyProcessor. To do this we need a CompositionContainer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;var processor = &lt;span class="kwrd"&gt;new&lt;/span&gt; AssemblyProcessor();
var container = &lt;span class="kwrd"&gt;new&lt;/span&gt; CompositionContainer(catalog);
container.ComposeParts(processor);

&lt;span class="kwrd"&gt;if&lt;/span&gt; (processor.CurrentProcessor != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{
       IProcessor currentProcessor = processor.CurrentProcessor;
       currentProcessor.Process();

}&lt;/pre&gt;&lt;br /&gt;
So here we  first create an Instance of AssemblyProcessor that I have defined in the assembly and then create an instance of CompositionContainer and pass our Catalog into it. &lt;br /&gt;
&lt;br /&gt;
The CompositionContainer gets Exports from the catalog and ultimately maps with Imports when ComposeParts extension method is called. &lt;br /&gt;
&lt;br /&gt;
Hence when we call ComposeParts and pass a type (in our case AssemblyProcessor) it will find all the Import defined on the type and maps the Export with its respective Import. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;What if I have more than one Type implements IProcessor with Export attribute ?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Interesting question. Yes in such a situation, you need to use ImportMany rather than Import. Lets see how to deal with such scenario.&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/-xrg5h0Jobgc/ThCaHiLJJNI/AAAAAAAADxs/aKoJ01LBsf0/s1600/MEF2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-xrg5h0Jobgc/ThCaHiLJJNI/AAAAAAAADxs/aKoJ01LBsf0/s1600/MEF2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
If you have more than one Type that matches the criteria, you need to use ImportMany attribute to load it into an IEnumerable. Now the CurrentProcessor will hold a collection of types that implements IProcessor and also has an Export Attribute.&lt;br /&gt;
&lt;br /&gt;
MEF is dynamically composed, How ?&lt;br /&gt;
&lt;br /&gt;
Managed Extensibility Framework actually takes help of Reflection API to load Types dynamically during runtime. It exposes and maps Export with Import directly during runtime and invokes each method at runtime. So once the appropriate types are loaded you can use it normally in your code.&lt;br /&gt;
&lt;br /&gt;
So our application is now ready. Lets try it now and it works.&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/-1pWRC2PGaBQ/ThCdTedh5KI/AAAAAAAADxw/Prew5WbiuWE/s1600/MEF3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-1pWRC2PGaBQ/ThCdTedh5KI/AAAAAAAADxw/Prew5WbiuWE/s1600/MEF3.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
So parallel will be invoked in First occation and then Serial. It also lists the Threads in Threadpool. You can find the complete application from here :&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="https://skydrive.live.com/embedicon.aspx/.Public/MefDemo.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;
Please try the application.&lt;br /&gt;
I hope this gives you a brief idea on why we need MEF. Looking for more advanced thing? Stay tune, its coming very soon. Follow me to get updates.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading.&lt;br /&gt;
Happy Programming&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-5107967067225673989?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-WVAQszUPheWkHN11KsxAVTs8GU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-WVAQszUPheWkHN11KsxAVTs8GU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-WVAQszUPheWkHN11KsxAVTs8GU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-WVAQszUPheWkHN11KsxAVTs8GU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=XDyCiPRvCJI:m_Fb4F6M37I: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=XDyCiPRvCJI:m_Fb4F6M37I: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=XDyCiPRvCJI:m_Fb4F6M37I: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=XDyCiPRvCJI:m_Fb4F6M37I:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=XDyCiPRvCJI:m_Fb4F6M37I: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/XDyCiPRvCJI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/5107967067225673989/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/07/managed-extensibility-framework-look.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/5107967067225673989?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/5107967067225673989?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/XDyCiPRvCJI/managed-extensibility-framework-look.html" title="Managed Extensibility Framework - A Look" /><author><name>Abhishek Sur</name><uri>https://profiles.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/-pg0IOD0Fu1A/ThCBHUE4AxI/AAAAAAAADxo/ZXOpz6MFv1M/s72-c/MEF1.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/07/managed-extensibility-framework-look.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMAQnY9fyp7ImA9WhZaEE0.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-7930320608467324223</id><published>2011-06-25T18:23:00.001+05:30</published><updated>2011-06-25T18:24:03.867+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-25T18:24:03.867+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="design pattern" /><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>Some facts about Null in .NET</title><content type="html">As I am tweeting around the facts on Nulls for last couple of days, I thought of writing a blog on that as many of you have already requested me on this regard.  This post is basically dealing with Nulls and will go through only with basic C# stuffs, so for geeks, it is not recommended and you might end up knowing a little or almost nothing. So if you just here for time pass, then I refer to read on. &lt;br /&gt;
&lt;br /&gt;
Considering the fact Nulls appear on any objects, we have mainly two categories of programmable storage in .NET.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Nullables (generally mutable with exceptions like strings)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Value Types / struct (generally immutable)&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;Nullables are types that either user defined or in framework in which one of  its value can be null. .NET treats null specially. Say for instance : &lt;/div&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;class&lt;/span&gt; Program
    {
        &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)
        {
            X xobj = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
            Y yobj = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

           
        }
    }
&lt;/pre&gt;&lt;br /&gt;
Here both xobj and yobj holds null, but you cannot equate &lt;b&gt;xobj == yobj&lt;/b&gt;. It is illegal.  &lt;br /&gt;
&lt;br /&gt;
Another important fact is Unassigned local values are not treated as null. .NET compiler throws exception when an unassigned variable is used. But if you declare the member of a class unassigned, it will automatically be assigned to null. Hence : &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;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
        {
            X xobj;
            Y yobj = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

            xobj = xobj ?? &lt;span class="kwrd"&gt;new&lt;/span&gt; X();


        }
&lt;/pre&gt;&lt;br /&gt;
Throws exception while : &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; X
    {
        Y yobj;

        &lt;span class="kwrd"&gt;public&lt;/span&gt; X()
        {
            yobj = yobj ?? &lt;span class="kwrd"&gt;new&lt;/span&gt; Y();
        }
    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Y
    {
    }
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
And it does not throw any exception.  &lt;br /&gt;
&lt;br /&gt;
Note : If you don’t remember ?? in the above code, then it’s the new &lt;b&gt;Null Coalesce Operator&lt;/b&gt; which assigns the value on the right when value on the left is null. &lt;br /&gt;
&lt;br /&gt;
Another important thing that comes with Nulls are Nullable value types. We can use Nullable&lt;t&gt; where T is a struct easily to interface a valuetypes to take nulls. &lt;br /&gt;
&lt;br /&gt;
&lt;/t&gt;&lt;br /&gt;
&lt;pre&gt;int x = 0;
int? x = null;&lt;/pre&gt;&lt;br /&gt;
Where int? is a short form for Nullable&lt;int&gt;. Cool huh.  Nullable object contains two properties, HasValue which indicates whether the object is assigned to any value. It returns false when the value is null, and Value which holds the value.  The value returns default(int) when the HasValue is false. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt; NullReferenceException&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Yes, while working with .NET one of the message that you see the most in your code is “Object reference is not set to an instance of object”. Well, its actually a message coming from NullReferenceException, and you can do nothing with it. When your code encounters a NullReferenceException it does not hold the call stack or even the actual object that generates the exception, so there is nothing we can do with it. &lt;br /&gt;
&lt;br /&gt;
Say for instance,&lt;br /&gt;
&lt;/int&gt;&lt;br /&gt;
&lt;pre class="csharpcode"&gt;X x1= &lt;span class="kwrd"&gt;null&lt;/span&gt;;
Console.WriteLine(x1.ToString());
&lt;/pre&gt;&lt;br /&gt;
Here ToString cannot be evaluated on Nulls, and hence throws NullReferenceException. So be careful to check your code full proof so that the value x1 cannot be null. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt; Null follows object hierarchy:  &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Well, it is interesting that Nulls actually follows object hierarchy. That means the object of a class which is the most derived is taken to be more nullable than its base.  Say for instance, &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Program
    {

        &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 mclass = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyClass();
            mclass.Call(&lt;span class="kwrd"&gt;null&lt;/span&gt;);

            Console.Read();
        }

        
    }

    &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;void&lt;/span&gt; Call(X x1)
        {
            Console.WriteLine(&lt;span class="str"&gt;"Called X1"&lt;/span&gt;);
        }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Call(Y y1)
        {
            Console.WriteLine(&lt;span class="str"&gt;"Called Y1"&lt;/span&gt;);
        }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Call(&lt;span class="kwrd"&gt;object&lt;/span&gt; x)
        {
            Console.WriteLine(&lt;span class="str"&gt;"Called object"&lt;/span&gt;);
        }
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; X
    {

    }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Y : X
    {

    }
&lt;/pre&gt;&lt;br /&gt;
The output will be “Called Y1” as you can see Y is the most derived class. &lt;br /&gt;
&lt;br /&gt;
Hence you can say, nulls are more prone to more nullables. If you have not defined the overload with Y, it would have called X, and finally it would have taken object. &lt;br /&gt;
&lt;br /&gt;
Note: If you overload the call method with a method which takes an object Z which does not belong to family of X, the call to the method Call would produce a compiler error saying about ambiguity. &lt;br /&gt;
&lt;br /&gt;
.NET nulls are very vital. Programmers generally try to avoid it but at times, it is the most important value for an object.  Any object derived from the family ValueType is not nullable, but other than that most of the others are nullable. &lt;br /&gt;
&lt;br /&gt;
That’s all folks. &lt;br /&gt;
&lt;br /&gt;
Happy Coding.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-7930320608467324223?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9d75UF_2QlU85qSmS0Uwg2qGIDg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9d75UF_2QlU85qSmS0Uwg2qGIDg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9d75UF_2QlU85qSmS0Uwg2qGIDg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9d75UF_2QlU85qSmS0Uwg2qGIDg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=mdEiUqtjE9Q:EOda48HLiIc: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=mdEiUqtjE9Q:EOda48HLiIc: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=mdEiUqtjE9Q:EOda48HLiIc: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=mdEiUqtjE9Q:EOda48HLiIc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=mdEiUqtjE9Q:EOda48HLiIc: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/mdEiUqtjE9Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/7930320608467324223/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/06/some-facts-about-null-in-net.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/7930320608467324223?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/7930320608467324223?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/mdEiUqtjE9Q/some-facts-about-null-in-net.html" title="Some facts about Null in .NET" /><author><name>Abhishek Sur</name><uri>https://profiles.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/06/some-facts-about-null-in-net.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMMRHc8fCp7ImA9WhZbGUk.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-6823571421652378075</id><published>2011-06-25T01:06:00.001+05:30</published><updated>2011-06-25T01:11:25.974+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-25T01:11:25.974+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="CodeProject" /><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="beyondrelational" /><title>Concept Overide vs Method Hiding in terms of C#</title><content type="html">Overriding is one of the most interesting topic that many software professionals are dealing with quite regularly. Most of the applications we write in .NET or other languages somehow uses overriding. While you write your class, one of the most important thing that you need to consider is overriding &lt;b&gt;ToString()&lt;/b&gt; to ensure that your class does not produce the&lt;b&gt; “Name of the class”&lt;/b&gt; rather you produce something useful on your context. Method hiding is another concept similar to Overriding but is actually different in many respect. But I saw many people does have a little confusion among these two concepts and does not know when to use what. Here is some sample which would help you deal with these concepts easy. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Overriding&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Overriding means redefining an existing method that comes inherited from parent class.  Say for instance, you have defined a class Animal. Animal can move and eat. So let’s define the class :&lt;br /&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; Animal
    {
        &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; Walk()
        {
            Console.WriteLine(&lt;span class="str"&gt;"Animal is now Walking"&lt;/span&gt;);
        }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Eat()
        {
            Console.WriteLine(&lt;span class="str"&gt;"Animal eats for living."&lt;/span&gt;);
        }
    }
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
So this is quite a simple class that provides two methods. The first one is Walk which prints a message, and another is Eat,  which again prints another message. Now notice, I have made the Walk method of Animal Virtual. Virtual means, the method will be bound at runtime, hence no compile time binding will be produced and runtime object will take over compile time bindings. &lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Now let’s define another class Dog which is derived from Animal. &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; Dog : Animal
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Bite()
        {
            Console.WriteLine(&lt;span class="str"&gt;"Dogs can bite"&lt;/span&gt;);
        }

        &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; Walk()
        {
            Console.WriteLine(&lt;span class="str"&gt;"Dog walks in four legs"&lt;/span&gt;);
            &lt;span class="kwrd"&gt;base&lt;/span&gt;.Walk();
        }
    }
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
So here the class Dog actually overrides the method Walk and writes another message. base keyword is used to point to base class method. &lt;br /&gt;
&lt;br /&gt;
Now let’s try the two classes&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/-JxGsVVE6g6g/TgTlUPyiI5I/AAAAAAAADw4/frvRbFRB-B4/s1600/oops1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-JxGsVVE6g6g/TgTlUPyiI5I/AAAAAAAADw4/frvRbFRB-B4/s1600/oops1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
So basically calling d.Walk will actually call the method that I have defined for Dog class. You can see when I create the object of Dog, it can also call the Walk method defined in Animal class which is inherited to it using base keyword. Hence you can say both method co-exists side by side. &lt;br /&gt;
&lt;br /&gt;
Now let’s change the call a little : &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-97bukk2lxzk/TgTlgzdpAAI/AAAAAAAADw8/DNU3pdG3b-g/s1600/oops2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-97bukk2lxzk/TgTlgzdpAAI/AAAAAAAADw8/DNU3pdG3b-g/s1600/oops2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
So here I just changed the Reference type to Animal from Dog. But it seems to have no effect on output. It can still call it.  So : &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Override for virtual method determine its link at runtime based on actual object rather than the Type it specifies. (as here reference of Animal actually calls Walk of Dog as we pass object of Dog to it)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;For every object both set of inherited members and its own overridden methods co-exist, where the base method can be accessed using base keyword.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Override keyword is used to override a virtual method.&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Method Hiding&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;
Method Hiding is a concept new to C# which hides the inherited member of a class with a new one. In case of Method hiding the runtime linking does not occur, hence compile time Links are important while both the method co-exists in the object. &lt;br /&gt;
&lt;br /&gt;
Let’s try to override the method Eat in Dog. &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; Dog : Animal
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Bite()
        {
            Console.WriteLine(&lt;span class="str"&gt;"Dogs can bite"&lt;/span&gt;);
        }

        &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; Walk()
        {
            Console.WriteLine(&lt;span class="str"&gt;"Dog walks in four legs"&lt;/span&gt;);
            &lt;span class="kwrd"&gt;base&lt;/span&gt;.Walk();
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Eat()
        {
            Console.WriteLine(&lt;span class="str"&gt;"Dog eats meat"&lt;/span&gt;);
            &lt;span class="kwrd"&gt;base&lt;/span&gt;.Eat();
        }
    }
&lt;/pre&gt;&lt;br /&gt;
Here the Eat method coming from base class Animal is hidden using a new keyword. This is called method Hiding.  Notice, you can still access Eat of Animal using “base” keyword. Then what is the difference? Let’s try: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-S79VCB1Y2Bg/TgTmMBehb9I/AAAAAAAADxA/TuaNgrlIwtw/s1600/oops3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-S79VCB1Y2Bg/TgTmMBehb9I/AAAAAAAADxA/TuaNgrlIwtw/s1600/oops3.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
So if I call Eat method from Dog object, it will call the Method Eat from class Dog which in turn can call the Animal. Hence the output in this is same as override. &lt;br /&gt;
&lt;br /&gt;
On the other hand, &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-aFZ4eOY_iOA/TgTmWIyT5kI/AAAAAAAADxE/xw15YHkHCvU/s1600/oops4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-aFZ4eOY_iOA/TgTmWIyT5kI/AAAAAAAADxE/xw15YHkHCvU/s1600/oops4.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Here you can see, the Runtime object cannot call the method Eat of Dog, even though we pass the object of Dog on Reference Animal.  Hence the Compile time binding cannot be overridden in case of Method Hiding. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;In terms of IL &lt;/span&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/-DU6Rg9kLlRM/TgTmh_Sa_2I/AAAAAAAADxI/UJO5Gffy1AU/s1600/oops6.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-DU6Rg9kLlRM/TgTmh_Sa_2I/AAAAAAAADxI/UJO5Gffy1AU/s1600/oops6.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Yes, IL is no different for the two cases. Callvirt is actually used to produce a late bound call to a method, but as I said Method hiding cannot override the Compile time bindings, it will call Eat method of Animal that is written during compilation rather than override, which calls Walk appropriately with because of virtual method. &lt;br /&gt;
&lt;br /&gt;
I hope this post comes handy. &lt;br /&gt;
&lt;br /&gt;
Thanks for reading.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-6823571421652378075?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PeymKWwwR2z7eUPmtsmcdLnw0hg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PeymKWwwR2z7eUPmtsmcdLnw0hg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PeymKWwwR2z7eUPmtsmcdLnw0hg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PeymKWwwR2z7eUPmtsmcdLnw0hg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=pMo6kzwg7Bc:UUXMwVSAAzs: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=pMo6kzwg7Bc:UUXMwVSAAzs: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=pMo6kzwg7Bc:UUXMwVSAAzs: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=pMo6kzwg7Bc:UUXMwVSAAzs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=pMo6kzwg7Bc:UUXMwVSAAzs: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/pMo6kzwg7Bc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/6823571421652378075/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/06/concept-overide-vs-method-hiding-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6823571421652378075?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/6823571421652378075?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/pMo6kzwg7Bc/concept-overide-vs-method-hiding-in.html" title="Concept Overide vs Method Hiding in terms of C#" /><author><name>Abhishek Sur</name><uri>https://profiles.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/-JxGsVVE6g6g/TgTlUPyiI5I/AAAAAAAADw4/frvRbFRB-B4/s72-c/oops1.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/06/concept-overide-vs-method-hiding-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUMERnw5eyp7ImA9WhZUEkQ.&quot;"><id>tag:blogger.com,1999:blog-2366485263164379453.post-703020617491407158</id><published>2011-06-05T22:30:00.001+05:30</published><updated>2011-06-05T22:33:27.223+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-05T22:33:27.223+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WPF" /><category scheme="http://www.blogger.com/atom/ns#" term="Unity" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Prism" /><category scheme="http://www.blogger.com/atom/ns#" term="design pattern" /><category scheme="http://www.blogger.com/atom/ns#" term="XAML" /><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="beyondrelational" /><title>Working With Prism 4.0 (Hello World Sample with MVVM)</title><content type="html">Modularity is one of the primary concern when working with a big projects. Most of us think of how we can implement our application that could be reusable across more than one applications. Patterns and Practices Team puts forward the notion of modularity with the help of Unity and Prism which most importantly focus on WPF and Silverlight applications. Being a WPF developer, it would be nice to take this apart and explain you a bit of how you can implement your application using Prism.&lt;br /&gt;
&lt;br /&gt;
Before you begin, I must tell you, this is the most basic article that guides you step by step how you can write your first Prism based application and what are the advantages of building such kind of application. I will take this further in my next posts to make more concrete samples. So if you know the basics of how you can work with Prism, I would recommend you to read my next posts.&lt;br /&gt;
&lt;br /&gt;
Also I assume you have some knowledge of &lt;a href="http://msdn.microsoft.com/en-us/library/ff649080.aspx"&gt;Unity&lt;/a&gt;, &lt;a href="http://www.abhisheksur.com/2010/12/wpf-tutorial.html"&gt;WPF &lt;/a&gt;and &lt;a href="http://www.abhisheksur.com/2010/08/woring-with-icollectionviewsource-in.html"&gt;MVVM &lt;/a&gt;to get you through with Prism.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Where do I find Prism?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Prism is a framework introduced by Patterns and Practices Team which is available &lt;a href="http://compositewpf.codeplex.com/"&gt;from here&lt;/a&gt;. After you install your bits, you will get a folder named Prism on your local drive. After you are done, lets start coding.&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;Starting Our Application&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Lets create a WPF Application now using Prism. To do that,&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Start Visual Studio and Create WPF Application.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;A MainWindow.xaml will be automatically created for you. Add some assemblies in the project you have just created.&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/-AW5JSI7xrSA/TeuWm8CCPNI/AAAAAAAADvs/40SmYdYAkpY/s1600/Prism1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-AW5JSI7xrSA/TeuWm8CCPNI/AAAAAAAADvs/40SmYdYAkpY/s1600/Prism1.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;You will find these dlls inside Bin directory under Prism. Remember to choose Desktop for WPF application.&lt;/li&gt;
&lt;li&gt;Once all the dlls successfully added we need to create a Shell first.&amp;nbsp; &lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;What is a Shell ?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;As Prism supports resolution of modules, you need a container where all the modules would appear. You can think of a Shell as your Window where all your UserControls can appear. Lets say I use MainWindow.xaml for our Shell.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;But that is not all, to make your window act like a UnityContainer, you need to change the design like below :&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;Window&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="SimplePrism.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:cal&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.codeplex.com/prism"&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;ItemsControl&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="MainRegion"&lt;/span&gt; &lt;span class="attr"&gt;cal:RegionManager&lt;/span&gt;.&lt;span class="attr"&gt;RegionName&lt;/span&gt;&lt;span class="kwrd"&gt;="MainRegion"&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 need to get rid of the Grid and specify an ItemsControl and specify the RegionName for the RegionManager which we will use later.&lt;br /&gt;
&lt;br /&gt;
Note : You can customize this window according to your wish, and the design will be common to all the modules. ItemsControl will act as a Container to the Shell.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Registering Types&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
After you have defined your Shell, you need to register some of the interfaces that will be called automatically from the container. Rather than doing this, we will use some existing Bootstraper that will do these for us. The Bootstrapper actually runs the Bootstrapping sequence to Resolve the classes needed to be configured before working with UnityContainer. The interfaces that it needs to Register are IServiceLocator, IModuleManager, IRegionManager, IModuleInitializer, IEventAggregator etc. &amp;nbsp;I will discuss them sometime later.&lt;br /&gt;
&lt;br /&gt;
As we are going to use Unity for modularity, we use UnityBootstrapper abstract class.&lt;br /&gt;
&lt;br /&gt;
Create a class in your project and derive it from UnityBootstrapper. We need to override the abstract method CreateShell at least to work with it. Lets do it now :&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; MyOwnBootStraper : UnityBootstrapper
{
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; DependencyObject CreateShell()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.Container.Resolve&amp;lt;MainWindow&amp;gt;();
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InitializeShell()
    {
        &lt;span class="kwrd"&gt;base&lt;/span&gt;.InitializeShell();

        App.Current.MainWindow = (Window)&lt;span class="kwrd"&gt;this&lt;/span&gt;.Shell;
        App.Current.MainWindow.Show();
    }

    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ConfigureModuleCatalog()
    {
        &lt;span class="kwrd"&gt;base&lt;/span&gt;.ConfigureModuleCatalog();

        ModuleCatalog moduleCatalog = (ModuleCatalog)&lt;span class="kwrd"&gt;this&lt;/span&gt;.ModuleCatalog;
        &lt;span class="rem"&gt;//ToDo : Add modules that you need. You can also use Configuration for this.&lt;/span&gt;
    }
}&lt;/pre&gt;&lt;br /&gt;
You can see we pass MainWindow to resolve the Shell inside CreateShell where the MainWindow is the name of the Window in the project that acts as a container for the Unity. &amp;nbsp;Other than that, we also need to ConfigureModuleCatalog. Here I didn't add any ModuleCatalog, and will do as we go on add a new Module for the application. And Finally the InitializeShell is used to Show the Window that is referred to the Shell (viz, MainWindow).&lt;br /&gt;
&lt;br /&gt;
Finally from App.xaml we need to Run the Bootstrapper.&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;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; App : Application
    {
        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnStartup(StartupEventArgs e)
        {
            &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnStartup(e);
            MyOwnBootStraper bootstrapper = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyOwnBootStraper();
            bootstrapper.Run();
        }
    }&lt;/pre&gt;&lt;br /&gt;
Hmm. Looks like we are done with the application. Lets try to run it. You will see the blank window appear on the screen. &lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Creating the Module&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now as you are done with the container, lets try to add a module which would be loaded into the Window. To do this, lets add a new project to the solution. You can add a Class Library if you wish, but in that case you need to add dlls that you need for Presentation layers. For the time being I am choosing another WPF application for the module.&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/-kzlQU20PZ8I/TeujsxlLcQI/AAAAAAAADvw/LS3ubeoYWzU/s1600/prism2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-kzlQU20PZ8I/TeujsxlLcQI/AAAAAAAADvw/LS3ubeoYWzU/s1600/prism2.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
We call it SimpleModule. For this project we need to add &lt;b&gt;Microsoft.Practices.Prism.dll.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Delete the App.Xaml and MainWindow.Xaml and add a new UserControl for your application. &lt;br /&gt;
&lt;br /&gt;
Before we start designing the module, lets add a ViewModel for the application. For that we use a ViewModelBase class which derives INotifyPropertyChanged event used to update the UI. The class is named as SimpleViewModel which looks like : &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; SimpleModule.ViewModel
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SimpleViewModel : ViewModelBase
    {
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _message;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Message
        {
            get { &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._message; }
            set
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.OnPropertyChanging(&lt;span class="str"&gt;"Message"&lt;/span&gt;);
                &lt;span class="kwrd"&gt;this&lt;/span&gt;._message = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.OnPropertyChanging(&lt;span class="str"&gt;"Message"&lt;/span&gt;); &lt;span class="rem"&gt;//ensures the UI gets updated.&lt;/span&gt;
            }
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; ICommand _SendToViewModel;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ICommand SendToViewModel
        {
            get
            {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;._SendToViewModel = &lt;span class="kwrd"&gt;this&lt;/span&gt;._SendToViewModel ?? &lt;span class="kwrd"&gt;new&lt;/span&gt; DelegateCommand(&lt;span class="kwrd"&gt;this&lt;/span&gt;.OnSendToViewModel);
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._SendToViewModel;
            }
        }

        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
        &lt;span class="rem"&gt;/// Called when Button SendToViewModel is clicked&lt;/span&gt;
        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnSendToViewModel()
        {
            &lt;span class="kwrd"&gt;string&lt;/span&gt; message = &lt;span class="kwrd"&gt;this&lt;/span&gt;.Message;

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrWhiteSpace(message))
            {
                MessageBox.Show(&lt;span class="str"&gt;"You passed the message "&lt;/span&gt; + message, &lt;span class="str"&gt;"Welcome!"&lt;/span&gt;, MessageBoxButton.OK);
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.Message = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty;
            }
        }
    }
}&lt;/pre&gt;&lt;br /&gt;
The class is very basic. It has one Property called Message which takes a Message from the UI. As mentioned, for any property that you use from UI you need to call INotifyPropertyChanged event to update the UI. The ICommand interface actually fired when the Button on the page is clicked. hence it shows up a messagebox and clears the text. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Let me put the ViewModelBase as well here to make it more clear : &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; ViewModelBase : INotifyPropertyChanged, INotifyPropertyChanging
    {

        &lt;span class="kwrd"&gt;public&lt;/span&gt; ViewModelBase()
        {
            
        }



        &lt;span class="rem"&gt;//Here you need to have your DataLayer Manager object or BizLogic to access database&lt;/span&gt;

        &lt;span class="rem"&gt;//private DataManager _manager;&lt;/span&gt;
        &lt;span class="rem"&gt;//public DataManager Manager&lt;/span&gt;
        &lt;span class="rem"&gt;//{&lt;/span&gt;
        &lt;span class="rem"&gt;//    get&lt;/span&gt;
        &lt;span class="rem"&gt;//    {&lt;/span&gt;
        &lt;span class="rem"&gt;//        this._manager = this._manager ?? new DataManager();&lt;/span&gt;
        &lt;span class="rem"&gt;//        return this._manager; &lt;/span&gt;
        &lt;span class="rem"&gt;//    }&lt;/span&gt;
        &lt;span class="rem"&gt;//}&lt;/span&gt;

        &lt;span class="preproc"&gt;#region&lt;/span&gt; INotifyPropertyChanged Members

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnPropertyChanged(&lt;span class="kwrd"&gt;string&lt;/span&gt; propertyName)
        {
            &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(propertyName);
        }
        &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="preproc"&gt;#region&lt;/span&gt; INotifyPropertyChanging Members

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnPropertyChanging(&lt;span class="kwrd"&gt;string&lt;/span&gt; propertyName)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;.PropertyChanging != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.PropertyChanging(&lt;span class="kwrd"&gt;this&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyChangingEventArgs(propertyName);
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; PropertyChangingEventHandler PropertyChanging;

        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
    }&lt;/pre&gt;&lt;br /&gt;
Even though INotifyPropertyChanging is not actually needed in this scenario, but it is better to use it together.  &lt;br /&gt;
&lt;br /&gt;
Note : From your ViewModelBase you should connect to Database Layer or BizLogic Layer if you have any so that data is available here. We have also added a class DelegateCommand which acts as a CommandPattern derived from ICommand interface for Button click. It just fires the Action that we pass.&lt;br /&gt;
&lt;br /&gt;
Once you are done with the ViewModels, lets add some xaml for our UserControl so that it could be loaded on the Container we have created.&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;="SimpleModuleLibrary.SampleView"&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:mc&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.openxmlformats.org/markup-compatibility/2006"&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:model&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:SimpleModuleLibrary.ViewModel"&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="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl.Resources&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;model:SimpleViewModel&lt;/span&gt; &lt;span class="attr"&gt;x:Key&lt;/span&gt;&lt;span class="kwrd"&gt;="SimpleModel"&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.Resources&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;DataContext&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource SimpleModel}"&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;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Write anything : "&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 Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"&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;="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;Button&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;ColumnSpan&lt;/span&gt;&lt;span class="kwrd"&gt;="2"&lt;/span&gt; 
                &lt;span class="attr"&gt;Content&lt;/span&gt;&lt;span class="kwrd"&gt;="Send Your Message"&lt;/span&gt;
                &lt;span class="attr"&gt;Command&lt;/span&gt;&lt;span class="kwrd"&gt;="{Binding SendToViewModel}"&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;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;
Hmm, So basically I create one textbox and one Button, which invokes the respective PropertyChanged on the ViewModel. &lt;br /&gt;
&lt;br /&gt;
Now after you have created the View in the Library, you need to register the View as Module. You should do it once for each Module (which may contain more than one view in turn).&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; SimpleModule : IModule
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IRegionViewRegistry regionViewRegistry;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; SimpleModule(IRegionViewRegistry registry)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.regionViewRegistry = registry;   
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize()
    {

        &lt;span class="rem"&gt;//We need to register our Module in MainRegion.&lt;/span&gt;
        regionViewRegistry.RegisterViewWithRegion(&lt;span class="str"&gt;"MainRegion"&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SampleView));
    }
}&lt;/pre&gt;&lt;br /&gt;
The IModule interface will tell the application to Register the View as a Module which could be loaded into MainRegion. If you have multiple Regions available, you can do it from here. &lt;br /&gt;
&lt;br /&gt;
Hey, I think the application is ready to be deployed. One thing that remains, is to add the Module in the ModuleCatalog. Lets do it now :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ConfigureModuleCatalog()
{
    &lt;span class="kwrd"&gt;base&lt;/span&gt;.ConfigureModuleCatalog();

    ModuleCatalog moduleCatalog = (ModuleCatalog)&lt;span class="kwrd"&gt;this&lt;/span&gt;.ModuleCatalog;
    &lt;span class="rem"&gt;//ToDo : Add modules that you need. You can also use Configuration for this.&lt;/span&gt;

    moduleCatalog.AddModule(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SimpleModuleLibrary.SimpleModule));
}&lt;/pre&gt;&lt;br /&gt;
Basically the ModuleCatalog will hold all the modules that you need to register for the whole application. &lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Please Note : Before you run the application change the Build Action of XAML to Page from ApplicationDefination.&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Running the App : &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So we have finished building our first application. Run the application you will see something like this  : &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-mZ7t83JvvJE/TeuyjjBh6BI/AAAAAAAADv0/nTNVdk2ksMQ/s1600/prism3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-mZ7t83JvvJE/TeuyjjBh6BI/AAAAAAAADv0/nTNVdk2ksMQ/s1600/prism3.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The MessageBox appears on the screen which shows the message you pass through the TextBox. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Please Note &amp;nbsp;: Rather than Registering the Modules directly from the Bootstrapper, you can also use Configuration to do the same. We will try to cover it on my next post.&amp;nbsp;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://cid-bafa39a62a57009c.office.live.com/self.aspx/.Public/SimplePrism.zip"&gt;You can Download Sample Code from here .&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://compositewpf.codeplex.com/"&gt;Read more about Prism.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;I&amp;nbsp;am sorry for not getting too deep in this post, you will find them in some of my next posts.&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Thank you for reading.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2366485263164379453-703020617491407158?l=www.abhisheksur.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Fn8szj3sSRw49rrdazVIqgz_oNY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Fn8szj3sSRw49rrdazVIqgz_oNY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Fn8szj3sSRw49rrdazVIqgz_oNY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Fn8szj3sSRw49rrdazVIqgz_oNY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?a=YrfzhBp-r9Y:jFSW5S7WPG8: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=YrfzhBp-r9Y:jFSW5S7WPG8: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=YrfzhBp-r9Y:jFSW5S7WPG8: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=YrfzhBp-r9Y:jFSW5S7WPG8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/abhisheksur/WTgI?i=YrfzhBp-r9Y:jFSW5S7WPG8: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/YrfzhBp-r9Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.abhisheksur.com/feeds/703020617491407158/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.abhisheksur.com/2011/06/working-with-prism-40-hello-world.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/703020617491407158?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2366485263164379453/posts/default/703020617491407158?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/abhisheksur/WTgI/~3/YrfzhBp-r9Y/working-with-prism-40-hello-world.html" title="Working With Prism 4.0 (Hello World Sample with MVVM)" /><author><name>Abhishek Sur</name><uri>https://profiles.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/-AW5JSI7xrSA/TeuWm8CCPNI/AAAAAAAADvs/40SmYdYAkpY/s72-c/Prism1.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.abhisheksur.com/2011/06/working-with-prism-40-hello-world.html</feedburner:origLink></entry></feed>

