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

<channel>
	<title>Pete Does Stuff .NET</title>
	<atom:link href="http://petedoesstuff.net/Blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://petedoesstuff.net/Blog</link>
	<description>General Musings on the World of Software Development</description>
	<lastBuildDate>Mon, 29 Jun 2009 19:11:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Command Behaviours</title>
		<link>http://petedoesstuff.net/Blog/?p=112</link>
		<comments>http://petedoesstuff.net/Blog/?p=112#comments</comments>
		<pubDate>Mon, 29 Jun 2009 18:48:16 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[mvvm]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=112</guid>
		<description><![CDATA[One of the challenges I have found when using MVVM in Prism, is that out of the box it only supports the click event. Luckily there is an extensibility point here using the CommandBehaviourBase class which means we can tie command execution to any event the control can raise and then bind this using an [...]]]></description>
			<content:encoded><![CDATA[<p>One of the challenges I have found when using MVVM in Prism, is that out of the box it only supports the click event. Luckily there is an extensibility point here using the CommandBehaviourBase class which means we can tie command execution to any event the control can raise and then bind this using an attached property in the XAML.</p>
<p>There are 3 parts to the code – the example I am going to use is the SelectionChanged event of the ListBox control. </p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">namespace</span> PrismExtension.<span class="me1">CommandBehaviours</span> <br />
<span class="br0">&#123;</span> <br />
&nbsp; <span class="kw1">public</span> <span class="kw4">class</span> SelectedChangedBehaviour <span class="sy0">:</span> CommandBehaviorBase<span class="sy0">&lt;</span>listbox<span class="sy0">&gt;</span> <br />
&nbsp; <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp;<span class="kw1">public</span> SelectedChangedBehaviour<span class="br0">&#40;</span>ListBox element<span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw1">base</span><span class="br0">&#40;</span>element<span class="br0">&#41;</span> <br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; element.<span class="me1">SelectionChanged</span> <span class="sy0">+=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> SelectionChangedEventHandler<span class="br0">&#40;</span>element_SelectedChanged<span class="br0">&#41;</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <br />
<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">void</span> element_SelectedChanged<span class="br0">&#40;</span><span class="kw4">object</span> sender, SelectionChangedEventArgs e<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">base</span>.<span class="me1">ExecuteCommand</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <br />
<span class="br0">&#125;</span></div></div>
<p></br><br />
This code is pretty simple in what it does.  The constructor takes an instance of the control you want to attach the event handling code to. The event handling code then executes the command when the event you are watching for is fired.  The next part is a bit more tricky.<br />
</br><br />
In order to get this into the XAML as an attached property we need to create a static class.<br />
</br></p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px;height:300px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">namespace</span> PrismExtension.<span class="me1">CommandBehaviours</span> <br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">class</span> SelectedChanged<br />
&nbsp; <span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">public</span> <span class="kw1">static</span> ICommand GetCommand<span class="br0">&#40;</span>DependencyObject obj<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>ICommand<span class="br0">&#41;</span>obj.<span class="me1">GetValue</span><span class="br0">&#40;</span>CommandProperty<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw1">void</span> SetCommand<span class="br0">&#40;</span>DependencyObject obj, ICommand value<span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; obj.<span class="me1">SetValue</span><span class="br0">&#40;</span>CommandProperty, value<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw1">readonly</span> DependencyProperty CommandProperty <span class="sy0">=</span> DependencyProperty.<span class="me1">RegisterAttached</span><span class="br0">&#40;</span><span class="st0">&quot;Command&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span class="kw3">typeof</span></a><span class="br0">&#40;</span>ICommand<span class="br0">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span class="kw3">typeof</span></a><span class="br0">&#40;</span>SelectedChanged<span class="br0">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> PropertyMetadata<span class="br0">&#40;</span>OnSetCommandCallback<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw1">readonly</span> DependencyProperty CommandParameterProperty <span class="sy0">=</span> DependencyProperty.<span class="me1">RegisterAttached</span><span class="br0">&#40;</span><span class="st0">&quot;CommandParameter&quot;</span>,<a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span class="kw3">typeof</span></a><span class="br0">&#40;</span><span class="kw4">object</span><span class="br0">&#41;</span>,<a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span class="kw3">typeof</span></a><span class="br0">&#40;</span>SelectedChanged<span class="br0">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> PropertyMetadata<span class="br0">&#40;</span>OnSetCommandParameterCallback<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">void</span> OnSetCommandCallback<span class="br0">&#40;</span>DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e<span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListBox element <span class="sy0">=</span> dependencyObject <span class="kw1">as</span> ListBox<span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>element <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SelectedChangedBehaviour behavior <span class="sy0">=</span> GetOrCreateBehavior<span class="br0">&#40;</span>element<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; behavior.<span class="me1">Command</span> <span class="sy0">=</span> e.<span class="me1">NewValue</span> <span class="kw1">as</span> ICommand<span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw1">void</span> SetCommandParameter<span class="br0">&#40;</span>ListBox listbox, <span class="kw4">object</span> parameter<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listbox.<span class="me1">SetValue</span><span class="br0">&#40;</span>CommandParameterProperty, parameter<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">object</span> GetCommandParameter<span class="br0">&#40;</span>ListBox listbox<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> listbox.<span class="me1">GetValue</span><span class="br0">&#40;</span>CommandParameterProperty<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">static</span> SelectedChangedBehaviour GetOrCreateBehavior<span class="br0">&#40;</span>ListBox element<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SelectedChangedBehaviour behavior <span class="sy0">=</span> element.<span class="me1">GetValue</span><span class="br0">&#40;</span>SelectedIndexChangedBehaviourProperty<span class="br0">&#41;</span> <span class="kw1">as</span> SelectedChangedBehaviour<span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>behavior <span class="sy0">==</span> <span class="kw1">null</span><span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;behavior <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> SelectedChangedBehaviour<span class="br0">&#40;</span>element<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;element.<span class="me1">SetValue</span><span class="br0">&#40;</span>SelectedIndexChangedBehaviourProperty, behavior<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> behavior<span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">void</span> OnSetCommandParameterCallback<span class="br0">&#40;</span>DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e<span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ListBox listbox <span class="sy0">=</span> dependencyObject <span class="kw1">as</span> ListBox<span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>listbox <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SelectedChangedBehaviour behavior <span class="sy0">=</span> GetOrCreateBehavior<span class="br0">&#40;</span>listbox<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;behavior.<span class="me1">CommandParameter</span> <span class="sy0">=</span> e.<span class="me1">NewValue</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">public</span> <span class="kw1">static</span> SelectedChangedBehaviour GetSelectedIndexChangedBehaviour<span class="br0">&#40;</span>DependencyObject obj<span class="br0">&#41;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">return</span> <span class="br0">&#40;</span>SelectedChangedBehaviour<span class="br0">&#41;</span>obj.<span class="me1">GetValue</span><span class="br0">&#40;</span>SelectedIndexChangedBehaviourProperty<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> <span class="kw1">void</span> SetSelectedIndexChangedBehaviour<span class="br0">&#40;</span>DependencyObject obj, SelectedChangedBehaviour value<span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;obj.<span class="me1">SetValue</span><span class="br0">&#40;</span>SelectedIndexChangedBehaviourProperty, value<span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> <span class="kw1">readonly</span> DependencyProperty SelectedIndexChangedBehaviourProperty <span class="sy0">=</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DependencyProperty.<span class="me1">RegisterAttached</span><span class="br0">&#40;</span><span class="st0">&quot;SelectedIndexChangedBehaviour&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span class="kw3">typeof</span></a><span class="br0">&#40;</span>SelectedChangedBehaviour<span class="br0">&#41;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span class="kw3">typeof</span></a><span class="br0">&#40;</span>SelectedChanged<span class="br0">&#41;</span>, <span class="kw1">null</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <br />
<span class="br0">&#125;</span></div></div>
<p></br>Essentially this consists of a Dependency Property for the command and another one for the CommandParameter.  The last part is to actually bind to it in XAML.  First add the namespace to the xaml file<br />
</br></p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">xmlns<span class="sy0">:</span>xt<span class="sy0">=</span><span class="st0">&quot;clr-namespace:PrismExtension.CommandBehaviours;assembly=PrismExtension&quot;</span></div></div>
<p></br>Then in a control that is derived from ListBox this is the code I have used to bind the command to the control<br />
</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sy0">&lt;</span>ListView Name<span class="sy0">=</span><span class="st0">&quot;notesListView&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; xt<span class="sy0">:</span>SelectedChanged.<span class="me1">Command</span><span class="sy0">=</span><span class="st0">&quot;{Binding SelectedNoteCommand}&quot;</span><br />
&nbsp; &nbsp; xt<span class="sy0">:</span>SelectedChanged.<span class="me1">CommandParameter</span><span class="sy0">=</span><span class="st0">&quot;{Binding ElementName=notesListView}&quot;</span><span class="sy0">&gt;</span></div></div>
<p></br><br />
         On my viewmodel for the view I have a command called SelectedNoteCommand exposed as a read-only property which is the command that the control will fire on the selected item changing.
<p>I pulled this together from a couple of sources &#8211; one is the click command itself from inside the Prism code.  The second was a really informative video found  <a href="http://development-guides.silverbaylabs.org/Video/Prism-Commands">here</a> by Erik Mork of Silver Bay Labs.  Also worth checking out if you are playing around with CommandBehaviours is <a href="http://nroute.codeplex.com/">nRoute</a> because here you will find implementations of a whole swathe of CommandBehaviours!  In fact check out nRoute anyway, as the guy writing it is a freaking Genius!  The Office 2010 demo app is just beautiful.</p>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=112</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Structure For Prism Projects</title>
		<link>http://petedoesstuff.net/Blog/?p=111</link>
		<comments>http://petedoesstuff.net/Blog/?p=111#comments</comments>
		<pubDate>Mon, 22 Jun 2009 19:47:33 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=111</guid>
		<description><![CDATA[This is how I am structuring my Prism projects. 
ProjectName
This is the project which contains the shell and bootstrapper.
ProjectName.Infrastructure
This project contains all the classes that are shared between the modules such as events and common interfaces.
ProjectName.Infrastructure.Resources
In this project I put all my resources for the project such as styles and images.&#160; This allows me to [...]]]></description>
			<content:encoded><![CDATA[<p>This is how I am structuring my Prism projects. </p>
<p><strong>ProjectName</strong></p>
<p>This is the project which contains the shell and bootstrapper.</p>
<p><strong>ProjectName.Infrastructure</strong></p>
<p>This project contains all the classes that are shared between the modules such as events and common interfaces.</p>
<p><strong>ProjectName.Infrastructure.Resources</strong></p>
<p>In this project I put all my resources for the project such as styles and images.&#160; This allows me to share specific icons and pictures etc between the different modules.</p>
<p><strong>ProjectName.ModuleName</strong></p>
<p>These projects are the modules loaded by the bootstrapper.&#160; Inside the project I have a separate folder for Views and one for ViewModels.&#160; The module class lives in the route of the assembly.&#160; I currently am separating out each area of functionality into separate modules though there has been discussion as to whether you should have a Core Module which holds most or all the core functionality of the app.&#160; I am against this as I think the notion of having more than 1 area of functionality in the one module does away with the advantages of modularity and increases the likelihood of having to do a full deployment when changing a single area of functionality.</p>
<p><strong>PrismExtensions</strong></p>
<p>This project contains my extensions for Prism or base code that helps speed up development.&#160; So far it has a couple of RegionAdapters, the start of an MVVM framework and a custom bootstrapper that loads all the extensions automatically.</p>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=111</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stuff I am Reading&#8230; and Watching..</title>
		<link>http://petedoesstuff.net/Blog/?p=109</link>
		<comments>http://petedoesstuff.net/Blog/?p=109#comments</comments>
		<pubDate>Mon, 22 Jun 2009 19:25:21 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[ted]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=109</guid>
		<description><![CDATA[Ok its been a while since I last posted anything major. I’ve spent a large chunk of that time reading – entirely non development stuff.
So what have I been reading?
Bad Science by Ben Goldacre. This book was great. It covers ‘complementary’ remedies, scientific testing of drugs, MMR, AIDS and HIV, MRSA and how the media [...]]]></description>
			<content:encoded><![CDATA[<p>Ok its been a while since I last posted anything major. I’ve spent a large chunk of that time reading – entirely non development stuff.</p>
<p>So what have I been reading?</p>
<p><a href="http://www.amazon.co.uk/Bad-Science-Ben-Goldacre/dp/0007240198">Bad Science by Ben Goldacre.</a> This book was great. It covers ‘complementary’ remedies, scientific testing of drugs, MMR, AIDS and HIV, MRSA and how the media amplifies our fears. One of the key points behind the book is educating the reader about what science really is. Definitely one of the best books I have ever read.</p>
<p><a href="http://www.amazon.co.uk/Logic-Life-Tim-Harford/dp/0349120412">The Logic of Life by Tim Harford.</a>&#160; A very interesting read about when life seems to defy logic but actually is based on rational decisions. He talks about speed dating, casinos, racism and numerous other topics and how they can be interpreted using economics.</p>
<p><a href="http://www.amazon.co.uk/Predictably-Irrational-Hidden-Forces-Decisions/dp/0007256531">Predictably Irrational by Dan Ariely.</a>&#160; Another economicsy (made up word) book on rationality and the decision making process. Especially like the decoy effect, I hadn’t come across it before but now its something I am very aware of when buying things. Covers some interesting experiments including the infamous Pepsi Challenge and one which featured making people recall the Ten Commandments before tests and whether it made them less likely to cheat at maths tests. </p>
<p><a href="http://www.amazon.co.uk/Predictably-Irrational-Hidden-Forces-Decisions/dp/0007256531">Blink by Malcolm Gladwell.</a>&#160; A book on snap decisions and how experts can make accurate snap decisions based on experience.  Good, but repetitive and could probably be half as long! </p>
<p><a href="http://www.amazon.com/Parasite-Rex-Bizarre-Dangerous-Creatures/dp/074320011X">Parasite Rex by Carl Zimmer.</a> A fascinating book on the life of parasites,how they evolve and the wars between host and parasite. Its a book that might make you a little squeamish but is definitely worth a read. And as one of the Amazon reviewers pointed out it will change the way you see the world. The fact that some of your behaviour may not be down to you but the toxoplasmosis living in your brain is more than mildly unsettling. </p>
<p>As to what I&#8217;ve been watching? </p>
<p>I seem to live on the website of the <a href="http://www.ted.com">TED Conference</a>. The videos here cover some mind blowing topics like advances in microbiology, robots, technology, economics, biology, psychology, neuroscience, computing&#8230; As a good friend found, its one of those sites you sit down to look at just a couple of talks, 20 talks later you find its 3am in the morning!</p>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=109</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prism Resources 2</title>
		<link>http://petedoesstuff.net/Blog/?p=105</link>
		<comments>http://petedoesstuff.net/Blog/?p=105#comments</comments>
		<pubDate>Thu, 18 Jun 2009 20:36:56 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[wpf prism]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=105</guid>
		<description><![CDATA[Videos 
Silverbay Labs have done a couple of videos on Prism 

Introduction to Composite Applications &#8211; this one covers all the basics of Prism. 
Regions in Prism &#8211; this one shows a couple of interesting things that I haven&#8217;t seen much of elsewhere &#8211; RegionAdapters and RegionContext.&#160; RegionAdapters allow you to use other controls to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Videos </strong>
<p>Silverbay Labs have done a couple of videos on Prism </p>
<ul>
<li><a href="http://development-guides.silverbaylabs.org/Video/Silverlight-Prism#videolocation_0">Introduction to Composite Applications</a> &#8211; this one covers all the basics of Prism. </li>
<li><a href="http://development-guides.silverbaylabs.org/Video/Prism-Regions">Regions in Prism</a> &#8211; this one shows a couple of interesting things that I haven&#8217;t seen much of elsewhere &#8211; RegionAdapters and RegionContext.&#160; RegionAdapters allow you to use other controls to host regions than the ones that come with Prism. RegionContext allows you to share information between different views in the same region. </li>
</ul>
<p><strong>Training Courses and Presentations</strong></p>
<p><a href="http://blog.batfishsolutions.com/2009/06/slides-for-my-prism-tation.html">Slides for my Prism-Tation </a>by John McLoughlin from NxtGen Southampton. I went to see John&#8217;s Introduction to Prism talk at NxtGen Birmingham recently and can recommend seeing it if you get a chance. </p>
<p><strong>General Articles on Prism</strong></p>
<ul>
<li><a href="http://www.mokosh.co.uk/?tag=/prism">Mokosh’s Blog</a> has a good set of info on Prism. Covers most of the basics and a few interesting bits and bobs. </li>
<li><a href="http://blogs.southworks.net/ejadib/2008/07/22/use-the-outlookbar-in-your-compositewpf-prism-applications/">How to use the outlookbar in Prism Apps</a>. This article shows how to use the OutlookBar control from <a href="http://www.codeplex.com/CompositeWPFContrib">CompositeWPF Contrib</a> in Prism Apps. In fact the whole blog section <a href="http://blogs.southworks.net/ejadib/tag/prism">here</a> on Prism has lots to read! </li>
<li><a href="http://www.codeproject.com/KB/WPF/PrismLayoutManager.aspx">Layout Manager for Prism v2</a> Interesting article on how to create an application with multiple layouts using prism. </li>
<li><a href="http://www.codeproject.com/KB/WPF/CalciumPart01.aspx">Calcium: A modular application toolset leveraging the Composite Application Library (PRISM) – Part 1</a> &#8211; Lots of stuff here. </li>
<li><a href="http://www.codeproject.com/Articles/35775/Model-View-Presenter-and-Model-View-ViewModel-in-Prism.aspx">Model-View-Presenter and Model-View-ViewModel in Prism</a>   </li>
<li><a href="http://www.codeproject.com/KB/WPF/IntroductionCompositeWPF.aspx">Introduction to Composite WPF (CAL, Prism) Part 1</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=105</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Onyx &#8211; Part 1</title>
		<link>http://petedoesstuff.net/Blog/?p=88</link>
		<comments>http://petedoesstuff.net/Blog/?p=88#comments</comments>
		<pubDate>Thu, 07 May 2009 21:06:13 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[Onyx]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[mvvm]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=88</guid>
		<description><![CDATA[After playing with Prism I have decided the next thing to look at is Onyx. This is a MVVM framework for WPF written by Bill Kempf. The best tutorial I have found on it so far is by Sacha Barber on CodeProject (WPF:FlipTile 3D) and these notes are based on my interpretation of his code.
The [...]]]></description>
			<content:encoded><![CDATA[<p>After playing with Prism I have decided the next thing to look at is Onyx. This is a MVVM framework for WPF written by Bill Kempf. The best tutorial I have found on it so far is by Sacha Barber on CodeProject (<a href="http://www.codeproject.com/KB/WPF/WPFOynxApp.aspx">WPF:FlipTile 3D</a>) and these notes are based on my interpretation of his code.</p>
<p>The View-ViewModel interaction is setup declaratively in the XAML for the view as illustrated below:</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sy0">&lt;</span>window title<span class="sy0">=</span><span class="st0">&quot;TestWindow&quot;</span><br />
xmlns<span class="sy0">=</span><span class="st0">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span> <br />
width<span class="sy0">=</span><span class="st0">&quot;300&quot;</span> <br />
height<span class="sy0">=</span><span class="st0">&quot;300&quot;</span> <br />
xmlns<span class="sy0">:</span>local<span class="sy0">=</span><span class="st0">&quot;clr-namespace:OnyxApp&quot;</span> <br />
xmlns<span class="sy0">:</span>onyx<span class="sy0">=</span><span class="st0">&quot;http://schemas.onyx.com/2009/fx/presentation&quot;</span> <br />
xmlns<span class="sy0">:</span>x<span class="sy0">=</span><span class="st0">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span><br />
x<span class="sy0">:</span><span class="kw4">class</span><span class="sy0">=</span><span class="st0">&quot;OnyxApp.TestWindow&quot;</span><br />
onyx<span class="sy0">:</span>view.<span class="me1">model</span><span class="sy0">=</span><span class="st0">&quot;{x:Type local:TestWindowViewModel}&quot;</span><span class="sy0">&gt;</span></div></div>
<p>The TestWindowViewModel class here is coded as below</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">namespace</span> OnyxApp<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">class</span> TestWindowViewModel<span class="sy0">:</span>ViewModel<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> TestWindowViewModel<span class="br0">&#40;</span>View view<span class="br0">&#41;</span><span class="sy0">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">base</span><span class="br0">&#40;</span>view<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="br0">&#125;</span></div></div>
<p>As far as I can see, this is the minimum amount of code to get the MVVM interaction going.</p>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=88</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prism Screencasts on Channel 9 Part 2</title>
		<link>http://petedoesstuff.net/Blog/?p=83</link>
		<comments>http://petedoesstuff.net/Blog/?p=83#comments</comments>
		<pubDate>Fri, 10 Apr 2009 17:26:06 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=83</guid>
		<description><![CDATA[Creating a modular application using Prism V2 &#8211; Screencast 3/4 : Implementing views and services
Step 5 – Creating the ViewModel

View model contains all the bindable elements that will appear in the view.
Use a ViewModel to allow easy testing and styling.
Just a normal class exposing data via properties.
Use constructor injection to add the ViewModel to the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://channel9.msdn.com/posts/akMSFT/Creating-a-modular-application-using-Prism-V2-Screencast-34--Implementing-views-and-services/">Creating a modular application using Prism V2 &#8211; Screencast 3/4 : Implementing views and services</a></p>
<p><strong>Step 5 – Creating the ViewModel</strong></p>
<ul>
<li>View model contains all the bindable elements that will appear in the view.</li>
<li>Use a ViewModel to allow easy testing and styling.</li>
<li>Just a normal class exposing data via properties.</li>
<li>Use constructor injection to add the ViewModel to the View and set the View&#8217;s DataContext to be the ViewModel.</li>
<li>Add HeaderData property to the ViewModel – if being used in tabs. <strong></strong></li>
</ul>
<ul><strong>Step 6 – Implementing Services</strong></p>
<li>Create interface for service to allow testing in isolation/swapping of concrete types etc.</li>
<li>Add service interface to constructor for ViewModel using constructor injection.</li>
<li>Initialise data using the service interface.</li>
<li>Add the unity container to the constructor for the module class.</li>
<li>In the module initialisation code register the Service with the unity container using the following code</li>
</ul>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">container.<span class="me1">RegisterType</span><span class="sy0">&lt;</span>IServiceInterface, ServiceClass<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<ul>
<li>If you want a singleton service use this instead</li>
</ul>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">container.<span class="me1">RegisterType</span><span class="sy0">&lt;</span>IServiceInterface, ServiceClass<span class="sy0">&gt;</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> ContainerControlledLifetimeManager<span class="br0">&#41;</span><span class="sy0">;</span></div></div>
<p><a href="http://channel9.msdn.com/posts/akMSFT/Creating-a-modular-application-using-Prism-v2-Screencast-44--Decoupled-Communication/">Creating a modular application using Prism v2 &#8211; Screencast 4/4 : Decoupled Communication</a></p>
<p>This video covered the event aggregator and how to publish/subscribe to loosely coupled events.  Pretty much covered the same stuff as my post on event aggregation.</p>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=83</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prism Links</title>
		<link>http://petedoesstuff.net/Blog/?p=79</link>
		<comments>http://petedoesstuff.net/Blog/?p=79#comments</comments>
		<pubDate>Sat, 04 Apr 2009 16:10:49 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=79</guid>
		<description><![CDATA[I’ve been trying to collect together all the good resources I am finding on Prism.  Here is some of what I have found so far.
Downloads

Prism: patterns &#38; practices Composite Application Guidance for WPF and Silverlight site – this is the main site where you can download Prism from and the Guidance document that goes with [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been trying to collect together all the good resources I am finding on Prism.  Here is some of what I have found so far.</p>
<p><strong>Downloads</strong></p>
<ul>
<li><a title="http://www.codeplex.com/CompositeWPF" href="http://www.codeplex.com/CompositeWPF">Prism: patterns &amp; practices Composite Application Guidance for WPF and Silverlight site</a> – this is the main site where you can download Prism from and the Guidance document that goes with it.</li>
<li><a href="http://compositewpfcontrib.codeplex.com/">Composite WPF Contrib</a> &#8211; Codeplex project for building a library of extensions to Prism. No default releases but it looks like they are adding support for other IOC/DI containers and some vendor control sets.</li>
<li><a href="http://code.google.com/p/cwpfsamples/">Late Night</a> &#8211; some samples of how to use the framework.</li>
</ul>
<p><strong>General Blogs/Blog Postings on Prism</strong></p>
<ul>
<li><a href="http://www.softinsight.com/bnoyes/default.aspx">.Net Ramblings &#8211; Brian Noyes&#8217; Blog</a> &#8211; Blog of one the guys producing a lot of good stuff on Prism.</li>
<li><a href="http://blogs.msdn.com/dphill/archive/tags/Prism/default.aspx">David Hill&#8217;s WebLog</a> &#8211; One of the P &amp; P guys who worked on Prism.</li>
<li><a href="http://blogs.msdn.com/mpuleio/">Espresso Fueled Agile Development</a> &#8211; Some good links <a href="http://blogs.msdn.com/mpuleio/archive/2008/07/31/composite-application-guidance-for-wpf-shipped.aspx">here </a></li>
<li><a href="http://blogs.msdn.com/blaine/">Blaine Wastell</a> &#8211; One of the guys in the Channel 9 Prism Videos. The videos are linked <a href="http://blogs.msdn.com/blaine/archive/2009/02/28/learn-prism.aspx">here</a></li>
<li><a href="http://blogs.msdn.com/francischeung/">Francis Cheung</a> &#8211; Another P &amp; P guy &#8211; Some good stuff here on decoupled communication.</li>
<li><a href="http://blogs.msdn.com/erwinvandervalk/default.aspx">Erwin van der Valk&#8217;s blog: Practicing patterns</a> &#8211; Another one of the P &amp; P guys and the other guy in the Channel 9 Prism videos. Stand out article &#8211; <a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/03/02/how-to-build-an-outlook-style-application.aspx">How to build an outlook style application</a></li>
<li><a href="http://www.ademiller.com/blogs/tech/2009/03/using-prism-with-entlib-and-unity/">Using Prism with Entlib and Unity</a></li>
<li><a href="http://geekswithblogs.net/hoarked/archive/2009/01/26/creating-a-wpf-application-with-prism-v2-ndash-background-amp.aspx">Creating a WPF Application with Prism v2</a> &#8211; Good series written by one of the guys on the P&amp;P Composite Architecture for WPF and Silverlight advisory board. Starts <a href="http://geekswithblogs.net/hoarked/archive/2009/01/26/creating-a-wpf-application-with-prism-v2-ndash-background-amp.aspx">here</a></li>
</ul>
<p><strong>Articles</strong></p>
<ul>
<li><a href="http://www.code-magazine.com/Article.aspx?quickid=0811041">Code magazine &#8211; Build Composite WPF Applications</a> by Brian Noyes</li>
<li><a href="http://msdn.microsoft.com/en-us/magazine/cc785479.aspx">MSDN Magazine &#8211; Patterns For Building Composite Applications With WPF</a> by Glenn Block</li>
<li><a href="http://www.tanguay.info/web/index.php?pg=howtos&amp;id=7">How to build a base Prism application</a> By Edward Tanguay</li>
<li><a href="http://www.tanguay.info/web/index.php?pg=howtos&amp;id=15">How to build a WPF application with Prism v2</a> by Edward Tanguay</li>
<li><a href="http://www.tanguay.info/web/index.php?pg=codeExamples&amp;id=105">WPF Master/Detail Functionality Application using Composite Application Guidance (Prism Version 2)</a> by Edward Tanguay</li>
</ul>
<p><strong>CodeProject Stuff</strong></p>
<p>Articles are now starting to popup on Code Project about Prism &#8211; heres the first few I have found</p>
<ul>
<li><a href="http://www.codeproject.com/KB/WPF/CompositeWpfApp.aspx">Composite Application Library in WPF Application</a> By Eugene Pankov</li>
<li><a href="http://www.codeproject.com/KB/WPF/GoalBook.aspx">GoalBook &#8211; Hybrid Smart Client</a> By Mark Brownsword</li>
</ul>
<p><strong>Webcasts</strong></p>
<ul>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=124">DNRTV &#8211; Brian Noyes on Prism</a></li>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=132">DNRTV &#8211; Brian Noyes on Prism Events and Commands</a></li>
<li><a href="http://www.slickthought.net/post/2008/10/Building-a-WPF-Composite-Application-Series-Part-1.aspx">Building a WPF Composite Application Series Part 1</a> &#8211; Jeff Brand&#8217;s video series on Prism.</li>
<li><a href="http://pixel8.infragistics.com/Default.aspx#Episode:9833">Pixel8 &#8211; 4 elements of professional WPF Applications</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=79</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prism &#8211; Event Aggregation</title>
		<link>http://petedoesstuff.net/Blog/?p=67</link>
		<comments>http://petedoesstuff.net/Blog/?p=67#comments</comments>
		<pubDate>Thu, 02 Apr 2009 20:42:03 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=67</guid>
		<description><![CDATA[These are my notes on how I got event aggregation working in Prism2.
Separate out the events that you want and any classes that they use into a separate assembly.&#160; This assembly/project needs to reference Composite.Presentation.Desktop and Composite.Desktop.
The event types are derived from Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent&#60;TPayload&#62;
Any project that is to publish or subscribe to those events needs a [...]]]></description>
			<content:encoded><![CDATA[<p>These are my notes on how I got event aggregation working in Prism2.</p>
<p>Separate out the events that you want and any classes that they use into a separate assembly.&#160; This assembly/project needs to reference Composite.Presentation.Desktop and Composite.Desktop.</p>
<p>The event types are derived from Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent&lt;TPayload&gt;</p>
<p>Any project that is to publish or subscribe to those events needs a reference to the Assembly they are in.&#160; Currently am favouring adding Infrastructure to the name of the assembly like the quick starts.&#160; </p>
<p><strong>To publish an Event</strong></p>
<p>Raising class needs a reference to the EventAggregator passed into the constructor.</p>
<p><div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">TypeOfEvent evnt <span class="sy0">=</span> eventAggregator.<span class="me1">GetEvent</span><span class="sy0">&lt;</span>TypeOfEvent<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <br />
evnt.<span class="me1">Publish</span><span class="br0">&#40;</span>TPayload<span class="br0">&#41;</span><span class="sy0">;</span></div></div>
</p>
<p><strong>To subscribe to an Event</strong></p>
<p>Subscribing class needs a reference to the EventAggregator passed into the constructor.</p>
<p><div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">TypeOfEvent evnt <span class="sy0">=</span> eventAggregator.<span class="me1">GetEvent</span><span class="sy0">&lt;</span>TypeOfEvent<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
SubscriptionToken tkn <span class="sy0">=</span> evnt.<span class="me1">Subscribe</span><span class="br0">&#40;</span>action<span class="br0">&#41;</span><span class="sy0">;</span></div></div>
</p>
<p><strong>Options for Subscribing </strong></p>
<ul>
<li><strong>KeepSubscriberReferenceAlive</strong> &#8211; Subscribes with a strong reference which prevents the garbage collection of the subscriber.
<ul>
<li>Would need to unsubscribe manually. </li>
<li>Improves performance if publishing a large number of events in a short time. </li>
</ul>
</li>
</ul>
<ul>
<li><strong>ThreadOption</strong> &#8211; The following options are available for ThreadOption:
<ul>
<li>PublisherThread. Receives the event on the publisher&#8217;s thread. </li>
<li>BackgroundThread. Receives asynchronously on background worker thread. </li>
<li>UIThread. Recieves the event on the UI thread. </li>
</ul>
</li>
<li><strong>Filter</strong> &#8211; predicate.
<ul>
<li>Returns true if the payload of the event matches a criteria that the subscriber is interested in receiving. </li>
<li>Can be a lambda expression in WPF &#8211; has to be a separate method in SL2. </li>
</ul>
</li>
</ul>
<p><strong>Unsubscribing from an Event</strong></p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">TypeOfEvent evnt <span class="sy0">=</span> eventAggregator.<span class="me1">GetEvent</span><span class="sy0">&lt;</span>TypeOfEvent<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
evnt.<span class="me1">Unsubscribe</span><span class="br0">&#40;</span>eventHandler<span class="br0">&#41;</span><span class="sy0">;</span><br />
<br />
evnt.<span class="me1">Unsubscriber</span><span class="br0">&#40;</span>subscriptionToken<span class="br0">&#41;</span><span class="sy0">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=67</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prism Screencasts on Channel 9 Part 1</title>
		<link>http://petedoesstuff.net/Blog/?p=48</link>
		<comments>http://petedoesstuff.net/Blog/?p=48#comments</comments>
		<pubDate>Sun, 29 Mar 2009 15:10:21 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Free Resources]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=48</guid>
		<description><![CDATA[There are 4 informative screencasts on Channel 9 on how to use Prism.  These are my notes on the first 2.
Creating a modular application using Prism V2 &#8211; Screencast 1/4 : Creating a shell and modules
Step 1 – Create a Shell Project.
Key things about the shell project :

This project contains the Unity Bootstrapper (assuming you [...]]]></description>
			<content:encoded><![CDATA[<p>There are 4 informative screencasts on Channel 9 on how to use Prism.  These are my notes on the first 2.</p>
<p><a href="http://channel9.msdn.com/posts/akMSFT/Creating-a-modular-application-using-Prism-V2-Part-1-of-4--Creating-a-shell-and-modules/">Creating a modular application using Prism V2 &#8211; Screencast 1/4 : Creating a shell and modules</a></p>
<p><strong>Step 1 – Create a Shell Project.</strong></p>
<p>Key things about the shell project :</p>
<ul>
<li>This project contains the Unity Bootstrapper (assuming you are using Unity).  This is a class inherited from UnityBootstrapper and is required by Prism to create the shell etc.</li>
<li>Must override the CreateShell() method to return the shell for Prism to use.</li>
<li>Override the GetModuleCatalog() method to return the list of available modules.</li>
<li>To run the bootstrapper – create a new one in the application startup code and then run it.</li>
</ul>
<p><strong>Step 2 – Create  a Module Project.</strong></p>
<p>Key things about the module project:</p>
<ul>
<li>Module must expose IModule.</li>
<li>Fill in implementation of Initialize()</li>
<li>Ensure the module is added to the shell’s ModuleCatalog.</li>
<li>Catalog.AddModule(typeof(module));</li>
</ul>
<p><a href="http://channel9.msdn.com/posts/akMSFT/Creating-a-modular-application-using-Prism-V2-Screencast-24--Visual-Composition/">Creating a modular application using Prism V2 &#8211; Screencast 2/4 : Visual Composition</a></p>
<p><strong>Step 3 – Adding Regions to the Shell</strong></p>
<ul>
<li>Views in Prism sit within regions in the Shell.</li>
<li>These regions are managed by the RegionManager.</li>
<li>Add the namespace to the xaml file</li>
</ul>
<p>xmlns:Regions=&#8221;clr-namespace:Microsoft.Practices.Composite.Presentation.Regions; assembly=Microsoft.Practices.Composite.Presentation&#8221;</p>
<ul>
<li>Then add to the xaml for the content hosting control you want the region to sit in the following</li>
</ul>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace">Regions.<span class="me1">RegionManager</span>.<span class="me1">RegionName</span><span class="sy0">=</span>”name of region”</div></div>
<p><strong> Step 4 – View Discovery</strong></p>
<ul>
<li>In the module project add a new user control to represent the view.</li>
<li>To the constructor of the module add IRegionManager.  This will automatically be resolved as Prism has previously registered the RegionManager with Unity.</li>
<li>To the initialise method add the following</li>
</ul>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">this</span>.<span class="me1">regionManager</span>.<span class="me1">RegisterViewWithRegion</span><span class="br0">&#40;</span>“regionName”, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span class="kw3">typeof</span></a><span class="br0">&#40;</span>viewToInstantiate<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=48</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Windows Presentation Foundation</title>
		<link>http://petedoesstuff.net/Blog/?p=43</link>
		<comments>http://petedoesstuff.net/Blog/?p=43#comments</comments>
		<pubDate>Sat, 14 Mar 2009 17:20:51 +0000</pubDate>
		<dc:creator>PeteDoesStuff.NET</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Free Resources]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://petedoesstuff.net/Blog/?p=43</guid>
		<description><![CDATA[I recently decided to start looking at expanding my skills to include some of the new .NET 3.5 stuff. WPF looked the most interesting to start off with as its the new Windows Forms and also getting into the XAML and design side of .NET development looks like a good way to get my head [...]]]></description>
			<content:encoded><![CDATA[<p>I recently decided to start looking at expanding my skills to include some of the new .NET 3.5 stuff. WPF looked the most interesting to start off with as its the new Windows Forms and also getting into the XAML and design side of .NET development looks like a good way to get my head around Silverlight. The learning curve so far hasn&#8217;t been nearly as steep as I was expecting &#8211; some of the things I was doing previously in Windows Forms now seem to be the MS-approved way of doing things now, such as the use of commands. I have found some really good free resources to help with picking up all the nuances   </p>
<ul>
<li><a href="http://www.windowsclient.net">The Official Microsoft WPF and Windows Forms Site</a> – This site has loads of code downloads and some really good training <a href="http://windowsclient.net/learn/videos_wpf.aspx">videos</a>.&#160; Most of the videos are pretty short and tell you how to do just one thing like how to use styles or perform layout.&#160; So once you have a basic understanding these are pretty good, easily digestible snippets to add to your knowledge. </li>
<li><a href="http://archive.visitmix.com/university/wpf/bc08/Default.aspx">The WPF 08 Boot Camp</a> – This site has the WPF boot camp course that was given by IdentityMine and various other people available to download for the grand price of free.&#160; I am about half way through this so far and its pretty darn good. </li>
<li><a href="http://www.codeproject.com/KB/WPF/">Code Project – WPF Section</a> – Lots of downloadable goodness here as well as some nice tutorials by Josh Smith (<a href="http://www.codeproject.com/KB/WPF/GuidedTourWPF_1.aspx">starting here</a>) and Sacha Barber (<a href="http://www.codeproject.com/KB/WPF/BeginWPF1.aspx">starting here</a>). </li>
</ul>
<p>The next set of videos I am going to start watching is the <a href="http://www.benkotips.com/Default.aspx?tabid=1324">WPF Soup to Nuts</a> series.</p>
<ul>I also purchased a number of books – expect some reviews of them in the future.</ul>
]]></content:encoded>
			<wfw:commentRss>http://petedoesstuff.net/Blog/?feed=rss2&amp;p=43</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
