<?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 &#187; .Net</title>
	<atom:link href="http://www.japf.fr/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.japf.fr</link>
	<description>Jeremy Alles Presentation Foundation: WPF, Silverlight, Windows Phone 7, Windows 8</description>
	<lastBuildDate>Fri, 27 Jan 2012 07:57:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Windows Phone performance analysis &amp; optimization during TechDays</title>
		<link>http://www.japf.fr/2012/01/windows-phone-performance-analysis-optimization-during-techdays/</link>
		<comments>http://www.japf.fr/2012/01/windows-phone-performance-analysis-optimization-during-techdays/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 07:57:31 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[analysis]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[techdays]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=1065</guid>
		<description><![CDATA[In about 2 weeks now, I&#8217;ll have the chance to be part of the French TechDays in Paris as a speaker. This year, I&#8217;ll own a session called &#8220;Windows Phone performance analysis &#38; optimisation&#8221; with my colleague Charlotte. The agenda looks like the following: why performance analysis ? device vs emulator leveraging WP7 threads using [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/LogoTechDays.png" rel="lightbox[1065]"><img class="alignnone size-full wp-image-1067" title="LogoTechDays" src="http://www.japf.fr/wp-content/uploads/2012/01/LogoTechDays.png" alt="" width="223" height="79" /></a></p>
<p>In about 2 weeks now, I&#8217;ll have the chance to be part of the French TechDays in Paris as a speaker. This year, I&#8217;ll own a session called &#8220;Windows Phone performance analysis &amp; optimisation&#8221; with my colleague Charlotte.</p>
<p>The agenda looks like the following:</p>
<ul>
<li>why performance analysis ?</li>
<li>device vs emulator</li>
<li>leveraging WP7 threads</li>
<li>using the VS profiler for WP7</li>
<li>tips and tricks</li>
</ul>
<p>During the session we will use a &#8220;real&#8221; app we&#8217;re working on for a few months now (I&#8217;ll share more details after the session). We have some cool tips that haven&#8217;t been shared anywhere before, so if performance is a topic of interest for you, stat tuned !</p>
<p>Click on the following image for a link to the TechDays website:</p>
<p><a href="http://www.microsoft.com/france/mstechdays/programmes/parcours.aspx#DomID=9e0aee6e-9896-4c59-ad3f-d4cd48109eaa&amp;SessionID=db46a2a8-566e-4954-8903-e133f2217857"><img class="alignnone  wp-image-1066" title="SessionTechDays" src="http://www.japf.fr/wp-content/uploads/2012/01/SessionTechDays.png" alt="" width="553" height="281" /></a></p>
<p>I&#8217;m planning to share the most of the content of this session on my blog soon after the event.</p>
<p>Don&#8217;t hesitate to stop by and say hi&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2012/01/windows-phone-performance-analysis-optimization-during-techdays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF databinding trick (part 2)</title>
		<link>http://www.japf.fr/2011/04/wpf-databinding-trick-part-2/</link>
		<comments>http://www.japf.fr/2011/04/wpf-databinding-trick-part-2/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 07:04:12 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[binding]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=861</guid>
		<description><![CDATA[Ok, let&#8217;s see another strange behavior that you might have already seen with the WPF databinding engine. INotifyPropertyChanged When we teach WPF to new developers, at some point we need to introduce the INotifyPropertyChanged interface. Usually, the kind of speech which is given looks like this one: &#8220;When you&#8217;re doing a binding to a standard [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, let&#8217;s see another strange behavior that you might have already seen with the WPF databinding engine.</p>
<p><strong>INotifyPropertyChanged</strong></p>
<p>When we teach WPF to new developers, at some point we need to introduce the INotifyPropertyChanged interface. Usually, the kind of speech which is given looks like this one:</p>
<p>&#8220;<em>When you&#8217;re doing a binding to a standard CLR property, you must add some kind of notification mechanisms in order to tell the binding when the value changes. In WPF, this is standardized by using the common INotifyPropertyChanged interface. This interface contains a single event which must be raised with the name of the property which has changed. Whenever this event is fired, the databinding engine is able to see the change and update the corresponding binding.</em>&#8221;</p>
<p><strong>Demo application</strong></p>
<p>Nothing really exciting here, right. Now, you start to do a demo with the following code:</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('p861code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8614"><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
</pre></td><td class="code" id="p861code4"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MainWindow <span style="color: #008000;">:</span> Window
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> MainWindow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        InitializeComponent<span style="color: #008000;">&#40;</span><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;">DataContext</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> Data <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;test &quot;</span> <span style="color: #008000;">&#125;</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;">class</span> DataObject
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> data<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Data
    <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;">data</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;">data</span> <span style="color: #008000;">=</span> value<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>Here the DataObject class I use as DataContext does not implement INotifyPropertyChanged.Then I added some XAML in the MainWindow:</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('p861code5'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8615"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p861code5"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Window</span> <span style="color: #000066;">x:Class</span>=<span style="color: #ff0000;">&quot;TestDataContext.MainWindow&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">Title</span>=<span style="color: #ff0000;">&quot;MainWindow&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;350&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;525&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Data}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Data}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBox</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Data}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Window<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>And the goal is to display 3 TextBoxes all databound to the same property. Now, we run the application, types some text in one of the TextBox and change the focus in order to update the binding. Most of us would expect to have the 2 other Textboxes with the old value: when the focus has been lost the new string value has been pushed into the Data property, but the other Textboxes have no way to detect this change.</p>
<p>Actually if you run this application, you&#8217;ll see all the Textboxes being updated That&#8217;s strange&#8230;</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/04/exemplebinding.png" rel="lightbox[861]"><img src="http://www.japf.fr/wp-content/uploads/2011/04/exemplebinding.png" alt="" title="exemplebinding" width="374" height="454" class="alignnone size-full wp-image-868" /></a></p>
<p><strong>Why does it works ?</strong></p>
<p>Ok, let&#8217;s get into the dirty details. Here are what happens during initialization:</p>
<ul type="disc">
<li>XAML is parsed</li>
<li>for the 3 TextBox
<ul type="disc">
<li>the Binding is initialized</li>
<li>a BindingExpression is       created. The BindingExpression is a IWeakEventListener.</li>
<li>its AttachOverride method is       called</li>
<li>if the UpdateOnLostFocus       flag is set (which is the case because the default value of       UpdateSourceTrigger is LostFocus), the static        LostFocusEventManager type is used and the AddListener is called
<ul type="circle"></ul>
</li>
</ul>
<ul type="disc">
<li>during the initialization of       the binding, the PropertyPathWorker class is added and at some point the        ReplaceItem method gets called</li>
<li> then the following code         gets execute</li>
</ul>
</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('p861code6'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8616"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p861code6"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>source <span style="color: #008000;">is</span> INotifyPropertyChanged<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	PropertyChangedEventManager<span style="color: #008000;">.</span><span style="color: #0000FF;">AddListener</span><span style="color: #008000;">&#40;</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>
	PropertyDescriptor descriptor <span style="color: #008000;">=</span> GetDescriptor<span style="color: #008000;">&#40;</span>source, path<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	ValueChangedEventManager<span style="color: #008000;">.</span><span style="color: #0000FF;">AddListener</span><span style="color: #008000;">&#40;</span>…<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Which means:</p>
<ul type="disc">
<li>if the source implements      INotifyPropertyChanged, use that to track the changes to the property</li>
<li>otherwise, use the      ValueChanged event of the cached PropertyDescriptor instance to track the changes</li>
</ul>
<p>What happens when one of the TextBox lost focus:</p>
<ul type="disc">
<li>the focus changes to another      control, the previously focused TextBox gets is LostFocus event raised</li>
<li>the LostFocusEventManager      gets the notification</li>
<li>the notification is      transferred to the BindingExpression (which is a IWeakEventListener) by      calling the IWeakEventListener.ReceiveWeakEvent method</li>
<li>several method calls&#8230; ending      in the PropertyPathWorker class where the PropertyDescriptor.SetValue      methods is called (where the PropertyDescriptor is the one which has been cached during initialization)</li>
<li>this method raises the      ValueChanged event at the PropertyDescriptor level</li>
<li>which is catched by the      ValueChangedEventManager</li>
<li>and the associated dependency      property (Text) is updated</li>
<li>and voila !</li>
</ul>
<p>So there are no miracle behind the demo application I was talking about, just the fact the binding engine is smart enough to cache the PropertyDescriptor used for setting value to CLR property and using the ValueChanged event to get notifications if the source does not implement INotifyPropertyChanged.</p>
<p>Happy coding !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2011/04/wpf-databinding-trick-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010 and HW acceleration on Windows XP&#8230;</title>
		<link>http://www.japf.fr/2011/03/visual-studio-2010-and-hw-acceleration-on-windows-xp/</link>
		<comments>http://www.japf.fr/2011/03/visual-studio-2010-and-hw-acceleration-on-windows-xp/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 07:46:48 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Stutio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=817</guid>
		<description><![CDATA[Last week during the MVP summit in Seattle we&#8217;d the confirmation that the SP1 of Visual Studio was almost ready and today we&#8217;ve more details: &#8220;Visual Studio 2010 Service Pack 1 will be available March 9th for download for MSDN Subscribers, and will be generally available for download on March 10th, 2011&#8221; [from G.Duthie's blog [...]]]></description>
			<content:encoded><![CDATA[<p>Last week during the MVP summit in Seattle we&#8217;d the confirmation that the SP1 of Visual Studio was almost ready and today we&#8217;ve more details: &#8220;<em>Visual Studio 2010 Service Pack 1 will be available March 9th for <a href="http://msdn.microsoft.com/subscriptions/downloads/">download for MSDN Subscribers</a>, and will be <a href="http://go.microsoft.com/fwlink/?LinkId=209902">generally available for download</a> on March 10th, 2011</em>&#8221; [from <a href="http://blogs.msdn.com/b/gduthie/archive/2011/03/08/visual-studio-2010-sp1-available-march-8th-for-msdn-subscribers-general-availability-march-10th.aspx">G.Duthie's blog on MSDN</a>].</p>
<p><em>&#8220;While the Service Pack is mostly focused on improvements in response to  feedback on Visual Studio 2010, one new feature I want to highlight is  the integration of IIS Express into Visual Studio 2010. IIS Express,  which was introduced with the new Microsoft WebMatrix editor, is a  lightweight, yet full-featured version of IIS that can run without  administrative permissions.&#8221;</em></p>
<p>Another important thing to notice about the SP1, is that <strong>it will disable the hardware acceleration of the IDE on Windows XP</strong>. Yes, you read correctly, despite WPF&#8217;s support for accelerated graphics, this feature will be disabled on XP (for VS only).</p>
<p><br/></p>
<h2>Background</h2>
<p>When the version 3.5 of the .Net framework was released, Microsoft added a new software rendering engine in case the hardware was not able to do the job. This feature could be enabled at the Window level using the following code:</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('p817code9'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8179"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p817code9"><pre class="csharp" style="font-family:monospace;">HwndSource hwndSource <span style="color: #008000;">=</span> PresentationSource<span style="color: #008000;">.</span><span style="color: #0000FF;">FromVisual</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> HwndSource<span style="color: #008000;">;</span>
HwndTarget hwndTarget <span style="color: #008000;">=</span> hwndSource<span style="color: #008000;">.</span><span style="color: #0000FF;">CompositionTarget</span><span style="color: #008000;">;</span>
hwndTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderMode</span> <span style="color: #008000;">=</span> RenderMode<span style="color: #008000;">.</span><span style="color: #0000FF;">SoftwareOnly</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>With WPF4, this is now possible at the Process level using a single line of code:</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('p817code10'); return false;">View Code</a> CHSARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p81710"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p817code10"><pre class="chsarp" style="font-family:monospace;">RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly</pre></td></tr></table></div>

<p>Another trick you can use in your application is to determine whether your application is currently using hardware acceleration. You can do that by looking at the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.rendercapability.tier.aspx">RenderCapability.Tier</a> enumeration.</p>
<p><br/></p>
<h2>In your applications running on XP&#8230;</h2>
<p>Now the immediate question that might come in your mind is: <em>&#8220;If VS2010 is disabling HW acceleration on XP, should I do the same on my WPF application which is shipped on XP too ?&#8221;</em></p>
<p>I guess the answer is &#8220;maybe&#8221; and it actually depends on various factors:</p>
<ul>
<li>does your user reported crash that seems correlated to video drivers issue ?</li>
<li>does your application extensively uses complex graphical effects (for example this is clearly not the case in VS2010) ?</li>
<li>what kind of hardware your users are using. Is this recent hardware (which are being downgraded to XP) or is this really old hardware ?</li>
</ul>
<p>Maybe a good option is to let the user change this settings (while having a default value). In VS2010, you&#8217;ll be able to turn on HW acceleration back by using the settings dialog:</p>
<p><em><a href="http://www.japf.fr/wp-content/uploads/2011/03/settings-vs2010.png" rel="lightbox[817]"><img class="alignnone size-full wp-image-820" title="settings-vs2010" src="http://www.japf.fr/wp-content/uploads/2011/03/settings-vs2010.png" alt="" width="482" height="280" /></a><br />
</em></p>
<p>Anyway, I thought at the beginning it was a very weird decision. But after all; if the majority of the crashes they see in VS on Windows XP is linked to bad drivers, it makes sense.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2011/03/visual-studio-2010-and-hw-acceleration-on-windows-xp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MSDN Ultimate Subscription Giveaway</title>
		<link>http://www.japf.fr/2010/09/msdn-ultimate-subscription-giveaway/</link>
		<comments>http://www.japf.fr/2010/09/msdn-ultimate-subscription-giveaway/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 06:44:00 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Visual Stutio]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=650</guid>
		<description><![CDATA[As a Microsoft MVP for this year, I got 3 MSDN Ultimate Subscriptions to share with friends and co-workers. I already gave 2 of them to co-workers and I’d like to offer the last one to one of my reader ! The “official” pricing for the MSDN Ultimate Subscription is $11,899. The subscription is valid [...]]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="98"><a href="http://www.japf.fr/wp-content/uploads/2010/09/IMG_0833.jpg" rel="lightbox[650]"><img title="IMG_0833" border="0" alt="IMG_0833" src="http://www.japf.fr/wp-content/uploads/2010/09/IMG_0833_thumb.jpg" width="99" height="130" /></a></td>
<td valign="top" width="302">As a Microsoft MVP for this year, I got 3 MSDN Ultimate Subscriptions to share with friends and co-workers. I already gave 2 of them to co-workers and I’d like to offer the last one to one of my reader !</td>
</tr>
</tbody>
</table>
<p>The “official” pricing for the MSDN Ultimate Subscription is $11,899. The subscription is valid one year and is not restricted to US only. The MSDN Ultimate has the following items (among many others &#8211; you can see the detailed list <a href="http://www.microsoft.com/visualstudio/en-us/support">here</a>):</p>
<ul>
<li>Windows Azure Platform </li>
<li>Visual Studio 2010 Ultimate </li>
<li>Visual Studio TFS 2010 </li>
<li>Expression Studio Ultimate </li>
<li>Windows 7, Windows Server 2008 R2 and SQL Server 2008 </li>
<li>Microsoft Office Professional Plus 2010, Project Professional 2010, Visio Premium 2010 </li>
</ul>
<p>In order to take your chance to get this subscription:</p>
<ul>
<li>let a comment on this blog post </li>
<li>explain what you would like to do with the subscription </li>
<li>share you blog address, community website or whatever to show how you’re involved in the .Net community </li>
</ul>
<p><strong>Contest is now over. The winner of the MSDN Ultimate License is Mike Strobel. Thank you all for letting a comment, I which I had more subscriptions to giveaway…<br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/09/msdn-ultimate-subscription-giveaway/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<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('p630code12'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63012"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p630code12"><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>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('p620code14'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62014"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p620code14"><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] 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>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('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
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="p483code22"><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('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
7
8
9
10
11
12
</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 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('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
</pre></td><td class="code" id="p483code24"><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('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
</pre></td><td class="code" id="p483code25"><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('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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p483code26"><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('p483code27'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48327"><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="p483code27"><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('p483code28'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p48328"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p483code28"><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>
		<item>
		<title>Mix10 starting today !</title>
		<link>http://www.japf.fr/2010/03/mix10-starting-today/</link>
		<comments>http://www.japf.fr/2010/03/mix10-starting-today/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 07:51:21 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Visual Stutio]]></category>
		<category><![CDATA[mix10]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=466</guid>
		<description><![CDATA[Mix10 is starting today and we can expect many cool announcements during the keynote. You can watch the keynote online at live.visitmix.com. I&#8217;ll try to give feedback as soon as possible. Because I&#8217;m not lucky enough to be in Vegas, I&#8217;ll watch the keynote tonight (French time !) at home with some coworkers. Last information [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2010/03/Mix101.jpg" rel="lightbox[466]"><img class="alignnone size-full wp-image-456" title="Mix10" src="http://www.japf.fr/wp-content/uploads/2010/03/Mix101.jpg" alt="" width="157" height="96" /></a></p>
<p>Mix10 is starting today and we can expect many cool announcements during the keynote. You can watch the keynote online at <a href="http://live.visitmix.com/">live.visitmix.com</a>. I&#8217;ll try to give feedback as soon as possible. Because I&#8217;m not lucky enough to be in Vegas, I&#8217;ll watch the keynote tonight (French time !) at home with some coworkers.</p>
<p>Last information before the keynote, it looks like we&#8217;ll have some announcements about <a href="http://blogs.zdnet.com/microsoft/?p=5550&amp;utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+zdnet%2Fmicrosoft+%28ZDNet+All+About+Microsoft%29&amp;utm_content=Google+Reader">Silverlight running on Symbian</a> devices&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/03/mix10-starting-today/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF internals part 2 : how the WPF controls are organized ?</title>
		<link>http://www.japf.fr/2010/01/wpf-internals-how-the-wpf-controls-are-organised/</link>
		<comments>http://www.japf.fr/2010/01/wpf-internals-how-the-wpf-controls-are-organised/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 19:35:32 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[architecture]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=394</guid>
		<description><![CDATA[A couple of weeks ago, I started a series of articles about WPF internals organization. In the first article I did a tour of the core WPF classes. In this second part, I&#8217;m reviewing the organization of the various controls that exist in the framework. Because the image of the diagram is pretty big, I [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago, I started a series of articles about <a href="http://www.japf.fr/wpf-internals/">WPF internals</a> organization. In <a href="http://www.japf.fr/2009/10/wpf-internals-part-1-what-are-the-core-wpf-classes/">the first article</a> I did a tour of the core WPF classes. In this second part, I&#8217;m reviewing the organization of the various controls that exist in the framework.</p>
<p>Because the image of the diagram is pretty big, I decided to use Silverlight DeepZoom and the result is just below this text <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  You can download the <a href="http://www.japf.fr/wp-content/uploads/2010/01/WpfControlsFull.png" target="_blank" rel="lightbox[394]">full image resolution here</a>. Please use the full screen button in the upper right corner of the viewer for the best browsing experience.</p>
<p><script type="text/javascript">
        function onSilverlightError(sender, args) 
        {
            var appSource = "";
            if (sender != null &#038;&#038; sender != 0)
            {
                appSource = sender.getHost().Source;
            }
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;</p>
<p>            var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n";</p>
<p>            errMsg += "Code: " + iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";</p>
<p>            if (errorType == "ParserError") 
            {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") 
            {
                if (args.lineNumber != 0) 
                {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " + args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }</p>
<p>            throw new Error(errMsg);
        }
</script></p>
<div id="slPluginHost">
		<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="540" height="500"><param name="minRuntimeVersion" value="3.0.40307.0" /><param name="autoUpgrade" value="false" /><param name="source" value="http://www.japf.fr/silverlight/wpfcontrolsexplorer/WpfControlsExplorer.xap"/><param name="onerror" value="onSilverlightError" /><param name="background" value="white" /><param name="initParams" value="adFile=http://www.japf.fr/silverlight/wpfcontrolsexplorer/GeneratedImages" /><a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><br />
                <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/><br />
            </a><br />
        </object><br />
	<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>
<ul></ul>
<p>Here are general remarks that might help you get information from those diagrams.</p>
<p>The top level <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.aspx">Control</a> class:</p>
<ul>
<li>Defines general UI properties such as Background, Foreground, BorderBrush and BorderThickness</li>
<li>Defines a set of properties to control font rendering: FontFamily, FontSize, FontStyle&#8230;</li>
<li>Has a DoubleClick event (other mouse events such as MouseUp/MouseDown comes from the UIElement class)</li>
</ul>
<p>Below the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.aspx">Control</a> class, we have (this list is not complete):</p>
<ul>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx">ContentControl</a> class: those controls have&#8230; a single Content</li>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.aspx">ItemsControls</a> class which handles a collection of child controls</li>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.textboxbase.aspx">TextBoxBase</a> class which is the parent of <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx">TextBox</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx">RichTextBox</a></li>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.rangebase.aspx">RangerBase</a> class which handles a range (minimum, maximum) and which is the parent of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.scrollbar.aspx">ScrollBar</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.slider.aspx">Slider</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.progressbar.aspx">ProgressBar</a> classes</li>
<li>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.thumb.aspx">Thumb</a> class which has the ability to be dragged over a surface</li>
</ul>
<p>Below the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx">ContentControl</a> class we can find many existing WPF controls:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.buttonbase.aspx">ButtonBase</a> and its child: <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.button.aspx">Button</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.aspx">ToggleButton</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.repeatbutton.aspx">RepeatButton</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.label.aspx">Label</a> (see <a href="http://joshsmithonwpf.wordpress.com/2007/07/04/differences-between-label-and-textblock/">this post</a> for an explanation of the differences between a Label and a TextBlock)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listboxitem.aspx">ListBoxItem</a> and its children: <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listviewitem.aspx">ListViewItem</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.comboboxitem.aspx">ComboBoxItem</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.aspx">ScrollViewer</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.headeredcontentcontrol.aspx">HeaderedContentControl</a>, a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx">ContentControl</a> that has both a Content and a Header. This is the case of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.expander.aspx">Expander</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.groupbox.aspx">GroupBox</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.tabitem.aspx">TabItem</a> controls</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.tooltip.aspx">Tooltip</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.window.aspx">Window</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.usercontrol.aspx">UserControl</a></li>
</ul>
<p>General other remarks:</p>
<ul>
<li>It&#8217;s funny to see that both Window and UserControl inherits from ContentControl. Before doing the diagram I though that Window came from somewhere else <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
<li>Having those diagrams in mind (or on a screen !) is very useful when you need to create your own custom control</li>
<li>We can see the differences between creating a custom control (inherit from Control or derived class) and a UserControl (inherit from UserControl)</li>
<li>.Net4 will introduce new controls (not in this diagram) in the WPF framework such: DataGrid, Calendar, TimePicker</li>
</ul>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.japf.fr%2f2010%2f01%2fwpf-internals-how-the-wpf-controls-are-organised%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.japf.fr%2f2010%2f01%2fwpf-internals-how-the-wpf-controls-are-organised%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2010/01/wpf-internals-how-the-wpf-controls-are-organised/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

