<?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>C# Disciples &#187; .Net 3.0</title>
	<atom:link href="http://marlongrech.wordpress.com/category/net-30/feed/" rel="self" type="application/rss+xml" />
	<link>http://marlongrech.wordpress.com</link>
	<description>my life in Avalon ....</description>
	<lastBuildDate>Thu, 15 Oct 2009 09:19:13 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='marlongrech.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/0c938eec94507e7222db1a9e8ad7ba9e?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>C# Disciples &#187; .Net 3.0</title>
		<link>http://marlongrech.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://marlongrech.wordpress.com/osd.xml" title="C# Disciples" />
		<item>
		<title>XBAPs Part 2: Consuming WCF services from an XBAP</title>
		<link>http://marlongrech.wordpress.com/2009/02/16/xbaps-part-2-consuming-wcf-services-from-an-xbap/</link>
		<comments>http://marlongrech.wordpress.com/2009/02/16/xbaps-part-2-consuming-wcf-services-from-an-xbap/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 20:48:00 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XBAP]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/2009/02/16/xbaps-part-2-consuming-wcf-services-from-an-xbap/</guid>
		<description><![CDATA[Introduction
One of the big improvements to XBAPs in .NET 3.5 is the ability to consume WCF services. Nowadays Service Oriented Architectures (SOAs) are very popular and used almost everywhere. This all makes sense, as SOA is very scalable, and for many cases it is the best approach to take for a project; so why not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=286&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>Introduction</h3>
<p>One of the big improvements to XBAPs in .NET 3.5 is the ability to consume WCF services. Nowadays Service Oriented Architectures (SOAs) are very popular and used almost everywhere. This all makes sense, as SOA is very scalable, and for many cases it is the best approach to take for a project; so why not enable SOA for XBAPs as well. To tell you the truth, you could consume WCF services from XBAP in .NET 3.0, yet the XBAP had to have Full Trust, and not Partial Trust, which usually spells trouble. Anyway we don’t have to worry much about this now because .NET 3.5 enables XBAPs to consume WCF services even in Partial Trust. <a href="http://msdn.microsoft.com/en-us/library/bb412186.aspx" target="_blank">Read more about this and it’s limitations here.</a></p>
<h3>Setting up our workspace</h3>
<p>Ok so let’s start by creating a simple WCF service. Open Visual Studio and create a WCF service by clicking File &gt; New &gt; Project and then select Web &gt; WCF Service application</p>
<p><a href="http://marlongrech.files.wordpress.com/2009/02/newwcf.jpg"><img style="display:inline;border-width:0;" title="NewWCF" src="http://marlongrech.files.wordpress.com/2009/02/newwcf-thumb.jpg?w=244&#038;h=189" border="0" alt="NewWCF" width="244" height="189" /></a></p>
<p>I am not going to cover the basics of how to create a WCF service, yet by default the WCF Service Visual Studio template creates a simple service for us already (called IService). So yes, if you hit F5 and run the service you will already have a service up and running. Once we have our simple service let’s create a Simple XBAP in the same solution (in order to do this please refer to <a href="http://marlongrech.wordpress.com/2009/02/05/xbaps-part-1-an-introduction-to-this-gem/" target="_blank">my previous post</a>).</p>
<p>Now that we have both the WCF service and the XBAP how are we going to make them communicate? Well, thanks to Visual Studio this is super simple. All you have to do is Right click the XBAP project, select the &#8220;Add Service Reference&#8221; option and a Dialog will pop up:</p>
<p><a href="http://marlongrech.files.wordpress.com/2009/02/addservicereference.jpg"><img style="display:inline;border-width:0;" title="AddServiceReference" src="http://marlongrech.files.wordpress.com/2009/02/addservicereference-thumb.jpg?w=244&#038;h=228" border="0" alt="AddServiceReference" width="244" height="228" /></a></p>
<p><strong>Please Note:</strong> If you do not run the service you will get an error while expanding the Tree nodes of the service in this Dialog. If the service is not running Visual Studio cannot get the Metadata of the service, since this is just another EndPoint of the service. In order to run the service just Right Click on Service1.svc and select View in Browser.</p>
<p>Ok, now that we added the Service Reference, Visual Studio will go to work and generate a Proxy class for us. We will use this proxy class to communicate with the WCF service. By default the Proxy class is called &lt;Name of service&gt;Client so in our case it will be called Service1Client. This proxy class will have a method for every OperationContract we have in our service. You can also choose to create an Async version of the service. In order to do so just right click the Service1 (in the XBAP project that got created when we added the Service Reference) and select Configure Service Reference.</p>
<p><a href="http://marlongrech.files.wordpress.com/2009/02/changetheservicetohaveasync.jpg"><img style="display:inline;border-width:0;" title="ChangeTheServiceToHaveASYNC" src="http://marlongrech.files.wordpress.com/2009/02/changetheservicetohaveasync-thumb.jpg?w=244&#038;h=226" border="0" alt="ChangeTheServiceToHaveASYNC" width="244" height="226" /></a></p>
<p>In this dialog check the Generate Async operations checkbox and Visual Studio will add an async version of the OperationContracts for you (Thank you VS… we love you <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<h3>The first error you’ll see</h3>
<p>Ok now that we have everything set up lets do a simple button in our XBAP and in the Click event handler call a method. Something like this….</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> Button_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span>     Service1Client client = <span style="color:#0000ff;">new</span> Service1Client();</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span>     MessageBox.Show(client.GetData(1));</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span> }</pre>
</div>
</div>
<p>Let’s hit F5 and run our XBAP and see what happens.</p>
<p>AND BAMMMM a big ugly exception is thown.</p>
<p>InvalidOperationException</p>
<p>The WSHttpBinding with name WSHttpBinding failed validation because it contains a BindingElement with type System.ServiceModel.Channels.SymmetricSecurityBindingElement which is not supported in partial trust</p>
<p>which in VS looks like this</p>
<p><a href="http://marlongrech.files.wordpress.com/2009/02/wcferror.jpg"><img style="display:inline;border-width:0;" title="WCFError" src="http://marlongrech.files.wordpress.com/2009/02/wcferror-thumb.jpg?w=244&#038;h=180" border="0" alt="WCFError" width="244" height="180" /></a></p>
<p>Yet I promised you guys that WCF is supported in Partial trust XBAPs…. And it is, it’s just that the default WCF EndPoint is not <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  By default a WCF Service has it’s EndPoint set up as WsHTTPBinding which is not supported in Partial trust XBAPs. In order to fix this Right click the app.config of your service and select &#8220;Edit WCF Configuration&#8221; (if this option is not available go to Tools &gt; WCF Service Configuration Editor then select open and specify the path of your App.config. Once you have the app.config opened in the editor Expand the Bindings Node and select the node under that. Open the Security tab and choose None as security level.</p>
<p><a href="http://marlongrech.files.wordpress.com/2009/02/changesecuritylevelofbinding.jpg"><img style="display:inline;border-width:0;" title="ChangeSecurityLevelOfBinding" src="http://marlongrech.files.wordpress.com/2009/02/changesecuritylevelofbinding-thumb.jpg?w=244&#038;h=112" border="0" alt="ChangeSecurityLevelOfBinding" width="244" height="112" /></a></p>
<p>Once that’s done run the app again.</p>
<h3>The Second error you’ll see</h3>
<p>And this time it’s a SecurityException saying</p>
<p>Request for the permission of type &#8216;System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&#8242; failed.</p>
<p><a href="http://marlongrech.files.wordpress.com/2009/02/seconderror.jpg"><img style="display:inline;border-width:0;" title="SecondError" src="http://marlongrech.files.wordpress.com/2009/02/seconderror-thumb.jpg?w=244&#038;h=84" border="0" alt="SecondError" width="244" height="84" /></a></p>
<p>In order to fix this Go to the XBAP project Properties and select Debug tab. Select the Start External Program option and enter the following exe path “C:\WINDOWS\System32\PresentationHost.exe” and in the Command Line arguments text field enter the following</p>
<p>-debug &lt;Path of XBAP&gt; –debugSecurityZoneUrl &lt;URL of service&gt;</p>
<p>in my case it was</p>
<p>-debug &#8220;D:\net resources\My Blog\XBAPAndWCF\XBAPClient\bin\Debug\XBAPClient.xbap&#8221; -debugSecurityZoneUrl <a href="http://localhost:53265/Service1.svc">http://localhost:53265/Service1.svc</a></p>
<p>[Update]</p>
<p>Thanks to <a href="http://www.julmar.com/blog/mark/">Mark Smith</a> I discovered a new an easier way of doing this. All you have to do is</p>
<p>1) Open XBAP project properties</p>
<p>2) Select Security tab</p>
<p>3) Advanced button</p>
<p>4) Check &#8220;Grant application access to site of origin&#8221; (should be checked already)</p>
<p>5) Type in the URL into the textbox where the web service is running</p>
<p><a href="http://marlongrech.files.wordpress.com/2009/02/security.jpg"><img style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" title="Security" src="http://marlongrech.files.wordpress.com/2009/02/security-thumb.jpg?w=244&#038;h=107" border="0" alt="Security" width="244" height="107" /></a></p>
<p>We have to do this so that we set up an envirorment for the XBAP just like it is running from the same URL of the service.</p>
<h3>Conclusion</h3>
<p>And there you have it. Now you should be armed and ready to start doing XBAPs that consume WCF service.</p>
<p><a href="http://cid-96f8d49aa44c79c1.skydrive.live.com/self.aspx/Public/XBAPAndWCF.zip" target="_blank">Download sample application</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=286&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2009/02/16/xbaps-part-2-consuming-wcf-services-from-an-xbap/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2009/02/newwcf-thumb.jpg" medium="image">
			<media:title type="html">NewWCF</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2009/02/addservicereference-thumb.jpg" medium="image">
			<media:title type="html">AddServiceReference</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2009/02/changetheservicetohaveasync-thumb.jpg" medium="image">
			<media:title type="html">ChangeTheServiceToHaveASYNC</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2009/02/wcferror-thumb.jpg" medium="image">
			<media:title type="html">WCFError</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2009/02/changesecuritylevelofbinding-thumb.jpg" medium="image">
			<media:title type="html">ChangeSecurityLevelOfBinding</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2009/02/seconderror-thumb.jpg" medium="image">
			<media:title type="html">SecondError</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2009/02/security-thumb.jpg" medium="image">
			<media:title type="html">Security</media:title>
		</media:content>
	</item>
		<item>
		<title>My wish came true&#8230;. I can now use DataBinding in a ConverterParameter</title>
		<link>http://marlongrech.wordpress.com/2008/08/03/my-wish-came-true-i-can-now-use-databinding-in-a-converterparameter/</link>
		<comments>http://marlongrech.wordpress.com/2008/08/03/my-wish-came-true-i-can-now-use-databinding-in-a-converterparameter/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 13:06:38 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/08/03/my-wish-came-true-i-can-now-use-databinding-in-a-converterparameter/</guid>
		<description><![CDATA[WARNING: This solution uses reflection so it cannot be used in XBAP or applications running with Partial Trust.
One of the things I hear often in forums and also lately on the WPF Disciples mailing list is, &#8220;How come I cannot use binding in ConverterParameters?&#8221; or &#8220;My personal pet peeve is the ConverterParameter. Ah if I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=191&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>WARNING: This solution uses reflection so it cannot be used in XBAP or applications running with Partial Trust.</p>
<p>One of the things I hear often in forums and also lately on the <a href="http://groups.google.com/group/wpf-disciples">WPF Disciples</a> mailing list is, &#8220;How come I cannot use binding in ConverterParameters?&#8221; or &#8220;My personal pet peeve is the ConverterParameter. Ah if I could only bind it to something in my ViewModel!!&#8221;</p>
<p>So let&#8217;s start by seeing why you cannot use binding for a ConverterParameter. The simple answer to that would be, a ConverterParameter is not a DependencyProperty thus you cannot use Binding. Yet the following question would be, WHY isn&#8217;t it a DependencyProperty?? Well there are a few things we must have a look at here. First of all the Binding class is not a DependencyObject. Secondly the BindingBase class seals itself when the binding activates, this means that once the Binding is activated you cannot change any properties. If you try to do so you get a nice InvalidOperationException saying &#8220;Binding cannot be changed after it has been used&#8221;.</p>
<p>Yet, the WPF platform is very flexible so I decided to start digging into it and see what I can come up with (obviously always consulting the <a href="http://www.drwpf.com/">WPF KING OF KINGS, Dr.WPF)</a>.</p>
<h3>The first idea&#8230;</h3>
<p>My first idea was to create a MarkupExtension that spits out an instance of an object that has a Dependency Property that you can bind with (some sort of Proxy that can update the Binding and specify a new value). So your XAML would look like this</p>
<p>{Binding ElementName=checkbox1, Path=IsChecked, Converter={StaticResource conv}, ConverterParameter={code:BindableParameter {Binding ElementName=checkbox2, Path=IsChecked}} }</p>
<p>Yet this failed miserably because of a simple yet hard problem in the design I had. You cannot get the BindingExpression of that binding because the BindingExpression is not constructed yet. I could get the Binding instance but the Binding instance alone is nothing without the BindingExpression since you can update a binding by calling the UpdateSource method of the Binding expression.</p>
<h3>Back to the drawing boards&#8230;. and finally the Solution</h3>
<p>So let&#8217;s have a look at what we want to achieve. We want to</p>
<p>1. Let the User Specify a Binding for a ConverterParameter somewhere in the XAML<br />
2. Make sure that when a value of the ConverterParameter changes the original Binding gets updated.</p>
<p>In order to solve problem 1, I decided to go to my best friend, AttachedProperties. Basically the idea is that you set an attached property that specifies the value of a ConverterParameter of a specific binding. So the XAML would look something like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> &lt;ToggleButton Content=<span style="color:#006080;">"I am bound to the checkbox"</span> x:Name=<span style="color:#006080;">"toggle"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>      code:BindableParameter.BindParameter=<span style="color:#006080;">"{code:BindableParameter ToggleButton.IsChecked, Binding={Binding ElementName=checkbox2, Path=IsChecked}}"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>      IsChecked=<span style="color:#006080;">"{Binding Converter={StaticResource conv}, ElementName=checkbox1, Path=IsChecked}"</span>/&gt;</pre>
</div>
</div>
<p>In the attached property you specify what Binding you want to target by supplying the DependencyProperty to which the original Binding is applied. In this case the original Binding is for the IsChecked property of the ToggleButton. Then you can simple specify the Binding you want for the ConverterParameter by setting the Binding property of the BindableParameter markup extension.</p>
<p>Now that you have supplied this information, the BindableParameter can do some tricks for you. Basically once you specify the BindParameter attached property the BindableParameter will get a BindingExpression for the original binding and make sure to set the ConverterParameter when ever needed. Have a look at the PropertyChanged event handler of the BindParameter Attached property.</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:1000px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> OnBindParameterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     FrameworkElement element = d <span style="color:#0000ff;">as</span> FrameworkElement;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#0000ff;">if</span> (element == <span style="color:#0000ff;">null</span>)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         <span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> InvalidOperationException(<span style="color:#006080;">"BindableParameter can be applied to a FrameworkElement only"</span>);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     BindableParameter parameter = (BindableParameter)e.NewValue;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>     element.Initialized += <span style="color:#0000ff;">delegate</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>     {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>         parameter.TargetExpression = BindingOperations.GetBindingExpression(element, parameter.TargetProperty);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>         parameter.TargetBinding = BindingOperations.GetBinding(element, parameter.TargetProperty);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>         <span style="color:#008000;">//update the converter parameter </span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>         InvalidateBinding(parameter);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>     };</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span> }</pre>
</div>
</div>
<p>As you can see, in the above code, all we are doing is get the instance of the BindingExpression and storing it in an instance variable(TargetExpression). Same goes for the Binding, storing it in the TargetBinding. Now that we have all this information we can do Step 2 (Make sure that when a value of the ConverterParameter changes the original Binding gets updated)</p>
<p>In the Property Changed event handler of the Binding we must force the BindingExpression to update and change the value of the converter parameter. This can be done quite easily one would say but there are 2 main problems.</p>
<p>Problem 1. How to make the binding work for the BindableParamater?? The BindableParameter is not in the LogicalTree because it is just a DependencyObject thus the Binding that you set will not be valid. In order to overcome this issue we can do a little trick with the Freezable class. If we make the BindableParameter inherit from the Freezable it gets the inheritance context thus Binding is now valid. <a href="http://www.drwpf.com/Blog/Default.aspx?tabid=36&amp;EntryID=36">For more info on this technique visit Dr. WPF blog</a></p>
<p>Problem 2. How can we change the value of ConverterParameter if the Binding is sealed (remember? the Binding class will throw an InvalidOperationException if we try to change a property of the Binding). This problem required me to do some hard core disassembling of the Binding class and I found out that each Property Setter of the Binding class has a call to a method CheckSealed. This method looks like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">internal</span> <span style="color:#0000ff;">void</span> CheckSealed()</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">this</span>._isSealed)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         <span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> InvalidOperationException(SR.Get(<span style="color:#006080;">"ChangeSealedBinding"</span>));</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     }</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> }</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span></pre>
</div>
</div>
<p>So what we must do is to get the _isSealed Field info by reflection and change it&#8217;s value to false, then change the ConverterParameter and finally put the _isSealed value back to true so that WPF does not notice us playing tricks on him <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Once we do that we are free to change the value of the ConverterParameter and we can Refresh the Binding</p>
<p>Something like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:1000px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> InvalidateBinding(BindableParameter param)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">if</span> (param.TargetBinding != <span style="color:#0000ff;">null</span> &amp;&amp; param.TargetExpression != <span style="color:#0000ff;">null</span>)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         <span style="color:#008000;">//this is a hack to trick the WPF platform in thining that the binding is not sealed yet and then change the value of the converter parameter</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>         <span style="color:#0000ff;">bool</span> isSealed = (<span style="color:#0000ff;">bool</span>)isSealedFieldInfo.GetValue(param.TargetBinding);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         <span style="color:#0000ff;">if</span> (isSealed)<span style="color:#008000;">//change the is sealed value</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>             isSealedFieldInfo.SetValue(param.TargetBinding, <span style="color:#0000ff;">false</span>);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>         param.TargetBinding.ConverterParameter = param.ConverterParameterValue;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>         <span style="color:#0000ff;">if</span> (isSealed)<span style="color:#008000;">//put the is sealed value back as it was...</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>             isSealedFieldInfo.SetValue(param.TargetBinding, <span style="color:#0000ff;">true</span>);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>         <span style="color:#008000;">//force an update to the binding</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>         param.TargetExpression.UpdateTarget();</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>     }</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span> }</pre>
</div>
</div>
<p>And there it is &#8230;. I can now use binding for a ConverterParameter and the XAML looks like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:1000px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> &lt;Window.Resources&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>    &lt;code:DummyConverter x:Key=<span style="color:#006080;">"conv"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> &lt;/Window.Resources&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> &lt;StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>    &lt;CheckBox x:Name=<span style="color:#006080;">"checkbox2"</span> Content=<span style="color:#006080;">"I am the parameter for the converter"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>    &lt;CheckBox x:Name=<span style="color:#006080;">"checkbox1"</span> Content=<span style="color:#006080;">"I am bound directly"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>    &lt;ToggleButton Content=<span style="color:#006080;">"I am bound to the checkbox"</span> x:Name=<span style="color:#006080;">"toggle"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>                  code:BindableParameter.BindParameter=<span style="color:#006080;">"{code:BindableParameter ToggleButton.IsChecked, Binding={Binding ElementName=checkbox2, Path=IsChecked}}"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>                  IsChecked=<span style="color:#006080;">"{Binding Converter={StaticResource conv}, ElementName=checkbox1, Path=IsChecked}"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span> &lt;/StackPanel&gt;</pre>
</div>
</div>
<p>Hope you enjoy this &#8230;..</p>
<p><a href="http://cid-96f8d49aa44c79c1.skydrive.live.com/self.aspx/Public/BinableConverterParameters.rar">DOWNLOAD SOURCE CODE</a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f08%2f03%2fmy-wish-came-true-i-can-now-use-databinding-in-a-converterparameter%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f08%2f03%2fmy-wish-came-true-i-can-now-use-databinding-in-a-converterparameter%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/191/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/191/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/191/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=191&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/08/03/my-wish-came-true-i-can-now-use-databinding-in-a-converterparameter/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f08%2f03%2fmy-wish-came-true-i-can-now-use-databinding-in-a-converterparameter%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>NameScope, my name is Marlon you know&#8230;.</title>
		<link>http://marlongrech.wordpress.com/2008/08/02/namescope-my-name-is-marlon-you-know/</link>
		<comments>http://marlongrech.wordpress.com/2008/08/02/namescope-my-name-is-marlon-you-know/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 09:26:00 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/08/02/namescope-my-name-is-marlon-you-know/</guid>
		<description><![CDATA[Introduction
Did you ever wonder why you can have the same name registered for different parts of your XAML? Here is an example (notice the name &#8220;border&#8221; in different parts of the XAML)


   1: &#60;ContentControl Content="Hello world" x:Name="border"&#62;
   2:     &#60;ContentControl.ContentTemplate&#62;
   3:      [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=189&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>Introduction</h3>
<p>Did you ever wonder why you can have the same name registered for different parts of your XAML? Here is an example (notice the name &#8220;border&#8221; in different parts of the XAML)</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:1000px;line-height:12pt;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> &lt;ContentControl Content=<span style="color:#006080;">"Hello world"</span> x:Name=<span style="color:red;"><strong>"border"</strong></span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span>     &lt;ContentControl.ContentTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span>         &lt;DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span>             &lt;Border BorderBrush=<span style="color:#006080;">"Silver"</span> BorderThickness=<span style="color:#006080;">"1"</span> CornerRadius=<span style="color:#006080;">"5"</span> Margin=<span style="color:#006080;">"20"</span> x:Name=<span style="color:red;"><strong>"border"</strong></span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span>                 &lt;StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   6:</span>                     &lt;TextBlock Text=<span style="color:#006080;">"I am a DataTemplate"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   7:</span>                     &lt;ContentPresenter Content=<span style="color:#006080;">"{Binding}"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span> VerticalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   8:</span>                 &lt;/StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   9:</span>             &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  10:</span>         &lt;/DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  11:</span>     &lt;/ContentControl.ContentTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  12:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  13:</span>     &lt;ContentControl.Template&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  14:</span>         &lt;ControlTemplate TargetType=<span style="color:#006080;">"ContentControl"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  15:</span>             &lt;Border BorderBrush=<span style="color:#006080;">"Silver"</span> BorderThickness=<span style="color:#006080;">"1"</span> CornerRadius=<span style="color:#006080;">"5"</span> x:Name=<span style="color:red;"><strong>"border"</strong></span> &gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  16:</span>                 &lt;StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  17:</span>                     &lt;TextBlock Text=<span style="color:#006080;">"I am a ControlTemplate"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  18:</span>                     &lt;ContentPresenter /&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  19:</span>                 &lt;/StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  20:</span>             &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  21:</span>         &lt;/ControlTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  22:</span>     &lt;/ContentControl.Template&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  23:</span> &lt;/ContentControl&gt;</pre>
</div>
</div>
<p>As you can see the XAML above <strong>&#8220;<span style="color:#ff0000;">border</span>&#8220;</strong> is registered 3 times. This is possible because of WPF <a href="http://msdn.microsoft.com/en-us/library/ms746659.aspx">Namescopes</a>. Basically the Window(that I am using to put the ContentControl in) has it&#8217;s own NameScope the DataTemplate also has it&#8217;s own and also the ControlTemplate (some actually implement the <a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.inamescope(VS.85).aspx">INameScope</a> interface themselves).</p>
<p>Namescopes are a very important concept that one must understand. Why? Let me give you an example.</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:1000px;line-height:12pt;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> &lt;StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span>     &lt;ContentControl Content=<span style="color:#006080;">"Hello world"</span> x:Name=<span style="color:#006080;">"border"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span>         &lt;ContentControl.ContentTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span>             &lt;DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span>                 &lt;Border BorderBrush=<span style="color:#006080;">"Silver"</span> BorderThickness=<span style="color:#006080;">"1"</span> CornerRadius=<span style="color:#006080;">"5"</span> Margin=<span style="color:#006080;">"20"</span> x:Name=<span style="color:#006080;">"border"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   6:</span>                     &lt;StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   7:</span>                         &lt;TextBlock Text=<span style="color:#006080;">"I am a DataTemplate"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   8:</span>                     &lt;ContentPresenter Content=<span style="color:#006080;">"{Binding}"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span> VerticalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   9:</span>                     &lt;CheckBox x:Name=<span style="color:red;"><strong>"checkbox"</strong></span> Content=<span style="color:#006080;">"Checkbox here"</span> /&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  10:</span>                 &lt;/StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  11:</span>                 &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  12:</span>             &lt;/DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  13:</span>         &lt;/ContentControl.ContentTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  14:</span>     &lt;/ContentControl&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  15:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  16:</span>     &lt;ToggleButton Content=<span style="color:#006080;">"Toggle button bound to checkbox"</span> IsChecked=<span style="color:red;"><strong>"{Binding ElementName=checkbox, Path=IsChecked}"</strong></span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  17:</span> &lt;/StackPanel&gt;</pre>
</div>
</div>
<p>The XAML above has a ContentControl that has a ContentTemplate with a CheckBox and a Toggle button that is trying to bind to that checkbox. The binding is using ElementName to try to find the checkbox yet that will <strong>NOT</strong> be successful because the &#8220;checkbox&#8221; is registered in a different NameScope (remember a DataTemplate has it&#8217;s own NameScope!)</p>
<h3></h3>
<h3>Namescope and Animations</h3>
<p>Another scenario where NameScopes are heavily used are animation. When you create a Storyboard you specify a Storyboard.TargetName attached property to specify which element you want to animate. Something like this&#8230;.</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:1000px;line-height:12pt;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> &lt;Window.Resources&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span>     &lt;Storyboard x:Key=<span style="color:#006080;">"animation"</span> &gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span>         &lt;DoubleAnimation To=<span style="color:#006080;">"50"</span> AutoReverse=<span style="color:#006080;">"True"</span> RepeatBehavior=<span style="color:#006080;">"Forever"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span>                        <span style="color:red;"><strong>Storyboard.TargetName=<span style="color:red;">"button"</span> </strong></span> Storyboard.TargetProperty=<span style="color:#006080;">"Height"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span>     &lt;/Storyboard&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   6:</span> &lt;/Window.Resources&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   7:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   8:</span> &lt;Window.Triggers&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   9:</span>     &lt;EventTrigger RoutedEvent=<span style="color:#006080;">"FrameworkElement.Loaded"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  10:</span>         &lt;BeginStoryboard Storyboard=<span style="color:#006080;">"{StaticResource animation}"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  11:</span>     &lt;/EventTrigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  12:</span> &lt;/Window.Triggers&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  13:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  14:</span> &lt;StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  15:</span>     &lt;ContentControl Content=<span style="color:#006080;">"Hello world"</span> x:Name=<span style="color:#006080;">"border"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  16:</span>         &lt;ContentControl.ContentTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  17:</span>             &lt;DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  18:</span>                 &lt;Border BorderBrush=<span style="color:#006080;">"Silver"</span> BorderThickness=<span style="color:#006080;">"1"</span> CornerRadius=<span style="color:#006080;">"5"</span> Margin=<span style="color:#006080;">"20"</span> x:Name=<span style="color:#006080;">"border"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  19:</span>                     &lt;StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  20:</span>                         &lt;TextBlock Text=<span style="color:#006080;">"I am a DataTemplate"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  21:</span>                     &lt;ContentPresenter Content=<span style="color:#006080;">"{Binding}"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span> VerticalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  22:</span>                     &lt;CheckBox x:Name=<span style="color:#006080;">"checkbox"</span> Content=<span style="color:#006080;">"Checkbox here"</span> /&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  23:</span>                 &lt;/StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  24:</span>                 &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  25:</span>             &lt;/DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  26:</span>         &lt;/ContentControl.ContentTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  27:</span>     &lt;/ContentControl&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  28:</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  29:</span>     &lt;ToggleButton Content=<span style="color:#006080;">"Toggle button bound to checkbox"</span> Height=<span style="color:#006080;">"25"</span> x:Name=<span style="color:red;"><strong>"button"</strong></span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  30:</span> &lt;/StackPanel&gt;</pre>
</div>
</div>
<p>The above code would execute as expected, the ToggleButton named &#8220;button&#8221; would start animating it&#8217;s height when the window is Loaded. But what if you want to animate something in the DataTemplate? If you try to create a Storyboard in the Resources section of the window to animate the Checkbox  named &#8220;checkbox&#8221; you would get an <strong>InvalidOperationException</strong> saying <strong><em>&#8216;checkbox&#8217; name cannot be found in the name scope of &#8216;NamescopeExample.Window1&#8242;. </em></strong>This is because the checkbox lives in a different NameScope from the storyboard. One thing you can do is to move the Storyboard in the DataTemplate.Resources so that the storyboard would be created in the same Namescope of the checkbox. Something like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:1000px;line-height:12pt;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> &lt;DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span>     &lt;DataTemplate.Resources&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span>         &lt;Storyboard x:Key=<span style="color:#006080;">"checkboxAnimation"</span> RepeatBehavior=<span style="color:#006080;">"Forever"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span>             &lt;ColorAnimation To=<span style="color:#006080;">"Red"</span> AutoReverse=<span style="color:#006080;">"True"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span>                 Storyboard.TargetName=<span style="color:#006080;">"checkbox"</span> Storyboard.TargetProperty=<span style="color:#006080;">"(Control.Background).(SolidColorBrush.Color)"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   6:</span>         &lt;/Storyboard&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   7:</span>     &lt;/DataTemplate.Resources&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   8:</span>     &lt;Border BorderBrush=<span style="color:#006080;">"Silver"</span> BorderThickness=<span style="color:#006080;">"1"</span> CornerRadius=<span style="color:#006080;">"5"</span> Margin=<span style="color:#006080;">"20"</span> x:Name=<span style="color:#006080;">"border"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   9:</span>         &lt;StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  10:</span>             &lt;TextBlock Text=<span style="color:#006080;">"I am a DataTemplate"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  11:</span>         &lt;ContentPresenter Content=<span style="color:#006080;">"{Binding}"</span> HorizontalAlignment=<span style="color:#006080;">"Center"</span> VerticalAlignment=<span style="color:#006080;">"Center"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  12:</span>         &lt;CheckBox x:Name=<span style="color:#006080;">"checkbox"</span> Content=<span style="color:#006080;">"Checkbox here"</span> Background=<span style="color:#006080;">"Black"</span> /&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  13:</span>     &lt;/StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  14:</span>     &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  15:</span>     &lt;DataTemplate.Triggers&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  16:</span>         &lt;EventTrigger RoutedEvent=<span style="color:#006080;">"FrameworkElement.Loaded"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  17:</span>             &lt;BeginStoryboard Storyboard=<span style="color:#006080;">"{StaticResource checkboxAnimation}"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  18:</span>         &lt;/EventTrigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  19:</span>     &lt;/DataTemplate.Triggers&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  20:</span> &lt;/DataTemplate&gt;</pre>
</div>
</div>
<h3>Namescope and C# code</h3>
<p>But what if you are creating elements in code&#8230; One would say out &#8220;Easy&#8230; Just set the name property&#8221; like so&#8230;.</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> ToggleButton button = <span style="color:#0000ff;">new</span> ToggleButton();</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span> button.Height = 25;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span> button.Content = <span style="color:#006080;">"Toggle Button"</span>;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span> button.Name = <span style="color:#006080;">"button"</span>;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span> container.Children.Add(button);</pre>
</div>
</div>
<p>No no no and NO&#8230;. This does not work! Setting the Name property of the control will not register that Control to the NameScope. So how to do it? Easy.. have a look</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> ToggleButton button = <span style="color:#0000ff;">new</span> ToggleButton();</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span> button.Height = 25;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span> button.Content = <span style="color:#006080;">"Toggle Button"</span>;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span> NameScope.GetNameScope(<span style="color:#0000ff;">this</span>).RegisterName(<span style="color:#006080;">"button"</span>, button);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span> container.Children.Add(button);</pre>
</div>
</div>
<p>All you have to do is, first find in which NameScope you want to register the element (in this case I want to add it to the Window NameScope), secondly register the element to that NameScope by using the <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.registername(VS.85).aspx">RegisterName</a> method of the INameScope interface.</p>
<p>You can even use the RegisterName method of the FrameworkElement. For example if I want to add a Button to a StackPanel, you can ask the StackPanel to register the name of the Button. In my case I could have done like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> ToggleButton button = <span style="color:#0000ff;">new</span> ToggleButton();</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span> button.Height = 25;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span> button.Content = <span style="color:#006080;">"Toggle Button"</span>;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span> container.RegisterName(<span style="color:#006080;">"button"</span>, button);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span> container.Children.Add(button);</pre>
</div>
</div>
<h3></h3>
<h3>Some other tips and related articles&#8230;</h3>
<p>If you have an element in the Resources section you will not be allowed to set a name for that element. One way of enabling that element with a name is by using the RegisterName method of the NameScope class as explained above (you might want to set the name for animations for example).</p>
<p>You might want to also implement your own NameScope by implementing the INameScope interface. I saw a <a href="http://agsmith.wordpress.com/2008/07/17/elementname-binding-in-tooltips-borrowing-a-namescope/">very clever solution by doing such a thing</a>, by WPF super hero Andrew Smith.</p>
<p><a href="http://joshsmithonwpf.wordpress.com/2008/07/22/enable-elementname-bindings-with-elementspy/">Josh Smith the WPF Rock star and his Element Spy</a> is also a brilliant article that must be read..</p>
<p>
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f08%2f02%2fnamescope-my-name-is-marlon-you-know%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f08%2f02%2fnamescope-my-name-is-marlon-you-know%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/189/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/189/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/189/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=189&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/08/02/namescope-my-name-is-marlon-you-know/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f08%2f02%2fnamescope-my-name-is-marlon-you-know%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>AvalonControlsLibrary DatePicker refactored</title>
		<link>http://marlongrech.wordpress.com/2008/04/04/avaloncontrolslibrary-datepicker-refactored/</link>
		<comments>http://marlongrech.wordpress.com/2008/04/04/avaloncontrolslibrary-datepicker-refactored/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 17:29:57 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF Custom Controls]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/04/04/avaloncontrolslibrary-datepicker-refactored/</guid>
		<description><![CDATA[Recently I received some requests from people to support some more styling for the DatePicker control. The initial idea for the DatePicker was to create a &#8220;lookless&#8221; control and then users would create a ControlTemplate to change the look and feel of the control (which is still 100% possible, see here for more info). Yet [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=159&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently I received some requests from people to support some more styling for the <a href="http://marlongrech.wordpress.com/2007/09/11/wpf-datepicker/" target="_blank">DatePicker</a> control. The initial idea for the DatePicker was to create a &#8220;lookless&#8221; control and then users would create a ControlTemplate to change the look and feel of the control (which is still 100% possible, <a href="http://marlongrech.wordpress.com/2007/09/11/wpf-datepicker/" target="_blank">see here for more info</a>). Yet sometimes users do not want to totally change the look of the control, sometimes it&#8217;s more a matter of changing colors and minor things like that. So I decided to make the DatePicker support some more styling so that users don&#8217;t need to create a new ControlTemplate for the DatePicker if they only need to change minor things in the DatePicker UI.</p>
<p><img src="http://marlongrech.files.wordpress.com/2008/04/datepicker.jpg" /></p>
<p>As you can see in the image above I added 5 new properties for styling the control. All of these properties are optional and if they are not set, a default value will be set for you.</p>
<h4>DayCellTemplate</h4>
<p>This property accepts a DataTemplate where the user can specify how each Day cell should look. The DataTemplate is fed with a DayCell object as DataContext. The DayCell class has the following properties which you can use in the DataTemplate</p>
<table border="0" cellpadding="2" cellspacing="0" width="782">
<tr>
<td valign="top" width="135"><b><i>Property Name</i></b></td>
<td valign="top" width="129"><b><i>Type</i></b></td>
<td valign="top" width="516"><b><i>Description</i></b></td>
</tr>
<tr>
<td valign="top" width="137"><b>DayNumber</b></td>
<td valign="top" width="128">int</td>
<td valign="top" width="516">Represents the Day number</td>
</tr>
<tr>
<td valign="top" width="138"><b>MonthNumber </b></td>
<td valign="top" width="127">int</td>
<td valign="top" width="516">Represents the Month number</td>
</tr>
<tr>
<td valign="top" width="139"><b>YearNumber </b></td>
<td valign="top" width="127">int</td>
<td valign="top" width="516">Represents the Year number</td>
</tr>
<tr>
<td valign="top" width="140"><b>IsEnabled </b></td>
<td valign="top" width="126">bool</td>
<td valign="top" width="516">Flag that indicates if the item falls out of the MinDate and MaxDate range</td>
</tr>
<tr>
<td valign="top" width="141"><b>IsInCurrentMonth</b></td>
<td valign="top" width="126">bool</td>
<td valign="top" width="516">Flag that indicates if the item is in the current selected month</td>
</tr>
</table>
<p>Here is a sample DataTemplate for the <i>DayCellTemplate.</i></p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;Border Name=<span style="color:#006080;">"border"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;TextBlock Text=<span style="color:#006080;">"{Binding DayNumber}"</span> Name=<span style="color:#006080;">"dayCell"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    &lt;DataTemplate.Triggers&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;!--This trigger <span style="color:#0000ff;">is</span> to <span style="color:#0000ff;">do</span> some thing with the template when an item <span style="color:#0000ff;">is</span> selected--&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;DataTrigger Binding=<span style="color:#006080;">"{Binding RelativeSource={</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                                RelativeSource AncestorType={x:Type ListBoxItem}},</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">                                Path=IsSelected}"</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                     Value=<span style="color:#006080;">"True"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            &lt;Setter Property=<span style="color:#006080;">"Background"</span> Value=<span style="color:#006080;">"Blue"</span> TargetName=<span style="color:#006080;">"border"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;/DataTrigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;!--This <span style="color:#0000ff;">is</span> <span style="color:#0000ff;">for</span> those dates that fall <span style="color:#0000ff;">out</span> of the MinDate and MaxDate.--&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;DataTrigger Binding=<span style="color:#006080;">"{Binding IsEnabled}"</span> Value=<span style="color:#006080;">"False"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            &lt;Setter Property=<span style="color:#006080;">"Background"</span> Value=<span style="color:#006080;">"Gray"</span> TargetName=<span style="color:#006080;">"border"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;/DataTrigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;DataTrigger Binding=<span style="color:#006080;">"{Binding IsInCurrentMonth}"</span> Value=<span style="color:#006080;">"False"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;Setter Property=<span style="color:#006080;">"Foreground"</span> Value=<span style="color:#006080;">"Gray"</span> TargetName=<span style="color:#006080;">"dayCell"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;/DataTrigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;/DataTemplate.Triggers&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;/DataTemplate&gt;</pre>
</div>
</div>
<p>So basically the DayCellTemplate will give you a lot of flexibility in terms of what you can do with the UI of the DatePicker because you can make the Day cell look however you want without the need of re building the whole UI for the control.</p>
<h4></h4>
<h4>DayHeaderTemplate</h4>
<p>The DayHeaderTemplate is again another DataTemplate, this time it will be a DataTemplate for the Header Day cell which basically is the Text -&gt; Sun, Mon, Tue etc.. The DataTemplate that you set as being the DayHeaderTemplate will be passed a string object as DataContext that contains the Text for the Header (ex. Mon, Tue etc..) Here is an example of a DataTemplate that can be applied for the DayHeaderTemplate property.</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;Border Background=<span style="color:#006080;">"Yellow"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;TextBlock Foreground=<span style="color:#006080;">"Lime"</span> Text=<span style="color:#006080;">"{Binding}"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;/DataTemplate&gt;</pre>
</div>
</div>
<h4>MonthBackButtonStyle/MonthForwardButtonStyle</h4>
<p>These two properties are the styles for the back and forward month navigation buttons of the DatePicker. Basically you can apply a style for the Back and Forward button in any way you like. So you may decide even to create a ControlTemplate for these two buttons which would be quite easy. Something like this&#8230;.</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;Style TargetType=<span style="color:#006080;">"Button"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;Setter Property=<span style="color:#006080;">"Template"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;Setter.Value&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;ControlTemplate TargetType=<span style="color:#006080;">"Button"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">                &lt;Border BorderBrush=<span style="color:#006080;">"Pink"</span> Width=<span style="color:#006080;">"20"</span> BorderThickness=<span style="color:#006080;">"2"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                    &lt;TextBlock Text=<span style="color:#006080;">"&lt;"</span> FontWeight=<span style="color:#006080;">"Bold"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">                &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;/ControlTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;/Setter.Value&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;/Setter&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;/Style&gt;</pre>
</div>
</div>
<h4>MonthSelectorStyle</h4>
<p>Last but not least is the MonthSelectorStyle property. This property enables you to set a style for the Months drop down list aka ComboBox. Since here we are setting a scyle for a ComboBox a user has full control over that combobox. One can decide to do a ControlTemplate for the ComboBox or maybe just set an ItemTemplate for the elements inside it&#8230; Here is a style that I used in the demo app of the DatePicker&#8230;</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;Style TargetType=<span style="color:#006080;">"ComboBox"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;Setter Property=<span style="color:#006080;">"Background"</span> Value=<span style="color:#006080;">"Yellow"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    &lt;Setter Property=<span style="color:#006080;">"ItemContainerStyle"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;Setter.Value&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            &lt;Style TargetType=<span style="color:#006080;">"ComboBoxItem"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                &lt;Setter Property=<span style="color:#006080;">"Background"</span> Value=<span style="color:#006080;">"Yellow"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            &lt;/Style&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;/Setter.Value&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    &lt;/Setter&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;Setter Property=<span style="color:#006080;">"ItemTemplate"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;Setter.Value&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">                &lt;TextBlock Foreground=<span style="color:#006080;">"Red"</span> Text=<span style="color:#006080;">"{Binding}"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;/DataTemplate&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;/Setter.Value&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;/Setter&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;/Style&gt;</pre>
</div>
</div>
<h4>Conclusion</h4>
<p>I think that with the introduction of these properties the DatePicker control will be much more easy to use and re style. Again I would suggest that if you need to totally re arrange the look of this control the best way would be to use a ControlTemplate and change the whole look of the control, yet if all you need is to change some colors and other minor things, these new properties will help you out in the process.</p>
<p>The new version of the DatePicker will be available in the <a href="https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=AvalonControlsLib&amp;ReleaseId=11518" target="_blank">AvalonControlsLibrary v3</a>, yet I know you can&#8217;t wait until you get your hands on this so I created a demo app for you  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>I am open to suggestions as usual! Please let me know if there is something missing or something that you would like to have in YOUR AvalonControlsLibarary DatePicker <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And as my friend <a href="http://www.sachabarber.net" target="_blank">Sacha Barber</a> says &#8211; &#8220;It&#8217;s all good!&#8221; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><a href="http://cid-96f8d49aa44c79c1.skydrive.live.com/self.aspx/Public/DatePickerRefactored.zip" target="_blank">Download Demo Project</a></p>
<p>
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f04%2f04%2favaloncontrolslibrary-datepicker-refactored%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f04%2f04%2favaloncontrolslibrary-datepicker-refactored%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/159/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/159/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/159/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=159&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/04/04/avaloncontrolslibrary-datepicker-refactored/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2008/04/datepicker.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f04%2f04%2favaloncontrolslibrary-datepicker-refactored%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Nice locking article</title>
		<link>http://marlongrech.wordpress.com/2008/03/23/nice-locking-article/</link>
		<comments>http://marlongrech.wordpress.com/2008/03/23/nice-locking-article/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 21:47:03 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/?p=151</guid>
		<description><![CDATA[My friend Karl, created an article on locking. It is really nice because he made some dead simple examples that are not only interesting but funny to read&#8230;
You must read his article&#8230;.
Have loads of fun reading it  
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=151&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My friend Karl, created <a href="http://karlagius.wordpress.com/2008/03/23/the-parable-of-the-bathroom/">an article on locking</a>. It is really nice because he made some dead simple examples that are not only interesting but funny to read&#8230;</p>
<p>You must <a href="http://karlagius.wordpress.com/2008/03/23/the-parable-of-the-bathroom/">read his article</a>&#8230;.</p>
<p>Have loads of fun reading it <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/151/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/151/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/151/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=151&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/03/23/nice-locking-article/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a File Explorer in WPF using MVC+M</title>
		<link>http://marlongrech.wordpress.com/2008/03/21/creating-a-file-explorer-in-wpf-using-mvcm/</link>
		<comments>http://marlongrech.wordpress.com/2008/03/21/creating-a-file-explorer-in-wpf-using-mvcm/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 16:51:37 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/03/21/creating-a-file-explorer-in-wpf-using-mvcm/</guid>
		<description><![CDATA[Introduction
In my previous article I explained how one can use the Mediator Pattern together with the MVC Pattern to structure the code in a very neat way. If you did not read my previous article I would suggest that you do, since I am basing this post on the assumption that readers already read that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=145&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>Introduction</h3>
<p>In my <a href="http://marlongrech.wordpress.com/2008/03/20/more-than-just-mvc-for-wpf/" target="_blank">previous article</a> I explained how one can use the <a href="http://www.dofactory.com/Patterns/PatternMediator.aspx" target="_blank">Mediator Pattern</a> together with the <a href="http://www.codeproject.com/KB/WPF/MVCtoUnitTestinWPF.aspx" target="_blank">MVC Pattern</a> to structure the code in a very neat way. If you did not read my <a href="http://marlongrech.wordpress.com/2008/03/20/more-than-just-mvc-for-wpf/" target="_blank">previous article</a> I would suggest that you do, since I am basing this post on the assumption that readers already read that post.</p>
<p>I am writing this post because some friends from <a href="http://groups.google.com/group/wpf-disciples/" target="_blank">WPF Disciple</a> suggested that I use a better example for the MVC+M. I agree 100% with them since the example that I did in my previous post was not the best one I could pick up&#8230;</p>
<p>Today I&#8217;ve got a new problem that I want to solve using the MVC+M. As the title of the post suggest, we are going to build a File Explorer and hopefully it will look something like this.</p>
<p><img src="http://marlongrech.files.wordpress.com/2008/03/fileexplorer.jpg" /></p>
<p>Yea, that&#8217;s where AvalonControlsLibrary and all other projects of mine live <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>This application is very simple to explain because I would assume that everyone reading this post has used a File Explorer. Basically we have a TreeView that shows the directories and when a directory is selected the list of files in that directory show up on screen.</p>
<h3>The Problem</h3>
<p>The problem is that we do not have a fixed list of objects. The list is generated on the fly. If we had to load all directories in memory we would have a big performance hit + I don&#8217;t want to imagine the memory consumption. So for the TreeView I used the <a href="http://www.dofactory.com/Patterns/PatternFlyweight.aspx" target="_blank">Flyweight Design Pattern</a>. I will not go into details of this pattern since it is not the purpose of this post, but to summarize, each node loads a dummy child so that the user can expand the items. Once an item is expanded the TreeView controller loads the child directories of the directory being expanded.</p>
<p>You&#8217;ll say &#8220;OK&#8230; But what does this have to do with the Mediator?&#8221;. The Mediator comes in handy for our second problem. When an item is Selected the list of files show up in the file list (on the right hand side of our application).</p>
<p>So the problem here is, we have a Dynamic Hierarchal List + we have a Treeview (which does not have an IsSynchronizedWithCurrentItem property that can make the underlying ICollectionView notify us with the currently selected item). Speaking of which we now don&#8217;t even have one ICollectionView, instead we have one for each level.</p>
<p>How can we tell the File List Controller that an item is selected without coupling it with the Tree View Controller?</p>
<h3>The Solution (or at least, how I would do this&#8230;)</h3>
<p>In such a case the Mediator is key, because the mediator will make the communication between the 2 controller very easy and loosely coupled. Let me first introduce the entities we have here</p>
<p><b>Views</b></p>
<p>- DirectorySelectorView</p>
<p>- FileSelectorView</p>
<p><b>Controllers</b></p>
<p>- DirectorySelectorController (mentioned above as TreeView contoller)</p>
<p>- FileSelectorController (mentioned above as File List Controller)</p>
<p><b>Model</b></p>
<p>- FileSystemDataService</p>
<p>OK so lets&#8217; do this&#8230; And guess what we are going to do this in 3 steps once again.</p>
<p>Step 1  &#8211; Publish the Directory Selected message via the Mediator<br />
Step 2 &#8211; Register the FileSelectorController to receive a notification for the Directory Selected message.<br />
Step 3 &#8211; Handle the Directory Selected message in the FileSelectorController and get the files to display.</p>
<p>Lets now talk in C#. The following is the code to do the above mentioned 3 steps.</p>
<p><b>Step 1</b></p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">//event handler for the selecting changed</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">void</span> ItemSelected(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">{</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    TreeView treeView = (TreeView)e.OriginalSource;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//Send a message that an item is selected and pass the object selected</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    Mediator.NotifyColleagues(</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        Messages.DirectorySelectedChanged, treeView.SelectedItem);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</div>
</div>
<p><b>Step 2</b></p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> FileSelectorController()</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    Mediator.Register(<span style="color:#0000ff;">this</span>, <span style="color:#0000ff;">new</span>[]</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        Messages.DirectorySelectedChanged</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    });</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</div>
</div>
<p><b>Step 3</b></p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> MessageNotification(<span style="color:#0000ff;">string</span> message, <span style="color:#0000ff;">object</span> args)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">switch</span> (message)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">case</span> Messages.DirectorySelectedChanged:</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#008000;">//load all files for the directory specified</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            LoadFiles((DirectoryDisplayItem)args);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">break</span>;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</div>
</div>
<p>That&#8217;s all folks &#8230;. Download the full source code to see all the rest&#8230;</p>
<h3>Some Side notes to keep in mind</h3>
<p>Developers are like artists. Everyone has his own style. For example, right now the Mediator implementation that I did, is using an interface driven design where you have an interface IColleague and the mediator notifies the colleagues passing the message that is being sent. One can implement a Mediator that uses strongly typed delegate so that you can avoid doing the switch statement (in the MessageNotification method) and implementing the IColleague interface for each controller. So the implementation of such a Mediator would look like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">Register( IDictionary&lt;<span style="color:#0000ff;">string</span>, Action&gt; callbacks);</pre>
</div>
</div>
<p>The Colleague that want to register simple do the following</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">Register( <span style="color:#0000ff;">new</span> Dictionary&lt;<span style="color:#0000ff;">string</span>, Action&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">     { Messages.SelectionChanged, <span style="color:#0000ff;">delegate</span>(<span style="color:#0000ff;">object</span> obj){ <span style="color:#008000;">//DoSomething here  } }</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</div>
</div>
<p>This would totally eliminate the switch statement and the ICollegue interface&#8230;</p>
<p>One thing that I have been discussing with some friend from <a href="http://groups.google.com/group/wpf-disciples/" target="_blank">WPF Disciples</a> is, What about big systems? Would big systems have to define loads of Messages?</p>
<p>The answer (at least how I see it from previous experiences working with this pattern) is <b>NO</b>. Why? Because the messages would be only for the controllers part. The other parts of the system would not need such a thing because if the controllers can talk together, the other entities would not need to. If we take the example of the File Explorer, the Views do not need to communicate because the controllers are synchronizing with each other. The views are just reading the data from the controllers. The model does not need this system either because the model will just give data that is being requested from the controller. So, please do not misinterpret this and use this system all around because you would create a MONSTER!</p>
<p><a href="http://joshsmithonwpf.wordpress.com/" target="_blank">Josh Smith</a>, also pointed out a very good point. What about memory leaks? If controllers do not unregister from the mediator once that the contoller is disposed than the controller would still exist in memory. This is a fact! I did not implement an unregister in the mediator because till now I only had controllers that do not get disposed throughout the application life cycle. Yet to implement an unregister would be just a piece of cake. All you have to do is to ask the mediator to remove the reference to a specific controller when the contoller is being disposed.</p>
<p>Besides the Mediator, there are loads of other ways of doing this, yet I decided to stick to this one because currently I feel that this pattern is given me the flexibility I need.</p>
<h3>Conclusion</h3>
<p>I like how this works because I feel that I can have a loosely coupled and high cohesion code base.</p>
<p><i>Loosely coupled</i>, because the controllers know nothing about each other and I can just disable or reuse one of them at any point in time.<br />
<i>High cohesion</i>, because knowing that I can make controllers communicate in an easy way, I create controllers that have one responsibility.</p>
<h3>Credits</h3>
<p>Thanks to all WPF Disciples for the <a href="http://groups.google.com/group/wpf-disciples/browse_thread/thread/9e09733a0321adb6" target="_blank">brilliant discussion</a><br />
My friend <a href="http://karlagius.wordpress.com/" target="_blank">Karl Agius</a> for even some more discussions</p>
<h3><a href="http://cid-96f8d49aa44c79c1.skydrive.live.com/self.aspx/Public/MoreThanJustMVPPart2%20-%20FileExplorer.zip" target="_blank">Download the full source code of the Demo application.</a></h3>
<p>
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f21%2fcreating-a-file-explorer-in-wpf-using-mvcm%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f21%2fcreating-a-file-explorer-in-wpf-using-mvcm%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/145/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/145/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/145/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=145&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/03/21/creating-a-file-explorer-in-wpf-using-mvcm/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2008/03/fileexplorer.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f21%2fcreating-a-file-explorer-in-wpf-using-mvcm%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>More than Just MVC for WPF</title>
		<link>http://marlongrech.wordpress.com/2008/03/20/more-than-just-mvc-for-wpf/</link>
		<comments>http://marlongrech.wordpress.com/2008/03/20/more-than-just-mvc-for-wpf/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 13:18:24 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/03/20/more-than-just-mvc-for-wpf/</guid>
		<description><![CDATA[Introduction
First of all I am assuming that the readers already know how to use the MVC design pattern for WPF (or at least read about it and understand the concept). If not I would suggest that you read this brilliant post by Josh Smith. I am writing this article because recently I found a problem [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=143&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>Introduction</h3>
<p>First of all I am assuming that the readers already know how to use the MVC design pattern for WPF (or at least read about it and understand the concept). If not I would suggest that you <a href="http://www.codeproject.com/KB/WPF/MVCtoUnitTestinWPF.aspx" target="_blank">read this brilliant post</a> by <a href="http://joshsmithonwpf.wordpress.com/" target="_blank">Josh Smith</a>. I am writing this article because recently I found a problem when using the MVC in WPF and I think I found a neat solution. Well I said that &#8220;I&#8221; found the solution, that is not true. The pattern that I am going to talk about is called the <a href="http://www.dofactory.com/Patterns/PatternMediator.aspx" target="_blank">Mediator Pattern</a> and I found it in the <a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612" target="_blank">Gang of Four book</a> that I was reading recently. I decided to mix the 2 patterns together and the result was beautiful code.</p>
<p>Warning: This article is a bit long. Readers can fall fast asleep <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<h3>Problem Definition</h3>
<p>The way I see it, Views must be as small as possible and handle only one specific job. Let&#8217;s do a practical example. Let&#8217;s say we have an application that displays a list of products. The application also lets you click on a specific product and the details of that product would show on the side. A search feature is also provided in this application. So our application would look something like this (I coloured the different sections of the app to make them more obvious)</p>
<p><img src="http://marlongrech.files.wordpress.com/2008/03/mvcapp.gif" /></p>
<p>Let me introduce the Entities that we have here</p>
<p><b>Controllers (These are simple class nothing more)</b></p>
<p>- ProductListController</p>
<p>- ProductDetailsController</p>
<p>- SearchController</p>
<p><b>Views (These are all User Controls)</b></p>
<p>- ProductListView</p>
<p>- ProductDetailsView</p>
<p>- SearchView</p>
<p>All views create an instance of the related Controller and set the Controller instance as the DataContext. By doing this the View can data bind to the properties of the Controller and also the Controller can handle routed command and routed events from the View since the Controller is now in the WPF logical tree. In this way the View has 0 lines(excluding the InitializeComponents) of code in the code behind file and all logic is inside the Controller class. By doing this you can easily Unit Test the logic and also Designers can use tools such as Expression Blend without having any problem because the logic is handled in the controller class and not in the view itself. Just like MVC in Web so to speak. Imagine commands in WPF as being the Routed URL for the controller to handle.</p>
<p>One may say &#8220;Wow, that&#8217;s a lot of classes&#8221; but hey if you want to be flexible, scalable and have code reusability that is the way to go. If not, then go ahead and put everything in one class but the result will be strongly coupled entities that are not reusable. Sometimes this is perfectly acceptable and so YES go ahead and do that. But let&#8217;s say you need to do a Search feature in another page. With MVC you can just re-use the search view and search controller in the other page.</p>
<p>In the MVC for WPF (or better in one of the implementations), there is a strong use of Routed Commands (sometimes one may use also Routed Events, well at the end of the day a RoutedCommand is just a Routed Event + the <a href="http://www.dofactory.com/Patterns/PatternCommand.aspx" target="_blank">Command Pattern</a> nothing more). The problem with Routing Commands is that the communication is always done from child to parent in the logical tree. In the application above there is a need of something different. Basically the Controllers need a way how to communicate. Yet we do not want that the Controllers know about each other because if that was so why not create 1 View and 1 Controller. We must ensure that no coupling is made between the controllers.</p>
<p>In the sample application above the <i>ProductListController</i> is handling the SelectionChanged event of the <i>ProductListView. </i><i>ProductListController</i> needs to communicate this to the <i>ProductDetailsController</i> so that it updates the data that is currently being shown in the <i>ProductDetailsView</i>.</p>
<p><b><i>The question is how can you achieve this?</i></b></p>
<h3>The <a href="http://www.dofactory.com/Patterns/PatternMediator.aspx#UML" target="_blank">Mediator Pattern</a> to the rescue</h3>
<p>The Mediator pattern can be described as a ChatRoom. In a Chat room there are Colleagues (the persons in the Chat Room) and via the Mediator (the chat room itself) they exchange messages. The same can be applied for our Controllers. There would be 1 Mediator and all Controllers communicate to each other via the Mediator. In simple english the <b>Colleagues would be the Controllers.</b></p>
<p>The following is the Class Diagram for the application I mentioned above</p>
<p><img src="http://marlongrech.files.wordpress.com/2008/03/mvcm-diagram.png" /></p>
<p>The interface for the Mediator would look something like this</p>
<p><img src="http://marlongrech.files.wordpress.com/2008/03/mediator.jpg" /></p>
<p>The signature of the methods would look like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// Registers a Colleague to a specific message</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;param name="colleague"&gt;The colleague to register&lt;/param&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;param name="messages"&gt;The message to register to&lt;/param&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">void</span> Register(IColleague colleague, IEnumerable&lt;<span style="color:#0000ff;">string</span>&gt; messages);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// Notify all colleagues that are registered to the specific message</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;param name="message"&gt;The message for the notify by&lt;/param&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;param name="args"&gt;The arguments for the message&lt;/param&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">void</span> NotifyColleagues(<span style="color:#0000ff;">string</span> message, <span style="color:#0000ff;">object</span> args);</pre>
</div>
</div>
<p>The IColleague interface is an interface that all Controllers implement and looks like this</p>
<p><img src="http://marlongrech.files.wordpress.com/2008/03/colleague.jpg" /></p>
<p>The Signature for the MessageNotification would look like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// Notification from the Mediator</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;param name="message"&gt;The message type&lt;/param&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;param name="args"&gt;Arguments for the message&lt;/param&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">void</span> MessageNotification(<span style="color:#0000ff;">string</span> message, <span style="color:#0000ff;">object</span> args);</pre>
</div>
</div>
<h3>Aha&#8230;. but Marlon how does this solve the Problem ??!!??</h3>
<p>With the Mediator pattern Controllers can send messages to each other without knowing of each other. Let&#8217;s do an example to try and make this more clear. Lets use the problem that I described above.</p>
<p>&#8220;<i>ProductListController</i> is handling the SelectionChanged event of the <i>ProductListView. </i><i>ProductListController</i> needs to communicate this to the <i>ProductDetailsController</i> so that it updates the Data that is currently being shown in the <i>ProductDetailsView&#8221;</i></p>
<p>All we need to do is 3 things</p>
<p>- <b>1.0</b> <i>ProductDetailsController</i> registers to the SelectProduct message (the message is just a constant string defined in a common class named Messages)</p>
<p>- <b>1.1</b> <i>ProductDetailsController</i> updated the Selected Product when this message is sent.</p>
<p>- <b>2.0</b> <i>ProductListController</i> sends a message via the Mediator that a new product has been selected</p>
<p><b>Code for 1.0</b></p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> ProductDetailsController()</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">{</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//register to the mediator for the SelectProduct message</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    Mediator.Register(<span style="color:#0000ff;">this</span>, <span style="color:#0000ff;">new string</span>[]</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        Messages.SelectProduct</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    });</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">}</pre>
</div>
</div>
<p><b>Code for 1.1</b></p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// Notification from the Mediator</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;param name="message"&gt;The message type&lt;/param&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">/// &lt;param name="args"&gt;Arguments for the message&lt;/param&gt;</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> MessageNotification(<span style="color:#0000ff;">string</span> message, <span style="color:#0000ff;">object</span> args)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">{</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">switch</span> (message)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#008000;">//change the CurrentProduct to be the newly selected product</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">case</span> Messages.SelectProduct:</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            CurrentProduct = (Product)args;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">break</span>;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</div>
</div>
<p>This will set the CurrentProduct property of the ProductDetailsController to be the new product that has been selected (the product object has been sent via the Code in 2.0). The CurrentProduct property of the ProductDetailsController is being data bound in the view. When the CurrentProduct is set the property raises a PropertyChanged notification, so that the binding is updated with the new value.</p>
<p><b>Code for 2.0</b></p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#008000;">//event handler for the selection changed</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">void</span> SelectionChanged(<span style="color:#0000ff;">object</span> sender, SelectionChangedEventArgs e)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">{</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    <span style="color:#008000;">//Notify that the selected item has changed</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    <span style="color:#0000ff;">if</span>(e.AddedItems != <span style="color:#0000ff;">null</span> &amp;&amp; e.AddedItems.Count &gt; 0)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        Mediator.NotifyColleagues(Messages.SelectProduct, e.AddedItems[0]);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">}</pre>
</div>
</div>
<h3></h3>
<h3>And this is what I call the MVC + M</h3>
<p>hehe&#8230; Funny name but for me this is doing miracles. I am currently using this in one of my projects at work and I can confirm that this absolutely works. One may say but this application could have been done with other thing that WPF offers, and I agree 100%. The example application that I used in this post can be easily implemented by putting the list of data in the Model and binding to it (like in MVVM). For the selection part, you can use the Current item of the ICollectionView and everything would work. Yet when you need to do more than just &#8220;Select item and data changes somewhere else&#8221; than the <b>MVC + M </b>comes useful.</p>
<h3>Conclusion</h3>
<p>MVC + M is a neat mix of the MVC pattern with the Mediator pattern. The MVC makes things much easier to test and much more isolated and controlled. The Mediator makes communication between Controllers possible in a loosely coupled manner. For me this works really well and I hope that it will do the same for your applications. Download the source code to have a look at my humble implementation.</p>
<p>Any comments, questions and suggestions are as usual most welcome&#8230;</p>
<p>P.S I am sorry if this post was a bit long but I didn&#8217;t manage to make it any shorter.</p>
<p><a href="http://marlongrech.wordpress.com/2008/03/21/creating-a-file-explorer-in-wpf-using-mvcm/">See also Part 2</a></p>
<p><a href="http://cid-96f8d49aa44c79c1.skydrive.live.com/self.aspx/Public/MoreThanJustMVC.zip" target="_blank">Download the Source code of the Sample Application</a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f20%2fmore-than-just-mvc-for-wpf%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f20%2fmore-than-just-mvc-for-wpf%2f" alt="kick it on DotNetKicks.com" border="0" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/143/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/143/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/143/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/143/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/143/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=143&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/03/20/more-than-just-mvc-for-wpf/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2008/03/mvcapp.gif" medium="image" />

		<media:content url="http://marlongrech.files.wordpress.com/2008/03/mvcm-diagram.png" medium="image" />

		<media:content url="http://marlongrech.files.wordpress.com/2008/03/mediator.jpg" medium="image" />

		<media:content url="http://marlongrech.files.wordpress.com/2008/03/colleague.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f20%2fmore-than-just-mvc-for-wpf%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF Treeview root node</title>
		<link>http://marlongrech.wordpress.com/2008/03/15/wpf-treeview-root-node/</link>
		<comments>http://marlongrech.wordpress.com/2008/03/15/wpf-treeview-root-node/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 15:20:35 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF Custom Controls]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/03/15/wpf-treeview-root-node/</guid>
		<description><![CDATA[Unfortunately the WPF native treeview or treeview items do not expose a property to determine which item is the root node in the treeview. I needed such a feature and thought to put it on my blog&#8230;
What is a treeview?
Well believe it or not a TreeView is just an Items Control nothing more. Yes, an [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=135&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Unfortunately the WPF native treeview or treeview items do not expose a property to determine which item is the root node in the treeview. I needed such a feature and thought to put it on my blog&#8230;</p>
<p>What is a treeview?<br />
Well believe it or not a TreeView is just an Items Control nothing more. Yes, an ItemsControl that creates TreeViewItems as it&#8217;s Item Containers. The TreeViewItems are also ItemsControl so a recursive data structure is formed and the TreeViewItems generate there own child nodes.</p>
<p>Today I will not go into details of how the treeview and ItemsControl work&#8230; For more info on this visit <a href="http://drwpf.com/blog/Home/tabid/36/EntryID/15/Default.aspx" target="_blank">Dr.Wpf Blog</a>. I will discuss more how I implemented the root nodes for the treeview.</p>
<p>So an ItemsControl has a very special method that one can override to do some custom logic, &#8220;<b>PrepareContainerForItemOverride</b>&#8220;. The following is the signature of the method</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> PrepareContainerForItemOverride(</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    DependencyObject element, <span style="color:#0000ff;">object</span> item)</pre>
</div>
</div>
<p>Basically this method gets called whenever an item (in our case a TreeViewItem) is being created and decorated with a DataTemplate (if set). In this method we can set a property of the TreeViewItem to identify the item as a root node.Ok, lets start. First we need to sub class the Treeview control. Once we did that we need a way how to attach information to the TreeViewItems&#8230; HMMM.. what better could do this then Attached Properties. Once we have all this, we need to set the attached property to True for the root nodes and we are done <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &#8230;. something like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;height:600px;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> MyTreeView : TreeView</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">bool</span> GetIsRootNode(DependencyObject obj)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">return</span> (<span style="color:#0000ff;">bool</span>)obj.GetValue(IsRootNodeProperty);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        }</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> SetIsRootNode(DependencyObject obj, <span style="color:#0000ff;">bool</span> <span style="color:#0000ff;">value</span>)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            obj.SetValue(IsRootNodeProperty, <span style="color:#0000ff;">value</span>);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        }</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">readonly</span> DependencyProperty IsRootNodeProperty =</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            DependencyProperty.RegisterAttached(<span style="color:#006080;">"IsRootNode"</span>, <span style="color:#0000ff;">typeof</span>(<span style="color:#0000ff;">bool</span>),</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">typeof</span>(MyTreeView), <span style="color:#0000ff;">new</span> UIPropertyMetadata(<span style="color:#0000ff;">false</span>));</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;"></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> PrepareContainerForItemOverride(</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            DependencyObject element, <span style="color:#0000ff;">object</span> item)</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        {</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            SetIsRootNode(element, <span style="color:#0000ff;">true</span>);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            <span style="color:#0000ff;">base</span>.PrepareContainerForItemOverride(element, item);</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        }</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    }</pre>
</div>
</div>
<p>So the most important part is where we set the Attached property IsRootNode to true (Please also note that by default the Attached property is set to false). You would be wondering, But wouldn&#8217;t this make all TreeViewItems root nodes???!!??? And the answer is, NO. Because the Treeview only generate root nodes. all other nodes are generated by the TreeViewItems themselves (Remember that the TreeViewItems are ItemsControl as well <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
<p>Once we have the property IsRootNode set we can restyle the TreeView as we want by using a Control Template. something like this</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;ControlTemplate TargetType=<span style="color:#006080;">"TreeViewItem"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;StackPanel Margin=<span style="color:#006080;">"10,2,0,0"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;WrapPanel Name=<span style="color:#006080;">"item"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;ToggleButton Name=<span style="color:#006080;">"expander"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">                          IsChecked=<span style="color:#006080;">"{Binding RelativeSource={RelativeSource TemplatedParent}, </span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                                              Path=IsExpanded}"</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">                          Content=<span style="color:#006080;">"+"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;ContentPresenter x:Name=<span style="color:#006080;">"PART_Header"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">                  ContentSource=<span style="color:#006080;">"Header"</span> /&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;/WrapPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;ItemsPresenter Name=<span style="color:#006080;">"children"</span> Visibility=<span style="color:#006080;">"Collapsed"</span> /&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;/Border&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;/StackPanel&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">    &lt;ControlTemplate.Triggers&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;Trigger Property=<span style="color:#006080;">"IsSelected"</span> Value=<span style="color:#006080;">"True"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            &lt;Setter TargetName=<span style="color:#006080;">"item"</span> Property=<span style="color:#006080;">"Background"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                    Value=<span style="color:#006080;">"LightBlue"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;/Trigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;Trigger Property=<span style="color:#006080;">"IsExpanded"</span> Value=<span style="color:#006080;">"True"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            &lt;Setter TargetName=<span style="color:#006080;">"children"</span> Property=<span style="color:#006080;">"Visibility"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                    Value=<span style="color:#006080;">"Visible"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;/Trigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;Trigger Property=<span style="color:#006080;">"HasItems"</span> Value=<span style="color:#006080;">"False"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            &lt;Setter TargetName=<span style="color:#006080;">"expander"</span> Property=<span style="color:#006080;">"Visibility"</span></pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">                    Value=<span style="color:#006080;">"Collapsed"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;/Trigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">        &lt;Trigger Property=<span style="color:#006080;">"local:MyTreeView.IsRootNode"</span> Value=<span style="color:#006080;">"True"</span>&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">            &lt;Setter TargetName=<span style="color:#006080;">"item"</span> Property=<span style="color:#006080;">"Background"</span> Value=<span style="color:#006080;">"Silver"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">            &lt;Setter TargetName=<span style="color:#006080;">"item"</span> Property=<span style="color:#006080;">"Height"</span>  Value=<span style="color:#006080;">"50"</span>/&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">        &lt;/Trigger&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;margin:0;padding:0;">    &lt;/ControlTemplate.Triggers&gt;</pre>
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;/ControlTemplate&gt;</pre>
</div>
</div>
<p>The most important part of this ControlTemplate is the Trigger on the attached property <i>local:MyTreeView.IsRootNode.</i>Here we are making the RootNodes for the treeview look different from all other nodes&#8230;</p>
<p>Hope this post helps&#8230;. Please contact me if you need any help <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://cid-96f8d49aa44c79c1.skydrive.live.com/self.aspx/Public/TreeViewRootNodes.zip" target="_blank">Download the full source code</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/135/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/135/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/135/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=135&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/03/15/wpf-treeview-root-node/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>
	</item>
		<item>
		<title>Input Prompt support in WPF</title>
		<link>http://marlongrech.wordpress.com/2008/03/09/input-prompt-support-in-wpf/</link>
		<comments>http://marlongrech.wordpress.com/2008/03/09/input-prompt-support-in-wpf/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 17:39:49 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF Custom Controls]]></category>
		<category><![CDATA[wpf tools]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/?p=133</guid>
		<description><![CDATA[Intro
If you look at Vista User experience guide, one thing that is a must have is the Input Prompt. I think that this is very important to improve the user experience. Yet unfortunately this is not supported natively by WPF  
But don&#8217;t worry because AvalonControlsLibrary is at the rescue  
I had noting to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=133&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3><u>Intro</u></h3>
<p>If you look at Vista User experience guide, one thing that is a must have is the <a href="http://ui-patterns.com/pattern/InputPrompt" target="_blank">Input Prompt</a>. I think that this is very important to improve the user experience. Yet unfortunately this is not supported natively by WPF <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>But don&#8217;t worry because <a href="http://www.codeplex.com/avaloncontrolslib" target="_blank">AvalonControlsLibrary</a> is at the rescue <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I had noting to do today so I decided to create this functionality and share it with you guys&#8230; You would say, aha; here comes Marlon with a new control. But NO. This is not a control as such. What I have created is a class with some attached properties that can be used to have the Prompt Input feature for any control (or better any control that would make sense such a feature). I choose the attached properties approach rather than creating a custom control for the simple reason to support any control that you wish to have an input prompt like the one displayed in the image below.</p>
<p><a href="http://marlongrech.files.wordpress.com/2008/03/inputprompt.jpg" title="Input prompt"><img src="http://marlongrech.files.wordpress.com/2008/03/inputprompt.jpg" alt="Input prompt" /></a></p>
<p>As you can see in the image above I am using the Input Prompt both for the TextBox and the ComboBox. And yes you can use it with any control that you want&#8230;</p>
<h3><u>How to use this&#8230;</u></h3>
<p>Well using this feature is quite easy, all you have to do is to set an attached property in your control. Something like this&#8230;</p>
<div style="border:1px solid gray;overflow:auto;font-size:8pt;width:97.5%;cursor:text;max-height:200px;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,'Courier New',courier,monospace;background-color:white;border-style:none;margin:0;padding:0;">&lt;TextBox local:InputPrompt.PromptText=<span style="color:#006080;">"Enter Search"</span> /&gt;</pre>
</div>
</div>
<p>[where local is the <a href="http://msdn2.microsoft.com/en-us/library/ms747086.aspx" target="_blank">XAML namespace mapping</a>]</p>
<p>In total there are 8 properties that you can set which are</p>
<ol>
<li>InputPrompt.PromptText               &#8211; I guess you already figured this one out <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </li>
<li>InputPrompt.PromptColor              &#8211; This is a brush used as foreground for the Prompt Text <i>(Default: Gray)</i></li>
<li>InputPrompt.PromptFontFamily     &#8211; The font family to use for the Prompt Text <i>(Default: Arial)</i></li>
<li>InputPrompt.PromptFontSize        &#8211; The font size of the Prompt Text <i>(Default: 12.0)</i></li>
<li>InputPrompt.PromptFontStretch   &#8211; The font stretch to use for the Prompt Text <i>(Default: FontStretches.Normal)</i></li>
<li>InputPrompt.PromptFontStyle       &#8211; The font style to use for the Prompt Text <i>(Default: FontStyles.Normal)</i></li>
<li>InputPrompt.PromptFontWeight    &#8211; The font weight to use for the Prompt Text <i>(Default: FontWeights.Normal)</i></li>
<li>InputPrompt.PromptBackColor       &#8211; This is a brush that is used to color the background of the prompt <i>(Default: Transparent)</i></li>
</ol>
<p><i>Please note: You must set the <b>InputPrompt.PromptText </b>in order for this to work all the other properties are optional. Also you must have you control under an <b>AdornerDecorator </b>because the InputPrompt will draw the prompt text in an adorner. </i></p>
<p><i></i></p>
<p>If you use the Input Prompt with a textbox the input prompt will be much more intelligent. What do I mean by this? Basically the Input Prompt handles the Text Changed event of the TextBox and if the user enters no text the prompt re appears. The same happens if the TextBox looses focus and there is no text in it. I did this behaviour for the TextBox because this is the standard behaviour for an Input Prompt for textboxes.</p>
<h3></h3>
<h3>How does this work behind the scenes</h3>
<p>Well it&#8217;s quite simple. Basically an Adorner is placed on top of the control which sets the Attached properties and draws the InputPrompt.PromptText. Besides drawing the text this also draws a rectangle covering the surface of the control so that as soon as the user click the control(or better mouse down on the control), the adorner disappears and the control gets activated once again.</p>
<p>When the InputPrompt.PromptText is set for a TextBox, the input prompt will register to the LostFocus event and the TextChanged event and make sure to display the Prompt Text if the Text of the TextBox is to empty.</p>
<h3>Conclusion</h3>
<p>All this will be included in AvalonControlsLibrary v3 but I decided to upload a demo as a stand alone so that you can start using this immediately.</p>
<p>Hope you like this and as usual I am all ears for feedback and suggestions&#8230;.</p>
<p>Thanks</p>
<p><a href="http://cid-96f8d49aa44c79c1.skydrive.live.com/self.aspx/Public/TestInputPrompt.zip" target="_blank">Download Source Code and Demo App</a></p>
<p>
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f09%2finput-prompt-support-in-wpf%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f09%2finput-prompt-support-in-wpf%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/133/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/133/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=133&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/03/09/input-prompt-support-in-wpf/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>

		<media:content url="http://marlongrech.files.wordpress.com/2008/03/inputprompt.jpg" medium="image">
			<media:title type="html">Input prompt</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmarlongrech.wordpress.com%2f2008%2f03%2f09%2finput-prompt-support-in-wpf%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Support for MinDate and MaxDate in DatePicker and TimePicker</title>
		<link>http://marlongrech.wordpress.com/2008/03/03/support-for-mindate-and-maxdate-in-datepicker-and-timepicker/</link>
		<comments>http://marlongrech.wordpress.com/2008/03/03/support-for-mindate-and-maxdate-in-datepicker-and-timepicker/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 22:22:45 +0000</pubDate>
		<dc:creator>marlongrech</dc:creator>
				<category><![CDATA[.Net 3.0]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF Custom Controls]]></category>

		<guid isPermaLink="false">http://marlongrech.wordpress.com/2008/03/03/support-for-mindate-and-maxdate-in-datepicker-and-timepicker/</guid>
		<description><![CDATA[I updated the sources for AvalonControlsLibrary v2 so that to support MinDate and MaxDate in the DatePicker.
Also added support for MinTime and MaxTime in TimePicker.
And while I was at it I also refactored the DateTimePicker to support these 2 properties.
The properties are DependencyProperties so you can easily databind to and do what every you like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=130&subd=marlongrech&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I updated the sources for AvalonControlsLibrary v2 so that to support MinDate and MaxDate in the DatePicker.</p>
<p>Also added support for MinTime and MaxTime in TimePicker.</p>
<p>And while I was at it I also refactored the DateTimePicker to support these 2 properties.</p>
<p>The properties are DependencyProperties so you can easily databind to and do what every you like with them&#8230;.</p>
<p>Great&#8230; now i should go to sleep <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />   <a href="http://www.codeplex.com/AvalonControlsLib" target="_blank"></a></p>
<p><a href="http://www.codeplex.com/AvalonControlsLib" target="_blank">Downlaod the new version</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marlongrech.wordpress.com/130/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marlongrech.wordpress.com/130/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marlongrech.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marlongrech.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marlongrech.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marlongrech.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marlongrech.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marlongrech.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marlongrech.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marlongrech.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marlongrech.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marlongrech.wordpress.com/130/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marlongrech.wordpress.com&blog=783168&post=130&subd=marlongrech&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://marlongrech.wordpress.com/2008/03/03/support-for-mindate-and-maxdate-in-datepicker-and-timepicker/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4231953dc5a7ec7d7b5acb2444eeeeab?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">C# Disciple</media:title>
		</media:content>
	</item>
	</channel>
</rss>