<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Andrew Clancy&#039;s blog</title>
	<atom:link href="http://znite.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://znite.wordpress.com</link>
	<description>FirePropertyChanged( () =&#62; Idea )</description>
	<lastBuildDate>Thu, 01 Apr 2010 00:17:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='znite.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Andrew Clancy&#039;s blog</title>
		<link>http://znite.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://znite.wordpress.com/osd.xml" title="Andrew Clancy&#039;s blog" />
	<atom:link rel='hub' href='http://znite.wordpress.com/?pushpress=hub'/>
		<item>
		<title>WPF/Silverlight MVVM Design Data &#8211; create once and share with Unit Tests</title>
		<link>http://znite.wordpress.com/2010/04/01/wpfsilverlight-mvvm-design-data-create-once-and-share-with-unit-tests-2/</link>
		<comments>http://znite.wordpress.com/2010/04/01/wpfsilverlight-mvvm-design-data-create-once-and-share-with-unit-tests-2/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 00:15:07 +0000</pubDate>
		<dc:creator>znite</dc:creator>
				<category><![CDATA[wpf]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://znite.wordpress.com/2010/04/01/wpfsilverlight-mvvm-design-data-create-once-and-share-with-unit-tests-2/</guid>
		<description><![CDATA[Getting data appearing in design view in Blend is key to being able to manipulate the your layout and styles without needing to run up your app (to quote Marcin, ‘nudge, nudge, nudge instead of nudge-F5-waaaait, nudge-F5-waaaaait’) As soon as a colleague pointed out to me VS2010 now supports Blend’s d:DataContext I brought forward getting [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=znite.wordpress.com&amp;blog=12149707&amp;post=56&amp;subd=znite&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:small;">Getting data appearing in design view in Blend is key to being able to manipulate the your layout and styles without needing to run up your app (to quote Marcin, ‘nudge, nudge, nudge instead of nudge-F5-waaaait, nudge-F5-waaaaait’)</span></p>
<p><span style="font-size:x-small;">As soon as a colleague pointed out to me VS2010 now supports Blend’s d:DataContext I brought forward getting things ‘working in in design view’, as I realised here was a way to quickly and easily wire up a test rig of data in C# that I could share between my unit tests, a mock session of my WPF/Silverlight app and design view in both Blend and VS2010 (rather than xaml test data for UI, C# or for tests/runtime test UI). Down to it …</span></p>
<p><span style="font-size:x-small;">Working backwards, here’s my end result (Bob and Alice are a List&lt;Person&gt; bound to a ListView). Doesn’t look like much, but it works with all xaml controls including DataGrids/TreeViews etc, so you should quickly start to see the power in simplicity.</span></p>
<p><span style="font-size:x-small;"> </span></p>
<p><a href="http://znite.files.wordpress.com/2010/04/image.png"><span style="font-size:x-small;"><img style="display:inline;border-width:0;" title="image" src="http://znite.files.wordpress.com/2010/04/image_thumb.png?w=500&#038;h=246" border="0" alt="image" width="500" height="246" /></span></a><span style="font-size:x-small;"> </span></p>
<p><span style="font-size:small;">Key XAML:</span></p>
<div id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:6766fbcf-b963-466a-98f4-1a1f101c2aa9" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#ffffff;white-space:pre-wrap;overflow:auto;font-family:Lucida Console;font-size:14.25px;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">UserControl </span><span style="color:#ff0000;">... xmlns:mc</span><span style="color:#0000ff;">="http://schemas.openxmlformats.org/markup-compatibility/2006"</span><span style="color:#ff0000;">
        xmlns:d</span><span style="color:#0000ff;">="http://schemas.microsoft.com/expression/blend/2008"</span><span style="color:#ff0000;">
        xmlns:md</span><span style="color:#0000ff;">="clr-namespace:MvvmDemo"</span><span style="color:#ff0000;"> mc:Ignorable</span><span style="color:#0000ff;">="d"</span><span style="color:#ff0000;">
        d:DesignHeight</span><span style="color:#0000ff;">="600"</span><span style="color:#ff0000;"> d:DesignWidth</span><span style="color:#0000ff;">="800"</span><span style="color:#ff0000;">
        d:DataContext</span><span style="color:#0000ff;">="</span><span style="color:#808000;">{x:Static md:DesignData.PersonListViewModel}</span><span style="color:#0000ff;">"</span><span style="color:#ff0000;">
        x:Name</span><span style="color:#0000ff;">="view"</span><span style="color:#ff0000;"> DataContext</span><span style="color:#0000ff;">="</span><span style="color:#808000;">{Binding ElementName=view, Path=ViewModel}</span><span style="color:#0000ff;">"</span><span style="color:#0000ff;">&gt;</span><span style="color:#000000;">
... </span><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">TextBox </span><span style="color:#ff0000;">Text</span><span style="color:#0000ff;">="</span><span style="color:#808000;">{Binding Filter.PersonName}</span><span style="color:#0000ff;">"</span><span style="color:#ff0000;">
... &lt;DatePicker SelectedDate</span><span style="color:#0000ff;">="</span><span style="color:#808000;">{Binding Filter.BirthDate}</span><span style="color:#0000ff;">"</span><span style="color:#ff0000;">
... &lt;ListBox ItemsSource</span><span style="color:#0000ff;">="</span><span style="color:#808000;">{Binding FilteredPeople}</span><span style="color:#0000ff;">"</span><span style="color:#0000ff;">&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p><span style="font-size:x-small;">By the way, this is very cool: the VS2010 Properties window now has navigation of my ViewModel object hierarchy, as long as I’m bound to my real DataContext in xaml. Still prefer the speed of resharper smart auto-completion though (ctrl+alt+space).</span></p>
<p><a href="http://znite.files.wordpress.com/2010/04/image1.png"><img style="display:inline;border-width:0;" title="image" src="http://znite.files.wordpress.com/2010/04/image_thumb1.png?w=478&#038;h=283" border="0" alt="image" width="478" height="283" /></a></p>
<p><span style="font-size:x-small;">Anyway, back to the xaml … note the d:DataContext is bound to a static DesignData class &amp; property. Here you could either inject a fake/mock repository and have the ViewModel do its thing, or stop it from loading and populate it in the DesignData class. Both are good techniques in unit testing and design data, and can be used interchangeably. Here I demo both (the viewmodel loads existing people from the repository, hence in design the fake, and I populate the form filter fields).</span></p>
<div style="background-color:white;color:black;">
<div id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:468250de-3890-4eef-a4ac-9c9c9edb0a65" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#ffffff;white-space:pre-wrap;overflow:auto;"><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> </span><span style="color:#0000ff;">class</span><span style="color:#000000;"> DesignData
{
    </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> DesignData()
    {
        Container.Register</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">IPersonRepository, FakePersonRepository</span><span style="color:#000000;">&gt;</span><span style="color:#000000;">();
    }

    </span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">static</span><span style="color:#000000;"> PersonListViewModel PersonListViewModel
    {
        </span><span style="color:#0000ff;">get</span><span style="color:#000000;">
        {
            </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> PersonListViewModel
                       {
                           Filter </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> PersonFilter
                                        {
                                            PersonName </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">Ca</span><span style="color:#800000;">"</span><span style="color:#000000;">,
                                            BirthDate </span><span style="color:#000000;">=</span><span style="color:#000000;"> DateTime.Now.AddYears(</span><span style="color:#000000;">-</span><span style="color:#800080;">20</span><span style="color:#000000;">)
                                        }
                       };
        }
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
</div>
<p><span style="font-size:x-small;">I inject &amp; reuse the FakeRepository in my TestUI exe (a separate exe so as not to pollute my release code with accidental fake data). </span></p>
<p><span style="font-size:x-small;">And just for good measure, here’s a kind of contrived test – the fake data doesn’t really effect the test but you get the idea: write once, use everywhere &#8211; same as the rest of your code. </span></p>
<div id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:6b6a0365-f2f6-4043-ad62-a5d17dbc968a" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<pre style="background-color:#ffffff;white-space:pre-wrap;overflow:auto;"><span style="color:#000000;">[TestMethod]
</span><span style="color:#0000ff;">public</span><span style="color:#000000;"> </span><span style="color:#0000ff;">void</span><span style="color:#000000;"> search_on_name_should_filter()
{
   </span><span style="color:#008000;">//</span><span style="color:#008000;"> ARRANGE </span><span style="color:#008000;">
</span><span style="color:#000000;">   _sut </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> PersonListViewModel();
   var people </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> FakePersonRepository().GetPeople();
   _sut.People.AddRange(people);
   people </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> List</span><span style="color:#000000;">&lt;</span><span style="color:#000000;">Person</span><span style="color:#000000;">&gt;</span><span style="color:#000000;"> { </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> Person {Name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">Carol</span><span style="color:#800000;">"</span><span style="color:#000000;">},
                        </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> Person {Name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">Carlos</span><span style="color:#800000;">"</span><span style="color:#000000;">},
                        </span><span style="color:#0000ff;">new</span><span style="color:#000000;"> Person {Name </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">Charlie</span><span style="color:#800000;">"</span><span style="color:#000000;">} };
   _sut.People.AddRange(people);
    </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> search </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#800000;">"</span><span style="color:#800000;">Ca</span><span style="color:#800000;">"</span><span style="color:#000000;">;
    _sut.PersonName </span><span style="color:#000000;">=</span><span style="color:#000000;"> search;

   </span><span style="color:#008000;">//</span><span style="color:#008000;"> ACT </span><span style="color:#008000;">
</span><span style="color:#000000;">   _sut.Search();

   </span><span style="color:#008000;">//</span><span style="color:#008000;"> ASSERT</span><span style="color:#008000;">
</span><span style="color:#000000;">   Assert.IsFalse(_sut.FilteredPeople.Any(p </span><span style="color:#000000;">=&gt;</span><span style="color:#000000;"> </span><span style="color:#000000;">!</span><span style="color:#000000;">p.Name.StartsWith(search)));
   Assert.IsTrue(_sut.FilteredPeople.Any(p </span><span style="color:#000000;">=&gt;</span><span style="color:#000000;"> p.Name.StartsWith(search)));
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p><span style="font-size:x-small;">Full code here: <img src="http://msc.wlxrs.com/Yab6BLiyg7PTichbq0kh4A/images/transparent.gif" alt="" /></span></p>
<p><a href="http://cid-7626f54897e758b0.skydrive.live.com/self.aspx/.Public/MvvmDemo.zip"><img style="display:inline;border-width:0;" title="image" src="http://znite.files.wordpress.com/2010/04/image2.png?w=90&#038;h=72" border="0" alt="image" width="90" height="72" /></a></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b3f23786-c5d3-4751-a720-0baec8d99dc7" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/wpf">wpf</a>,<a rel="tag" href="http://technorati.com/tags/silverlight">silverlight</a>,<a rel="tag" href="http://technorati.com/tags/mvvm">mvvm</a></div>
<p><span style="font-size:x-small;"> </span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/znite.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/znite.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/znite.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/znite.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/znite.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/znite.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/znite.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/znite.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/znite.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/znite.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/znite.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/znite.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/znite.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/znite.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=znite.wordpress.com&amp;blog=12149707&amp;post=56&amp;subd=znite&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://znite.wordpress.com/2010/04/01/wpfsilverlight-mvvm-design-data-create-once-and-share-with-unit-tests-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4255fe6a529ecaef1d31d0cf766cd43b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">znite</media:title>
		</media:content>

		<media:content url="http://znite.files.wordpress.com/2010/04/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://znite.files.wordpress.com/2010/04/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://msc.wlxrs.com/Yab6BLiyg7PTichbq0kh4A/images/transparent.gif" medium="image" />

		<media:content url="http://znite.files.wordpress.com/2010/04/image2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Upgrade to Linq AsParallel</title>
		<link>http://znite.wordpress.com/2010/02/22/upgrade-to-linq-asparallel/</link>
		<comments>http://znite.wordpress.com/2010/02/22/upgrade-to-linq-asparallel/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 08:27:15 +0000</pubDate>
		<dc:creator>znite</dc:creator>
				<category><![CDATA[linq]]></category>
		<category><![CDATA[parallel linq]]></category>
		<category><![CDATA[plinq]]></category>

		<guid isPermaLink="false">http://znite.wordpress.com/2010/02/22/upgrade-to-linq-asparallel/</guid>
		<description><![CDATA[I was amazed &#38; delighted a couple of weeks ago when resharper 5 suddenly decided a huge piece of code I was refactoring could be converted in to linq – my esteemed ex-colleague John Rayner has already blogged about this so no need to repeat it (check out the amazing chunk of code it reduced). [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=znite.wordpress.com&amp;blog=12149707&amp;post=34&amp;subd=znite&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was amazed &amp; delighted a couple of weeks ago when resharper 5 suddenly decided a huge piece of code I was refactoring could be <a href="http://www.jetbrains.com/resharper/beta/beta.html#code_analysis">converted in to linq</a> – my esteemed ex-colleague <a href="http://consultingblogs.emc.com/johnrayner">John Rayner</a> has already blogged about this so no need to repeat it (check out the amazing chunk of code it reduced). I showed it to someone at work though and he asked the question ‘why?’, as to him the original was more readable. I tend to agree with John that linq (methods chaining) is more readable now, and as everyone groks it I’m sure you will too. However I have come up with another neat reason ‘why’ – you can parallelize your (thread-safe) .Net 4 code for free.</p>
<p>Run this code:</p>
<div id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:9911a5bb-18cd-488c-8965-bef9d89bad00" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 2;  toolbar: true; ">int c = 0;
foreach (var i in Enumerable.Range(1, 1000000))
{
    if (IsPrime(i))
    {
        c++;
    }
}
// ...
static bool IsPrime(int val)
{
    foreach (var i in Enumerable.Range(2, val))
    {
        if (val % i == 0)
        {
            return false;
        }
    }
    return true;
}</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>Watch it churn a single CPU (to be fair this didn&#8217;t dent my CPU too much, but it did take over 2 minutes)</p>
<p><a href="http://znite.files.wordpress.com/2010/02/image.png"><img style="display:inline;border-width:0;" title="image" src="http://znite.files.wordpress.com/2010/02/image_thumb.png?w=393&#038;h=148" border="0" alt="image" width="393" height="148" /></a></p>
<p>upgrade to linq (alt-enter on the foreach)</p>
<div id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:c5e5ab16-837f-49ae-8037-019767af753e" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 2;  toolbar: true; ">int c = Enumerable.Range(1, 1000000)
                .Count(IsPrime)</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>stick in a strategic AsParallel, and watch it use up all of your CPUs nicely.</p>
<div id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:18bb6239-2107-431e-99d8-2277f7991a55" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 2;  toolbar: true; ">int c = Enumerable.Range(1, 1000000)
    .AsParallel()
    .Count(IsPrime);</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p><a href="http://znite.files.wordpress.com/2010/02/image1.png"><img style="display:inline;border-width:0;" title="image" src="http://znite.files.wordpress.com/2010/02/image_thumb1.png?w=394&#038;h=145" border="0" alt="image" width="394" height="145" /></a></p>
<p>The latter took ~30s.</p>
<p>Credit here to this <a href="http://labs.dropit.se/blogs/post/2009/11/29/Parallell-computing-in-net-4.aspx">Christer</a> for the IsPrime AsParallel example, I really did just paste 2 blogs together here but I hope someone finds it useful <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/znite.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/znite.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/znite.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/znite.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/znite.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/znite.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/znite.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/znite.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/znite.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/znite.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/znite.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/znite.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/znite.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/znite.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=znite.wordpress.com&amp;blog=12149707&amp;post=34&amp;subd=znite&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://znite.wordpress.com/2010/02/22/upgrade-to-linq-asparallel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4255fe6a529ecaef1d31d0cf766cd43b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">znite</media:title>
		</media:content>

		<media:content url="http://znite.files.wordpress.com/2010/02/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://znite.files.wordpress.com/2010/02/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>MVVM MouseOver Binding</title>
		<link>http://znite.wordpress.com/2010/02/20/mvvm-mouseover-binding/</link>
		<comments>http://znite.wordpress.com/2010/02/20/mvvm-mouseover-binding/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 21:14:48 +0000</pubDate>
		<dc:creator>znite</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://znite.wordpress.com/2010/02/20/mvvm-mouseover-binding/</guid>
		<description><![CDATA[I’m doing a mouse-over-for-more-info implementation, and wanted to update a section of real UI rather than creating some sort of super-tooltip. This allows the user to potentially see more, and keep what they last moused over on screen. I wanted a MVVM-style solution the ViewModel is blissfully ignorant of what’s modifying the current item of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=znite.wordpress.com&amp;blog=12149707&amp;post=11&amp;subd=znite&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’m doing a mouse-over-for-more-info implementation, and wanted to update a section of real UI rather than creating some sort of super-tooltip. This allows the user to potentially see more, and keep what they last moused over on screen. I wanted a MVVM-style solution the ViewModel is blissfully ignorant of what’s modifying the current item of relevance to the user. I looked in Mark Smith’s <a href="http://www.julmar.com/blog/mark/2009/04/17/WPFMVVMHelperLibraryWPFMVVMTestability.aspx">Julmar MVVM Helpers</a> hoping for a solution, if not inspiration. His EventCommander came close but it would mean I’d need to wire up ‘MouseEnterCommand’ on the viewModel thus making it implementation aware. I definitely found inspiration though.</p>
<p>Here’s my solution:</p>
<p><a href="http://znite.files.wordpress.com/2010/02/screen.png"><img style="display:inline;border-width:0;" title="screen" border="0" alt="screen" src="http://znite.files.wordpress.com/2010/02/screen_thumb.png?w=444&#038;h=189" width="444" height="189" /></a></p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:bb5e4bf9-a89f-4183-a828-3bfca241d507" class="wlWriterEditableSmartContent">
<pre class="brush: xml; gutter: false; first-line: 1; tab-size: 2;  toolbar: true; ">&lt;ListBox ItemsSource=&quot;{Binding People}&quot;&gt;
    &lt;ListBox.ItemTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;TextBlock Text=&quot;{Binding Name}&quot;
amc:Behaviours.MouseOver=&quot;{Binding ViewModel.CurrentPerson, ElementName=view}&quot; /&gt;
        &lt;/DataTemplate&gt;
    &lt;/ListBox.ItemTemplate&gt;
&lt;/ListBox&gt;

&lt;TextBlock DataContext=&quot;{Binding CurrentPerson}&quot;&gt;
    &lt;TextBlock.Text&gt;
       &lt;MultiBinding StringFormat=&quot;Name: {0} BirthDate: {1:d/M/yyyy}&quot;&gt;
          &lt;Binding Path=&quot;Name&quot; /&gt;
          &lt;Binding Path=&quot;BirthDate&quot; /&gt;
        &lt;/MultiBinding&gt;
    &lt;/TextBlock.Text&gt;
&lt;/TextBlock&gt;</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>So the underlying viewmodel simply has an ObservableCollection of Person called People and property ‘CurrentPerson’.</p>
<p>The Behaviours implementation follows:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:121d5277-81bb-45a6-8e92-d10523b4d6e2" class="wlWriterEditableSmartContent">
<pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 2;  toolbar: true;  collapse: true;">public static partial class Behaviours
{
    private static readonly List&lt;FrameworkElement&gt; _wiredUpElements = new List&lt;FrameworkElement&gt;();
    private static readonly object _wiredUpElementsLock = new object();

    public static readonly DependencyProperty MouseOverProperty
        = DependencyProperty.RegisterAttached(
            &quot;MouseOver&quot;,
            typeof(object),
            typeof(Behaviours),
            new FrameworkPropertyMetadata(false,
                FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
                MouseOverBindingPropertyChanged));

    public static void SetMouseOver(FrameworkElement element, object value)
    {
        element.SetValue(MouseOverProperty, value);
    }

    private static void MouseOverBindingPropertyChanged(
        DependencyObject d,
        DependencyPropertyChangedEventArgs e)
    {
        var element = d as FrameworkElement;
        if (element == null || _wiredUpElements.Contains(element))
        {
            return;
        }
        lock (_wiredUpElementsLock)
        {
            if (_wiredUpElements.Contains(element))
            {
                return;
            }
            _wiredUpElements.Add(element);
        	  element.MouseEnter += (sender, args) =&gt;
                                  {
                                      var e = (FrameworkElement) sender;
                                      SetMouseOver(e, e.DataContext);
                                  };
        }
    }
}</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/znite.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/znite.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/znite.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/znite.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/znite.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/znite.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/znite.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/znite.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/znite.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/znite.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/znite.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/znite.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/znite.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/znite.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=znite.wordpress.com&amp;blog=12149707&amp;post=11&amp;subd=znite&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://znite.wordpress.com/2010/02/20/mvvm-mouseover-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4255fe6a529ecaef1d31d0cf766cd43b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">znite</media:title>
		</media:content>

		<media:content url="http://znite.files.wordpress.com/2010/02/screen_thumb.png" medium="image">
			<media:title type="html">screen</media:title>
		</media:content>
	</item>
		<item>
		<title>Static reflection INotifyPropertyChanged</title>
		<link>http://znite.wordpress.com/2010/02/20/static-reflection-inotifypropertychanged-2/</link>
		<comments>http://znite.wordpress.com/2010/02/20/static-reflection-inotifypropertychanged-2/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 20:49:50 +0000</pubDate>
		<dc:creator>znite</dc:creator>
				<category><![CDATA[wpf]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[static reflection]]></category>

		<guid isPermaLink="false">http://znite.wordpress.com/2010/02/20/static-reflection-inotifypropertychanged-2/</guid>
		<description><![CDATA[Every MVVM framework contains a ViewModelBase with an implementation of INotifyPropertyChanged. Mine&#8217;s no different, but I wanted to have the flexibility to control when propertychanges are fired, and whether to do other stuff/fire other propertychanges at the same time, all strongly typed (for resharper renaming, navigation etc). Static reflection came into play, and I came [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=znite.wordpress.com&amp;blog=12149707&amp;post=6&amp;subd=znite&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Every MVVM framework contains a ViewModelBase with an implementation of INotifyPropertyChanged. Mine&#8217;s no different, but I wanted to have the flexibility to control when propertychanges are fired, and whether to do other stuff/fire other propertychanges at the same time, all strongly typed (for resharper renaming, navigation etc). Static reflection came into play, and I came up with a solution that gave me the ability to do this: </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:43018951-8006-43d2-ba05-ef484051689d" class="wlWriterEditableSmartContent">
<pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 4;  toolbar: true; ">if ( SetProperty( ref this._company, value, () =&gt; this.Company ) )
{
	// update something else, fire other property changes etc ...
	this.FirePropertyChanged( () =&gt; this.Salary );
}</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>To achieve this I used static reflection as thus </p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:5699c189-8375-4bb1-842f-3faf71ce395d" class="wlWriterEditableSmartContent">
<pre class="brush: csharp; gutter: false; first-line: 1; tab-size: 2;  toolbar: true; ">public bool SetProperty&lt;T&gt;( ref T field, T value, Expression&lt;Func&lt;T&gt;&gt; property )
{
	if ( ( Equals( field, default( T ) ) &amp;&amp; Equals( value, default( T ) ) )
		  || ( !Equals( field, default( T ) ) &amp;&amp; field.Equals( value ) ) )
	{
		return false;
	}
	field = value;
	if ( property != null )
	{
		this.FirePropertyChanged( property );
	}
	return true;
}

public void FirePropertyChanged&lt;T&gt;( Expression&lt;Func&lt;T&gt;&gt; property )
{
	if ( this.PropertyChanged != null )
	{
		this.PropertyChanged( this, new PropertyChangedEventArgs( property.GetPropertyName() ) );
	}
}

public static class StaticReflectionExtensions
{
	public static string GetPropertyName&lt;T&gt;( this Expression&lt;Func&lt;T&gt;&gt; property )
	{
		return ( ( (MemberExpression)property.Body ).Member ).Name;
	}
}</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/znite.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/znite.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/znite.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/znite.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/znite.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/znite.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/znite.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/znite.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/znite.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/znite.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/znite.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/znite.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/znite.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/znite.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=znite.wordpress.com&amp;blog=12149707&amp;post=6&amp;subd=znite&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://znite.wordpress.com/2010/02/20/static-reflection-inotifypropertychanged-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4255fe6a529ecaef1d31d0cf766cd43b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">znite</media:title>
		</media:content>
	</item>
	</channel>
</rss>
