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

<channel>
	<title>JAPF</title>
	<atom:link href="http://www.japf.fr/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.japf.fr</link>
	<description>Jeremy Alles Presentation Foundation: WPF, .Net and modern software development</description>
	<lastBuildDate>Thu, 29 Jul 2010 07:29:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Attributes-based validation in a WPF MVVM application</title>
		<link>http://www.japf.fr/2010/07/attributes-based-validation-in-a-wpf-mvvm-application/</link>
		<comments>http://www.japf.fr/2010/07/attributes-based-validation-in-a-wpf-mvvm-application/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 07:29:32 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[codeproject]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=630</guid>
		<description><![CDATA[Today, I&#8217;m proud to share with you my very first article available on CodeProject. This article presents a technique which can be used in order to add validation in a WPF MVVM application based on attribute. Basically, it means that you can write validation logic like that (notice the attribute associated to this property): ?View [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I&#8217;m proud to share with you my very first article available on <a href="http://www.codeproject.com/KB/smart/WPF_Validation_Attribute.aspx">CodeProject</a>. This article presents a technique which can be used in order to add validation in a WPF MVVM application based on attribute. Basically, it means that you can write validation logic like that (notice the attribute associated to this property):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p630code2'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6302"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p630code2"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#40;</span>ErrorMessage <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Field 'FirstName' is required.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FirstName
<span style="color: #008000;">&#123;</span>
    get
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">firstName</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    set
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">firstName</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnPropertyChanged</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FirstName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Of course the article comes with a nice demo application:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/07/02.png" rel="lightbox[630]"><img class="alignnone size-full wp-image-631" title="02" src="http://www.japf.fr/wp-content/uploads/2010/07/02.png" alt="" width="411" height="160" /></a></p>
<p>You can read the full article here: <a href="http://www.codeproject.com/KB/smart/WPF_Validation_Attribute.aspx">Attributes-based validation in a WPF MVVM application</a></p>
<p><em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/07/attributes-based-validation-in-a-wpf-mvvm-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVVM Frameworks Explorer updated</title>
		<link>http://www.japf.fr/2010/07/mvvm-frameworks-explorer-updated/</link>
		<comments>http://www.japf.fr/2010/07/mvvm-frameworks-explorer-updated/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 18:44:25 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[mvvm]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=625</guid>
		<description><![CDATA[Today I&#8217;m releasing a new version of my MVVM Frameworks Explorer application. You can find the updated version here: http://www.japf.fr/silverlight/mvvm/index.html Here is a list of the changes in this new version: application updated to Silverlight 4 support is now detailed for WPF, Silverlight and Windows Phone new frameworks added (MEFedMVVM&#8230;) framework&#8217;s logo added download count [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m releasing a new version of my MVVM Frameworks Explorer application. You can find the updated version here: <a href="http://www.japf.fr/silverlight/mvvm/index.html">http://www.japf.fr/silverlight/mvvm/index.html</a></p>
<p><a href="http://www.japf.fr/wp-content/uploads/2009/11/silverlight-mvvm-app.png" rel="lightbox[625]"><img class="alignnone size-full wp-image-370" title="silverlight-mvvm-app" src="http://www.japf.fr/wp-content/uploads/2009/11/silverlight-mvvm-app.png" alt="" width="341" height="177" /></a></p>
<p>Here is a list of the changes in this new version:</p>
<ul>
<li>application updated to Silverlight 4</li>
<li>support is now detailed for WPF, Silverlight and Windows Phone</li>
<li>new frameworks added (MEFedMVVM&#8230;)</li>
<li>framework&#8217;s logo added</li>
<li>download count added (based on the information I found on CodePlex website)</li>
<li>about window</li>
</ul>
<p>As always, feel free to give feedback <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/07/mvvm-frameworks-explorer-updated/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Where does the default TwoWay binding comes from ?</title>
		<link>http://www.japf.fr/2010/07/where-does-the-default-twoway-binding-comes-from/</link>
		<comments>http://www.japf.fr/2010/07/where-does-the-default-twoway-binding-comes-from/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 11:50:43 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[dependency properties]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=620</guid>
		<description><![CDATA[I got a comment on my post about a very simple MVVM application about the fact that removing the TwoWay mode on a binding did not change the behavior of the application. This is a quick occasion for me to share a quick explanation about this. Actually and as you already know if you can [...]]]></description>
			<content:encoded><![CDATA[<p>I got a comment on my post about <a href="http://www.japf.fr/2009/02/very-simple-mvvm-demo-application/">a very simple MVVM application</a> about the fact that removing the TwoWay mode on a binding did not change the behavior of the application. This is a quick occasion for me to share a quick explanation about this.</p>
<p>Actually and as you already know if you can write <em>XAML </em>like <em>Text={Binding &#8230;}</em> it is only because <em>Text </em>is a<em> Dependency Property</em>. Also, dependency properties are defined in a static way (so that if you have 50 textboxes you don&#8217;t have to instantiate 50 times the Text property). The default behavior for the mode of the binding (TwoWay, OneWay, etc.) can be found in the static declaration of the dependency property. For example, in the case of the Text property of the TextBox we have:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p620code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6204"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p620code4"><pre class="csharp" style="font-family:monospace;">TextProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span>
	<span style="color: #666666;">&quot;Text&quot;</span>, 
	<span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>, 
	<span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>TextBox<span style="color: #008000;">&#41;</span>, 
	<span style="color: #008000;">new</span> FrameworkPropertyMetadata<span style="color: #008000;">&#40;</span>
		<span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span>, 
		FrameworkPropertyMetadataOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">Journal</span> 
		<span style="color: #008000;">|</span> FrameworkPropertyMetadataOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">BindsTwoWayByDefault</span>,
	<span style="color: #008000;">new</span> PropertyChangedCallback<span style="color: #008000;">&#40;</span>TextBox<span style="color: #008000;">.</span><span style="color: #0000FF;">OnTextPropertyChanged</span><span style="color: #008000;">&#41;</span>, 
	<span style="color: #008000;">new</span> CoerceValueCallback<span style="color: #008000;">&#40;</span>TextBox<span style="color: #008000;">.</span><span style="color: #0000FF;">CoerceText</span><span style="color: #008000;">&#41;</span>,
	<span style="color: #0600FF; font-weight: bold;">true</span>, 
	UpdateSourceTrigger<span style="color: #008000;">.</span><span style="color: #0000FF;">LostFocus</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>The interesting part here if of course the <em>BindsTwoWayByDefault</em> option. Note that this is the only default option available (we can&#8217;t have a OneWayToSource binding by default).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/07/where-does-the-default-twoway-binding-comes-from/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[WP7] Beta build of the Windows Phone 7 tools is available</title>
		<link>http://www.japf.fr/2010/07/wp7-eta-build-of-the-windows-phone-7-tools-available/</link>
		<comments>http://www.japf.fr/2010/07/wp7-eta-build-of-the-windows-phone-7-tools-available/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 21:40:30 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=610</guid>
		<description><![CDATA[I guess many Windows Phone 7 developers have been waiting for this news since many weeks. It&#8217;s finally official: the Beta build of the Windows Phone 7 tools is out. If you want to download the new version here is the link. This new version has been released during WPC (Microsoft Worldwide Partner Conference). For [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2010/07/windowsphone.png" rel="lightbox[610]"><img class="alignnone size-full wp-image-612" title="windowsphone" src="http://www.japf.fr/wp-content/uploads/2010/07/windowsphone.png" alt="" width="289" height="50" /></a></p>
<p>I guess many Windows Phone 7 developers have been waiting for this news since many weeks. It&#8217;s finally official: <strong>the Beta build of the Windows Phone 7 tools is out</strong>. If you want to download the new version <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&amp;displaylang=en">here is the link</a>.</p>
<p>This new version has been released during <a href="http://digitalwpc.com/">WPC</a> (Microsoft Worldwide Partner Conference). For more information, please check-out:</p>
<ul>
<li><a href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/07/12/windows-phone-developer-tools-beta-released.aspx">the post</a> on the Windows Phone Developer Tools blog.</li>
<li><a href="http://blogs.msdn.com/b/jaimer/archive/2010/06/28/migrating-apps-from-windows-phone-ctps-to-the-beta-build.aspx">this post</a> by Jaime Rodriguez about all breaking change between the April CTP Refresh and the Beta build</li>
<li><a href="http://blogs.msdn.com/b/expression/archive/2010/07/12/windows-phone-developer-tools-beta-released.aspx">this post</a> by the Blend team about the new features available in Blend</li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=194469">the release note</a></li>
</ul>
<p>Here are a summary of the changes in this new version:</p>
<ul>
<li>Despite HW acceleration effects have been removed from the platform (DropShadow and Blur effects are now no-op). This feature might come back later.</li>
<li>Compatibility with Blend 4 RTM</li>
<li>API near final</li>
<li>Various fixes</li>
</ul>
<p>Note that panorama and pivot controls are coming in the next weeks&#8230; Grab you copy now and enjoy Windows Phone 7 development <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&amp;displaylang=en</div>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/07/wp7-eta-build-of-the-windows-phone-7-tools-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVP in Client Application Development !</title>
		<link>http://www.japf.fr/2010/07/mvp/</link>
		<comments>http://www.japf.fr/2010/07/mvp/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 07:12:57 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[mvp]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=572</guid>
		<description><![CDATA[A couple of days ago I received an email telling me I got the MVP Award for 2010 ! I&#8217;ve been waiting a little bit before I wrote this post because I invited my coworkers at home in order to celebrate this yesterday and I wanted to keep the surprise This is the very first [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2010/07/mvp.png" rel="lightbox[572]"><img class="size-full wp-image-573 alignleft" style="margin: 0px 10px;" title="mvp" src="http://www.japf.fr/wp-content/uploads/2010/07/mvp.png" alt="" width="99" height="155" /></a>A couple of days ago I received an email telling me I got the MVP Award for 2010 ! I&#8217;ve been waiting a little bit before I wrote this post because I invited my coworkers at home in order to celebrate this yesterday and I wanted to keep the surprise <img src='http://www.japf.fr/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>This is the very first year I got the MVP award. I&#8217;m very proud to have this recognition from Microsoft and it is giving me new ideas for the future. I started this blog almost 2 years ago now and I&#8217;d never imagine I&#8217;d get so much feedback about it. My MVP award is also recognizing my work in the French community (on the <a href="http://www.developpez.com">developpez.com</a> website) or for conferences I&#8217;m giving in my daily job.</p>
<p>The MVP award will be also for me the occasion to have pre-release of Microsoft software (but I&#8217;ll not be able to publicly give information about them since I&#8217;ve just signed an NDA) and also to enjoy a free MSDN-Premium subscription !</p>
<p>For more information about the MVP Award Program you can check-out:</p>
<ul>
<li><a href="http://mvp.support.microsoft.com/">the home page</a> of the program</li>
<li><a href="http://blogs.msdn.com/b/mvpawardprogram/">the blog</a> the program</li>
</ul>
<p>Thanks to all my readers also who are giving me feedback and support.  I&#8217;d also like to thank my co-workers who are helpful in my daily job. I&#8217;m very lucky to be part of this very nice team. By reading posts before they go public (Charlotte, Fred !) or discussion about software programming in general (the whole Pythagore group!) I get cool ideas about things I want to share. So thank you every one for supporting me <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/07/mvp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>[WP7] Windows Phone 7 challenge for french readers !</title>
		<link>http://www.japf.fr/2010/06/wp7-windows-phone-7-challenge-for-french-readers/</link>
		<comments>http://www.japf.fr/2010/06/wp7-windows-phone-7-challenge-for-french-readers/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 13:49:48 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=565</guid>
		<description><![CDATA[A couple of months ago, the french programming website www.developpez.com organized an event to discover Windows Azure programming (I wrote a blog post about it here). A similar event has just been launched for Windows Phone 7 development at challenge-windowsphone7.developpez.com (tr: &#8220;Let&#8217;s go !&#8221; &#8220;World cup ?&#8221; &#8220;No&#8230; Windows Phone 7 challenge by developpez.com !&#8221;) [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of months ago, the french programming website <a href="http://www.developpez.com">www.developpez.com</a> organized an event to discover Windows Azure programming (I wrote a blog post about it <a href="http://www.japf.fr/2010/01/windows-azure-challenge/">here</a>).</p>
<p>A similar event has just been launched for Windows Phone 7 development at <a href="http://challenge-windowsphone7.developpez.com">challenge-windowsphone7.developpez.com</a></p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/06/header.png" rel="lightbox[565]"><img class="alignnone size-full wp-image-566" title="header" src="http://www.japf.fr/wp-content/uploads/2010/06/header.png" alt="" width="420" height="115" /></a></p>
<p><em>(tr: &#8220;Let&#8217;s go !&#8221; &#8220;World cup ?&#8221; &#8220;No&#8230; Windows Phone 7 challenge by developpez.com !&#8221;)</em></p>
<p>The challenge is made of 6 steps:</p>
<ol>
<li>Tools : download and install the required tools</li>
<li>Quizz : first basic quizz</li>
<li>Silverlight development</li>
<li>Silverlight and push notifications</li>
<li>XNA</li>
<li>Quizz : advanced quizz</li>
</ol>
<p>Each winner will have the following gifts:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/06/cadeaux-all.png" rel="lightbox[565]"><img class="alignnone size-full wp-image-567" title="cadeaux-all" src="http://www.japf.fr/wp-content/uploads/2010/06/cadeaux-all.png" alt="" width="555" height="111" /></a></p>
<p>This kind of challenge is really helpful to discover a new technology the funny way ! I hope I&#8217;ll get my &#8220;I Love Windows Phone&#8221; tee-shirt to wear it this summer <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/06/wp7-windows-phone-7-challenge-for-french-readers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[WP7] Using the camera in the emulator</title>
		<link>http://www.japf.fr/2010/05/wp7-using-the-camera-in-the-emulator/</link>
		<comments>http://www.japf.fr/2010/05/wp7-using-the-camera-in-the-emulator/#comments</comments>
		<pubDate>Wed, 05 May 2010 22:11:11 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=553</guid>
		<description><![CDATA[In the very first release of the SDK for Windows Phone 7 development, it was not possible to use the camera in the emulator. The latest version of the SDK fixes this problem. Windows Phone 7 SDK comes with a set of Task (in the Microsoft.Phone.Tasks namespace). A task can be launched from your application [...]]]></description>
			<content:encoded><![CDATA[<p>In the very first release of the SDK for Windows Phone 7 development, it was not possible to use the camera in the emulator. The latest version of the SDK fixes this problem.</p>
<p>Windows Phone 7 SDK comes with a set of Task (in the <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks%28v=VS.92%29.aspx">Microsoft.Phone.Tasks</a> namespace). A task can be launched from your application in order to perform some work. Currently available tasks are:</p>
<ul>
<li> Capture Camera (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.cameracapturetask(v=VS.92).aspx">StartCameraTask</a>)</li>
<li> Choose Email Address (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.emailaddresschoosertask(v=VS.92).aspx">EmailAddressChooserTask</a>)</li>
<li> Compose Email (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.emailcomposetask(v=VS.92).aspx">EmailComposeTask</a>)</li>
<li> Open Market Place (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.marketplacelauncher(v=VS.92).aspx">MarketplaceLauncher</a>)</li>
<li> Open Media Player (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.mediaplayerlauncher(v=VS.92).aspx">MediaPlayerLauncher</a>)</li>
<li> Make Phone Call (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.phonecalltask(v=VS.92).aspx">PhoneCallTask</a>)</li>
<li> Pick Phone Number (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.phonenumberchoosertask(v=VS.92).aspx">PhoneNumberChooserTask</a>)</li>
<li> Choose Photo (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.photochoosertask(v=VS.92).aspx">PhotoChooserTask</a>)</li>
<li> Save Email (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.saveemailaddresstask(v=VS.92).aspx">SaveEmailAddressTask</a>)</li>
<li> Save Phone Number (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.savephonenumbertask(v=VS.92).aspx">SavePhoneNumberTask</a>)</li>
<li> Search (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.searchtask(v=VS.92).aspx">SearchTask</a>)</li>
<li> Compose SMS (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.smscomposetask(v=VS.92).aspx">SmsComposeTask</a>)</li>
<li> Browse Web (<a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.webbrowsertask(v=VS.92).aspx">WebBrowserTask</a>)</li>
</ul>
<p>In order to launch a task from your application, all you need to do is to instantiate the associated type and call the Show() method.</p>
<p>Here is a sample code which launchs the StartCameraTask and then gets the capture images in order to use it in a standard Silverlight Image control:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p553code7'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5537"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p553code7"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// launch the camera capture when the user touch the screen</span>
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MouseLeftButtonUp</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">new</span> CameraCaptureTask<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Show</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// this static event is raised when a task completes its job</span>
ChooserListener<span style="color: #008000;">.</span><span style="color: #0000FF;">ChooserCompleted</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
<span style="color: #008000;">&#123;</span>
    var taskEventArgs <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>TaskEventArgs<span style="color: #008000;">&lt;</span>PhotoResult<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#41;</span>e<span style="color: #008000;">;</span>
    var photoStream <span style="color: #008000;">=</span> taskEventArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">Result</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ChosenPhoto</span><span style="color: #008000;">;</span>
&nbsp;
    var bitmapImage <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BitmapImage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    bitmapImage<span style="color: #008000;">.</span><span style="color: #0000FF;">SetSource</span><span style="color: #008000;">&#40;</span>photoStream<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">image</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Source</span> <span style="color: #008000;">=</span> bitmapImage<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>The <em>image</em> is just a standard Silverlight Image control:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p553code8'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5538"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p553code8"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;image&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>The emulator while the task is running:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/05/EmulatorCaptureCamera1.png" rel="lightbox[553]"><img class="alignnone size-full wp-image-557" title="EmulatorCaptureCamera" src="http://www.japf.fr/wp-content/uploads/2010/05/EmulatorCaptureCamera1.png" alt="" width="300" height="153" /></a></p>
<p>The captured image (shown once the task has completed):</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/05/ResultImage1.png" rel="lightbox[553]"><img class="alignnone size-full wp-image-558" title="ResultImage" src="http://www.japf.fr/wp-content/uploads/2010/05/ResultImage1.png" alt="" width="297" height="151" /></a></p>
<p>If you haven&#8217;t download the tool already, go ahead and grab them ! Everything is available <strong>for free</strong> in a <strong>single download</strong> at <a href="http://developer.windowsphone.com/windows-phone-7-series/">http://developer.windowsphone.com/windows-phone-7-series/</a>.</p>
<p>Hope this helps <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><em>Note: even though the StartCameraTask is now working, this is not yet the case for all the tasks&#8230; </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/05/wp7-using-the-camera-in-the-emulator/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>[WP7] Bug when using NavigationService in Windows Phone 7</title>
		<link>http://www.japf.fr/2010/05/bug-when-using-navigationservice-in-windows-phone-7/</link>
		<comments>http://www.japf.fr/2010/05/bug-when-using-navigationservice-in-windows-phone-7/#comments</comments>
		<pubDate>Mon, 03 May 2010 20:45:20 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=542</guid>
		<description><![CDATA[The last couple of days, I&#8217;m playing with my favourite tools in order to build a simple WP7 demo application. I just encountered a weird problem which I wanted to share here&#8230; I&#8217;ll update this article as soon as I&#8217;ll get some feedback from Microsoft about this issue. Note: this problem did not occur if [...]]]></description>
			<content:encoded><![CDATA[<p>The last couple of days, I&#8217;m playing with my favourite tools in order to build a simple WP7 demo application. I just encountered a weird problem which I wanted to share here&#8230; I&#8217;ll update this article as soon as I&#8217;ll get some feedback from Microsoft about this issue.</p>
<p><em>Note: this problem did not occur if you&#8217;re using the first CTP of the WP7 tools</em></p>
<p><strong>To reproduce the bug:</strong></p>
<ul>
<li>Create a new Windows Phone 7 application in VS2010</li>
<li>Add a new page (use the default name: Page1)</li>
<li>In the MainPage, add the following XAML code:</li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p542code11'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p54211"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p542code11"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ListBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> <span style="color: #000066;">MouseLeftButtonDown</span>=<span style="color: #ff0000;">&quot;Handler&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ListBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<ul>
<li>In the code-behind, add the following handler:</li>
</ul>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p542code12'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p54212"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p542code12"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Handler<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, MouseButtonEventArgs mouseButtonEventArgs<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">NavigationService</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Navigate</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Uri<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;/Page1.xaml&quot;</span>, UriKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Relative</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<ul>
<li>Run the application and click on the TextBlock</li>
<li>You&#8217;ll get an ArgumentException with the following StackTrace:</li>
</ul>
<p><em>at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[]  cvData)<br />
at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr,  String methodName, Object[] rawData)<br />
at  MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element,  UIElement visual)<br />
at  System.Windows.UIElement.TransformToVisual(UIElement visual)<br />
at  System.Windows.Controls.ScrollViewer.OnManipulationStarted(ManipulationStartedEventArgs  e)<br />
at System.Windows.Controls.Control.OnManipulationStarted(Control  ctrl, EventArgs e)<br />
at MS.Internal.JoltHelper.FireEvent(IntPtr  unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String  eventName)</em></p>
<p><strong>Analysis:</strong></p>
<p>It took me some time to reproduce this problem in a very simple application. At the very beginning, I though it has something do to with the EventToCommand behavior I was using (from the famous <a href="http://www.galasoft-lb.ch/mvvm/getstarted/">MVVM-Light</a> framework of Laurent Bugnion) but after talking with Laurent it was clear it wasn&#8217;t the case.</p>
<p>The StackTrace seems to indicate a problem with the ScrollViewer of the ListBox&#8230;</p>
<p><strong>Workaround:</strong></p>
<p>Several possibilities seems to be working:</p>
<ol>
<li>Change the ListBox to an ItemsControl</li>
<li>Or, change the event to ManipulationCompleted</li>
</ol>
<p>I didn&#8217;t find the correct location in order to log this issue on Microsoft Connect. Pleas let me know if you have the URL</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/05/bug-when-using-navigationservice-in-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R# can create resources for you in XAML</title>
		<link>http://www.japf.fr/2010/04/resharper-to-creates-resources-in-xaml/</link>
		<comments>http://www.japf.fr/2010/04/resharper-to-creates-resources-in-xaml/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 12:33:36 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[resharper]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=498</guid>
		<description><![CDATA[I was aware for some time now that R# offers some support for editing XAML but I didn&#8217;t know the following features until recently.When you create a StaticResource in XAML, R# is able to help you by generating some code for you. The famous R# &#8220;bubble&#8221; shows up offering various options to create the resource: [...]]]></description>
			<content:encoded><![CDATA[<p>I was aware for some time now that R# offers some support for editing XAML but I didn&#8217;t know the following features until recently.When you create a StaticResource in XAML, R# is able to help you by generating some code for you. The famous R# &#8220;bubble&#8221; shows up offering various options to create the resource:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/04/2.png" rel="lightbox[498]"><img class="alignnone size-full wp-image-501" title="2" src="http://www.japf.fr/wp-content/uploads/2010/04/2.png" alt="" width="507" height="191" /></a></p>
<p>Then the resource is automatically created for you:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/04/3.png" rel="lightbox[498]"><img class="alignnone size-full wp-image-502" title="3" src="http://www.japf.fr/wp-content/uploads/2010/04/3.png" alt="" width="469" height="173" /></a></p>
<p>Note that it works with converter too:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2010/04/4.png" rel="lightbox[498]"><img class="alignnone size-full wp-image-503" title="4" src="http://www.japf.fr/wp-content/uploads/2010/04/4.png" alt="" width="691" height="255" /></a></p>
<p>R# 5.0 has been released a couple of weeks ago. Go ahead and <a href="http://www.jetbrains.com/resharper/">grab your copy</a> !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/04/resharper-to-creates-resources-in-xaml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leveraging expression trees to unit test ViewModel classes</title>
		<link>http://www.japf.fr/2010/03/leveraging-expression-trees-to-unit-test-viewmodel-classes/</link>
		<comments>http://www.japf.fr/2010/03/leveraging-expression-trees-to-unit-test-viewmodel-classes/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 13:36:53 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[moq]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=483</guid>
		<description><![CDATA[Introduction: In this article, I&#8217;m describing a technique which leverage the expression trees of C# 3.0 in order to facilitate the unit testing of ViewModel&#8217;s properties. My final goal is to be able to unit test a ViewModel property in 1 line. Without any doubt MVVM is now the most used framework to leverage WPF [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction:</strong> In this article, I&#8217;m describing a technique which leverage the expression trees of C# 3.0 in order to facilitate the unit testing of ViewModel&#8217;s properties. My final goal is to be able to unit test a ViewModel property in 1 line.</p>
<p>Without any doubt MVVM is now the most used framework to leverage WPF and Silverlight functionalities in the best way ! During the last <a href="http://live.visitmix.com">Mix</a>, 3 sessions were dedicated to this methodology (you can watch the videos online <a href="http://live.visitmix.com/Videos">here</a>).</p>
<p>As you already know one of the key advantage of the MVVM methodology is to <strong>improve the testability</strong> of the overall application by reducing the amount of code in the code-behind and producing ViewModel classes which are testable. We use to say that ViewModel classes are testable because:</p>
<ul>
<li>they are not coupled to UI concepts (controls, focus, keyboard input&#8230;)</li>
<li>they can wrap model objects using interfaces (for instance a PersonViewModel wraps a IPerson object)</li>
<li>they are not subclassing a UI control (such as Button or Window)</li>
</ul>
<p>Today I&#8217;d like to share a technique I&#8217;m using to facilitate the unit tests of some properties of my ViewModel classes.</p>
<p>Let&#8217;s use a very simple ViewModel class as example:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code20'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48320"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code" id="p483code20"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> PersonViewModel <span style="color: #008000;">:</span> ViewModelBase
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> IPerson person<span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> isSelected<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name 
  <span style="color: #008000;">&#123;</span>
     get
     <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">person</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
     <span style="color: #008000;">&#125;</span>
     set
     <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">person</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnPropertyChanged</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
     <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsSelected
  <span style="color: #008000;">&#123;</span>
    get
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">isSelected</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    set
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">isSelected</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnPropertyChanged</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;IsSelected&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// rest of the code omitted for simplicity</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The Name property, as usually with the MVVM pattern gets its value from the wrapped model object. The easiest way to unit test this property is to use a mocking library. Here is a example using <a href="http://code.google.com/p/moq/">MOQ</a> (my favourite mocking library):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code21'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48321"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p483code21"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> TestName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var mockPerson <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Mock<span style="color: #008000;">&lt;</span>IPerson<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  var vm <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PersonViewModel<span style="color: #008000;">&#40;</span>mockPerson<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  vm<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Jeremy&quot;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// verify that the Name property of the IPerson interface has been set</span>
  mockPerson<span style="color: #008000;">.</span><span style="color: #0000FF;">VerifySet</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Jeremy&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The Selected property is different because it doesn&#8217;t wrap a model property. It&#8217;s an information that is added to the ViewModel layer in order to control a UI-related property (for example the IsSelected property of a ListBoxItem). This technique is heavily used to have ViewModel classes interact with the WPF or Silverlight TreeView or ListBox control (you can check out this <a href="http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx">excellent article</a> of Josh Smith for more detail).</p>
<p>In order to unit test this property, we must:<br />
1/ ensure the PropertyChanged event of the INotifyPropertyChanged is  raised properly<br />
2/ ensure we can write a value and read back the  correct value</p>
<p>Here is a sample code which does this unit test:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code22'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48322"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p483code22"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> TestName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
var vm <span style="color: #008000;">=</span> <span style="color: #008000;">new</span>  PersonViewModel<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">bool</span> propertyChanged <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
vm<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> propertyChanged <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyName</span> <span style="color: #008000;">==</span>  <span style="color: #666666;">&quot;Name&quot;</span><span style="color: #008000;">;</span>
vm<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;newName&quot;</span><span style="color: #008000;">;</span>
&nbsp;
Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">IsTrue</span><span style="color: #008000;">&#40;</span>propertyChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;newName&quot;</span>, vm<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>It quickly become cumbersome to copy/paste this unit test for all the ViewModel properties we have. That&#8217;s the reason I started thinking about another way to do it&#8230;</p>
<p>Here is the feature I&#8217;m proposing:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code23'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48323"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p483code23"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> TestName<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
var vm <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PersonViewModel<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
TestHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">TestProperty</span><span style="color: #008000;">&#40;</span>vm, v <span style="color: #008000;">=&gt;</span> v<span style="color: #008000;">.</span><span style="color: #0000FF;">IsSelected</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>In this sample, I&#8217;m telling I want to test the IsSelected property of the PersonViewModel type. The advantages are:<br />
1/ less code involved : 1 line to test 1 property<br />
2/ intellisense support in order to prevent typing error and no more &#8220;magic&#8221; string to give the name of the property<br />
3/ refactoring the name of the property will refactor this sample code too<br />
4/ automatic generation of default test values behind the scene</p>
<p><strong>How does it works ?</strong></p>
<ul>
<li>TestProperty treats the second parameter as an Expression&lt;Func&gt; and not as a Func directly</li>
<li>Using expression tree (the &#8220;v =&gt; v.IsSelected&#8221; part),  I&#8217;m able to retrieve the name of the property and its type</li>
<li>Using reflection, I&#8217;m able to get and set the value</li>
<li>Depending on the type of the property (string, bool, int, double), I have default values write and read back (with a test to ensure that the PropertyChanged event has been raised properly).</li>
</ul>
<p>Here is the code of the TestPropertyMethod:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code24'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48324"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p483code24"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> TestProperty<span style="color: #008000;">&lt;</span>T, U<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>T viewmodel, Expression<span style="color: #008000;">&lt;</span>Func<span style="color: #008000;">&lt;</span>T, U<span style="color: #008000;">&gt;&gt;</span> expression<span style="color: #008000;">&#41;</span>
    <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> INotifyPropertyChanged
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>expression<span style="color: #008000;">.</span><span style="color: #0000FF;">Body</span> <span style="color: #008000;">is</span> MemberExpression<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        MemberExpression memberExpression <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>MemberExpression<span style="color: #008000;">&#41;</span> expression<span style="color: #008000;">.</span><span style="color: #0000FF;">Body</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>expression<span style="color: #008000;">.</span><span style="color: #0000FF;">Body</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            TestViewModelProperty<span style="color: #008000;">&#40;</span>viewmodel, memberExpression<span style="color: #008000;">.</span><span style="color: #0000FF;">Member</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span>, <span style="color: #0600FF; font-weight: bold;">true</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>expression<span style="color: #008000;">.</span><span style="color: #0000FF;">Body</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            TestViewModelProperty<span style="color: #008000;">&#40;</span>viewmodel, memberExpression<span style="color: #008000;">.</span><span style="color: #0000FF;">Member</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span>, <span style="color: #666666;">&quot;value1&quot;</span>, <span style="color: #666666;">&quot;value2&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span> 
        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>expression<span style="color: #008000;">.</span><span style="color: #0000FF;">Body</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            TestViewModelProperty<span style="color: #008000;">&#40;</span>viewmodel, memberExpression<span style="color: #008000;">.</span><span style="color: #0000FF;">Member</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span>, <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">99</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>expression<span style="color: #008000;">.</span><span style="color: #0000FF;">Body</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            TestViewModelProperty<span style="color: #008000;">&#40;</span>viewmodel, memberExpression<span style="color: #008000;">.</span><span style="color: #0000FF;">Member</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span>, <span style="color: #FF0000;">1.0</span>, <span style="color: #FF0000;">99.0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> NotSupportedException<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Type is not supported&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
   <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And the TestViewModelProperty:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code25'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48325"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p483code25"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> TestViewModelProperty<span style="color: #008000;">&lt;</span>T, U<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>T viewModel, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName, U value1, U value2<span style="color: #008000;">&#41;</span>
    <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> INotifyPropertyChanged
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">bool</span> propertyChanged<span style="color: #008000;">;</span>
    viewModel<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> propertyChanged <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyName</span> <span style="color: #008000;">==</span> propertyName<span style="color: #008000;">;</span>
&nbsp;
    propertyChanged <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    viewModel<span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>propertyName, value1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">IsTrue</span><span style="color: #008000;">&#40;</span>propertyChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">IsTrue</span><span style="color: #008000;">&#40;</span>viewModel<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&lt;</span>U<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span>value1<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    propertyChanged <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    viewModel<span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>propertyName, value2<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">IsTrue</span><span style="color: #008000;">&#40;</span>propertyChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">IsTrue</span><span style="color: #008000;">&#40;</span>viewModel<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&lt;</span>U<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span>value2<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;m using 2 extensions methods in order to get and set value from the ViewModel object using reflection. Here they are:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p483code26'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48326"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p483code26"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> T GetValue<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">object</span> obj, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    var propertyInfo <span style="color: #008000;">=</span> obj<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetProperty</span><span style="color: #008000;">&#40;</span>propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span>propertyInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>obj, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> SetValue<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">object</span> obj, <span style="color: #6666cc; font-weight: bold;">string</span> propertyName, T value<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    var propertyInfo <span style="color: #008000;">=</span> obj<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetProperty</span><span style="color: #008000;">&#40;</span>propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    propertyInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>obj, value, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Please feel free to <a href="http://www.japf.fr/wp-content/uploads/2010/03/TestViewModelHelper.txt">download the source code</a> of the ViewModelTestHelper class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/03/leveraging-expression-trees-to-unit-test-viewmodel-classes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
