<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns: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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Sergey Barskiy's Blog</title>
	
	<link>http://dotnetspeak.com</link>
	<description>All things .NET</description>
	<lastBuildDate>Mon, 06 Sep 2010 22:50:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DotNetSpeak" /><feedburner:info uri="dotnetspeak" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/DotNetSpeak" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2FDotNetSpeak" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>Using WinDbg to Find Memory Leaks in Silverlight Applications</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/mzl3gm4Go0M/</link>
		<comments>http://dotnetspeak.com/index.php/2010/09/using-windbg-to-find-memory-leaks-in-silverlight-applications/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 22:50:21 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/09/using-windbg-to-find-memory-leaks-in-silverlight-applications/</guid>
		<description><![CDATA[In light of recent issues with memory leaks in Silverlight and the fact that service pack that was supposed to address these issues was released last week, I found myself working on an application, trying to confirm that it does not leak any longer.&#160; To simplify my approach, I created a destructor for my view [...]]]></description>
			<content:encoded><![CDATA[<p>In light of recent issues with memory leaks in Silverlight and the fact that service pack that was supposed to address these issues was released last week, I found myself working on an application, trying to confirm that it does not leak any longer.&#160; To simplify my approach, I created a destructor for my view with the following code:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; ~BaseView()     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br /><span style="color: blue">#if</span> DEBUG      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.Diagnostics.<span style="color: #2b91af">Debug</span>.WriteLine(<span style="color: #a31515">&quot;Destructed view &quot;</span> + <span style="color: blue">this</span>.GetType().Name);      <br /><span style="color: blue">#endif</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>This code will echo to Debug window when garbage collector hits my view.&#160; To my dismay, the view was never collected after being removed from a region.&#160; (I am using Prism for my sample application).&#160; I did some research, and decided to use WinDbg to help me pinpoint memory leaks. </p>
<p>First step is to download tools for my Windows 7 64 bit machine.&#160; I found the link here:<a title="http://www.microsoft.com/whdc/devtools/debugging/install64bit.mspx" href="http://www.microsoft.com/whdc/devtools/debugging/install64bit.mspx">http://www.microsoft.com/whdc/devtools/debugging/install64bit.mspx</a></p>
<p>So I installed checking all options.&#160; I started WinDbg and tried to load Silverlight debug symbols from (C:\\Program Files (x86)\\Microsoft Silverlight\\4.0.50826.0\\sos.dll).&#160; Unfortunately I got an error – not a valid 32 bit application, even though I am running 64 bit.&#160; Come to find out, I actually need 32 bit version of WinDbg since Silverlight only runs in 32 bit environment.&#160; Would be nice to have a better message, but here we go.&#160; Next step is to install 32 bit version of WinDbg.&#160; make sure you checked ALL options during main tools install.&#160; If so, you will find that version here: C:\Program Files\Microsoft SDKs\Windows\v7.1\Redist\Debugging Tools for Windows.</p>
<p>Now, start WinDbg from Program Files (x86) folder.&#160; I just use search feature in Windows 7, and type WinDbg into search box after clicking on Start button.</p>
<p>Now I run my application in IE, and load my UserView (user control) a few times, and close it (remove from region) a few times, 3 times to be specific.. </p>
<p>With WinDbg running, I now have to attach to a process, Internet explorer in my case. Make sure you do not have Visual Studio running in debug mode, or you will get&#160; an error trying to attach second debugger to IE.&#160; I use File-&gt;Attach To Process menu in WinDbg and look for iexplore process.&#160; Then I will see Command window.&#160; In the bottom portion of the window I see a textbox – this is WinDbg command line.&#160; I type the following: <strong>.load C:\\Program Files (x86)\\Microsoft Silverlight\\4.0.50826.0\\sos.dll</strong> and hit enter.&#160; Make sure to start with a period(.).</p>
<p>Now, let’s take a memory snapshot.&#160; Type the following and hit enter: <strong>!dumpheap –stat</strong>&#160;</p>
<p>Once that is done, hit Ctrl+Home to go to the top of command window, then hit Ctrl+F to pull up search window, type your control name (UserView) in my case and hit Enter.&#160; You now will see how many instance of your view there are in memory:</p>
<p>05dcaa14&#160;&#160;&#160;&#160;&#160;&#160;&#160; 3&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 300 KSS.Silverlight.SystemWide.Views.UserView</p>
<p>In my case there are three.The first column is MT, which will contain my type.&#160; using this value I can find addresses of each of three instances.&#160; Type the following and hit Enter:</p>
<p><strong>!dumpheap -MT 05dcaa14</strong></p>
<p>Now I see addresses for each of three instances.&#160; I pick up one at random to see the references that keep the object from being picked up by garbage collector.&#160; Type the following and hit Enter:</p>
<p><strong>!gcroot 12753bfc</strong></p>
<p>Here is the output for this command:</p>
<p>0:035&gt; !gcroot 12753bfc   <br />Note: Roots found on stacks may be false positives. Run &quot;!help gcroot&quot; for    <br />more info.    <br />Scan Thread 4 OSTHread 1c28    <br />Scan Thread 30 OSTHread cc4    <br />Scan Thread 31 OSTHread 15b0    <br />Scan Thread 33 OSTHread cb8    <br />DOMAIN(05FE3BD8):HANDLE(Pinned):2f812f8:Root:&#160; 13594260(System.Object[])-&gt;    <br />&#160; 125a8888(System.Collections.Generic.Dictionary`2[[System.IntPtr, mscorlib],[System.Object, mscorlib]])-&gt;    <br />&#160; 127a9408(System.Collections.Generic.Dictionary`2+Entry[[System.IntPtr, mscorlib],[System.Object, mscorlib]][])-&gt;    <br />&#160; 127dd420(System.Windows.Controls.Grid)-&gt;    <br />&#160; 127dd484(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])-&gt;    <br />&#160; 127dd4d0(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])-&gt;    <br />&#160; 127dd54c(System.Windows.Controls.Border)-&gt;    <br />&#160; 127e9874(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])-&gt;    <br />&#160; 127e98c0(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])-&gt;    <br />&#160; 127ddd88(System.Windows.Controls.Grid)-&gt;    <br />&#160; 127dddec(System.Collections.Generic.Dictionary`2[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]])-&gt;    <br />&#160; 127dde38(System.Collections.Generic.Dictionary`2+Entry[[MS.Internal.IManagedPeerBase, System.Windows],[System.Object, mscorlib]][])-&gt;    <br />&#160; 127dde84(System.Windows.Controls.ScrollViewer)-&gt;    <br />&#160; 127e97f0(System.Windows.Controls.ItemsPresenter)-&gt;    <br />&#160; 127e9858(MS.Internal.CoreTypeEventHelper)-&gt;    <br />&#160; 127ea1b4(System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]])-&gt;    <br />&#160; 127ea200(System.Collections.Generic.Dictionary`2+Entry[[System.Int32, mscorlib],[MS.Internal.CoreTypeEventHelper+EventAndDelegate, System.Windows]][])-&gt;    <br />&#160; 127ea1a4(MS.Internal.CoreTypeEventHelper+EventAndDelegate)-&gt;    <br />&#160; 127ea16c(System.Windows.Input.KeyEventHandler)-&gt;    <br />&#160; 12760854(Telerik.Windows.Controls.RadComboBox)-&gt;    <br />&#160; 12757a7c(System.Windows.Controls.Grid)-&gt;    <br />&#160; 127cf2ac(System.Windows.Controls.ContentPresenter)-&gt;    <br />&#160; 127cf188(System.Windows.Controls.Grid)-&gt;    <br />&#160; 12757160(Groupbox.GroupBox)-&gt;    <br />&#160; 12756df4(System.Windows.Controls.Grid)-&gt;    <br />&#160; 12753bfc(KSS.Silverlight.SystemWide.Views.UserView)</p>
<p>You should start looking from the bottom and work your way up to the gcroot – garbage collector root object.&#160; In my case I find RadComboBox object – first reference that looks like it is causing issues.&#160; I remove the combo box from my UserView user control and repeat the test.&#160; This time view disposes.&#160; I found my leak!</p>
<p>More typically, leaks are caused by hanging references to your objects, most commonly by event handlers.&#160; In my case this was not the case, but this is typically where you would look first.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/09/using-windbg-to-find-memory-leaks-in-silverlight-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/09/using-windbg-to-find-memory-leaks-in-silverlight-applications/</feedburner:origLink></item>
		<item>
		<title>Modular Silverlight Development, App.xaml, Blend and Resources</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/Ty6YJzsN3ec/</link>
		<comments>http://dotnetspeak.com/index.php/2010/08/modular-silverlight-development-app-xaml-blend-and-resources/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 14:09:33 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[Prsim]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/08/modular-silverlight-development-app-xaml-blend-and-resources/</guid>
		<description><![CDATA[As I was working on one of my personal learning projects, I encountered a small problem. The project was Prism based with multiple modules.&#160; I wanted to isolate my resource files, so I created a separate project that included my XAML resources, such as styles.&#160; This approach works just fine by using merged dictionaries in [...]]]></description>
			<content:encoded><![CDATA[<p>As I was working on one of my personal learning projects, I encountered a small problem. The project was Prism based with multiple modules.&#160; I wanted to isolate my resource files, so I created a separate project that included my XAML resources, such as styles.&#160; This approach works just fine by using merged dictionaries in App.xaml:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&lt;</span><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">Application</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160; <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>      <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>&#160; <br />&#160;&#160; <span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;MyApp.Silverlight.App&quot;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue"> &gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Application.Resources</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ResourceDictionary</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ResourceDictionary.MergedDictionaries</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ResourceDictionary</span><span style="color: red"> Source</span><span style="color: blue">=&quot;/MyResources.Silverlight.Common;component/Resources/MyResourcesDictionary.xaml&quot;/&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">ResourceDictionary.MergedDictionaries</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">ResourceDictionary</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Application.Resources</span><span style="color: blue">&gt;</span>      <br /><span style="color: blue">&lt;/</span><span style="color: #a31515">Application</span><span style="color: blue">&gt;</span>
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>Now I can reference those resource in my other modules’ screens and use them.&#160; Now back to the original issue.&#160; I can use styles from MyResourceDictionary.xaml, but Blend generates an error for me – it cannot find my resources.&#160; Here is an easy way to overcome this issue.&#160; You have to add the same dictionary into the resources of each screen:&#160; In the example below I am showing resources area for a user control called MySampleView from MyApp module.,</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;&#160;&#160; </span><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&lt;</span><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">MyApp</span><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">:</span><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">MySampleView.Resources</span><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&gt;</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">     <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ResourceDictionary</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ResourceDictionary.MergedDictionaries</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">ResourceDictionary</span><span style="color: red"> Source</span><span style="color: blue">=&quot;/MyResources.Silverlight.Common;component/Resources/MyResourcesDictionary.xaml&quot;/&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">ResourceDictionary.MergedDictionaries</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">resource</span><span style="color: blue">:</span><span style="color: #a31515">Resource</span><span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">=&quot;LocalizedResource&quot;/&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">ResourceDictionary</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">MyApp</span><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">:</span><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">MySampleView.Resources</span><span style="color: blue">&gt;</span>
</p>
<p>   </span></p>
<p class="MsoNormal">
<p> As you can see, I combine the styles dictionary with a local resource, in example localized user strings.&#160; You can just as easily add converters, etc… in the same fashion.</p>
</p>
<p class="MsoNormal">
<p>There is some cost of course associated with merging dictionaries into each screen, but using Blend is a big benefit.&#160; You can get around this issue by keeping this code commented out, and uncomment when using Blend</p>
</p>
<p class="MsoNormal">
<p>There is also another solution, involving having #DEBUG that moves this exact code into code behind of each view.&#160; Of course, this is annoying as well, and this is when the base class for the view comes in.&#160; Here is the code I could add to it to accomplish the same as XAML approach:</p>
</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">#if</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;"> DEBUG     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> dictionary = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">ResourceDictionary</span>()&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { Source = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Uri</span>(<span style="color: #a31515">&quot;/MyResources.Silverlight.Common;component/Resources/MyResourceDictionary.xaml&quot;</span>, <span style="color: #2b91af">UriKind</span>.RelativeOrAbsolute) };      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Resources.MergedDictionaries.Add(dictionary);      <br /><span style="color: blue">#endif</span>
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p class="MsoNormal">
<p>This of course underscores the usefulness of having base classes for all your major components, such as views in your applications.&#160; It could be an inconvenience since you cannot just add new user control.&#160; You would have to edit both XAML and code behind to change the inheritance structure of your user controls (views).</p>
</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&lt;</span><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">MyApp</span><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">:</span><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">MySampleViewBase</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">     <br />&#160;&#160; <span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;MyApp.Views.MySampleView&quot;</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">public</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;<span style="color: blue">partial</span>&#160;<span style="color: blue">class</span>&#160;<span style="color: #2b91af">MySampleView</span> : <span style="color: #2b91af">MySampleViewBase</span>, <span style="color: #2b91af">IMySampleView</span>
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p class="MsoNormal">
<p>You can further optimize this process by creating custom control templates that would write all this code for you.&#160; This way you would not have to modify the files after creating a new user control.</p>
</p>
<p class="MsoNormal">
<p>Thanks.</p></p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/08/modular-silverlight-development-app-xaml-blend-and-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/08/modular-silverlight-development-app-xaml-blend-and-resources/</feedburner:origLink></item>
		<item>
		<title>Encryption in Silverlight and .NET Applications</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/bqw39MBjjlU/</link>
		<comments>http://dotnetspeak.com/index.php/2010/08/encryption-in-silverlight-and-net-applications/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 17:37:30 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/08/encryption-in-silverlight-and-net-applications/</guid>
		<description><![CDATA[Today I would like to cover a specific use case that came up a few times in Silverlight applications I wrote.&#160; For example, I wand a user to enter some sensitive information, encrypt it in Silverlight client, transfer it over to the server, then decrypt it and perforation some operations on that data.
First step of [...]]]></description>
			<content:encoded><![CDATA[<p>Today I would like to cover a specific use case that came up a few times in Silverlight applications I wrote.&#160; For example, I wand a user to enter some sensitive information, encrypt it in Silverlight client, transfer it over to the server, then decrypt it and perforation some operations on that data.</p>
<p>First step of course is to find sufficiently strong encryption protocol that can be implemented in both Silverlight and .NET and be completely compatible between both run times.&#160; I am going to go for AES encryption.&#160; AES stands for “Advanced Encryption Standard”.&#160; This standard is widely used and approved by US government and standard bodies.&#160; See <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard" target="_blank">this article</a> for details.</p>
<p>Luckily, AES encryption is implemented in both Silverlight and .NET run times, using exact same set of classes, primary one being <a href="http://msdn.microsoft.com/en-us/library/bb352553.aspx" target="_blank">AesManaged</a> class.&#160; My goal is to create a class that I can cross-compile in both runt times, so this comes in super handy.&#160; Second, I wand to implement two methods Decrypt and Encrypt, while paying attention to IDisposable interfaces that the vast majority of classes inside Cryptography namespace implement.&#160; Both static methods take two parameters, input string and a password to be used.&#160; Of course, you have to make sure you use the same password in both methods while encrypting and decrypting information.&#160; You should probably dynamically generate a password during handshake process between a Silverlight client and a .NET server.&#160; I will also use maximum key size and block size of encryption.&#160; I will also dynamically generate key (Key) and initialization vector(IV) properties.&#160;&#160;&#160; I am going to now spare everyone a number of boring details, and will simply post final version of my utility class:&#160; You can include this class in both .NET and Silverlight project, and even link the physical .cs file from one to the other to ensure that you only have a single version in source control.</p>
<p>Thanks</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">using</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;"> System;     <br /><span style="color: blue">using</span> System.Text;      <br /><span style="color: blue">using</span> System.Security.Cryptography;      <br /><span style="color: blue">using</span> System.IO;      <br /><span style="mso-spacerun: yes">&#160;</span>      <br /><span style="color: blue">namespace</span> Encryption      <br />{      <br />&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">class</span>&#160;<span style="color: #2b91af">EncryptionUtility</span>      <br />&#160;&#160;&#160; {      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Encrypt the data</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;/summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;param name=&quot;input&quot;&gt;</span><span style="color: green">String to encrypt</span><span style="color: gray">&lt;/param&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;returns&gt;</span><span style="color: green">Encrypted string</span><span style="color: gray">&lt;/returns&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">string</span> Encrypt(<span style="color: blue">string</span> input, <span style="color: blue">string</span> password)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">byte</span>[] utfData = <span style="color: #2b91af">UTF8Encoding</span>.UTF8.GetBytes(input);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">byte</span>[] saltBytes = <span style="color: #2b91af">Encoding</span>.UTF8.GetBytes(password);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">string</span> encryptedString = <span style="color: blue">string</span>.Empty;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: #2b91af">AesManaged</span> aes = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">AesManaged</span>())      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Rfc2898DeriveBytes</span> rfc = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Rfc2898DeriveBytes</span>(password, saltBytes);      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; aes.KeySize = aes.LegalKeySizes[0].MaxSize;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; aes.Key = rfc.GetBytes(aes.KeySize / 8);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; aes.IV = rfc.GetBytes(aes.BlockSize / 8);      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: #2b91af">ICryptoTransform</span> encryptTransform = aes.CreateEncryptor())      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: #2b91af">MemoryStream</span> encryptedStream = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">MemoryStream</span>())      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: #2b91af">CryptoStream</span> encryptor =&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">CryptoStream</span>(encryptedStream, encryptTransform, <span style="color: #2b91af">CryptoStreamMode</span>.Write))      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; encryptor.Write(utfData, 0, utfData.Length);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; encryptor.Flush();      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; encryptor.Close();      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">byte</span>[] encryptBytes = encryptedStream.ToArray();      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; encryptedString = <span style="color: #2b91af">Convert</span>.ToBase64String(encryptBytes);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> encryptedString;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Decrypt a string</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;/summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;param name=&quot;input&quot;&gt;</span><span style="color: green">Input string in base 64 format</span><span style="color: gray">&lt;/param&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;returns&gt;</span><span style="color: green">Decrypted string</span><span style="color: gray">&lt;/returns&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">string</span> Decrypt(<span style="color: blue">string</span> input, <span style="color: blue">string</span> password)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">byte</span>[] encryptedBytes = <span style="color: #2b91af">Convert</span>.FromBase64String(input);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">byte</span>[] saltBytes = <span style="color: #2b91af">Encoding</span>.UTF8.GetBytes(password);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">string</span> decryptedString = <span style="color: blue">string</span>.Empty;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: blue">var</span> aes = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">AesManaged</span>())      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Rfc2898DeriveBytes</span> rfc = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Rfc2898DeriveBytes</span>(password, saltBytes);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; aes.KeySize = aes.LegalKeySizes[0].MaxSize;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; aes.Key = rfc.GetBytes(aes.KeySize / 8);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; aes.IV = rfc.GetBytes(aes.BlockSize / 8);      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: #2b91af">ICryptoTransform</span> decryptTransform = aes.CreateDecryptor())      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">using</span> (<span style="color: #2b91af">MemoryStream</span> decryptedStream = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">MemoryStream</span>())      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">CryptoStream</span> decryptor =&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">CryptoStream</span>(decryptedStream, decryptTransform, <span style="color: #2b91af">CryptoStreamMode</span>.Write);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; decryptor.Write(encryptedBytes, 0, encryptedBytes.Length);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; decryptor.Flush();      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; decryptor.Close();      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">byte</span>[] decryptBytes = decryptedStream.ToArray();      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; decryptedString =&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">UTF8Encoding</span>.UTF8.GetString(decryptBytes, 0, decryptBytes.Length);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> decryptedString;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160; }      <br />}
</p>
<p>   </span></p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/08/encryption-in-silverlight-and-net-applications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/08/encryption-in-silverlight-and-net-applications/</feedburner:origLink></item>
		<item>
		<title>XAML Intellisense Stops Working in Visual Studio 2010</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/OWN3s2k5GjU/</link>
		<comments>http://dotnetspeak.com/index.php/2010/08/xaml-intellisense-stops-working-in-visual-studio-2010/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 22:24:42 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/08/xaml-intellisense-stops-working-in-visual-studio-2010/</guid>
		<description><![CDATA[Today as I was working on a Silverlight application in Visual Studio 2010, XAML Intellisense just stopped working for me.&#160; Quick internet search yielded no useful results, so I was to figure this out on my own.&#160; Just to test I created a brand new application, and Intellisense was fine there.&#160; Logical answer was that [...]]]></description>
			<content:encoded><![CDATA[<p>Today as I was working on a Silverlight application in Visual Studio 2010, XAML Intellisense just stopped working for me.&#160; Quick internet search yielded no useful results, so I was to figure this out on my own.&#160; Just to test I created a brand new application, and Intellisense was fine there.&#160; Logical answer was that there was something wrong with my project.&#160; I re-created the project, and slowly retraced my steps, testing XAML Intellisense&#160; after each step.&#160; The feature broke again as soon as I added a reference to&#160; third party library I downloaded off the internet.&#160; Something wrong with a file, obviously.&#160; What I saw is that the DLL in question was blocked by Windows security.&#160; I unblocked by right-clicking on the file in Windows explorer, going to properties and clicking Unblock button.</p>
<p>The package that I downloaded included many files, and I really hated to go through each one. Next internet search yielded a great solution from SysInternals.&#160; You can download it <a href="http://technet.microsoft.com/en-us/sysinternals/bb897440.aspx" target="_blank">here</a>.&#160; Once I got streams utility, I ran it on entire folder, and voila – Intellisense was back.&#160; The command line is “streams –s –d ‘Folder with DLLs to Unblock’”, in my case “streams –s –d “c:\ThirdParty””</p>
<p>So, my research solved two problems for me – missing XAML Intellisense&#160; and ability to unblock multiple files which is something I wanted to find an answer to a while ago,</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/08/xaml-intellisense-stops-working-in-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/08/xaml-intellisense-stops-working-in-visual-studio-2010/</feedburner:origLink></item>
		<item>
		<title>Unit Testing Silverlight Applications – UI testing and Test Automation</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/dOY4cUlYkFk/</link>
		<comments>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-ui-testing-and-test-automation/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 19:21:11 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-ui-testing-and-test-automation/</guid>
		<description><![CDATA[In my last post I am going to cover the last two topics I set out to address.&#160; The first topic is UI testing.&#160; What unit test frameworks lack sometime is the actually UI testing.&#160; What I mean by that is for example, click on a button, then see what happens.&#160; In case of Silverlight, [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post I am going to cover the last two topics I set out to address.&#160; The first topic is UI testing.&#160; What unit test frameworks lack sometime is the actually UI testing.&#160; What I mean by that is for example, click on a button, then see what happens.&#160; In case of Silverlight, Silverlight framework itself has a number of helper classes to help us achieve this goal.&#160; For example, <span style="font-family: consolas; color: #2b91af; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">ButtonAutomationPeer </span>class allows us to drive button actions from within unit tests.&#160; Also, Microsoft Silverlight unit testing framework allows developers to insert UI components onto unit testing surface.&#160; Let me illustrate both concepts via an example.&#160; Here is my code for such unit test”</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">[<span style="color: #2b91af">TestMethod</span>]      <br />[<span style="color: #2b91af">Asynchronous</span>]      <br />[<span style="color: #2b91af">Description</span>(<span style="color: #a31515">&quot;Asynch Get Companies in UI&quot;</span>)]      <br />[<span style="color: #2b91af">Tag</span>(<span style="color: #a31515">&quot;Asynch&quot;</span>)]      <br /><span style="color: blue">public</span>&#160;<span style="color: blue">void</span> TestUIGetCompanies()      <br />{      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160; <span style="color: blue">var</span> companyVM = <span style="color: blue">new</span> CompanyModule.ViewModels.<span style="color: #2b91af">CompanyListViewModel</span>(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span> Microsoft.Practices.Composite.Events.<span style="color: #2b91af">EventAggregator</span>());      <br />&#160;&#160;&#160; <span style="color: #2b91af">CompanyListView</span> companyV = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">CompanyListView</span>();      <br />&#160;&#160;&#160; companyV.DataContext = companyVM;      <br />&#160;&#160;&#160; TestPanel.Children.Add(companyV);      <br />&#160;&#160;&#160; <span style="color: #2b91af">ButtonAutomationPeer</span> buttonPeer =&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">ButtonAutomationPeer</span>(companyV.FindName(<span style="color: #a31515">&quot;GetCompaniesButton&quot;</span>) <span style="color: blue">as</span>&#160;<span style="color: #2b91af">Button</span>);      <br />&#160;&#160;&#160; <span style="color: #2b91af">DataGrid</span> grid = companyV.FindName(<span style="color: #a31515">&quot;CompanyGrid&quot;</span>) <span style="color: blue">as</span>&#160;<span style="color: #2b91af">DataGrid</span>;      <br />&#160;&#160;&#160; <span style="color: #2b91af">IInvokeProvider</span> buttonInvoker = (<span style="color: #2b91af">IInvokeProvider</span>)buttonPeer;      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160; <span style="color: #2b91af">IGridProvider</span> gridPeer = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">DataGridAutomationPeer</span>(grid);      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160; EnqueueCallback(() =&gt; buttonInvoker.Invoke());      <br />&#160;&#160;&#160; EnqueueConditional(() =&gt; { <span style="color: blue">return</span> companyVM.CompanyList != <span style="color: blue">null</span>; });      <br />&#160;&#160;&#160; EnqueueCallback(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.IsTrue(companyVM.CompanyList.Count() &gt; 0, <span style="color: #a31515">&quot;Should have data&quot;</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.IsTrue(grid.Columns.Count == 3, <span style="color: #a31515">&quot;Should have 3 columns&quot;</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.IsTrue(gridPeer.RowCount &gt; 0, <span style="color: #a31515">&quot;Should have rows&quot;</span>));      <br />&#160;&#160;&#160; EnqueueTestComplete();      <br />}
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>Let’s trace down what is going on in this test.&#160; First of all, I am creating view model class.&#160; Since I do not have a bootstrapper, I manually create EventAggregator myself.&#160; Next, I am create a view to put my view model into.&#160; I create view, then put my view model into the data context of my view.&#160; Nest important step is to add my view to unit te3swt harness.&#160; This is accomplished by adding my view to test panel.&#160; My screenshot below illustrates where test panel is in terms of test runnier UI.&#160; I added hand cursor to illustrate the test panel referred to in UI below as “Test Stage.”&#160; As I run the unit tests, I will actually see my view there in the test stage.&#160; Just like I added the view, I can remove it from test stage.</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image6.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb6.png" width="485" height="381" /></a> </p>
<p>Next I am setting up code to invoke a button.&#160; I am creating new instance of <span style="font-family: consolas; color: #2b91af; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">ButtonAutomationPeer </span>class.&#160; Of course, I need to find a button to attach the automation peer to, and I am using FindName method to find an i9nstance of my button.&#160; To use this functionality I had to name my button.&#160; Then, I am setting up an automation peer for my grid as well.&#160; In general, most user input controls in Silverlight framework have matching automation objects.&#160; In my case, I am testing the results of my button invocation directly against the grid, making sure that the grid has correct number of rows and columns.&#160; I can also combine this type of testing with mocking,&#160; Here is the unit test for this case:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">[<span style="color: #2b91af">TestMethod</span>]      <br />[<span style="color: #2b91af">Asynchronous</span>]      <br />[<span style="color: #2b91af">Description</span>(<span style="color: #a31515">&quot;Asynch Get Companies in UI With Mocking&quot;</span>)]      <br />[<span style="color: #2b91af">Tag</span>(<span style="color: #a31515">&quot;Asynch&quot;</span>)]      <br /><span style="color: blue">public</span>&#160;<span style="color: blue">void</span> TestUIGetCompaniesWithMock()      <br />{      <br />&#160;&#160;&#160; <span style="color: blue">var</span> companyVM = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">ICompanyListViewModel</span>&gt;();      <br />&#160;&#160;&#160; companyVM.SetupGet(testVM =&gt; testVM.CompanyList).      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Returns(<span style="color: blue">new</span>&#160;<span style="color: #2b91af">ObservableCollection</span>&lt;<span style="color: #2b91af">Company</span>&gt;(<span style="color: blue">new</span>[] {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Company</span>(){      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CompanyID = <span style="color: #2b91af">Guid</span>.NewGuid(), DateAdded = <span style="color: #2b91af">DateTime</span>.Now, CompanyName = <span style="color: #a31515">&quot;some random company&quot;</span>},      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Company</span>(){&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CompanyID = <span style="color: #2b91af">Guid</span>.NewGuid(), DateAdded = <span style="color: #2b91af">DateTime</span>.Now.AddDays(-1), CompanyName = <span style="color: #a31515">&quot;another company&quot;</span>}}));      <br />&#160;&#160;&#160; companyVM.SetupGet(testVM =&gt; testVM.GetCompaniesCommand).      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Returns(<span style="color: blue">new</span>&#160;<span style="color: #2b91af">DelegateCommand</span>&lt;<span style="color: blue">object</span>&gt;((o) =&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; companyVM.Raise(vm =&gt;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; vm.PropertyChanged += <span style="color: blue">null</span>, <span style="color: blue">new</span> System.ComponentModel.<span style="color: #2b91af">PropertyChangedEventArgs</span>(<span style="color: #a31515">&quot;CompanyList&quot;</span>))));      <br /><span style="mso-spacerun: yes">&#160;</span>      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160; <span style="color: #2b91af">CompanyListView</span> companyV = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">CompanyListView</span>();      <br />&#160;&#160;&#160; companyV.DataContext = companyVM.Object;      <br />&#160;&#160;&#160; TestPanel.Children.Add(companyV);      <br />&#160;&#160;&#160; <span style="color: #2b91af">ButtonAutomationPeer</span> buttonPeer = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">ButtonAutomationPeer</span>(companyV.FindName(<span style="color: #a31515">&quot;GetCompaniesButton&quot;</span>) <span style="color: blue">as</span>&#160;<span style="color: #2b91af">Button</span>);      <br />&#160;&#160;&#160; <span style="color: #2b91af">DataGrid</span> grid = companyV.FindName(<span style="color: #a31515">&quot;CompanyGrid&quot;</span>) <span style="color: blue">as</span>&#160;<span style="color: #2b91af">DataGrid</span>;      <br />&#160;&#160;&#160; <span style="color: #2b91af">IInvokeProvider</span> buttonInvoker = (<span style="color: #2b91af">IInvokeProvider</span>)buttonPeer;      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160; <span style="color: #2b91af">IGridProvider</span> gridPeer = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">DataGridAutomationPeer</span>(grid);      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160; EnqueueCallback(() =&gt; buttonInvoker.Invoke());      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; EnqueueCallback(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.IsTrue(companyVM.Object.CompanyList.Count() &gt; 0, <span style="color: #a31515">&quot;Should have data&quot;</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.AreEqual(3, grid.Columns.Count, <span style="color: #a31515">&quot;Should have 3 columns&quot;</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.AreEqual(2, gridPeer.RowCount, <span style="color: #a31515">&quot;Should have rows&quot;</span>));      <br />&#160;&#160;&#160; EnqueueTestComplete();      <br />}      <br style="mso-special-character: line-break" />      <br style="mso-special-character: line-break" />
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>In the case above I am mocking property changed event by invoking it when a button is clicked, causing UI to re-bind.&#160; The rest of testing code is very similar to actual invocation of server side code.</p>
<p>The last topic I would like to cover is <a href="http://statlight.codeplex.com/" target="_blank">StatLight</a> framework.&#160; You can take a closer look at the framework <a href="http://statlight.codeplex.com/" target="_blank">here</a>.&#160; This framework allows developers to invoke unit tests written with Microsoft unit testing framework for Silverlight from a command line and also read in results of such runs.&#160; Once you download and unzip the DLLs into a folder, you will need to do one more thing – Unblock those DLLs in the properties of each file in Windows explorer.&#160; Also, if you want to test server side code using StatLight, you will need to convert your web site to use local IIS inste4ad of Cassini (Visual Studio built-in IIS Server).&#160; You will also need to put clientaccesspolicy.xml into the root of your IIS in order to avoid cross domain exceptions.&#160; Using the StatLight framework is very simple.&#160; Simply call StatLight.exe and pass XAP file on command line that contains your unit tests.&#160; Here is a screenshot of what it looks like:</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image7.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb7.png" width="564" height="137" /></a>&#160;</p>
<p>As you can see, your –x parameter is the only one you have to specify to test.&#160; You will also see that unit test is launched at the same time.&#160; Now, to test results you have to add one more parameter – r.&#160; Here is what that command would look like:</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image8.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb8.png" width="575" height="97" /></a> </p>
<p>Once you run this, you will end up with out.txt in the specified folder.&#160; Here is the content of this file:</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image9.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb9.png" width="1069" height="244" /></a> </p>
<p>The last parameter I want to mention is ability to limit test run by tag attribute I covered in an earlier post.&#160; To user this feature, you have to add –t command line attribute like so:&#160; Here is what this command line look like:</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image10.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb10.png" width="577" height="104" /></a> </p>
<p>You can download complete solution <a href="/Downloads/SilverlightTestingDempPart3.zip" target="_blank">here</a>.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-ui-testing-and-test-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-ui-testing-and-test-automation/</feedburner:origLink></item>
		<item>
		<title>Windows Phone 7 Beta is here</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/1F9Tvj3R-RM/</link>
		<comments>http://dotnetspeak.com/index.php/2010/07/windows-phone-7-beta-is-here/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 01:31:12 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/07/windows-phone-7-beta-is-here/</guid>
		<description><![CDATA[Windows Phone 7 Developer tool beat has been released by Microsoft.&#160; You can download it here.    Make sure to download and read release note available on the page above.
&#160;
Thanks.
]]></description>
			<content:encoded><![CDATA[<p>Windows Phone 7 Developer tool beat has been released by Microsoft.&#160; You can download it <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&amp;displaylang=en" target="_blank">here</a>.    <br />Make sure to download and read release note available on the page above.</p>
<p>&#160;</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/07/windows-phone-7-beta-is-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/07/windows-phone-7-beta-is-here/</feedburner:origLink></item>
		<item>
		<title>Unit Testing Silverlight Applications – Mocking</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/XkkruGKI1Co/</link>
		<comments>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-mocking/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 23:43:23 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-mocking/</guid>
		<description><![CDATA[In this post I will explore ability to mock various Silverlight classes in order to enable mocking in your unit tests.&#160; There is a variety of mocking frameworks available, but I will pick one for my testing – Moq.&#160; You can download the framework here,&#160; Once this is done, I need to add some references [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will explore ability to mock various Silverlight classes in order to enable mocking in your unit tests.&#160; There is a variety of mocking frameworks available, but I will pick one for my testing – Moq.&#160; You can download the framework <a href="http://code.google.com/p/moq/" target="_blank">here</a>,&#160; Once this is done, I need to add some references to my Silverlight unit test project.</p>
<p>Moq requires three assemblies available in the folder where Moq is installed:</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb4.png" width="511" height="308" /></a> </p>
<p>If we are mocking view model or another object relying on Prism, we also need to add Prism references</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image5.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb5.png" width="508" height="403" /></a> </p>
<p>Now we are ready to mock!</p>
<p>Let’s start by doing something simple.&#160; I will mock my view model.&#160; The only property I really want to test is my model property, which in my case exposes list of companies.&#160; TO do so, I just need to setup property getter that contains my model.&#160; The getter will be called when first accessed.&#160; Here is what we have:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">[<span style="color: #2b91af">TestMethod</span>]      <br />[<span style="color: #2b91af">Tag</span>(<span style="color: #a31515">&quot;Mocking&quot;</span>)]      <br />[<span style="color: #2b91af">Description</span>(<span style="color: #a31515">&quot;VM Mocking&quot;</span>)]      <br /><span style="color: blue">public</span>&#160;<span style="color: blue">void</span> TestMocking()      <br />{      <br />&#160;&#160;&#160; <span style="color: blue">var</span> vm = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Mock</span>&lt;<span style="color: #2b91af">ICompanyListViewModel</span>&gt;();      <br />&#160;&#160;&#160; vm.SetupGet(testVM =&gt; testVM.CompanyList).      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Returns(<span style="color: blue">new</span>&#160;<span style="color: #2b91af">ObservableCollection</span>&lt;<span style="color: #2b91af">Company</span>&gt;(<span style="color: blue">new</span>[] {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Company</span>()      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { CompanyID = <span style="color: #2b91af">Guid</span>.NewGuid(), DateAdded = <span style="color: #2b91af">DateTime</span>.Now, CompanyName = <span style="color: #a31515">&quot;some random company&quot;</span>},      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Company</span>()      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { CompanyID = <span style="color: #2b91af">Guid</span>.NewGuid(), DateAdded = <span style="color: #2b91af">DateTime</span>.Now.AddDays(-1), CompanyName = <span style="color: #a31515">&quot;another company&quot;</span>}}));      <br />&#160;&#160;&#160; <span style="color: #2b91af">Assert</span>.AreEqual(2, vm.Object.CompanyList.Count, <span style="color: #a31515">&quot;Mocking failed&quot;</span>);      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />}
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>I am only mocking view model in this case.&#160; With Moq framework, as it is the case with most mocking frameworks, you are required to have interfaces in order to mock.&#160; In case of RIA Services, this is an issue because client side classes are sealed and do not implement interfaces.&#160; If you are using your own WCF service with custom classes, you can avoid this small issue.&#160; You can also mock events as well.&#160; This is how I would mock property changed event in my view model:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">companyVM.SetupGet(testVM =&gt; testVM.GetCompaniesCommand).Returns(<span style="color: blue">new</span>&#160;<span style="color: #2b91af">DelegateCommand</span>&lt;<span style="color: blue">object</span>&gt;((o) =&gt;      <br />&#160;&#160;&#160; companyVM.Raise(vm =&gt; vm.PropertyChanged += <span style="color: blue">null</span>, <span style="color: blue">new</span> System.ComponentModel.<span style="color: #2b91af">PropertyChangedEventArgs</span>(<span style="color: #a31515">&quot;CompanyList&quot;</span>))));
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>As you can see, mocking is pretty easy concept, and the web page for Moq has <a href="http://code.google.com/p/moq/wiki/QuickStart" target="_blank">quick start guide</a> to help you get started.&#160; Feel free to use a different mocking framework as well.&#160; In the next post I will show how to unit test user interface using Silverlight unit testing framework.</p>
<p>Thanks</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-mocking/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-mocking/</feedburner:origLink></item>
		<item>
		<title>Unit Testing Silverlight Applications – Asynchronous Testing</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/RIq5tMhqOJg/</link>
		<comments>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-asynchronous-testing/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 00:41:19 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-asynchronous-testing/</guid>
		<description><![CDATA[In this post I will describe how to create asynchronous unit tests for Silverlight applications.&#160; First of all, I’d like to point out that any communication with a server component in Silverlight must be asynchronous.&#160; Reason being is that if communication was synchronous and the remote service was not responding, browser which host Silverlight application [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will describe how to create asynchronous unit tests for Silverlight applications.&#160; First of all, I’d like to point out that any communication with a server component in Silverlight must be asynchronous.&#160; Reason being is that if communication was synchronous and the remote service was not responding, browser which host Silverlight application would lock up.&#160; As you can see, asynchronous communication with a RIA Services WCF service is very important in our case.&#160; </p>
<p>Let’s take a look on how to write a test that would assert that we can successfully get a list of companies from the server.&#160; To do so, we must first take a look on how to write such a test.&#160; This can be accomplished using asynchronous constructs available in Silverlight unit testing framework.&#160; First of all, we have to change inheritance for our test class.&#160; When you create a new test class, it does not inherit from any class, and we have to change this first of all.&#160; Here is what old test class declaration look like:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">[<span style="color: #2b91af">TestClass</span>]      <br /><span style="color: blue">public</span>&#160;<span style="color: blue">class</span>&#160;<span style="color: #2b91af">Tests</span>
</p>
<p>   </span></p>
<p class="MsoNormal">Here is what we are going to change it to:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">[<span style="color: #2b91af">TestClass</span>]      <br /><span style="color: blue">public</span>&#160;<span style="color: blue">class</span>&#160;<span style="color: #2b91af">Tests</span> : Microsoft.Silverlight.Testing.<span style="color: #2b91af">SilverlightTest</span>
</p>
<p>   </span></p>
<p class="MsoNormal">Now we must decorate our test method with appropriate attribute to signal to test running harness that it is about to execute asynchronous test:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">[<span style="color: #2b91af">TestMethod</span>]      <br />[<span style="color: #2b91af">Asynchronous</span>]      <br />[<span style="color: #2b91af">Description</span>(<span style="color: #a31515">&quot;Asynch Get Companies&quot;</span>)]      <br />[<span style="color: #2b91af">Tag</span>(<span style="color: #a31515">&quot;Asynch&quot;</span>)]      <br /><span style="color: blue">public</span>&#160;<span style="color: blue">void</span> TestGetCompanies()
</p>
<p>   </span></p>
<p class="MsoNormal">Now, let take a deeper look into framework itself to see the key methods that we can use in base class – <font color="#0000ff">SilverlightTest</font>.</p>
<p class="MsoNormal">First one is <font color="#0000ff">EnqueueConditional</font>.&#160; This method is designed to let unit test wait until condition specified as an argument to <font color="#0000ff">EnqueueConditional</font> is met.&#160; It is very useful when you want to wait until a method call to the service is completed.&#160; Here is how I would use this method:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">TestMethod</span>]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Asynchronous</span>]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Description</span>(<span style="color: #a31515">&quot;Asynch Get Companies&quot;</span>)]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Tag</span>(<span style="color: #a31515">&quot;Asynch&quot;</span>)]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">void</span> TestGetCompanies()      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">bool</span> isLoaded = <span style="color: blue">false</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Exception</span> error = <span style="color: blue">null</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #2b91af">Company</span>&gt; results = <span style="color: blue">null</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">CompanyDomainContext</span> context = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">CompanyDomainContext</span>(<span style="color: blue">new</span>&#160;<span style="color: #2b91af">Uri</span>(<span style="color: #a31515">@&quot;http://localhost:4988/SilverlightTestingDemo-Web-CompanyDomainService.svc&quot;</span>, <span style="color: #2b91af">UriKind</span>.Absolute));      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> query = context.GetCompaniesQuery();      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Load&lt;<span style="color: #2b91af">Company</span>&gt;(query, (result) =&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; isLoaded = <span style="color: blue">true</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; results = result.Entities;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; error = result.Error;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }, <span style="color: blue">null</span>);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EnqueueConditional(() =&gt; isLoaded);
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p class="MsoNormal">What I am doing above is declaring a Boolean variable isLoaded that would signal to the framework to continue the test once data has been loaded.&#160; I am setting this variable to true in the lambda expression callback that is called one server method’s execution is completed &#8211; (result)=&gt; expression.</p>
<p class="MsoNormal">Next interesting method is <font color="#0000ff">EnqueueCallback</font>.&#160; This method simply declares multiple or in Action delegates that will be executed one they are popped off execution stack when harness processes test method calls.&#160; What I mean is that the harness will execute all Action delegates that <font color="#0000ff">EnqueueCallback</font> declares when it proceeds with running a test method once condition that&#160; EnqueueConditional declares is met. If there are no such calls in the method body and there are no calls to <font color="#0000ff">EnqueueDelay</font> that would also pause execution, then <font color="#0000ff">EnqueueCallback</font> has no meaning, and asynchronous test essentially becomes synchronous.&#160; Here is what we have so far:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">TestMethod</span>]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Asynchronous</span>]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Description</span>(<span style="color: #a31515">&quot;Asynch Get Companies&quot;</span>)]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Tag</span>(<span style="color: #a31515">&quot;Asynch&quot;</span>)]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">void</span> TestGetCompanies()      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">bool</span> isLoaded = <span style="color: blue">false</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Exception</span> error = <span style="color: blue">null</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #2b91af">Company</span>&gt; results = <span style="color: blue">null</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">CompanyDomainContext</span> context = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">CompanyDomainContext</span>(<span style="color: blue">new</span>&#160;<span style="color: #2b91af">Uri</span>(<span style="color: #a31515">@&quot;http://localhost:4988/SilverlightTestingDemo-Web-CompanyDomainService.svc&quot;</span>, <span style="color: #2b91af">UriKind</span>.Absolute));      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> query = context.GetCompaniesQuery();      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Load&lt;<span style="color: #2b91af">Company</span>&gt;(query, (result) =&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; isLoaded = <span style="color: blue">true</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; results = result.Entities;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; error = result.Error;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }, <span style="color: blue">null</span>);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EnqueueConditional(() =&gt; isLoaded);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EnqueueCallback(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.IsTrue(results.Count() &gt; 0, <span style="color: #a31515">&quot;Should have data&quot;</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.IsNull(error, <span style="color: #a31515">&quot;Should have no errors&quot;</span>));
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p class="MsoNormal">The last important method is <font color="#0000ff">EnqueueTestComplete</font>.&#160; This method puts Test Completed signal onto the execution stack. This method is typically the very last statement of the test method body.&#160; Here is our final version of the method:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">TestMethod</span>]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Asynchronous</span>]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Description</span>(<span style="color: #a31515">&quot;Asynch Get Companies&quot;</span>)]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Tag</span>(<span style="color: #a31515">&quot;Asynch&quot;</span>)]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">void</span> TestGetCompanies()      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">bool</span> isLoaded = <span style="color: blue">false</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Exception</span> error = <span style="color: blue">null</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #2b91af">Company</span>&gt; results = <span style="color: blue">null</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">CompanyDomainContext</span> context = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">CompanyDomainContext</span>(<span style="color: blue">new</span>&#160;<span style="color: #2b91af">Uri</span>(<span style="color: #a31515">@&quot;http://localhost:4988/SilverlightTestingDemo-Web-CompanyDomainService.svc&quot;</span>, <span style="color: #2b91af">UriKind</span>.Absolute));      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> query = context.GetCompaniesQuery();      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.Load&lt;<span style="color: #2b91af">Company</span>&gt;(query, (result) =&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; isLoaded = <span style="color: blue">true</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; results = result.Entities;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; error = result.Error;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }, <span style="color: blue">null</span>);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EnqueueConditional(() =&gt; isLoaded);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EnqueueCallback(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.IsTrue(results.Count() &gt; 0, <span style="color: #a31515">&quot;Should have data&quot;</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; () =&gt; <span style="color: #2b91af">Assert</span>.IsNull(error, <span style="color: #a31515">&quot;Should have no errors&quot;</span>));      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EnqueueTestComplete();      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p class="MsoNormal">You can download the complete code <a href="/Downloads/SilverlightTestingDemoPost2.zip" target="_blank">here</a>.&#160; In the next post I will cover mocking for synchronous and asynchronous unit tests.</p>
<p class="MsoNormal">Thanks..</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-asynchronous-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications-asynchronous-testing/</feedburner:origLink></item>
		<item>
		<title>Unit Testing Silverlight Applications</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/teKUyvMkXMw/</link>
		<comments>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 23:09:05 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications/</guid>
		<description><![CDATA[I am starting a short series of posts on unit testing of Silverlight applications.&#160; I will be using the following set of technologies.&#160; 

Microsoft Silverlight Unit testing framework that ships with Silverlight tool kit
Moq – mocking framework that supports Silverlight 4
StatLight – unit testing automation framework that will allow for unattended / automated running unit [...]]]></description>
			<content:encoded><![CDATA[<p>I am starting a short series of posts on unit testing of Silverlight applications.&#160; I will be using the following set of technologies.&#160; </p>
<ul>
<li>Microsoft Silverlight Unit testing framework that ships with <a href="http://silverlight.codeplex.com/" target="_blank">Silverlight tool kit</a></li>
<li><a href="http://code.google.com/p/moq/" target="_blank">Moq</a> – mocking framework that supports Silverlight 4</li>
<li><a href="http://statlight.codeplex.com/" target="_blank">StatLight</a> – unit testing automation framework that will allow for unattended / automated running unit tests </li>
</ul>
<p>I am going to start with a simple Silverlight application that is using RIA services and Prism.&#160; First things first, let’s create unit test project.&#160; Project template will be installed when you install the Silverlight toolkit.&#160; Here is what add project dialog looks like.&#160; The template is located under Silverlight tab</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb.png" width="652" height="455" /></a> </p>
<p>Here are the setting for the next dialog:</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb1.png" width="449" height="460" /></a> </p>
<p>Once project is created, a simple test class is also created.&#160; If you ever worked with Microsoft unit testing in Visual Studio, you will find the API quite familiar, including all key classed, attributes and namespaces.&#160; I am going to create a simple synchronous test first, testing my RIA services class to ensure that validation rules are setup properly.&#160; To do so, I first add a reference to my simple Company module to my Silverlight unit test project.&#160; Since I am also testing RIA services classes, I will add two more references: System.ComponentModel.DataAnnotations and System.ServiceModel.DomainServices.Client.dll.&#160; Now with this our of the way, here is what my test class and method look like:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">using</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;"> System;     <br /><span style="color: blue">using</span> System.Net;      <br /><span style="color: blue">using</span> System.Windows;      <br /><span style="color: blue">using</span> System.Windows.Controls;      <br /><span style="color: blue">using</span> System.Windows.Documents;      <br /><span style="color: blue">using</span> System.Windows.Ink;      <br /><span style="color: blue">using</span> System.Windows.Input;      <br /><span style="color: blue">using</span> System.Windows.Media;      <br /><span style="color: blue">using</span> System.Windows.Media.Animation;      <br /><span style="color: blue">using</span> System.Windows.Shapes;      <br /><span style="color: blue">using</span> Microsoft.Silverlight.Testing;      <br /><span style="color: blue">using</span> System.Collections.ObjectModel;      <br /><span style="color: blue">using</span> Microsoft.VisualStudio.TestTools.UnitTesting;      <br /><span style="color: blue">using</span> SilverlightTestingDemo.Web;      <br /><span style="mso-spacerun: yes">&#160;</span>      <br /><span style="color: blue">namespace</span> SilverlightUnitTest      <br />{      <br />&#160;&#160;&#160; [<span style="color: #2b91af">TestClass</span>]      <br />&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">class</span>&#160;<span style="color: #2b91af">Tests</span>      <br />&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">TestMethod</span>]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Tag</span>(<span style="color: #a31515">&quot;Synch&quot;</span>)]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; [<span style="color: #2b91af">Description</span>(<span style="color: #a31515">&quot;Rules&quot;</span>)]      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">void</span> TestCompanyRules()      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Company</span> company = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">Company</span>();      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; company.CompanyName = <span style="color: #a31515">&quot;test&quot;</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Assert</span>.AreEqual(0, company.ValidationErrors.Count, <span style="color: #a31515">&quot;Should be valid&quot;</span>);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; company.CompanyName = <span style="color: blue">string</span>.Empty;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Assert</span>.AreEqual(1, company.ValidationErrors.Count, <span style="color: #a31515">&quot;Should be in valid&quot;</span>);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160; }      <br />}
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>Let me go over the attributes I used.&#160; TestClass attribute is what signals to Unit testing framework as to what classes contain unit tests.&#160; TestMethod attribute identifies methods that represent a single unit test.&#160; Tag attribute is used by unit test runner UI to filter out what tests based on attributes will be run.&#160; Description attribute data will be shown in runner UI when unit tests are run. Assert class is used to assert test results.&#160; For example, in my first Assert statement I make sure that Company instance is valid once name is set.</p>
<p>When I run unit tests after setting up unit test application&#8217;s web site as start up project, here is what I see.</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb2.png" width="682" height="433" /></a> </p>
<p>Test are setup to auto-run by default.&#160; You will see the countdown label, and if you click on count down label, you will have a chance to select specific tests to run.</p>
<p><a href="http://dotnetspeak.com/wp-content/uploads/2010/07/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dotnetspeak.com/wp-content/uploads/2010/07/image_thumb3.png" width="427" height="217" /></a> </p>
<p>After tests are run, you will see test run summary in the top left cornet of the screen.&#160; In my case I see that I had total of 1 test, and 2 test has passed.&#160; if a test fails, you will see that in the test run summary.&#160; You can download solution so far <a href="/Downloads/SilverlightTestingDemoPost1.zip" target="_blank">here</a>.&#160; In my next post I will cover asynchronous testing in Silverlight application.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/07/unit-testing-silverlight-applications/</feedburner:origLink></item>
		<item>
		<title>Implementing Double-Click In Silverlight DataGrid</title>
		<link>http://feedproxy.google.com/~r/DotNetSpeak/~3/LJuVyHKZies/</link>
		<comments>http://dotnetspeak.com/index.php/2010/07/implementing-double-click-in-silverlight-datagrid/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 15:59:57 +0000</pubDate>
		<dc:creator>Sergey Barskiy</dc:creator>
				<category><![CDATA[Prsim]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://dotnetspeak.com/index.php/2010/07/implementing-double-click-in-silverlight-datagrid/</guid>
		<description><![CDATA[As I was working on one of my presentations, I wanted to go to a detail from from query form by letting user double-click.&#160; No standard Silverlight controls implement double-clicks, and this includes DataGrid.&#160; So, naturally one would need to listen to click events and interpret clicks within a certain time to be a double-click.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>As I was working on one of my presentations, I wanted to go to a detail from from query form by letting user double-click.&#160; No standard Silverlight controls implement double-clicks, and this includes DataGrid.&#160; So, naturally one would need to listen to click events and interpret clicks within a certain time to be a double-click.&#160; In my case I will use 300 milliseconds.&#160; Another fact to consider is that if you try to do hook up double-click to the DataGrid itself, you will be disappointed because LeftMouseButtonUp event only fires when there are no rows to get in the way.&#160; So, to make this work we will have to use each row’s mouse events.&#160; I am going to wrap this up in a behavior first.&#160; I am going to call this behavior&#160; <span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior.&#160; </span>Here is what my class looks like, and it is very simple.&#160; As you see, I am inheriting from CommandBase from <a href="http://compositewpf.codeplex.com/" target="_blank">Prism (Composite Application Guidance for Silverlight/WPF</a>).</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">using</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;"> System;     <br /><span style="color: blue">using</span> Microsoft.Practices.Composite.Presentation.Commands;      <br /><span style="color: blue">using</span> System.Windows.Controls;      <br /><span style="color: blue">using</span> System.Windows.Input;      <br /><span style="mso-spacerun: yes">&#160;</span>      <br /><span style="color: blue">namespace</span> CompanyModule.Converters      <br />{      <br />&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;summary&gt;</span>      <br />&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Inherit from command base from Prism</span>      <br />&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;/summary&gt;</span>      <br />&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">class</span>&#160;<span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior</span> : <span style="color: #2b91af">CommandBehaviorBase</span>&lt;<span style="color: #2b91af">DataGrid</span>&gt;      <br />&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Last time mouse was clicked</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;/summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: #2b91af">DateTime</span> _lastTime;      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Number of milliseconds to interpret as doible-click</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;/summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: blue">const</span>&#160;<span style="color: blue">long</span> MillisesondsForDoubleClick = 300;      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Create new instance</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;/summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;param name=&quot;dataGrid&quot;&gt;</span><span style="color: green">DataGrid to attach behavior to</span><span style="color: gray">&lt;/param&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span> DataGridMouseLeftButtonDownCommandBehavior(<span style="color: #2b91af">DataGrid</span> dataGrid)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; : <span style="color: blue">base</span>(dataGrid)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataGrid.LoadingRow += OnLoadingRow;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataGrid.UnloadingRow += OnUnloadingRow;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Hook up mouse events</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;/summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;param name=&quot;sender&quot;&gt;&lt;/param&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;param name=&quot;e&quot;&gt;&lt;/param&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: blue">void</span> OnUnloadingRow(<span style="color: blue">object</span> sender, <span style="color: #2b91af">DataGridRowEventArgs</span> e)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Row.MouseLeftButtonUp -= OnMouseLeftButtonDown;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green"> Unhook events to avoid memory leaks</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;/summary&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;param name=&quot;sender&quot;&gt;&lt;/param&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: gray">///</span><span style="color: green">&#160;</span><span style="color: gray">&lt;param name=&quot;e&quot;&gt;&lt;/param&gt;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: blue">void</span> OnLoadingRow(<span style="color: blue">object</span> sender, <span style="color: #2b91af">DataGridRowEventArgs</span> e)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.Row.MouseLeftButtonUp += OnMouseLeftButtonDown;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br /><span style="mso-spacerun: yes">&#160;</span>      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: blue">void</span> OnMouseLeftButtonDown(<span style="color: blue">object</span> sender, <span style="color: #2b91af">MouseButtonEventArgs</span> e)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// if timing is right, fire command</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> ((<span style="color: #2b91af">DateTime</span>.Now.Subtract(_lastTime).TotalMilliseconds) &lt; MillisesondsForDoubleClick)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ExecuteCommand();      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: green">// reset the time</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _lastTime = <span style="color: #2b91af">DateTime</span>.Now;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160; }      <br />}
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>Now that we have behavior of the way, we need to come up with a clean way to hook it up as well as setting a command and command parameter onto a DataGrid.</p>
<p>I am going to use a static class and attached properties.&#160; Attached properties are a feature of Silverlight that would allow us to set properties on one object via properties defined on another object.&#160; Most common example of them is Grid control in Silverlight.&#160; If you add a child control to a Grid, you set its location by using Grid.Column or Grid.Row on child control itself, such as Textbox.&#160; Properties that I am going to need are Command and CommandParameter as well as a property I can attach my behavior to.&#160; I am again using Prism for my project.&#160; Here is what my attached properties look like:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">class</span>&#160;<span style="color: #2b91af">DataGridDoubleClick</span>      <br />&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">readonly</span>&#160;<span style="color: #2b91af">DependencyProperty</span> DataGridDoubleClickCommandBehaviorProperty =&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DependencyProperty</span>.RegisterAttached(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515">&quot;DataGridDoubleClickCommandBehavior&quot;</span>,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">typeof</span>(<span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">typeof</span>(<span style="color: #2b91af">DataGridDoubleClick</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">null</span>);      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">readonly</span>&#160;<span style="color: #2b91af">DependencyProperty</span> CommandProperty =&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DependencyProperty</span>.RegisterAttached(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515">&quot;Command&quot;</span>,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">typeof</span>(<span style="color: #2b91af">ICommand</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">typeof</span>(<span style="color: #2b91af">DataGridDoubleClick</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">PropertyMetadata</span>(OnSetCommand));      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">public</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">readonly</span>&#160;<span style="color: #2b91af">DependencyProperty</span> CommandParameterProperty =&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DependencyProperty</span>.RegisterAttached(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515">&quot;CommandParameter&quot;</span>,      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">typeof</span>(<span style="color: blue">object</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">typeof</span>(<span style="color: #2b91af">DataGridDoubleClick</span>),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span>&#160;<span style="color: #2b91af">PropertyMetadata</span>(OnSetCommandParameter));
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>I am defining call backs in order to be able to attach my behavior to the DataGrid in those.&#160; The reason I cannot just put behavior inside XAML is because I need to pass DataGrid to my behavior as a parameter.&#160; I am using attached property for the behavior because this makes it easy to store in static environment.</p>
<p>Here is how I am hooking up behavior in call back methods.</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">void</span> OnSetCommand      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (<span style="color: #2b91af">DependencyObject</span> dependencyObject, <span style="color: #2b91af">DependencyPropertyChangedEventArgs</span> e)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DataGrid</span> dataGrid = dependencyObject <span style="color: blue">as</span>&#160;<span style="color: #2b91af">DataGrid</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (dataGrid != <span style="color: blue">null</span>)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior</span> behavior = GetBehavior(dataGrid);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; behavior.Command = e.NewValue <span style="color: blue">as</span>&#160;<span style="color: #2b91af">ICommand</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br /><span style="mso-spacerun: yes">&#160;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: blue">void</span> OnSetCommandParameter      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (<span style="color: #2b91af">DependencyObject</span> dependencyObject, <span style="color: #2b91af">DependencyPropertyChangedEventArgs</span> e)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DataGrid</span> dataGrid = dependencyObject <span style="color: blue">as</span>&#160;<span style="color: #2b91af">DataGrid</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (dataGrid != <span style="color: blue">null</span>)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior</span> behavior = GetBehavior(dataGrid);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; behavior.CommandParameter = e.NewValue;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>The final part is how to set the behavior.&#160; Here is the short method for it:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span>&#160;<span style="color: blue">static</span>&#160;<span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior</span> GetBehavior(<span style="color: #2b91af">DataGrid</span> dataGrid)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior</span> behavior =      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataGrid.GetValue(DataGridDoubleClickCommandBehaviorProperty)&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">as</span>&#160;<span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior</span>;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (behavior == <span style="color: blue">null</span>)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; behavior = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">DataGridMouseLeftButtonDownCommandBehavior</span>(dataGrid);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataGrid.SetValue(DataGridDoubleClickCommandBehaviorProperty, behavior);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> behavior;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>Now the final step – XAML for my data grid:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&lt;</span><span style="font-family: consolas; color: #a31515; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">UserControl</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">     <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>      <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">x</span><span style="color: blue">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>      <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">d</span><span style="color: blue">=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;</span>      <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">mc</span><span style="color: blue">=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;</span>      <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">my</span><span style="color: blue">=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data&quot;</span>&#160;&#160; <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">command</span><span style="color: blue">=&quot;clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; assembly=Microsoft.Practices.Composite.Presentation&quot;</span>      <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">converters</span><span style="color: blue">=&quot;clr-namespace:CompanyModule.Converters&quot;</span>      <br />&#160;&#160; <span style="color: red"> xmlns</span><span style="color: blue">:</span><span style="color: red">i</span><span style="color: blue">=&quot;http://schemas.microsoft.com/expression/2010/interactivity&quot;</span>&#160; <br />&#160;&#160; <span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Class</span><span style="color: blue">=&quot;CompanyModule.Views.CompanyListView&quot;</span>      <br />&#160;&#160; <span style="color: red"> mc</span><span style="color: blue">:</span><span style="color: red">Ignorable</span><span style="color: blue">=&quot;d&quot;</span>      <br />&#160;&#160; <span style="color: red"> d</span><span style="color: blue">:</span><span style="color: red">DesignHeight</span><span style="color: blue">=&quot;300&quot;</span><span style="color: red"> d</span><span style="color: blue">:</span><span style="color: red">DesignWidth</span><span style="color: blue">=&quot;400&quot;&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">UserControl.Resources</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">converters</span><span style="color: blue">:</span><span style="color: #a31515">BooleanToVisibilityConverter</span><span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">=&quot;BooleanToVisibilityConverter&quot;/&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">UserControl.Resources</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Grid</span><span style="color: red"> x</span><span style="color: blue">:</span><span style="color: red">Name</span><span style="color: blue">=&quot;LayoutRoot&quot;</span><span style="color: red"> Background</span><span style="color: blue">=&quot;White&quot;</span><span style="color: red"> HorizontalAlignment</span><span style="color: blue">=&quot;Stretch&quot;&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Grid.RowDefinitions</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">RowDefinition</span><span style="color: red"> Height</span><span style="color: blue">=&quot;Auto&quot;/&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">RowDefinition</span><span style="color: red"> Height</span><span style="color: blue">=&quot;*&quot;/&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Grid.RowDefinitions</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Button</span><span style="color: red"> Content</span><span style="color: blue">=&quot;Get Companies&quot;</span><span style="color: red"> command</span><span style="color: blue">:</span><span style="color: red">Click.Command</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding</span><span style="color: red"> GetCompaniesCommand</span><span style="color: blue">}&quot;/&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">my</span><span style="color: blue">:</span><span style="color: #a31515">DataGrid</span>&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> Grid.Row</span><span style="color: blue">=&quot;1&quot;</span>&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> ItemsSource</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding</span><span style="color: red"> CompanyList</span><span style="color: blue">}&quot;</span>&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> HorizontalAlignment</span><span style="color: blue">=&quot;Stretch&quot;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> converters</span><span style="color: blue">:</span><span style="color: red">DataGridDoubleClick.Command</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding</span><span style="color: red"> Path</span><span style="color: blue">=DoubleClickCommad}&quot;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> converters</span><span style="color: blue">:</span><span style="color: red">DataGridDoubleClick.CommandParameter</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding</span><span style="color: red"> RelativeSource</span><span style="color: blue">={</span><span style="color: #a31515">RelativeSource</span><span style="color: red"> Self</span><span style="color: blue">},       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">Path</span><span style="color: blue">=SelectedItem}&quot;</span>      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> SelectionMode</span><span style="color: blue">=&quot;Single&quot;&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">my</span><span style="color: blue">:</span><span style="color: #a31515">DataGrid</span><span style="color: blue">&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">&lt;</span><span style="color: #a31515">Rectangle</span><span style="color: red"> Grid.RowSpan</span><span style="color: blue">=&quot;2&quot;</span>&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> Fill</span><span style="color: blue">=&quot;LightBlue&quot;</span>&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> Visibility</span><span style="color: blue">=&quot;{</span><span style="color: #a31515">Binding</span><span style="color: red"> IsBusy</span><span style="color: blue">,</span><span style="color: red"> Converter</span><span style="color: blue">={</span><span style="color: #a31515">StaticResource</span><span style="color: red"> BooleanToVisibilityConverter</span><span style="color: blue">}}&quot;</span>&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: red"> Opacity</span><span style="color: blue">=&quot;0.3&quot;/&gt;</span>      <br /><span style="color: #a31515">&#160;&#160;&#160; </span><span style="color: blue">&lt;/</span><span style="color: #a31515">Grid</span><span style="color: blue">&gt;</span>      <br /><span style="color: blue">&lt;/</span><span style="color: #a31515">UserControl</span><span style="color: blue">&gt;</span>
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>Here is what my command looks like in ViewModel:</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; color: blue; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">public</span><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">&#160;<span style="color: #2b91af">DelegateCommand</span>&lt;<span style="color: blue">object</span>&gt; DoubleClickCommad { <span style="color: blue">get</span>; <span style="color: blue">private</span>&#160;<span style="color: blue">set</span>; }
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">DoubleClickCommad = <span style="color: blue">new</span>&#160;<span style="color: #2b91af">DelegateCommand</span>&lt;<span style="color: blue">object</span>&gt;(SelectCompanyForEdit);
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p style="line-height: normal; margin-bottom: 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class="MsoNormal" align="left"><span style="font-family: consolas; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;"><span style="color: blue">private</span>&#160;<span style="color: blue">void</span> SelectCompanyForEdit(<span style="color: blue">object</span> load)      <br />{      <br /><span style="color: blue">&#160; if</span> (load != <span style="color: blue">null</span> &amp;&amp; load <span style="color: blue">is</span>&#160;<span style="color: #2b91af">Company</span>)      <br />&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">MessageBox</span>.Show(((<span style="color: #2b91af">Company</span>)load).CompanyName);      <br />&#160;&#160;&#160; }      <br />}
</p>
<p>   </span></p>
<p class="MsoNormal">
<p>&#160;</p>
</p>
<p>And that is all there is to it.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetspeak.com/index.php/2010/07/implementing-double-click-in-silverlight-datagrid/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://dotnetspeak.com/index.php/2010/07/implementing-double-click-in-silverlight-datagrid/</feedburner:origLink></item>
	</channel>
</rss>
