<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Akash Kava</title>
	<atom:link href="http://akashkava.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://akashkava.com/blog</link>
	<description>Founder of NeuroSpeech</description>
	<lastBuildDate>Tue, 10 Apr 2012 18:00:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Entity Atoms Flex Edition released</title>
		<link>http://akashkava.com/blog/428/entity-atoms-flex-edition-released/</link>
		<comments>http://akashkava.com/blog/428/entity-atoms-flex-edition-released/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 18:00:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Entity]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[FLEX]]></category>
		<category><![CDATA[Flex Mobile]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[RIA Services]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/428/entity-atoms-flex-edition-released/</guid>
		<description><![CDATA[We are happy to announce release of Entity Atoms Flex Edition, which provides client frameworks and tools for ASP.NET MVC and RIA Services to access Entity Framework on any mobile platforms. Microsoft’s latest Entity Framework makes it very easy to setup complex transactional applications. However in order to extend Change Set, Authorization and Audit controls [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/428/entity-atoms-flex-edition-released/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Entity+Atoms+Flex+Edition+released";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F428%2Fentity-atoms-flex-edition-released%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F428%2Fentity-atoms-flex-edition-released%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>We are happy to announce release of <a href="http://entityatoms.neurospeech.com/" target="_blank">Entity Atoms Flex Edition</a>, which provides client frameworks and tools for ASP.NET MVC and RIA Services to access Entity Framework on any mobile platforms.</p>
<p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://store.neurospeech.com/products/entityatoms/screenshot" width="590" height="284" /></p>
<p>Microsoft’s latest Entity Framework makes it very easy to setup complex transactional applications. However in order to extend Change Set, Authorization and Audit controls to all mobile platforms Entity Atoms was designed.</p>
<p>Currently, only Flex Edition is available for download, Flex Edition lets you create Flex Mobile application that can execute on any mobile platform.</p>
<p>We are going to release new native framework and tools for major mobile platforms very soon.</p>
<h1>Key Highlights</h1>
<ul>
<li>Extend Entity Framework to all platforms using RIA Services </li>
<li>Simple LINQ Expression Rules to enable Security </li>
<li>Enable Table Audits/History including Cascade Delete </li>
<li>Customizable Code Generator (Flex, Android, C#, VB.net) </li>
<li>Simple Client and Server side validations </li>
<li>Easy Access to related entities (navigation properties) </li>
<li>JSON Endpoint with Date Handling </li>
<li>Additional UI Elements for Flex Mobile </li>
<li>Advanced Search (Search navigation properties) </li>
<li>Full ChangeSet management at Client Side </li>
<li>Unit Of Work pattern at Client Side </li>
</ul>
<h2>System Requirements</h2>
<ul>
<li>Windows 7, Windows Vista Service Pack 2,Windows XP Professional. </li>
<li>Microsoft .NET Framework 4.0 and above. </li>
<li>Microsoft Visual Studio 2010 </li>
<li>Flash Builder 4.6 </li>
<li>MS SQL Express 2005 onwards or MySQL or Oracle </li>
</ul>
<h3><a href="http://store.neurospeech.com/products/entityatoms/download" target="_blank">Click here to Download Free Demo</a></h3>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F428%2Fentity-atoms-flex-edition-released%2F&amp;title=Entity%20Atoms%20Flex%20Edition%20released"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/428/entity-atoms-flex-edition-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 8 Developer Preview (First Look)</title>
		<link>http://akashkava.com/blog/421/windows-8-developer-preview-first-look/</link>
		<comments>http://akashkava.com/blog/421/windows-8-developer-preview-first-look/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 16:21:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Developer]]></category>
		<category><![CDATA[Developer Preview]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Metro UI]]></category>
		<category><![CDATA[Preview]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[UI Atoms]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/421/windows-8-developer-preview-first-look/</guid>
		<description><![CDATA[I installed Windows Developer Preview of upcoming operating system Windows 8, and it has few good and bad things. Just like a new product, it has new dashboard and cool way to navigate between apps using touch gesture, these things sure excites me up but also looking at the internals, there are more challenges for [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/421/windows-8-developer-preview-first-look/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Windows+8+Developer+Preview+%28First+Look%29";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F421%2Fwindows-8-developer-preview-first-look%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F421%2Fwindows-8-developer-preview-first-look%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I installed Windows Developer Preview of upcoming operating system Windows 8, and it has few good and bad things. Just like a new product, it has new dashboard and cool way to navigate between apps using touch gesture, these things sure excites me up but also looking at the internals, there are more challenges for everyone to catch up with Window 8.</p>
<h1>New Task Manager</h1>
<p>Nice of all, I like the new improved Task Manager, which lets me look into complete Process Tree as well as I can see user wise Process Tree.</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/09/WindowsTaskManager.png" target="_blank"><img style="background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border: 0px;" title="WindowsTaskManager" src="http://akashkava.com/blog/wp-content/uploads/2011/09/WindowsTaskManager_thumb.png" border="0" alt="WindowsTaskManager" width="628" height="484" /></a></p>
<p>It also displays Process Tree grouped by Users.</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/09/UserProcesses.png" target="_blank"><img style="background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border: 0px;" title="UserProcesses" src="http://akashkava.com/blog/wp-content/uploads/2011/09/UserProcesses_thumb.png" border="0" alt="UserProcesses" width="579" height="484" /></a></p>
<p>And best of all, it lets me control my startup items from here, I can disable items I don’t want to auto start.</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/09/StartupItems.png" target="_blank"><img style="background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border: 0px;" title="StartupItems" src="http://akashkava.com/blog/wp-content/uploads/2011/09/StartupItems_thumb.png" border="0" alt="StartupItems" width="644" height="321" /></a></p>
<h1>New File Copy Dialog</h1>
<p>Another improved user interface is, File Copy dialog, instead of old style animation, it now displays a graph of progress with real cool line graph that’s very live.</p>
<p><img style="background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border: 0px;" title="FileCopyDialog" src="http://akashkava.com/blog/wp-content/uploads/2011/09/FileCopyDialog.png" border="0" alt="FileCopyDialog" width="467" height="302" /></p>
<h1>New Search</h1>
<p>Search is redesigned completely and you can search for settings by pressing Window + W key. Let’s say I want to change my desktop background, so I pressed Window + W and I typed “wallpaper”, it did give me these options.</p>
<p>Well I just tried all combinations of Window keys and only found following five useful combinations.</p>
<ol>
<li>Window + W lets you search the settings (usually control panel)</li>
<li>Window + P lets you switch between dual desktop and connect to projector settings</li>
<li>Window + D brings back the desktop</li>
<li>Window + F lets you search the files</li>
<li>Window + Q lets you search Metro App’s Items</li>
</ol>
<p><strong>To a big disappointment, I did not find anything to search apps, so I have to click on Windows + W and then click on App to actually search applications installed on my machine.</strong></p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/09/Wallpaper.png"><img style="background-image: none; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; margin-right: auto; border-width: 0px;" title="Wallpaper" src="http://akashkava.com/blog/wp-content/uploads/2011/09/Wallpaper_thumb.png" border="0" alt="Wallpaper" width="644" height="380" /></a></p>
<h1>No Old Apps on Metro Desktop</h1>
<p>Metro UI Apps are redesigned using HTML5+JS and Appx with Windows Runtime (XAML + Windows Runtime). So none of your old Win32, .NET apps will execute on Metro UI. They can only execute inside the desktop (old fashion windows). So we have to redesign and rewrite the applications for Metro Desktop completely from scratch.</p>
<h1>Metro Desktop Apps are not Silverlight</h1>
<p>Although they quite look like silverlight, but looking at the documentation, Microsoft has introduced complete new set of library with “Windows.UI” namespace, which represents complete copy of Silverlight controls (and more) but they are not silverlight. So if you wrote your apps in Silverlight, they wont directly run on Metro UI, but you might be able to port them to Metro UI with some code changes as namespace changes System.Windows.Controls to Windows.UI.Controls. However, it may not be so easy but you will get very unexpected behavior if you try to port it directly.</p>
<h1>Three Different UI Technologies to Deal With</h1>
<p>Well the only sad part is, now we have total 3 different UI technologies to deal with.</p>
<ol>
<li>WPF 3.0, 3.5, 4.0 (Original WPF based on XAML). Apps written on WPF are old fashioned, and they will not execute on Metro UI, they will only run in Desktop version.</li>
<li>Silverlight (Web and Phone), Once again, two different forms of same Silverlight for web and phone. However all web that runs Silverlight (and even flash) wont run on Metro UI.</li>
<li>Windows Runtime (XAML,HTML5+JS), this is complete new set of library including various controls from Silverlight and WPF, however it is still not complete with both of them and it also includes more controls of its own. This is purely for Metro UI. HTML5 and JS are once again little different as Microsoft has its own API embedded to make developers feel easy to write code. But this does not mean that your HTML5 code will work absolutely correctly without any changes on Metro UI. In IE 10, it may run, but to make it an appx, you might need to change few things.</li>
</ol>
<p>As new UI stack is introduced by Microsoft, we will soon release a new version of “<a href="http://uiatoms.neurospeech.com" target="_blank">UI Atoms</a>” that will allow users to write Windows Runtime Metro UI apps with UI Atoms Controls.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F421%2Fwindows-8-developer-preview-first-look%2F&amp;title=Windows%208%20Developer%20Preview%20%28First%20Look%29"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/421/windows-8-developer-preview-first-look/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Captcha &#8211; What do you really see?</title>
		<link>http://akashkava.com/blog/409/captcha-what-do-you-really-see/</link>
		<comments>http://akashkava.com/blog/409/captcha-what-do-you-really-see/#comments</comments>
		<pubDate>Sat, 14 May 2011 08:46:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bad]]></category>
		<category><![CDATA[Captcha]]></category>
		<category><![CDATA[Frustration]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Live]]></category>
		<category><![CDATA[Pain]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/409/captcha-what-do-you-really-see/</guid>
		<description><![CDATA[I was trying to login to my Windows Live account and I may have mistyped my password but next screen locked me out for nearly 4 times asking me more and more difficult captchas. What is Captcha? Well there are some dirty people who write automated programs to login to website and steal data, so [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/409/captcha-what-do-you-really-see/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Captcha+%26%238211%3B+What+do+you+really+see%3F";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F409%2Fcaptcha-what-do-you-really-see%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F409%2Fcaptcha-what-do-you-really-see%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I was trying to login to my Windows Live account and I may have mistyped my password but next screen locked me out for nearly 4 times asking me more and more difficult captchas.</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/05/What-Do-You-See-Captcha.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="What-Do-You-See-Captcha" border="0" alt="What-Do-You-See-Captcha" src="http://akashkava.com/blog/wp-content/uploads/2011/05/What-Do-You-See-Captcha_thumb.png" width="502" height="336" /></a></p>
<h1>What is Captcha?</h1>
<p>Well there are some dirty people who write automated programs to login to website and steal data, so website owners needed something to identify the user as Human or Program. And they made Captcha, a real painful way to prove that I am a human.</p>
<h1>Captcha Implemented wrongly on Windows Live</h1>
<p>Now I have no way to know whether the password I typed was wrong or the captcha went wrong? Because the error message says,</p>
<blockquote><p><font style="background-color: #ffffff">Type your password and characters in the picture correctly.</font></p>
</blockquote>
<p>So even after nearly 4th effort I posted this blog, because I have no idea what is this. I can figure out first character is probably X or it is a and e. Second character could be anything, A or n or even U for that matter.</p>
<h1>Image Captcha is bad</h1>
<p>I feel Image Captcha is very bad, I hear from senior citizens that they just cant read and cant understand what is it.</p>
<h1>Bad Captcha Implementations</h1>
<h3>&#160;</h3>
<h3>Windows Live</h3>
<p>Great, just after my experience with Captcha, I posted this blog, that my second attempt of entering password got me feel guilty and I was presented to certify myself as a human.</p>
<h3>StackOverflow</h3>
<p>It is website where we ask and answer questions, always if I have answered and I may have realized spelling or semantic mistake and I go back to edit it quickly, this website turns on me thinking I am an evil computer program and posts me back a CAPTCHA thinking that it is very rare for a human to click and edit and correct spelling or words within 10 seconds.</p>
<p>I want to add more painful captcha implementations in this post so guys help me adding your own experiences.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F409%2Fcaptcha-what-do-you-really-see%2F&amp;title=Captcha%20%26%238211%3B%20What%20do%20you%20really%20see%3F"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/409/captcha-what-do-you-really-see/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MEF vs. Unity in composite application (Prism)</title>
		<link>http://akashkava.com/blog/391/mef-vs-unity-in-composite-application-prism/</link>
		<comments>http://akashkava.com/blog/391/mef-vs-unity-in-composite-application-prism/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 07:40:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/?p=391</guid>
		<description><![CDATA[This article describes differences between MEF and Unity which may help you in deciding which technology you must use while making composite application. Both technologies are useful and easy to understand, and offer a rich set of features that can make integration of various software components very easy. However, both being little different in functioning [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/391/mef-vs-unity-in-composite-application-prism/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "MEF+vs.+Unity+in+composite+application+%28Prism%29";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F391%2Fmef-vs-unity-in-composite-application-prism%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F391%2Fmef-vs-unity-in-composite-application-prism%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This article describes differences between MEF and Unity which may help you in deciding which technology you must use while making composite application.
</p>
<p>Both technologies are useful and easy to understand, and offer a rich set of features that can make integration of various software components very easy. However, both being little different in functioning they offer exact same level of features but choosing wrong one can lead to chaos.
</p>
<p>So we will drill down to differences between their operations.
</p>
<div>
<table style="border-collapse:collapse" border="0">
<colgroup>
<col style="width:284px"/>
<col style="width:344px"/></colgroup>
<tbody valign="top">
<tr style="background: #d9d9d9">
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  solid #d9d9d9 0.5pt; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  solid #d9d9d9 0.5pt; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity creates new instance of type by default.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF creates singleton instance of type by default.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity does not require registration for classes. This means you can instantiate any other third party type.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF requires Export attribute to be specified on the class. MEF cannot create instance of third party type unless it defines Export.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity requires type registration in code for interface types.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>No registration, simple Export attribute does it all.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity container can compose IUnityContainer property in the composed class where you can further access it easily in your own scope. This behavior is not useful for Plugin architecture as getting access to IUnityContainer may result in full access to your application.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF does not allow composition of CompositionContainer, which blocks access to MEF in your own scope if you do not have CompositionContainer. This is useful in Plugin architecture where third party code has limited access to your application. </p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity offers injection method mechanism, that can define IUnityContainer parameter and get the unity container object, with which you can compose other private properties manually.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF can only compose public properties, this is dangerous as anyone can change public property and make application crash easily.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Inside your application&#8217;s framework code, Unity serves the best as it gives you full control over type hierarchy, lifecycle and allows you to utilize third party components easily without writing much of code. </p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Inside your application, MEF will put lots of restrictions in which your framework can operate as it cannot easily compose third party components and it will force you to write numerous attributes in your code without which it will fail drastically.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Mostly, User Interface objects like your View, or UserControl or any UIElement can never be shared as no UIElement can have two parents at same time. So default behavior of Unity to create a new instance of type is very helpful.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Default behavior of MEF will create only one single instance of UI object, that will lead to trouble, not only that, if UI object is third party tool, MEF will not compose it. You can create multiple copies of exported type by specifying one more attribute called [PartCreationPolicy(Shared)], however it is very time comsuming and tedious to define this one every UI related type we create.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity does allow singleton objects, but for that you have to register an instance to the container.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF by default creates singleton object only.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity does not allow multiple registrations for same instance in same scope sharing same interface but different type. </p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF allows multiple singleton objects of different type sharing same interface.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity works best for MVVM, as composing user interface parts can be very easy with unity.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF does not work great with MVVM as it will create singleton objects that will behave strangely in runtime and lead to UI failure.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>Unity is not good for Modularity, as composing IUnityContainer will offer more control of unity lifecycle to third party modules.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>MEF is good for Modularity, as it will not allow modification of composition thus offering great deal of security between modules.</p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  solid #d9d9d9 0.5pt; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>So, to develop a framework, MVVM Crud application and a UI framework, Unity is the best.</p>
</td>
<td vAlign="middle" style="padding-top: 2px; padding-left: 2px; padding-bottom: 2px; padding-right: 2px; border-top:  none; border-left:  none; border-bottom:  solid #d9d9d9 0.5pt; border-right:  solid #d9d9d9 0.5pt">
<p>To expose some functionality of your application for third party modules to register and access limited functionality, MEF is the best.</p>
</td>
</tr>
</tbody>
</table>
</div>
<p> <br />
 </p>
<p>Following is outline of how your application should be,
</p>
<p>Unity Container must compose and manage your application&#8217;s framework, UI and MEF modules.
</p>
<p>MEF will only expose limited functionality from Unity Container to third party modules.
</p>
<p>No module, through MEF should have access to unity container at all.
</p>
<p><img src="http://akashkava.com/blog/wp-content/uploads/2011/04/042711_0740_MEFvsUnityi12.png" alt=""/>
	</p>
<p>Thank you for reading this article, please put your suggestions below in the comment. I do not intend to make any specific rules and regulations here but I am suggesting the architecture based on the differences I have outlined.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F391%2Fmef-vs-unity-in-composite-application-prism%2F&amp;title=MEF%20vs.%20Unity%20in%20composite%20application%20%28Prism%29"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/391/mef-vs-unity-in-composite-application-prism/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>UI Atoms 1.7.5 Released</title>
		<link>http://akashkava.com/blog/387/ui-atoms-1-7-5-released/</link>
		<comments>http://akashkava.com/blog/387/ui-atoms-1-7-5-released/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 09:04:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Customize]]></category>
		<category><![CDATA[DataForm]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[UI Atoms]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/387/ui-atoms-1-7-5-released/</guid>
		<description><![CDATA[We are happy to announce new release of UI Atoms 1.7.5 with following new features. New AtomDataForm Control Tabs in AtomForm and AtomDataForm Lambda Binding Extensions Introducing new Control AtomDataForm AtomForm did support UI Validations, however Microsoft RIA Services Client has some inbuilt validation and support for IEditableObject. So we created a new AtomDataForm that [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/387/ui-atoms-1-7-5-released/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "UI+Atoms+1.7.5+Released";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F387%2Fui-atoms-1-7-5-released%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F387%2Fui-atoms-1-7-5-released%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>We are happy to announce new release of UI Atoms 1.7.5 with following new features.</p>
<ol>
<li>New AtomDataForm Control </li>
<li>Tabs in AtomForm and AtomDataForm </li>
<li>Lambda Binding Extensions </li>
</ol>
<h2>Introducing new Control AtomDataForm</h2>
<p>AtomForm did support UI Validations, however Microsoft RIA Services Client has some inbuilt validation and support for IEditableObject. So we created a new AtomDataForm that supports RIA Services validation and IEditableObject support.</p>
<ol>
<li>AtomDataForm supports object with IEditableObject interface and fires event for BeginEdit, CancelEdit and EndEdit </li>
<li>AtomDataForm displays items in read only mode unless Edit button is clicked </li>
<li>After edit button is clicked, Save and Cancel button appear for you to persist changes or cancel changes </li>
<li>AtomDataForm contains UI Element (TextBox, ComboBox etc) as children, so you can easily define child ui element in your xaml as shown in sample below </li>
<li>AtomDataForm supports Tabbed layout, for that you can insert your items within AtomDataFormTab as shown in example below </li>
<li>Following sample illustrates Tabs, but you can also create simple user interface without tab as well </li>
<li>You can also use AtomDataFormGroup to group items in to a headered group </li>
<li>Every child element of AtomDataForm can be accessed in code behind file easily because they appear as a variables when you define x:Name property </li>
<li>AtomDataForm supports CanChangeDataContext property, which is false when the form is in edit mode </li>
<li>You can easily reuse any third party control within AtomDataForm, AtomDataFormGroup and AtomDataFormTab </li>
</ol>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4af705bb-bc40-4470-8c60-7e87ee7745ca" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">AtomDataForm Sample</div>
<div style="background: #ddd; max-height: 500px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataForm</span> </li>
<li>   <span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">=&quot;1&quot;</span> </li>
<li>   <span style="color:#ff0000"> DataContext</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> SelectedItem</span><span style="color:#0000ff">,</span><span style="color:#ff0000">ElementName</span><span style="color:#0000ff">=dataGrid}&quot; &gt;</span></li>
<li>            <span style="color:#a31515"></span></li>
<li>    <span style="color:#a31515"></span><span style="color:#008000">&lt;!&#8211; 1st Tab&#8211;&gt;</span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataFormTab</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">=&quot;Default&quot;&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBox</span> </li>
<li>           <span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomDataForm.Label</span><span style="color:#0000ff">=&quot;Name:&quot;</span> </li>
<li>           <span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> ProductName</span><span style="color:#0000ff">,</span><span style="color:#ff0000"> Mode</span><span style="color:#0000ff">=TwoWay}&quot;/&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomToggleButtonBar</span> </li>
<li>           <span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomDataForm.Label</span><span style="color:#0000ff">=&quot;Type:&quot;</span></li>
<li>           <span style="color:#ff0000"> SelectedItem</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> ProductType</span><span style="color:#0000ff">,</span><span style="color:#ff0000">Mode</span><span style="color:#0000ff">=TwoWay}&quot;&gt;</span></li>
<li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">sys</span><span style="color:#0000ff">:</span><span style="color:#a31515">String</span><span style="color:#0000ff">&gt;</span><span style="color:#a31515">Product</span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">sys</span><span style="color:#0000ff">:</span><span style="color:#a31515">String</span><span style="color:#0000ff">&gt;</span></li>
<li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">sys</span><span style="color:#0000ff">:</span><span style="color:#a31515">String</span><span style="color:#0000ff">&gt;</span><span style="color:#a31515">Service</span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">sys</span><span style="color:#0000ff">:</span><span style="color:#a31515">String</span><span style="color:#0000ff">&gt;</span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomToggleButtonBar</span><span style="color:#0000ff">&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBox</span></li>
<li>           <span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomDataForm.Label</span><span style="color:#0000ff">=&quot;Folder:&quot;&gt;</span></li>
<li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataForm.CommandBox</span><span style="color:#0000ff">&gt;</span></li>
<li>                <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Button</span><span style="color:#ff0000"> Content</span><span style="color:#0000ff">=&quot;&#8230;&quot;/&gt;</span></li>
<li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataForm.CommandBox</span><span style="color:#0000ff">&gt;</span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">TextBox</span><span style="color:#0000ff">&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataFormTab</span><span style="color:#0000ff">&gt;</span></li>
<li>            <span style="color:#a31515"></span></li>
<li>    <span style="color:#a31515"></span><span style="color:#008000">&lt;!&#8211; 2nd Tab&#8211;&gt;</span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataFormTab</span><span style="color:#ff0000"> Header</span><span style="color:#0000ff">=&quot;General&quot;&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBox</span> </li>
<li>           <span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomDataForm.Label</span><span style="color:#0000ff">=&quot;Email:&quot;</span>  </li>
<li>           <span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> Email</span><span style="color:#0000ff">,</span><span style="color:#ff0000"> Mode</span><span style="color:#0000ff">=TwoWay}&quot;/&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataFormTab</span><span style="color:#0000ff">&gt;</span></li>
<li>            <span style="color:#a31515"></span></li>
<li>    <span style="color:#a31515"></span><span style="color:#008000">&lt;!&#8211; 3rd Conditional Tab&#8211;&gt;</span></li>
<li>    <span style="color:#a31515"></span><span style="color:#008000">&lt;!&#8211; This tab will be visible only if Product&#39;s </span></li>
<li>    <span style="color:#008000">IsTypeService is true&#8211;&gt;</span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataFormTab</span> </li>
<li>       <span style="color:#ff0000"> Header</span><span style="color:#0000ff">=&quot;Service&quot;</span> </li>
<li>       <span style="color:#ff0000"> IsEnabled</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> IsTypeService}</span><span style="color:#0000ff">&quot;&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBox</span> </li>
<li>           <span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomDataForm.Label</span><span style="color:#0000ff">=&quot;Service Details:&quot;/&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataFormTab</span><span style="color:#0000ff">&gt;</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#a31515"></span><span style="color:#008000">&lt;!&#8211; 4th Conditional Tab&#8211;&gt;</span></li>
<li>    <span style="color:#a31515"></span><span style="color:#008000">&lt;!&#8211; This tab will be visible only if Product&#39;s </span></li>
<li>    <span style="color:#008000">IsTypeProduct is true&#8211;&gt;</span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataFormTab</span> </li>
<li>       <span style="color:#ff0000"> Header</span><span style="color:#0000ff">=&quot;Product&quot;</span> </li>
<li>       <span style="color:#ff0000"> IsEnabled</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> IsTypeProduct}</span><span style="color:#0000ff">&quot;&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBox</span><span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomDataForm.Label</span><span style="color:#0000ff">=&quot;Product Details:&quot;</span> <span style="color:#0000ff"> &gt;</span></li>
<li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataForm.CommandBox</span><span style="color:#0000ff">&gt;</span></li>
<li>                <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Button</span><span style="color:#ff0000"> Content</span><span style="color:#0000ff">=&quot;Search&quot;/&gt;</span></li>
<li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataForm.CommandBox</span><span style="color:#0000ff">&gt;</span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">TextBox</span><span style="color:#0000ff">&gt;</span></li>
<li>                <span style="color:#a31515"></span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataFormTab</span><span style="color:#0000ff">&gt;</span></li>
<li>            <span style="color:#a31515"></span></li>
<li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomDataForm</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>In above sample you can notice following things,</p>
<ol>
<li>Header property of AtomDataFormTab is displayed in the title section on the top </li>
<li>AtomDataFormTab contains children and each child can have properties as below
<ol>
<li>ns:AtomDataForm.Label displays label on left side </li>
<li>ns:AtomDataForm.Description displays description on bottom </li>
<li>ns:AtomDataForm.Title displays title on the top of control </li>
<li>ns:AtomDataForm.CommandBox displays a UI Element on the right corner, usually a search button or expand button </li>
</ol>
</li>
<li>AtomDataFormTab supports IsEnabled binding, you can bind this property to show/hide the tab as shown in the example above </li>
<li>Every child elemen of either AtomDataForm , AtomDataFormTab or AtomDataFormGroup supports Visibility and IsEnabled binding
<ol>
<li>If Visibility is bound and it results in Collapsed then entire form item is not displayed </li>
<li>IsEnabled binding can enable/disable the editable control </li>
</ol>
</li>
</ol>
<p>Following is screenshot of Tabbed AtomDataForm in edit mode</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/04/AtomDataForm.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="AtomDataForm" border="0" alt="AtomDataForm" src="http://akashkava.com/blog/wp-content/uploads/2011/04/AtomDataForm_thumb.png" width="367" height="275" /></a></p>
<h2>Introducing Lambda Binder Extensions</h2>
<p>Writing binding expressions with conditions and converters can be very complex especially rewriting many and same logic at different classes. Now UI Atoms support, Lambda Binding Extensions which lets you do binding within the code without creating any complex IValueConverter implementation.</p>
<h3>Bind Method Extension</h3>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e332ae3d-d3f7-4a80-9c53-c235f4c6914e" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Element Property Binding</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li>theForm.Bind(<span style="color:#2b91af">AtomDataForm</span>.HeaderProperty,</li>
<li>    () =&gt; <span style="color:#0000ff">string</span>.Format(<span style="color:#a31515">&quot;{0} ({1})&quot;</span>,</li>
<li>            productName.Text,</li>
<li>            typeToggleButtonBar.SelectedItem</li>
<li>        ));</li>
</ol></div>
</p></div>
</p></div>
<p>This will bind theForm’s Header property to an expression that will combine properties of two different elements. And this will also automatically update when any of bound source or its property will change.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3002cb7e-bef1-4f9b-9df1-b62ba184b9b3" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">DataContext Property Binding</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li>theForm.Bind(<span style="color:#2b91af">AtomDataForm</span>.HeaderProperty, </li>
<li>    () =&gt; <span style="color:#0000ff">string</span>.Format(<span style="color:#a31515">&quot;{0} ({1})&quot;</span>,</li>
<li>            theForm.DataContext.Property(<span style="color:#a31515">&quot;ProductName&quot;</span>),</li>
<li>            theForm.DataContext.Property(<span style="color:#a31515">&quot;ProductType&quot;</span>)</li>
<li>        ));</li>
</ol></div>
</p></div>
</p></div>
<p>Assuming, we may not have property information at design time, but we know that DataContext will be set to an object containing properties, then we can write Property extension method as shown above.</p>
<h3>BindVisibility Method Extension</h3>
<p>Visibility converters are very frequent so we created a BindVisibility extension method that will let you specify a boolean expression that will be converted to Visibility on the fly.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a064c496-433a-43e7-a96f-5b55bd5a8449" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">BindVisibility Extension</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li>productTab.BindVisibility(</li>
<li>    () =&gt; </li>
<li>        typeToggleButtonBar.SelectedIndex == 0);</li>
</ol></div>
</p></div>
</p></div>
<p>These extensions can be used anywhere in any third party controls as well.</p>
<h3>Download Now</h3>
<p><a href="http://uiatoms.neurospeech.com/v1/download/UIAtoms2010Demo.zip" target="_blank">Click here</a> to download your free demo copy of NeuroSpeech UI Atoms 1.7.5</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F387%2Fui-atoms-1-7-5-released%2F&amp;title=UI%20Atoms%201.7.5%20Released"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/387/ui-atoms-1-7-5-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lambda Binder for WPF and Silverlight</title>
		<link>http://akashkava.com/blog/382/lamda-binder-for-wpf-and-silverlight/</link>
		<comments>http://akashkava.com/blog/382/lamda-binder-for-wpf-and-silverlight/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 10:19:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Binding]]></category>
		<category><![CDATA[Expression]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MultiBinding]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[UI Atoms]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/382/lamda-binder-for-wpf-and-silverlight/</guid>
		<description><![CDATA[LambdaBinder class helps in creating complex binding expressions without having to create IValueConverter and IMultiValueConverter, it lets you write inline expresions with advanced binding scenarios. Lets say, you have two TextBox for first and last name and you want a Title to be displayed as addition of both. So lets say, you can write it [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/382/lamda-binder-for-wpf-and-silverlight/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Lambda+Binder+for+WPF+and+Silverlight";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F382%2Flamda-binder-for-wpf-and-silverlight%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F382%2Flamda-binder-for-wpf-and-silverlight%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>LambdaBinder class helps in creating complex binding expressions without having to create IValueConverter and IMultiValueConverter, it lets you write inline expresions with advanced binding scenarios.</p>
<p>Lets say, you have two TextBox for first and last name and you want a Title to be displayed as addition of both.</p>
<p>So lets say, you can write it as follow,</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9061959b-fde6-475a-bf14-95c7053acc05" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Adding Two Properties</div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;">title.Bind(<span style="color:#2b91af">TextBlock</span>.TextProperty, <br />     () =&gt; firstName.Text + <span style="color:#a31515">&quot; &quot;</span> + lastName.Text);</div>
</p></div>
</p></div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:be7019f9-9dce-4972-870e-e80107dfd84c" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Formatting Properties</div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;">title.Bind(<span style="color:#2b91af">TextBlock</span>.TextProperty, <br />     () =&gt; <span style="color:#0000ff">string</span>.Format(<span style="color:#a31515">&quot;{0} {1}&quot;</span>, <br />         firstName.Text, lastName.Text));</div>
</p></div>
</p></div>
<p>You can pass on the Linq expression to Bind extension method of LamdaBinder and that will convert and set binding so that anytime if firstName or lastName is modified, the title will be updated automatically.</p>
<p>Assuming I want some hypothetical visibility logic, for example, only if the firstName is entered, lastName should be visible.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5714191b-945b-42ad-ab19-bb35ba18d822" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Conditional Visibility Binding</div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;">lastName.Bind(<span style="color:#2b91af">TextBox</span>.VisibilityProperty, <br />     () =&gt; firstName.Text.Length &gt; 0 ? <span style="color:#2b91af">Visibility</span>.Visible : <br />         <span style="color:#2b91af">Visibility</span>.Collapsed);</div>
</p></div>
</p></div>
<p>You can also use this to avoid writing IValueConverters and do inline binding in code very easily.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3581c9f9-18d6-4824-97c5-f4d710e7ecd4" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Lambda Binder</div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">LambdaBinder</span><br /> {</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> Bind(<br />         <span style="color:#0000ff">this</span> <span style="color:#2b91af">DependencyObject</span> dest, <br />         <span style="color:#2b91af">DependencyProperty</span> destProperty, <br />         <span style="color:#2b91af">Expression</span>&lt;Func&lt;<span style="color:#0000ff">object</span>&gt;&gt; func)<br />     {<br />         <span style="color:#2b91af">MultiBinding</span> b = <span style="color:#0000ff">new</span> <span style="color:#2b91af">MultiBinding</span>();<br />         b.Converter = <span style="color:#0000ff">new</span> <span style="color:#2b91af">MultiDelegateConverter</span>(func.Compile());<br />         <span style="color:#2b91af">LambdaBindingBuilder</span> bb = <span style="color:#0000ff">new</span> <span style="color:#2b91af">LambdaBindingBuilder</span>(b);<br />         bb.Visit(func.Body);<br />         <span style="color:#2b91af">BindingOperations</span>.SetBinding(dest, destProperty, b);<br />     }</p>
<p> }</p>
<p> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">LambdaBindingBuilder</span> : <span style="color:#2b91af">ExpressionVisitor</span><br /> {<br />     <span style="color:#0000ff">private</span> <span style="color:#2b91af">MultiBinding</span> multiBinding;</p>
<p>     <span style="color:#0000ff">private</span> <span style="color:#0000ff">string</span> lastPath = <span style="color:#0000ff">null</span>;</p>
<p>     <span style="color:#0000ff">public</span> LambdaBindingBuilder(<span style="color:#2b91af">MultiBinding</span> mb)<br />     {<br />         <span style="color:#0000ff">this</span>.multiBinding = mb;<br />     }</p>
<p>     <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> System.Linq.Expressions.<span style="color:#2b91af">Expression</span> VisitMember(<span style="color:#2b91af">MemberExpression</span> node)<br />     {<br />         <span style="color:#2b91af">PropertyInfo</span> p = node.Member <span style="color:#0000ff">as</span> <span style="color:#2b91af">PropertyInfo</span>;<br />         <span style="color:#0000ff">if</span> (p != <span style="color:#0000ff">null</span>) {<br />             <span style="color:#0000ff">if</span> (<span style="color:#0000ff">string</span>.IsNullOrWhiteSpace(lastPath))<br />             {<br />                 lastPath = p.Name;<br />             }<br />             <span style="color:#0000ff">else</span> {<br />                 lastPath = p.Name + <span style="color:#a31515">&quot;.&quot;</span> + lastPath;<br />             }<br />         }<br />         <span style="color:#2b91af">FieldInfo</span> f = node.Member <span style="color:#0000ff">as</span> <span style="color:#2b91af">FieldInfo</span>;<br />         <span style="color:#0000ff">if</span> (f != <span style="color:#0000ff">null</span>) { <br />             <span style="color:#2b91af">Binding</span> b = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Binding</span>(lastPath);<br />             b.Source = System.Linq.Expressions.<span style="color:#2b91af">Expression</span>.Lambda&lt;Func&lt;<span style="color:#0000ff">object</span>&gt;&gt;(node).Compile()();<br />             multiBinding.Bindings.Add(b);<br />             lastPath = <span style="color:#0000ff">null</span>;<br />         }<br />         <span style="color:#0000ff">return</span> <span style="color:#0000ff">base</span>.VisitMember(node);<br />     }</p>
<p>     <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> System.Linq.Expressions.<span style="color:#2b91af">Expression</span> VisitConstant(<span style="color:#2b91af">ConstantExpression</span> node)<br />     {<br />         <span style="color:#0000ff">if</span> (!<span style="color:#0000ff">string</span>.IsNullOrWhiteSpace(lastPath)) {<br />             <span style="color:#2b91af">Binding</span> b = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Binding</span>(lastPath);<br />             b.Source = node.Value;<br />             multiBinding.Bindings.Add(b);<br />             lastPath = <span style="color:#0000ff">null</span>;<br />         }<br />         <span style="color:#0000ff">return</span> <span style="color:#0000ff">base</span>.VisitConstant(node);<br />     }<br /> }</p>
<p> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">MultiDelegateConverter</span> : <span style="color:#2b91af">IMultiValueConverter</span><br /> {<br />     <span style="color:#0000ff">private</span> Func&lt;<span style="color:#0000ff">object</span>&gt; func;</p>
<p>     <span style="color:#0000ff">public</span> MultiDelegateConverter(Func&lt;<span style="color:#0000ff">object</span>&gt; func)<br />     {<br />         <span style="color:#0000ff">this</span>.func = func;<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">object</span> Convert(<span style="color:#0000ff">object</span>[] values, <br />         <span style="color:#2b91af">Type</span> targetType, <br />         <span style="color:#0000ff">object</span> parameter, <br />         System.Globalization.<span style="color:#2b91af">CultureInfo</span> culture)<br />     {<br />         <span style="color:#0000ff">return</span> func();<br />     }</p>
<p>     <span style="color:#0000ff">public</span> <span style="color:#0000ff">object</span>[] ConvertBack(<span style="color:#0000ff">object</span> value, <br />         <span style="color:#2b91af">Type</span>[] targetTypes, <br />         <span style="color:#0000ff">object</span> parameter, <br />         System.Globalization.<span style="color:#2b91af">CultureInfo</span> culture)<br />     {<br />         <span style="color:#0000ff">throw</span> <span style="color:#0000ff">new</span> <span style="color:#2b91af">NotImplementedException</span>();<br />     }<br /> }</div>
</p></div>
</p></div>
<p>&#160;</p>
<p>LambdaBinder is part of UI Atoms suite. At NeuroSpeech, we do research on UI and we are coming up with more interesting featues in UI Atoms.</p>
<p>Please <a href="http://uiatoms.neurospeech.com/silverlight/" target="_blank">Click Here</a> to download latest update of UI Atoms with AtomForm including Tabs in the form.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F382%2Flamda-binder-for-wpf-and-silverlight%2F&amp;title=Lambda%20Binder%20for%20WPF%20and%20Silverlight"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/382/lamda-binder-for-wpf-and-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detach Entities Recursively and Attach to New DomainContext in Entity Framework and RIA Services</title>
		<link>http://akashkava.com/blog/379/detach-entities-recursively-and-attach-to-new-domaincontext-in-entity-framework-and-ria-services/</link>
		<comments>http://akashkava.com/blog/379/detach-entities-recursively-and-attach-to-new-domaincontext-in-entity-framework-and-ria-services/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 08:03:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[EF4]]></category>
		<category><![CDATA[Entity]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Services]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/?p=379</guid>
		<description><![CDATA[Entity Framework and RIA Services do not allow Entities to be added/removed from cross containers. In order to move Entity from one DomainContext/ObjectContext to another DomainContext/ObjectContext, we need to recursively detach the object graph and attach it to other DomainContext/ObjectContext. Object Graph Single entity can be easily detached and attached from EntitySet where it belongs, [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/379/detach-entities-recursively-and-attach-to-new-domaincontext-in-entity-framework-and-ria-services/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Detach+Entities+Recursively+and+Attach+to+New+DomainContext+in+Entity+Framework+and+RIA+Services";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F379%2Fdetach-entities-recursively-and-attach-to-new-domaincontext-in-entity-framework-and-ria-services%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F379%2Fdetach-entities-recursively-and-attach-to-new-domaincontext-in-entity-framework-and-ria-services%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Entity Framework and RIA Services do not allow Entities to be added/removed from cross containers. In order to move Entity from one DomainContext/ObjectContext to another DomainContext/ObjectContext, we need to recursively detach the object graph and attach it to other DomainContext/ObjectContext.</p>
<h2>Object Graph</h2>
<p>Single entity can be easily detached and attached from EntitySet where it belongs, but the problem comes when navigation properties of entity are not empty. Entity object along with navigation properties is called Object Graph because if you notice, navigation property’s navigation property will contain reference to same entity and that will result in endless recursive code for Detach/Attach.</p>
<h2>An entity with the same identity already exists in the EntitySet</h2>
<p>When you try to detach entity from old DomainContext/ObjectContext and attach it to DomainContext/ObjectContext, it may give you an error that entity with same identity already exists and it will throw an exception. In this case we will just simply reuse the existing entity instead of attaching the entity we have.</p>
<h2>Entity cannot be attached to this EntityContainer because it is already attached to another EntityContainer</h2>
<p>In case of ObjectGraph, your root level entity is already detached, but navigation properties are not detached, and while you try to attach your root level entity, it will throw same error for entities that exist in navigation properties.&#160; Because detach method does not recursively detach every entity from navigation properties.</p>
<h2>Attach/Detach Extension Methods</h2>
<p>Finally after brainstorming little, I made following class that will allow you to recursively detach/attach object graphs from DomainContext. You can replace DomainContext to ObjectContext to use it inside Entity Framework.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1357a75c-1e52-42b7-8917-81a262c881ac" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">DomainContext Extensions</div>
<div style="background: #ddd; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap">
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#808080">///</span><span style="color:#008000"> DomainContext Extensions</span></li>
<li><span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">DomainContextExtensions</span> {</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span></li>
<li>    <span style="color:#808080">///</span><span style="color:#008000"> Recursively Attaches entity loaded from Other DomainContext to </span></li>
<li style="background: #f3f3f3">    <span style="color:#808080">///</span><span style="color:#008000"> current specified DomainContext</span></li>
<li>    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;context&quot;&gt;</span><span style="color:#008000">DomainContext where entity will be attached</span><span style="color:#808080">&lt;/param&gt;</span></li>
<li>    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;entity&quot;&gt;</span><span style="color:#008000">Entity loaded from other DomainContext</span><span style="color:#808080">&lt;/param&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;returns&gt;&lt;/returns&gt;</span></li>
<li>    <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#2b91af">Entity</span> Attach(<span style="color:#0000ff">this</span> <span style="color:#2b91af">DomainContext</span> context, <span style="color:#2b91af">Entity</span> entity)</li>
<li style="background: #f3f3f3">    {</li>
<li>        <span style="color:#0000ff">if</span> (entity == <span style="color:#0000ff">null</span> || entity.EntityState != <span style="color:#2b91af">EntityState</span>.Detached)</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">return</span> entity;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">        <span style="color:#2b91af">Entity</span> newEntity = entity;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">        <span style="color:#2b91af">Entity</span>[] list = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Entity</span>[] { entity };</li>
<li>        <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">Entity</span> c <span style="color:#0000ff">in</span> context.EntityContainer.LoadEntities(list, </li>
<li style="background: #f3f3f3">            <span style="color:#2b91af">LoadBehavior</span>.MergeIntoCurrent))</li>
<li>        {</li>
<li style="background: #f3f3f3">            newEntity = c;</li>
<li>            <span style="color:#0000ff">break</span>;</li>
<li style="background: #f3f3f3">        }</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">        <span style="color:#008000">// recursively attach all entities..</span></li>
<li>        <span style="color:#2b91af">Type</span> entityType = <span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">Entity</span>);</li>
<li style="background: #f3f3f3">&nbsp;</li>
<li>        <span style="color:#008000">// get all navigation properties&#8230;</span></li>
<li style="background: #f3f3f3">        <span style="color:#2b91af">Type</span> type = entity.GetType();</li>
<li>        <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> item <span style="color:#0000ff">in</span> type.GetProperties())</li>
<li style="background: #f3f3f3">        {</li>
<li>            <span style="color:#0000ff">if</span> (entityType.IsAssignableFrom(item.PropertyType))</li>
<li style="background: #f3f3f3">            {</li>
<li>                <span style="color:#2b91af">Entity</span> navEntity = Attach(context, item.GetValue(entity, <span style="color:#0000ff">null</span>) </li>
<li style="background: #f3f3f3">                    <span style="color:#0000ff">as</span> <span style="color:#2b91af">Entity</span>);</li>
<li>                item.SetValue(newEntity,navEntity, <span style="color:#0000ff">null</span>);</li>
<li style="background: #f3f3f3">                <span style="color:#0000ff">continue</span>;</li>
<li>            }</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">if</span> (item.PropertyType.Name.StartsWith(<span style="color:#a31515">&quot;EntityCollection&quot;</span>))</li>
<li>            {</li>
<li style="background: #f3f3f3">                <span style="color:#2b91af">IEnumerable</span> coll = item.GetValue(entity, <span style="color:#0000ff">null</span>) <span style="color:#0000ff">as</span> <span style="color:#2b91af">IEnumerable</span>;</li>
<li>                <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">Entity</span>&gt; newList = <span style="color:#0000ff">new</span> <span style="color:#2b91af">List</span>&lt;<span style="color:#2b91af">Entity</span>&gt;();</li>
<li style="background: #f3f3f3">                <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">Entity</span> child <span style="color:#0000ff">in</span> coll)</li>
<li>                {</li>
<li style="background: #f3f3f3">                    newList.Add(Attach(context, child));</li>
<li>                }</li>
<li style="background: #f3f3f3">                <span style="color:#0000ff">dynamic</span> dcoll = item.GetValue(newEntity,<span style="color:#0000ff">null</span>);</li>
<li>                <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">dynamic</span> child <span style="color:#0000ff">in</span> newList)</li>
<li style="background: #f3f3f3">                {</li>
<li>                    dcoll.Add(child);</li>
<li style="background: #f3f3f3">                }</li>
<li>            }</li>
<li style="background: #f3f3f3">        }</li>
<li>        <span style="color:#0000ff">return</span> newEntity;</li>
<li style="background: #f3f3f3">    }</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;summary&gt;</span></li>
<li>    <span style="color:#808080">///</span><span style="color:#008000"> Recursively detaches entities from DomainContext, this </span></li>
<li style="background: #f3f3f3">    <span style="color:#808080">///</span><span style="color:#008000"> method detaches every navigation properties</span></li>
<li>    <span style="color:#808080">///</span><span style="color:#008000"> of current Entity as well.</span></li>
<li style="background: #f3f3f3">    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;/summary&gt;</span></li>
<li>    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;context&quot;&gt;&lt;/param&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#808080">///</span><span style="color:#008000"> </span><span style="color:#808080">&lt;param name=&quot;entity&quot;&gt;&lt;/param&gt;</span></li>
<li>    <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span> Detach(<span style="color:#0000ff">this</span> <span style="color:#2b91af">DomainContext</span> context, <span style="color:#2b91af">Entity</span> entity)</li>
<li style="background: #f3f3f3">    {</li>
<li>        <span style="color:#0000ff">if</span> (entity == <span style="color:#0000ff">null</span> || entity.EntityState == <span style="color:#2b91af">EntityState</span>.Detached)</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">return</span>;</li>
<li>        <span style="color:#2b91af">EntitySet</span> nes = context.EntityContainer.GetEntitySet(entity.GetType());</li>
<li style="background: #f3f3f3">        nes.Detach(entity);</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">        <span style="color:#2b91af">Type</span> entityType = <span style="color:#0000ff">typeof</span>(<span style="color:#2b91af">Entity</span>);</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">        <span style="color:#008000">// get all navigation properties&#8230;</span></li>
<li>        <span style="color:#2b91af">Type</span> type = entity.GetType();</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">var</span> item <span style="color:#0000ff">in</span> type.GetProperties())</li>
<li>        {</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">if</span> (entityType.IsAssignableFrom(item.PropertyType))</li>
<li>            {</li>
<li style="background: #f3f3f3">                Detach(context,item.GetValue(entity, <span style="color:#0000ff">null</span>) <span style="color:#0000ff">as</span> <span style="color:#2b91af">Entity</span>);</li>
<li>                <span style="color:#0000ff">continue</span>;</li>
<li style="background: #f3f3f3">            }</li>
<li>            <span style="color:#0000ff">if</span> (item.PropertyType.Name.StartsWith(<span style="color:#a31515">&quot;EntityCollection&quot;</span>))</li>
<li style="background: #f3f3f3">            {</li>
<li>                <span style="color:#2b91af">IEnumerable</span> coll = item.GetValue(entity, <span style="color:#0000ff">null</span>) <span style="color:#0000ff">as</span> <span style="color:#2b91af">IEnumerable</span>;</li>
<li style="background: #f3f3f3">                <span style="color:#0000ff">foreach</span> (<span style="color:#2b91af">Entity</span> child <span style="color:#0000ff">in</span> coll)</li>
<li>                {</li>
<li style="background: #f3f3f3">                    Detach(context,child);</li>
<li>                }</li>
<li style="background: #f3f3f3">            }</li>
<li>        }</li>
<li style="background: #f3f3f3">    }</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">}</li>
</ol></div>
</p></div>
</p></div>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F379%2Fdetach-entities-recursively-and-attach-to-new-domaincontext-in-entity-framework-and-ria-services%2F&amp;title=Detach%20Entities%20Recursively%20and%20Attach%20to%20New%20DomainContext%20in%20Entity%20Framework%20and%20RIA%20Services"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/379/detach-entities-recursively-and-attach-to-new-domaincontext-in-entity-framework-and-ria-services/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>UI Atoms 1.5.8 Released</title>
		<link>http://akashkava.com/blog/378/ui-atoms-1-5-8-released/</link>
		<comments>http://akashkava.com/blog/378/ui-atoms-1-5-8-released/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 11:47:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Customize]]></category>
		<category><![CDATA[DataForm]]></category>
		<category><![CDATA[Form Designer]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Release]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[UI Atoms]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/378/ui-atoms-1-5-8-released/</guid>
		<description><![CDATA[We are happy to announce new release of UI Atoms 1.5.8 with following new features. UI Atoms for WPF 4.0 In this release of UI Atoms, we have a new library of dlls specially designed for WPF 4.0, which now includes support for Visual State Managers and renders everything in WPF 4.0 presentation. You can [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/378/ui-atoms-1-5-8-released/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "UI+Atoms+1.5.8+Released";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F378%2Fui-atoms-1-5-8-released%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F378%2Fui-atoms-1-5-8-released%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>We are happy to announce new release of UI Atoms 1.5.8 with following new features.</p>
<h2>UI Atoms for WPF 4.0</h2>
<p>In this release of UI Atoms, we have a new library of dlls specially designed for WPF 4.0, which now includes support for Visual State Managers and renders everything in WPF 4.0 presentation. You can find Bin.Net4 folder inside WPF, that contains libraries only for WPF 4.0 version.</p>
<h2>AtomForm Label Alignment for Silverlight and WPF</h2>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/01/Silverlight-Form-Label-Alignment.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="Silverlight-Form-Label-Alignment" border="0" alt="Silverlight-Form-Label-Alignment" src="http://akashkava.com/blog/wp-content/uploads/2011/01/Silverlight-Form-Label-Alignment_thumb.png" width="592" height="294" /></a></p>
<p>AtomForm now provides following two properties,</p>
<ul>
<li>LabelHorizontalAlignment property that can align the label horizontally in the form item. </li>
<li>LabelVerticalAlignment property that can align the label vertically in the form item. </li>
</ul>
<h2>Label Can now contain string or UI Element object</h2>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fcb2ac16-ff98-412b-bd36-3a1216a32b41" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Rich Label Format</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomTextBox</span><span style="color:#ff0000"> HorizontalAlignment</span><span style="color:#0000ff">=&quot;Stretch&quot;</span> </li>
<li style="background: #f3f3f3">               <span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> Path</span><span style="color:#0000ff">=ProjectName,</span><span style="color:#ff0000"> Mode</span><span style="color:#0000ff">=TwoWay}&quot;</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">=&quot;Auto&quot; &gt;</span></li>
<li>    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomForm.Label</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">StackPanel</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">=&quot;Horizontal&quot;&gt;</span></li>
<li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBlock</span><span style="color:#0000ff">&gt;</span><span style="color:#a31515">Name:</span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">TextBlock</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Image</span><span style="color:#ff0000"> Source</span><span style="color:#0000ff">=&quot;/PrismTest;component/Images/Logo.png&quot;</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">=&quot;16&quot;</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">=&quot;16&quot; /&gt;</span></li>
<li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">StackPanel</span><span style="color:#0000ff">&gt;</span></li>
<li style="background: #f3f3f3">    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomForm.Label</span><span style="color:#0000ff">&gt;</span></li>
<li><span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomTextBox</span><span style="color:#0000ff">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/01/Rich-Label-Silverlight-WPF-Form.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="Rich-Label-Silverlight-WPF-Form" border="0" alt="Rich-Label-Silverlight-WPF-Form" src="http://akashkava.com/blog/wp-content/uploads/2011/01/Rich-Label-Silverlight-WPF-Form_thumb.png" width="283" height="163" /></a></p>
<p>&#160;</p>
<h2>Advanced Quick Form Designer</h2>
<p>Typing Tags with all Bindings could be quite time consuming, where it involves moving items up and down, deleting and adding new Form Items. Advanced Quick Form Designer resolves all this problems by giving you state of art designer, which provides one quick grid to enter all necessary information. However the form designer works well even for existing forms, and you can generate entire new form by selecting some Type as well.</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/01/Advanced-Silverlight-WPF-Form-Designer.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="Advanced-Silverlight-WPF-Form-Designer" border="0" alt="Advanced-Silverlight-WPF-Form-Designer" src="http://akashkava.com/blog/wp-content/uploads/2011/01/Advanced-Silverlight-WPF-Form-Designer_thumb.png" width="584" height="500" /></a></p>
<p>As you see, type of control can be changed that will represent the form item and corresponding binding property can be changed as well. Just with simple one click, you can move items up and down or delete them. You can add a new control that is defaulted to AtomTextBox at the top, you can change default control to add multiple one after another very easily. Also you can click “Generate From Type” to select any Business Object Type and generate a brand new form.</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2011/01/Generate-Form-From-Type-Silverlight-WPF.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="Generate-Form-From-Type-Silverlight-WPF" border="0" alt="Generate-Form-From-Type-Silverlight-WPF" src="http://akashkava.com/blog/wp-content/uploads/2011/01/Generate-Form-From-Type-Silverlight-WPF_thumb.png" width="420" height="420" /></a></p>
<p>Selecting type will automatically generate form with its bindings.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F378%2Fui-atoms-1-5-8-released%2F&amp;title=UI%20Atoms%201.5.8%20Released"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/378/ui-atoms-1-5-8-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVVM + AtomForm + Cascaded ComboBoxes for WPF &amp; Silverlight</title>
		<link>http://akashkava.com/blog/361/mvvm-atomform-cascaded-comboboxes/</link>
		<comments>http://akashkava.com/blog/361/mvvm-atomform-cascaded-comboboxes/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 11:47:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AtomForm]]></category>
		<category><![CDATA[Cacaded]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[DataForm]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[UI Atoms]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/361/mvvm-atomform-cascaded-comboboxes/</guid>
		<description><![CDATA[UI Atoms version 1.2.22 resolves Cascaded ComboBoxes issue in MVVM pattern. Advanced AtomForm is now capable of handling cascaded ComboBoxes with MVVM and it also integrates well with third party controls. Recently we identified few issues with MVVM implementation in Silverlight regarding ComboBoxes. ComboBox looses its “SelectedValue” binding once the ItemsSource of ComboBox changes. This [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/361/mvvm-atomform-cascaded-comboboxes/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "MVVM+%2B+AtomForm+%2B+Cascaded+ComboBoxes+for+WPF+%26amp%3B+Silverlight";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F361%2Fmvvm-atomform-cascaded-comboboxes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F361%2Fmvvm-atomform-cascaded-comboboxes%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>UI Atoms version 1.2.22 resolves Cascaded ComboBoxes issue in MVVM pattern. Advanced AtomForm is now capable of handling cascaded ComboBoxes with MVVM and it also integrates well with third party controls.</p>
<p>Recently we identified few issues with MVVM implementation in Silverlight regarding ComboBoxes. ComboBox looses its “SelectedValue” binding once the ItemsSource of ComboBox changes. This needed some workaround as well as Modifying DataForm is very painful as you may need very complex form designs in regular business applications.</p>
<h2>1. Create Models</h2>
<p>Lets assume we need to edit a Customer’s Country and City, as we change the Country the list of cities should change it. Problem with existing ComboBox and DataForm is, as soon as list of cities changes, ComboBox’s SelectedValue binding vanishes. So lets create Customer Model first.</p>
<p>&#160;</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2010/10/MVVMViewModels.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="MVVM-View-Models" border="0" alt="MVVM-View-Models" src="http://akashkava.com/blog/wp-content/uploads/2010/10/MVVMViewModels_thumb.png" width="576" height="451" /></a> </p>
<p>Each of properties in CustomerViewModel raises PropertyChanged event for corresponding properties when modified.</p>
<p>When selected customer changes, SelectedCountry also changes and which changes Cities property, so in drop down we can display the list of cities of selected country.</p>
<p>Important:</p>
<blockquote><p>Your SelectedCountry property, where you need Change of Selection event must not raise PropertyChanged event in “set” method as shown below…, however you may turn it off or on based on your UI behavior. WPF has no problem but Silverlight has issues and it works better if PropertyChanged event is not raised. </p>
</blockquote>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3d18f7bc-84e2-4abf-abc6-ed36b294659b" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Selected Country Property</div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap">        <span style="color:#0000ff">public</span> <span style="color:#2b91af">Country</span> SelectedCountry<br />         {<br />             <span style="color:#0000ff">get</span><br />             {<br />                 <span style="color:#0000ff">return</span> _SelectedCountry;<br />             }<br />             <span style="color:#0000ff">set</span><br />             {<br />                 _SelectedCountry = <span style="color:#0000ff">value</span>;<br />                 <span style="color:#008000">//if (PropertyChanged != null)</span><br />                 <span style="color:#008000">//    PropertyChanged(this, new PropertyChangedEventArgs(&quot;SelectedCountry&quot;));</span><br />                 <span style="color:#0000ff">if</span> (_SelectedCountry != <span style="color:#0000ff">null</span>)<br />                 {<br />                     Cities = _SelectedCountry.Cities;<br />                 }<br />             }<br />         }</div>
</p></div>
</p></div>
<h2>2. Create Master View</h2>
<p>Master View control declares grid with two columns, left side displaying list of customers and on right side displaying details of the selected customer.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:96234641-c16b-4664-9f6b-9c61573d7bfe" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">MainPage Master View Control</div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">UserControl</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Class</span><span style="color:#0000ff">=&quot;PrismTest.MainPage&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">x</span><span style="color:#0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">d</span><span style="color:#0000ff">=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">mc</span><span style="color:#0000ff">=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">ns</span><span style="color:#0000ff">=&quot;http://uiatoms.neurospeech.com/silverlight&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">local</span><span style="color:#0000ff">=&quot;clr-namespace:PrismTest&quot;</span><br />    <span style="color:#ff0000"> mc</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Ignorable</span><span style="color:#0000ff">=&quot;d&quot;</span><br />    <span style="color:#ff0000"> d</span><span style="color:#0000ff">:</span><span style="color:#ff0000">DesignHeight</span><span style="color:#0000ff">=&quot;300&quot;</span><span style="color:#ff0000"> d</span><span style="color:#0000ff">:</span><span style="color:#ff0000">DesignWidth</span><span style="color:#0000ff">=&quot;400&quot;&gt;</span><br /> <span style="color:#a31515">    </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">UserControl.Resources</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">local</span><span style="color:#0000ff">:</span><span style="color:#a31515">ViewModelLocator</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Key</span><span style="color:#0000ff">=&quot;locator&quot;/&gt;</span><br /> <span style="color:#a31515">    </span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">UserControl.Resources</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515">    </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">=&quot;LayoutRoot&quot;</span><span style="color:#ff0000"> Background</span><span style="color:#0000ff">=&quot;White&quot;&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid.RowDefinitions</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515">            </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#0000ff">/&gt;</span><br /> <span style="color:#a31515">            </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">RowDefinition</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">=&quot;400&quot; /&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid.RowDefinitions</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Grid.ColumnDefinitions</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515">            </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ColumnDefinition</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">=&quot;200&quot; /&gt;</span><br /> <span style="color:#a31515">            </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ColumnDefinition</span><span style="color:#0000ff"> /&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid.ColumnDefinitions</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ListBox</span> <br />            <span style="color:#ff0000"> DisplayMemberPath</span><span style="color:#0000ff">=&quot;Name&quot;</span><br />            <span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Name</span><span style="color:#0000ff">=&quot;list&quot;</span><br />            <span style="color:#ff0000"> SelectedItem</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> ViewModel</span><span style="color:#0000ff">.SelectedCustomer,</span><span style="color:#ff0000">Source</span><span style="color:#0000ff">={</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> locator}</span><span style="color:#0000ff">,</span><span style="color:#ff0000"> Mode</span><span style="color:#0000ff">=TwoWay}&quot;</span><br />            <span style="color:#ff0000"> ItemsSource</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> ViewModel</span><span style="color:#0000ff">.Customers,</span><span style="color:#ff0000">Source</span><span style="color:#0000ff">={</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> locator}}</span><span style="color:#0000ff">&quot; /&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">local</span><span style="color:#0000ff">:</span><span style="color:#a31515">CustomerView</span><br />            <span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">=&quot;1&quot;</span> <span style="color:#0000ff"> /&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomTraceView</span> <br />            <span style="color:#ff0000"> Grid.Row</span><span style="color:#0000ff">=&quot;1&quot;</span><span style="color:#ff0000"> Grid.ColumnSpan</span><span style="color:#0000ff">=&quot;2&quot;/&gt;</span><br /> <span style="color:#a31515">    </span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">Grid</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">UserControl</span><span style="color:#0000ff">&gt;</span></div>
</p></div>
</p></div>
</p>
<p>Lets analyze Bindings,</p>
<ol>
<li>ListBox’s ItemsSource is bound to ViewModel.Customers which returns list of available customers. </li>
<li>ListBox’s SelectedItem is bound (two way) to ViewModel.SelectedCustomer. </li>
</ol>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:84aa2d82-f688-4de0-802a-75749ed7d12c" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Customer View Control</div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="color:#0000ff">&lt;</span><span style="color:#a31515">UserControl</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Class</span><span style="color:#0000ff">=&quot;PrismTest.CustomerView&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">x</span><span style="color:#0000ff">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">d</span><span style="color:#0000ff">=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">mc</span><span style="color:#0000ff">=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">ns</span><span style="color:#0000ff">=&quot;http://uiatoms.neurospeech.com/silverlight&quot;</span><br />    <span style="color:#ff0000"> xmlns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">local</span><span style="color:#0000ff">=&quot;clr-namespace:PrismTest&quot;</span><br />    <span style="color:#ff0000"> mc</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Ignorable</span><span style="color:#0000ff">=&quot;d&quot;</span><br />    <span style="color:#ff0000"> d</span><span style="color:#0000ff">:</span><span style="color:#ff0000">DesignHeight</span><span style="color:#0000ff">=&quot;300&quot;</span><span style="color:#ff0000"> d</span><span style="color:#0000ff">:</span><span style="color:#ff0000">DesignWidth</span><span style="color:#0000ff">=&quot;400&quot;&gt;</span><br /> <span style="color:#a31515">    </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">UserControl.Resources</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">local</span><span style="color:#0000ff">:</span><span style="color:#a31515">ViewModelLocator</span><span style="color:#ff0000"> x</span><span style="color:#0000ff">:</span><span style="color:#ff0000">Key</span><span style="color:#0000ff">=&quot;locator&quot;/&gt;</span><br /> <span style="color:#a31515">    </span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">UserControl.Resources</span><span style="color:#0000ff">&gt;</span><br /> <span style="color:#a31515">    </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomForm</span><span style="color:#ff0000"> DataContext</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> ViewModel</span><span style="color:#0000ff">.SelectedCustomer,</span><span style="color:#ff0000">Source</span><span style="color:#0000ff">={</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> locator}}</span><span style="color:#0000ff">&quot;&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomTextBox</span><span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> Name</span><span style="color:#0000ff">,</span><span style="color:#ff0000"> Mode</span><span style="color:#0000ff">=TwoWay}&quot;</span> <br />                        <span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomForm.Label</span><span style="color:#0000ff">=&quot;Name:&quot; /&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomComboBox</span><span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomForm.Label</span><span style="color:#0000ff">=&quot;Country:&quot;</span> <br />                         <span style="color:#ff0000"> SelectedValuePath</span><span style="color:#0000ff">=&quot;CountryID&quot;</span><br />                         <span style="color:#ff0000"> DisplayMemberPath</span><span style="color:#0000ff">=&quot;Name&quot;</span><br />                         <span style="color:#ff0000"> ItemsSource</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> ViewModel</span><span style="color:#0000ff">.Countries,</span><span style="color:#ff0000">Source</span><span style="color:#0000ff">={</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> locator}}</span><span style="color:#0000ff">&quot;</span><br />                         <span style="color:#ff0000"> SelectedItem</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> ViewModel</span><span style="color:#0000ff">.SelectedCountry,</span><span style="color:#ff0000">Source</span><span style="color:#0000ff">={</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> locator}</span><span style="color:#0000ff">,</span><span style="color:#ff0000"> Mode</span><span style="color:#0000ff">=TwoWay}&quot;</span><br />                         <span style="color:#ff0000"> SelectedValue</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> CountryID</span><span style="color:#0000ff">,</span><span style="color:#ff0000"> Mode</span><span style="color:#0000ff">=TwoWay}&quot;</span><br />                         <span style="color:#0000ff"> /&gt;</span><br /> <span style="color:#a31515">        </span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomComboBox</span><span style="color:#ff0000"> ns</span><span style="color:#0000ff">:</span><span style="color:#ff0000">AtomForm.Label</span><span style="color:#0000ff">=&quot;City:&quot;</span>                          <br />                         <span style="color:#ff0000"> SelectedValuePath</span><span style="color:#0000ff">=&quot;CityID&quot;</span><br />                         <span style="color:#ff0000"> DisplayMemberPath</span><span style="color:#0000ff">=&quot;Name&quot;</span><br />                         <span style="color:#ff0000"> ItemsSource</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> ViewModel</span><span style="color:#0000ff">.Cities,</span><span style="color:#ff0000">Source</span><span style="color:#0000ff">={</span><span style="color:#a31515">StaticResource</span><span style="color:#ff0000"> locator}}</span><span style="color:#0000ff">&quot;</span><br />                         <span style="color:#ff0000"> SelectedValue</span><span style="color:#0000ff">=&quot;{</span><span style="color:#a31515">Binding</span><span style="color:#ff0000"> CityID</span><span style="color:#0000ff">,</span><span style="color:#ff0000"> Mode</span><span style="color:#0000ff">=TwoWay}&quot;</span><br />                         <span style="color:#0000ff"> /&gt;</span><br /> <span style="color:#a31515">    </span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ns</span><span style="color:#0000ff">:</span><span style="color:#a31515">AtomForm</span><span style="color:#0000ff">&gt;</span><span style="color:#a31515">    </span><br /> <span style="color:#0000ff">&lt;/</span><span style="color:#a31515">UserControl</span><span style="color:#0000ff">&gt;</span></div>
</p></div>
</p></div>
<p>Lets analyze the bindings,</p>
<ol>
<li>AtomForm’s DataContext is bound to SelectedCustomer of ViewModel, which comes from SelectedItem of Parent Control </li>
<li>AtomTextBox’s&#160; Text is bound to Name (of AtomForm’s DataContext’s binding) with Mode=TwoWay </li>
<li>AtomComboBox
<ol>
<li>ItemsSource is bound to ViewModel.Countries which returns list of countries. </li>
<li>SelectedValue is bound to CountryID (of AtomForm’s DataContext’s binding) with Mode=TwoWay </li>
<li>SelectedItem is bound to ViewModel.SelectedCountry, which triggers change of SelectedCountry property on ViewModel which changes list of cities. </li>
</ol>
</li>
<li>AtomComboBox (this is the one that’s tricky, normal ComboBox does not work here)
<ol>
<li>ItemsSource is bound to ViewModel.Cities which returns list of cities of SelectedCountry. </li>
<li>SelectedValue is bound to CityID (of AtomForm’s DataContext’s binding) with Mode=TwoWay </li>
</ol>
</li>
</ol>
<p>&#160;</p>
</p>
</p>
<h2>3. Cascaded ComboBox</h2>
<p>You can see that the cascaded ComboBox work well with AtomForm and AtomComboBox and its easy to design AtomForm with MVVM with so much less code then that of DataForm and ComboBoxes.</p>
<p><a href="http://akashkava.com/blog/wp-content/uploads/2010/10/Form.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Form" border="0" alt="Form" src="http://akashkava.com/blog/wp-content/uploads/2010/10/Form_thumb.png" width="591" height="161" /></a> </p>
<p>Please download the latest version of <a href="http://uiatoms.neurospeech.com/v1/download/UIAtoms2010Demo.zip" target="_blank">UI Atoms 2010 suite</a> to try MVVM + AtomForm + Cascaded ComboBoxes.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F361%2Fmvvm-atomform-cascaded-comboboxes%2F&amp;title=MVVM%20%2B%20AtomForm%20%2B%20Cascaded%20ComboBoxes%20for%20WPF%20%26amp%3B%20Silverlight"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/361/mvvm-atomform-cascaded-comboboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NeuroSpeech releases XamlGenerator 1.0</title>
		<link>http://akashkava.com/blog/356/neurospeech-releases-xamlgenerator-1-0/</link>
		<comments>http://akashkava.com/blog/356/neurospeech-releases-xamlgenerator-1-0/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 16:51:00 +0000</pubDate>
		<dc:creator>Akash Kava</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Generator]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://akashkava.com/blog/356/neurospeech-releases-xamlgenerator-1-0/</guid>
		<description><![CDATA[XamlGenerator is Code Behind source code Generator for Xaml. Xaml Code Behind Generator makes it easier to generate Code Behind designer code from XAML, where code can be used at places where Xaml Services are not accessible. Features Using XAML 2009 in Silverlight and WPF Reusing Xaml Business Pages in Silverlight and WPF Support for [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://akashkava.com/blog/356/neurospeech-releases-xamlgenerator-1-0/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "NeuroSpeech+releases+XamlGenerator+1.0";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fakashkava.com%2Fblog%2F356%2Fneurospeech-releases-xamlgenerator-1-0%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fakashkava.com%2Fblog%2F356%2Fneurospeech-releases-xamlgenerator-1-0%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>XamlGenerator is Code Behind source code Generator for Xaml. </p>
<p>Xaml Code Behind Generator makes it easier to generate Code Behind designer code from XAML, where code can be used at places where Xaml Services are not accessible.   <br /><b>Features</b></p>
<ol>
<li>Using XAML 2009 in Silverlight and WPF </li>
<li>Reusing Xaml Business Pages in Silverlight and WPF </li>
<li>Support for User Controls derived from any Control </li>
<li>Using Complied code instead of BAML </li>
<li>Improving speed of XAML runtime </li>
<li>Using XAML to generate code to be used in ASP.NET, Server Core etc, where XAML Services are not available </li>
<li>Generated code is pure .NET 2.0 compliant, and you can target xaml objects to run in earlier .NET version too. </li>
<li>You can also create Xaml for WinForms and use it for your .NET 2.0 projects, however please notice, the features of WPF will not be available, it can only create object hierarchies based on XAML, but it can not give you binding etc features. </li>
<li>x:Name support for Resources, very useful for MVVM Pattern </li>
<li>Support for Custom Extension with Custom Code Generator</li>
</ol>
<h3>Xaml Code Generator</h3>
<p> .Net 4 introduces Xaml Services that can load Xaml Object Trees and it provides great deal in terms of intellisense and code behind facilities, however this can only be used where Xaml Services are installed. Also it is quite painful to debug and hide the generated baml resources, that actually is quite easy to disassemble and view the source.  <br />Xaml Code Generator can easily solve these problems by creating source code equivalent to loading object via Xaml Services. Instead, once generated, the performance of source code is quite faster then baml and xaml. Since ASP.NET and WinForms, code behind files did serve great support to link the UI and Code. However in WPF and Silverlight does not support simple references to code behind objects except events. There are work arounds, but we decided to create Xaml Code Generator that will solve lot of problems.<br />
<h4>Benefits to WPF and Silverlight</h4>
<ol>
<li>Xaml pages can now use x:Reference markup extension </li>
<li>Xaml pages can support generic type parameters </li>
<li>Xaml page can now derive from any control/panel </li>
<li>Xaml can easily reference any expression that involves code behind operation including &quot;this&quot; keyword </li>
<li>By using custom Xaml markup extensions, you can reuse Xaml between WPF and Silverlight</li>
</ol>
<h4>Known limitations with Xaml Code Generated files</h4>
<ol>
<li>Control Templates and Styles must use respective WPF/Silverlight markup only </li>
<li>No code behind files can be generated for Control Templates and Styles </li>
<li>Xaml pages can not be used with Navigation Urls </li>
<li>Instead code generated files are simply source code equivalent of Xaml, and they should be treated as .Net CLR Objects instead of Xaml Pages and there exists no equivalent baml resources</li>
</ol>
<h4>So how to use benefits of Code Generator as well as XAML</h4>
<p> We recommend following pattern to make use of best of both the worlds
<ol>
<li>Create Main Application Window/Page as regular Xaml </li>
<li>Instead of User Controls, use Xaml derived from Equivalent controls, such as StackPanel, Grid etc, and use them in Main Window/Pages </li>
<li>In this pattern, generated CLR objects of xaml will perform exactly same</li>
</ol>
<h3>Why Generate source code from XAML?</h3>
<p> Xaml and Xaml Services are great, they give a huge benefit in terms of runtime model loading and behaviour. For larger systems, and for complex enterprise applications Xaml is perfect. But we still have lot of code in .NET 2.0 and applications that are still heavily dependent on the components that do not support Xaml Services.  <br />Plus, shift of paradigm from code behind to view model is quite painful. Infact ability to use more code behind features is quite needed for current generation.  <br />Debugging Xaml is quite painful still, we still have lot of logic that lies in functional code and there is little more time still before we reach to completely modelled code.  <br />Here are few benefits outlined of generated code,
<ol>
<li>View Model can be replaced by Code behind, as we can easily reference xc:This and xc:Ref extensions </li>
<li>Debugging c# code can be easier which involves more complex UI designs </li>
<li>Xaml Generated can generate anything, even non UI code </li>
<li>You can even use Xaml Generator in your DSL tool</li>
</ol>
<p>For more details, please visit, <a title="http://xamlgenerator.codeplex.com/" href="http://xamlgenerator.codeplex.com/">http://xamlgenerator.codeplex.com/</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fakashkava.com%2Fblog%2F356%2Fneurospeech-releases-xamlgenerator-1-0%2F&amp;title=NeuroSpeech%20releases%20XamlGenerator%201.0"><img src="http://akashkava.com/blog/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://akashkava.com/blog/356/neurospeech-releases-xamlgenerator-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

