<?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; WPF</title>
	<atom:link href="http://www.japf.fr/category/wpf/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>If you like typing XAML you will love ReSharper 6.1 !</title>
		<link>http://www.japf.fr/2012/01/if-you-like-typing-xaml-you-will-love-resharper-6-1/</link>
		<comments>http://www.japf.fr/2012/01/if-you-like-typing-xaml-you-will-love-resharper-6-1/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 17:42:25 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[resharper]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=1029</guid>
		<description><![CDATA[Resharper is an amazing tool for any .Net developers. The latest version 6.1 has been released just a couple of weeks ago and I wanted to share with you a brief overview of the new workflow available in the XAML world ! Visual Studio 2010 introduced 2 new design time properties: d:DesignInstance and d:DesignData. Those [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jetbrains.com/resharper/">Resharper</a> is an amazing tool for any .Net developers. The latest version 6.1 has been released just a couple of weeks ago and I wanted to share with you a brief overview of the new workflow available in the XAML world !</p>
<p>Visual Studio 2010 introduced 2 new design time properties: d:DesignInstance and d:DesignData. Those properties can be used in order to specify a design time DataContext in order to have more help during the creation of a binding.</p>
<p>For example, when you create a binding using the Property dialog of VS2010 you can browse your DataContext to select the right property (image from this <a href="http://karlshifflett.wordpress.com/2009/10/28/ddesigninstance-ddesigndata-in-visual-studio-2010-beta2/">blog post</a> from <a href="http://karlshifflett.wordpress.com/">Karl Shifflet</a>):</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/bindingbuilder_thumb.png" rel="lightbox[1029]"><img class="alignnone size-medium wp-image-1031" title="bindingbuilder_thumb" src="http://www.japf.fr/wp-content/uploads/2012/01/bindingbuilder_thumb-300x291.png" alt="" width="300" height="291" /></a></p>
<p>Resharper 6.1 is now able to use those metadata in order to improve the experience you have while typing XAML (which I personally do a LOT!). Here is how it works:</p>
<ul>
<li>you create a new ViewModel with a simple property (this property has just get/set because we don&#8217;t need much more in the context of this post&#8230;)</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/01.png" rel="lightbox[1029]"><img class="alignnone size-medium wp-image-1034" title="01" src="http://www.japf.fr/wp-content/uploads/2012/01/01-300x99.png" alt="" width="300" height="99" /></a></p>
<ul>
<li>you setup a binding in your view</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/02.png" rel="lightbox[1029]"><img class="alignnone size-full wp-image-1035" title="02" src="http://www.japf.fr/wp-content/uploads/2012/01/02.png" alt="" width="514" height="126" /></a></p>
<p>At this point the ReSharper magic comes into play&#8230;</p>
<ul>
<li>ReSharper warns you the DataContext is unknown</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/02.1.png" rel="lightbox[1029]"><img class="alignnone size-full wp-image-1043" title="02.1" src="http://www.japf.fr/wp-content/uploads/2012/01/02.1.png" alt="" width="565" height="126" /></a></p>
<ul>
<li>Offer the ability to fix this</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/03.png" rel="lightbox[1029]"><img title="03" src="http://www.japf.fr/wp-content/uploads/2012/01/03.png" alt="" width="545" height="271" /></a></p>
<ul>
<li>Note that like in C#, you can very easily resolve namespace issues</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/041.png" rel="lightbox[1029]"><img class="alignnone size-full wp-image-1046" title="04" src="http://www.japf.fr/wp-content/uploads/2012/01/041.png" alt="" width="602" height="192" /></a></p>
<ul>
<li>Then notice that the warning is gone (the Title property is no longer underlined)</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/06.png" rel="lightbox[1029]"><img class="alignnone size-full wp-image-1039" title="06" src="http://www.japf.fr/wp-content/uploads/2012/01/06.png" alt="" width="577" height="191" /></a></p>
<ul>
<li>You can now add a new binding</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/07.png" rel="lightbox[1029]"><img class="alignnone size-full wp-image-1040" title="07" src="http://www.japf.fr/wp-content/uploads/2012/01/07.png" alt="" width="576" height="207" /></a></p>
<ul>
<li>You can then ask ReSharper to create the property in your ViewModel</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/08.png" rel="lightbox[1029]"><img class="alignnone size-full wp-image-1041" title="08" src="http://www.japf.fr/wp-content/uploads/2012/01/08.png" alt="" width="580" height="378" /></a></p>
<ul>
<li>Choosing the first option will get you to the ViewModel definition</li>
</ul>
<p><a href="http://www.japf.fr/wp-content/uploads/2012/01/09.png" rel="lightbox[1029]"><img class="alignnone size-full wp-image-1042" title="09" src="http://www.japf.fr/wp-content/uploads/2012/01/09.png" alt="" width="417" height="242" /></a></p>
<p>Now that I&#8217;ve upgraded my installation to version 6.1, I think this is a must have !</p>
<p>That&#8217;s all for today ! Hope it helps <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2012/01/if-you-like-typing-xaml-you-will-love-resharper-6-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Meet me during the Microsoft Days in Lyon next Wednesday !</title>
		<link>http://www.japf.fr/2011/11/meet-me-during-the-microsoft-days-in-lyon-next-wednesday/</link>
		<comments>http://www.japf.fr/2011/11/meet-me-during-the-microsoft-days-in-lyon-next-wednesday/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 12:59:32 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[build]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[techdays]]></category>
		<category><![CDATA[windows8]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=1005</guid>
		<description><![CDATA[Next Wednesday (November 9th), I&#8217;ll be at the Microsoft Days 11 as a member of the Ask The Expert team. I&#8217;ll be playing with the Samsung Slate I got at //BUILD/, discussing WPF, Silverlight, Windows Phone 7 and Windows 8. Don&#8217;t hesitate to stop by and say hi if you&#8217;re coming to this event !]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2011/11/msdays.png" rel="lightbox[1005]"><img class="alignnone size-full wp-image-1006" title="msdays" src="http://www.japf.fr/wp-content/uploads/2011/11/msdays.png" alt="" width="349" height="69" /></a></p>
<p><strong>Next Wednesday (November 9th), I&#8217;ll be at the Microsoft Days 11 as a member of the <em>Ask The Expert</em> team</strong>. I&#8217;ll be playing with the Samsung Slate I got at //BUILD/, discussing WPF, Silverlight, Windows Phone 7 and Windows 8.</p>
<p>Don&#8217;t hesitate to stop by and say hi if you&#8217;re coming to this event !</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/11/slate.png" rel="lightbox[1005]"><img class="alignnone size-full wp-image-1008" title="slate" src="http://www.japf.fr/wp-content/uploads/2011/11/slate.png" alt="" width="342" height="256" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2011/11/meet-me-during-the-microsoft-days-in-lyon-next-wednesday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BUILD: WinRT, Silverlight, WPF, XAML</title>
		<link>http://www.japf.fr/2011/09/build-winrt-silverlight-wpf-xaml/</link>
		<comments>http://www.japf.fr/2011/09/build-winrt-silverlight-wpf-xaml/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 03:23:39 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Metro]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[metro]]></category>
		<category><![CDATA[windows8]]></category>
		<category><![CDATA[winrt]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=976</guid>
		<description><![CDATA[This blog post is part of my BUILD series. I&#8217;m having a very busy week here in Anaheim ! I&#8217;m meeting many new people and had the chance to enjoy the conference from the inside. I&#8217;m also playing with this new Windows 8 slate Microsoft gave us ! I&#8217;m not going to do a blog [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2011/09/build_logo.png" rel="lightbox[976]"><img title="build_logo" src="http://www.japf.fr/wp-content/uploads/2011/09/build_logo.png" alt="" width="132" height="47" /></a></p>
<p><em>This blog post is part of my <a href="http://build.japf.fr">BUILD series</a>.</em></p>
<p>I&#8217;m having a very busy week here in Anaheim ! I&#8217;m meeting many new people and had the chance to enjoy the conference from the inside. I&#8217;m also playing with this new Windows 8 slate Microsoft gave us ! I&#8217;m not going to do a blog post trying to summarize everything because there is just so much to say.I&#8217;m going to try to share my point of view on what I&#8217;ve seen here.</p>
<p><strong>Our new platform</strong></p>
<p><strong></strong>The original picture shown during the keynote to introduce the new platform was this one:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/09/win8-platform-and-tools.jpg" rel="lightbox[976]"><img class="alignnone size-full wp-image-978" title="win8-platform-and-tools" src="http://www.japf.fr/wp-content/uploads/2011/09/win8-platform-and-tools.jpg" alt="" width="490" height="276" /></a></p>
<p>There has been a lot of confusion about that because of having XAML with C# in the Metro Style Apps without any reference to the CLR&#8230; <a href="http://dougseven.com/">Doug Steven</a> did a pretty great job (blog post is <a href="http://dougseven.com/2011/09/15/a-bad-picture-is-worth-a-thousand-long-discussions/">here</a>) by discussing with key people from the engineering team of Microsoft and creates this new more accurate picture:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/09/win8-new-platform.png" rel="lightbox[976]"><img class="alignnone size-full wp-image-977" title="win8-new-platform" src="http://www.japf.fr/wp-content/uploads/2011/09/win8-new-platform.png" alt="" width="490" height="275" /></a></p>
<p>Here is a quick summary:</p>
<ul>
<li>there is only one CLR</li>
<li>.Net framework 4.5 is used in both Metro apps and Classic apps</li>
<li>it&#8217;s the same MSIL for Metro apps and Classic apps</li>
<li>in the Metro platform, we have a subset of the .Net framework (for example no OpenFileDialog&#8230;)</li>
</ul>
<p><strong>New opportunities</strong></p>
<p>Before //BUILD we had already many choices to choose our development environment. we now have even more:</p>
<ul>
<li>WPF and managed code for classic desktop apps</li>
<li>Silverlight in a web environment</li>
<li>Silverlight out of browser</li>
<li>WinRT + XAML for Metro apps</li>
<li>WinRT + HTML for Metro apps</li>
</ul>
<p>I personally think that Silverlight in a web browser has not a great future. Microsoft just announced for example that the immersive version of IE will not run any plugins (so no Silverlight in the Metro UI) and we &#8216;ll know Microsoft is pushing HTML5 very strongly.</p>
<p>For classic desktop apps we have 2 options: WPF and Silverlight. Each of them has advantages and the choice we&#8217;ll have to do will depend on our constraints (deployment, business needs, connectivity&#8230;). I think there is room for the 2 platforms there.</p>
<p>For the Metro UI, you can choose between XAML and HTML. Microsoft told us they will keep a good feature parity between the 2 options. If you choose XAML and managed code you&#8217;ll be able to leverage a subset of the .Net framework.</p>
<p>I think another important aspect is that Metro will be available on Windows 8 only. Even though this new version of the OS might have a fast deployment rate (thanks to the slates), in many companies I don&#8217;t think it will be that fast.This, plus the fact that some LOB apps will not benefit the Metro UI leaves a lot of work to do in the desktop applications world (where we have both WPF and SL)&#8230; For WPF, we now have a new version coming in .Net 4.5. You can check out the new stuff <a href="http://msdn.microsoft.com/en-us/library/bb613588(v=VS.110).aspx">here</a> in the documentation.</p>
<p>In my next blog post I&#8217;m going to try to go deeper in the new WinRT/XAML world and see how it looks like for us, WPF and Silverlight developers.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2011/09/build-winrt-silverlight-wpf-xaml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MVVM Framework explorer updated</title>
		<link>http://www.japf.fr/2011/09/mvvm-framework-explorer-updated/</link>
		<comments>http://www.japf.fr/2011/09/mvvm-framework-explorer-updated/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 11:57:50 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=954</guid>
		<description><![CDATA[I just updated my MVVM frameworks explorer Silverlight application. You can find the updated application here. Here is the top 5 of MVVM frameworks supporting WPF, Silverlight and Windows Phone 7: MVVM Light (61k downloads) nRoute (19k downloads) Caliburn Micro (18k downloads) Simple MVVM toolkit (5k downloads) Catel (5k downloads)]]></description>
			<content:encoded><![CDATA[<p>I just updated my MVVM frameworks explorer Silverlight application. You can find the updated application <a href="http://www.japf.fr/silverlight/mvvm/index.html">here</a>.</p>
<p>Here is the top 5 of MVVM frameworks supporting WPF, Silverlight and Windows Phone 7:</p>
<ol>
<li><a href="http://mvvmlight.codeplex.com/">MVVM Light</a> (61k downloads)</li>
<li><a href="http://nroute.codeplex.com/">nRoute</a> (19k downloads)</li>
<li><a href="http://caliburnmicro.codeplex.com/">Caliburn Micro</a> (18k downloads)</li>
<li><a href="http://simplemvvmtoolkit.codeplex.com/">Simple MVVM toolkit</a> (5k downloads)</li>
<li><a href="http://catel.codeplex.com/">Catel</a> (5k downloads)</li>
</ol>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/09/mvvm-frameworks.png" rel="lightbox[954]"><img class="alignnone size-full wp-image-955" title="mvvm-frameworks" src="http://www.japf.fr/wp-content/uploads/2011/09/mvvm-frameworks.png" alt="" width="464" height="80" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2011/09/mvvm-framework-explorer-updated/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>When enough ViewModel is enough</title>
		<link>http://www.japf.fr/2011/04/when-enough-viewmodel-is-enough/</link>
		<comments>http://www.japf.fr/2011/04/when-enough-viewmodel-is-enough/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 12:26:59 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=906</guid>
		<description><![CDATA[In the last few years, we&#8217;ve seen the WPF and Silverlight community embracing the MVVM methodology. As one of the early adopters of MVVM (one of my first post about the subject was late 2008), I&#8217;ve seen the pattern evolving both in the web community and with developers I&#8217;ve met in my daily life. Today, [...]]]></description>
			<content:encoded><![CDATA[<p>In the last few years, we&#8217;ve seen the WPF and Silverlight community embracing the MVVM methodology. As one of the early adopters of MVVM (one of <a href="http://www.japf.fr/2008/12/why-should-i-use-model-view-viewmodel-pattern/">my first post</a> about the subject was late 2008), I&#8217;ve seen the pattern evolving both in the web community and with developers I&#8217;ve met in my daily life.</p>
<p>Today, I&#8217;d like to share with you a simple concept I try to stick to when I&#8217;m doing WPF, Silverlight or Windows Phone 7 development. It can be summarized as &#8220;Enough ViewModel is enough&#8221;.</p>
<p>The simple idea behind this slogan is that there ARE stuff which are view-related and SHOULD NOT be embedded in the ViewModel layer. I&#8217;ve seen too many developers going the &#8220;100% viewmodel way&#8221; which means for them absolutely no code-behind without any dispensation.</p>
<p>For example, I came across this code. It&#8217;s the ViewModel layer associated to a simple view where the user fills various input and has immediate feedback about the progress (like &#8220;75% of the fields are completed&#8221;). If by the way you&#8217;re interested in implementing this behavior you can check out <a href="http://www.codeproject.com/KB/smart/WPF_Validation_Attribute.aspx">this article</a> I wrote on CodeProject)</p>
<p>The following code is simplified to the sake of the article:</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('p906code3'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9063"><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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code" id="p906code3"><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> ViewModel
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// data field acts as the model object behind the VM layer</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> Data data<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// missing code...</span>
    <span style="color: #008080; font-style: italic;">// public properties used by the view using databinding</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> ViewModel<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// very simplified for this article...</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;">new</span> Data<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</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: #0000FF;">SelectedValuesChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #008000;">&#40;</span>data_SelectedValuesChanged<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;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> UpdateProgress<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// some code...</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">void</span> data_SelectedValuesChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<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;">UpdateProgress</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Initialize</span><span style="color: #008000;">&#40;</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;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Initialize<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        var item <span style="color: #008000;">=</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: #0000FF;">GetItem</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;id1&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>item <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            item<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> PropertyChangedEventHandler<span style="color: #008000;">&#40;</span>item_PropertyChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            item<span style="color: #008000;">.</span><span style="color: #0000FF;">SelectedValuesChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #008000;">&#40;</span>item_SelectedValuesChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var value <span style="color: #0600FF; font-weight: bold;">in</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">Values</span><span style="color: #008000;">&#41;</span>
                value<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> PropertyChangedEventHandler<span style="color: #008000;">&#40;</span>item_PropertyChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        item <span style="color: #008000;">=</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: #0000FF;">GetItem</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;id2&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>item <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            item<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> PropertyChangedEventHandler<span style="color: #008000;">&#40;</span>item_PropertyChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            item<span style="color: #008000;">.</span><span style="color: #0000FF;">SelectedValuesChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #008000;">&#40;</span>item_SelectedValuesChanged<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var value <span style="color: #0600FF; font-weight: bold;">in</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">Values</span><span style="color: #008000;">&#41;</span>
                value<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> PropertyChangedEventHandler<span style="color: #008000;">&#40;</span>item_PropertyChanged<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: #6666cc; font-weight: bold;">void</span> item_PropertyChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, <span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyChangedEventArgs</span> e<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;">UpdateProgress</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">void</span> item_SelectedValuesChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<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;">UpdateProgress</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: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The idea is simple, as soon as the user changes a value in the View, we must compute the current progress. Because the ViewModel have several levels, we end-up having to register to every single PropertyChanged event which leads to cumbersome code. By the way, this code can also creates memory leaks since we register a lot of event handlers without removing them, but that&#8217;s another discussion&#8230;</p>
<p>Here is my way to solve this problem:</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('p906code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9064"><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
</pre></td><td class="code" id="p906code4"><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> View <span style="color: #008000;">:</span> UserControl
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> ViewModel viewmodel<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> View<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;">viewmodel</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ViewModel<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;">AddHandler</span><span style="color: #008000;">&#40;</span>
            FocusManager<span style="color: #008000;">.</span><span style="color: #0000FF;">LostFocusEvent</span>,
            <span style="color: #008000;">new</span> RoutedEventHandler<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnLostFocus</span><span style="color: #008000;">&#41;</span>,
            <span style="color: #0600FF; font-weight: bold;">true</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: #6666cc; font-weight: bold;">void</span> OnLostFocus<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<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;">viewmodel</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UpdateProgress</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: #008000;">&#125;</span></pre></td></tr></table></div>

<p>What is wrong with this way ? The View has code-behind ? That&#8217;s not a big deal: the code is more readable, maintainable. It makes also more sense: when a view-related operation occurs (in this case, focus has changed), update the progress.</p>
<p>The simple message I&#8217;d like to spread is the fact that there is nothing wrong with the fact to have <strong>sometime</strong>, a <strong>little bit of code-behind</strong> in your view<strong> if</strong> that facilitates your architecture. There is no need to create a complicated infrastructure with behaviors, commands or bindings just to keep the view empty if that does not make sense.</p>
<p>Another great example in a real application is available in the <a href="http://stores.lulu.com/joshsmithonwpf">Advanced MVVM</a> book by <a href="http://joshsmithonwpf.wordpress.com/">Josh Smith</a>.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2011/04/when-enough-viewmodel-is-enough/feed/</wfw:commentRss>
		<slash:comments>9</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('p861code8'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8618"><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="p861code8"><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('p861code9'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8619"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p861code9"><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('p861code10'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86110"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p861code10"><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>WPF databinding trick (part 1)</title>
		<link>http://www.japf.fr/2011/03/wpf-databinding-trick-part-1/</link>
		<comments>http://www.japf.fr/2011/03/wpf-databinding-trick-part-1/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 14:14:54 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[binding]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=844</guid>
		<description><![CDATA[The last week, one of my colleague was doing a WPF training session and she ended up having a very strange behavior with the WPF databinding engine. I&#8217;ll describe a not well-known behavior of the WPF databinding engine and I&#8217;ll try to explain how its works under the scene. Binding the Text property of a [...]]]></description>
			<content:encoded><![CDATA[<p>The last week, one of my colleague was doing a WPF training session and she ended up having a very strange behavior with the WPF databinding engine. I&#8217;ll describe a not well-known behavior of the WPF databinding engine and I&#8217;ll try to explain how its works under the scene.</p>
<p><strong>Binding the Text property of a TextBlock to a collection of objects</strong></p>
<p>This is something you&#8217;re not supposed to do, but you&#8217;ll see it actually works in an unexpected way. In the code-behind of our Window, we have the following C# 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('p844code15'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84415"><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
</pre></td><td class="code" id="p844code15"><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;
        Person person1 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Person <span style="color: #008000;">&#123;</span> Age <span style="color: #008000;">=</span> <span style="color: #FF0000;">45</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
        Person person2 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Person <span style="color: #008000;">&#123;</span> Age <span style="color: #008000;">=</span> <span style="color: #FF0000;">63</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
        Person person3 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Person <span style="color: #008000;">&#123;</span> Age <span style="color: #008000;">=</span> <span style="color: #FF0000;">71</span> <span style="color: #008000;">&#125;</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> List<span style="color: #008000;">&lt;</span>Person<span style="color: #008000;">&gt;</span> <span style="color: #008000;">&#123;</span> person1, person2, person3 <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> Person
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Age
    <span style="color: #008000;">&#123;</span>
        get<span style="color: #008000;">;</span>
        set<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The associated XAML looks like the following:</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('p844code16'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84416"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p844code16"><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;WpfApplicationDataContext.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>
&nbsp;
    <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;TextBlock</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Age}&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>Here we&#8217;re doing something not usual: we&#8217;re binding the Text property of the TextBlock (which is of type string) to a collection of objects.</p>
<p><strong>What do you think the Window will display ?</strong></p>
<p>The first time I saw this code, I thought the Window will remain empty. The DataContext is set to a List and we&#8217;re trying to find an &#8220;Age&#8221; property on this collection: THAT CANNOT WORK.</p>
<p>Actually, it does&#8230;</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/03/window.png" rel="lightbox[844]"><img src="http://www.japf.fr/wp-content/uploads/2011/03/window.png" alt="" title="window" width="263" height="105" class="alignnone size-full wp-image-852" /></a></p>
<p><strong>What&#8217;s happening behind the scene ?</strong></p>
<p>Let&#8217;s take a deep breath a take a look at what&#8217;s happening behind the scene to make this works.</p>
<p><em>1. A CollectionView is created</em></p>
<p>The first thing I was thinking while talking about the problem with my colleague was the use of a collection view. As you probably now, every time you create a binding to a collection property, the engine creates a collection view for you. This view will serve as an intermediate layer between your source and the target to manage selection, filtering and grouping. A good introduction to collection views is available <a href="http://marlongrech.wordpress.com/2008/11/22/icollectionview-explained/">here</a>.</p>
<p>What is important to know is that collection views are shared along same objects instance. It means that when you use the CollectionViewSource.GetDefaultView() method, you&#8217;re either creating a default view for the collection (if no one has requested one before) or getting the default view (if it has been created by calling the same method before you).</p>
<p>To make sure I was right about my hypothesis, I added the following code in the C#:</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('p844code17'); return false;">View Code</a> CHSARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84417"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p844code17"><pre class="chsarp" style="font-family:monospace;">var collectionView = CollectionViewSource.GetDefaultView(this.DataContext);
collectionView.MoveCurrentToNext();
this.MouseDoubleClick += (s, e) =&gt; collectionView.MoveCurrentToNext();</pre></td></tr></table></div>

<p>And the Window is now displaying the second item of the list:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/03/window2.png" rel="lightbox[844]"><img src="http://www.japf.fr/wp-content/uploads/2011/03/window2.png" alt="" title="window2" width="263" height="105" class="alignnone size-full wp-image-854" /></a></p>
<p>So we&#8217;re definitively dealing with a collection view. The next question was, where the value comes from, I specified &#8220;Age&#8221; as binding path&#8230;</p>
<p><em>2. The CurrentItem property of ICollectionView<br />
</em></p>
<p>If you take a look at the documentation about ICollectionView, you&#8217;ll find this property:</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/03/CurrentItem.png" rel="lightbox[844]"><img class="alignnone size-full wp-image-849" title="CurrentItem" src="http://www.japf.fr/wp-content/uploads/2011/03/CurrentItem.png" alt="" width="537" height="30" /></a></p>
<p>So it looks like the Text property of my TextBlock is databound to this CurrentItem property while I explicitly set to the Age property&#8230;</p>
<p><em>3. The magic of the PropertyPathWorker class</em></p>
<p>Using Reflector, I looked for potential types using the ICollectionView.CurrentItem property. I found an interesting class: PropertyPathWorker.In the source code of the .Net framework, this type is defines as &#8220;<em>the workhorse for CLR binding</em>&#8220;.</p>
<p>In particular, take a look at this method:</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('p844code18'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84418"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p844code18"><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> ReplaceItem<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> k, <span style="color: #6666cc; font-weight: bold;">object</span> newO, <span style="color: #6666cc; font-weight: bold;">object</span> parent<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// some code...</span>
&nbsp;
    view <span style="color: #008000;">=</span> CollectionViewSource<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDefaultCollectionView</span><span style="color: #008000;">&#40;</span>parent, TreeContext<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// some more code...</span>
&nbsp;
    newO <span style="color: #008000;">=</span> view<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentItem</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>newO <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        GetInfo<span style="color: #008000;">&#40;</span>k, newO, <span style="color: #0600FF; font-weight: bold;">ref</span> svs<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        svs<span style="color: #008000;">.</span><span style="color: #0000FF;">collectionView</span> <span style="color: #008000;">=</span> view<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span> 
&nbsp;
    <span style="color: #008080; font-style: italic;">// and bam ! we're now using view.CurrentItem as source for our binding</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>So we&#8217;ve a special case when we&#8217;re creating a binding with a collection view: the CurrentItem property is automatically used and merge with the specificied path. In our case, it&#8217;s like creating a binding to CurrentItem.Age.</p>
<p><em>3. And voila !</em></p>
<p>Finally we&#8217;ve a lot going on within the engine to make this works. Of course the original binding was not something we would do in normal application but it was kind of cool doing the investigations to find out why it was working ! Hope you learn something cool about the databinding engine <img src='http://www.japf.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Next week I&#8217;ll try to write a similar article about another strange behavior you might have already seen&#8230;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2011/03/wpf-databinding-trick-part-1/feed/</wfw:commentRss>
		<slash:comments>2</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('p817code21'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p81721"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p817code21"><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('p817code22'); return false;">View Code</a> CHSARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p81722"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p817code22"><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>TechDays 2011: Rx talk, slides and source code</title>
		<link>http://www.japf.fr/2011/02/techdays-2011-rx-talk-slides-and-source-code/</link>
		<comments>http://www.japf.fr/2011/02/techdays-2011-rx-talk-slides-and-source-code/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 15:53:21 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Rx]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[rx]]></category>
		<category><![CDATA[techdays]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=791</guid>
		<description><![CDATA[As promised, here is a blog post which shares source code and slides for the Rx talk I gave during last TechDays in Paris. I animated this session with my co-worker Charlotte and with Mitsu. Download slides here. Download source code here. Demo1: Drag&#8217;n'drop in a WPF application The goal was to implement a basic [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2011/02/techdays.png" rel="lightbox[791]"><img class="alignnone size-full wp-image-783" title="techdays" src="http://www.japf.fr/wp-content/uploads/2011/02/techdays.png" alt="" width="389" height="48" /></a></p>
<p>As promised, here is a blog post which shares source code and slides for the Rx talk I gave during last TechDays in Paris. I animated this session with my co-worker Charlotte and with <a href="http://mitsufu.wordpress.com/">Mitsu</a>.</p>
<p>Download slides <a href="http://www.japf.fr/wp-content/uploads/2011/02/TechDays2011_RxSlides.pdf">here</a>.<br />
Download source code <a href="http://www.japf.fr/wp-content/uploads/2011/02/TechDays2011_RxDemos.zip">here</a>.</p>
<p><strong>Demo1: Drag&#8217;n'drop in a WPF application</strong></p>
<p>The goal was to implement a basic drag&#8217;n'drop functionality in a WPF application. The Rx query looks like the following:</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('p791code26'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p79126"><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="p791code26"><pre class="csharp" style="font-family:monospace;">var query <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">from</span> mouseDown <span style="color: #0600FF; font-weight: bold;">in</span> <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;">GetMouseLeftButtonDownObservable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
            let downPosition <span style="color: #008000;">=</span> mouseDown<span style="color: #008000;">.</span><span style="color: #0000FF;">EventArgs</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span>
            let rect <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Rect<span style="color: #008000;">&#40;</span>downPosition<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">10</span>, downPosition<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">10</span>, <span style="color: #FF0000;">20</span>, <span style="color: #FF0000;">20</span><span style="color: #008000;">&#41;</span>
            let delta <span style="color: #008000;">=</span> mouseDown<span style="color: #008000;">.</span><span style="color: #0000FF;">EventArgs</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">image</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">from</span> mouseMove <span style="color: #0600FF; font-weight: bold;">in</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetMouseMoveObservable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>ea <span style="color: #008000;">=&gt;</span> ea<span style="color: #008000;">.</span><span style="color: #0000FF;">EventArgs</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</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: #008000;">&#41;</span>
                <span style="color: #008000;">.</span><span style="color: #0000FF;">SkipWhile</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> rect<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>p<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">.</span><span style="color: #0000FF;">DoOnce</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">onMouseEnter</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">image</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">Offset</span><span style="color: #008000;">&#40;</span>delta<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">.</span><span style="color: #0000FF;">TakeUntil</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetMouseLeftButtonUpObservable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Finally</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">onMouseLeave</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">image</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">select</span> mouseMove<span style="color: #008000;">;</span>
&nbsp;
query<span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> <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;">SetPosition</span><span style="color: #008000;">&#40;</span>p<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><br/><br />
<strong>Demo2: online Twitter search and Bing map </strong>geolocalization</p>
<p>This time, the goal was to query Twitter asynchronously and to geolocalize the associated Tweets. The Rx query:</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('p791code27'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p79127"><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="p791code27"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">textbox</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetTextChangedObservable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">DistinctUntilChanged</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>ea<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">textbox</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">Throttle</span><span style="color: #008000;">&#40;</span>TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromMilliseconds</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">300</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">ObserveOnDispatcher</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Do</span><span style="color: #008000;">&#40;</span>ea <span style="color: #008000;">=&gt;</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ShowLoadingIndicator</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>ea <span style="color: #008000;">=&gt;</span> TweeterHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">Search</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">textbox</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Switch</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">ObserveOn</span><span style="color: #008000;">&#40;</span>Scheduler<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispatcher</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>page <span style="color: #008000;">=&gt;</span> TweeterHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">ParseTwitterSearch</span><span style="color: #008000;">&#40;</span>page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>tweets<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</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;">HideLoadingIndicator</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">listbox</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> tweets<span style="color: #008000;">;</span>
&nbsp;
                        TweeterHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">LocalizeTweets</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">map</span>, tweets<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><br/><br />
<strong>Demo3: using the accelerometer in a Windows Phone 7 application</strong></p>
<p>The last demo was about the usage of the accelerometer in a Windows Phone 7 application. Here is the relevant Rx query:</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('p791code28'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p79128"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p791code28"><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> MoveEllipse<span style="color: #008000;">&#40;</span>IObservable<span style="color: #008000;">&lt;</span>Acceleration<span style="color: #008000;">&gt;</span> accelerationObservable<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    accelerationObservable
        <span style="color: #008000;">.</span><span style="color: #0000FF;">SlidingBuffer</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>accCouple <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">new</span> Acceleration<span style="color: #008000;">&#40;</span>accCouple<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, accCouple<span style="color: #008000;">.</span><span style="color: #0000FF;">Last</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">.</span><span style="color: #0000FF;">ObserveOnDispatcher</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Do</span><span style="color: #008000;">&#40;</span>acc <span style="color: #008000;">=&gt;</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">textBlock</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> acc<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">.</span><span style="color: #0000FF;">Scan</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>x0, y0<span style="color: #008000;">&#41;</span>, <span style="color: #008000;">&#40;</span>point, acc<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> point<span style="color: #008000;">.</span><span style="color: #0000FF;">Move</span><span style="color: #008000;">&#40;</span>acc<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ClipTo</span><span style="color: #008000;">&#40;</span>horizontalInterval, verticaInterval<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ellipse</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetCenter</span><span style="color: #008000;">&#40;</span>p<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>Doing this session was a really great experience ! I&#8217;d like to thank Charlotte and Mitsu for doing it with me. Also, I&#8217;d like to thank all users who came to the presentation !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2011/02/techdays-2011-rx-talk-slides-and-source-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TechDays 2011: Rx talk in Paris</title>
		<link>http://www.japf.fr/2011/02/techdays-2011-rx-talk-in-paris/</link>
		<comments>http://www.japf.fr/2011/02/techdays-2011-rx-talk-in-paris/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 15:56:23 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[Rx]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[rx]]></category>
		<category><![CDATA[techdays]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=780</guid>
		<description><![CDATA[During the next 3 days, the &#8220;Palais des Congrès&#8221; in Paris will hosting the TechDays 2011. For the very first time, I&#8217;ll have the chance to be part of it as a speaker for a talk about Rx (Reactive Extensions). The session will take place in room 241, tomorrow Thursday 8, from 1pm to 2pm. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.japf.fr/wp-content/uploads/2011/02/728x90_inscription.gif" rel="lightbox[780]"><img class="alignnone size-full wp-image-781 jzlhsoljhgbqhvqemcua jzlhsoljhgbqhvqemcua jzlhsoljhgbqhvqemcua jzlhsoljhgbqhvqemcua jzlhsoljhgbqhvqemcua jzlhsoljhgbqhvqemcua jzlhsoljhgbqhvqemcua jzlhsoljhgbqhvqemcua dffmfrpvuitqtkhgypts dffmfrpvuitqtkhgypts" title="728x90_inscription" src="http://www.japf.fr/wp-content/uploads/2011/02/728x90_inscription.gif" alt="" width="728" height="90" /></a><a href="http://www.japf.fr/wp-content/uploads/2011/02/techdays.png" rel="lightbox[780]"><img class="alignnone size-full wp-image-783" title="techdays" src="http://www.japf.fr/wp-content/uploads/2011/02/techdays.png" alt="" width="461" height="57" /></a></p>
<p>During the next 3 days, the <em>&#8220;Palais des Congrès&#8221;</em> in Paris will hosting the TechDays 2011. For the very first time, I&#8217;ll have the chance to be part of it as a speaker for a talk about Rx (<a href="http://msdn.microsoft.com/fr-fr/data/gg577609">Reactive Extensions</a>).</p>
<p>The <strong>session will take place in room 241</strong>, tomorrow Thursday 8, from 1pm to 2pm. Here is <a href="http://www.microsoft.com/france/mstechdays/programmes/Session.aspx?CellID=fc95ffb7-3dee-4365-acbf-971c586937a6&amp;DomID=3b2f53d1-855e-4d14-b76d-e5c8686da6ec">the link</a> to the session&#8217;s description (in French).</p>
<p><a href="http://www.japf.fr/wp-content/uploads/2011/02/rxlogo.png" rel="lightbox[780]"><img class="alignnone size-full wp-image-786" title="rxlogo" src="http://www.japf.fr/wp-content/uploads/2011/02/rxlogo.png" alt="" width="249" height="95" /></a></p>
<p>I&#8217;ll share presentation slides and source code by the end of the week <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/2011/02/techdays-2011-rx-talk-in-paris/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

