<?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>Wes Aday's Weblog</title>
	<atom:link href="http://wesaday.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://wesaday.wordpress.com</link>
	<description>Programming Ramblings blog</description>
	<lastBuildDate>Mon, 28 Nov 2011 14:33:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='wesaday.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Wes Aday's Weblog</title>
		<link>http://wesaday.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://wesaday.wordpress.com/osd.xml" title="Wes Aday&#039;s Weblog" />
	<atom:link rel='hub' href='http://wesaday.wordpress.com/?pushpress=hub'/>
		<item>
		<title>EMX &#8211; SD card reader</title>
		<link>http://wesaday.wordpress.com/2010/06/02/emx-sd-card-reader/</link>
		<comments>http://wesaday.wordpress.com/2010/06/02/emx-sd-card-reader/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 01:17:24 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[EMX]]></category>
		<category><![CDATA[GHIElectronics]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=250</guid>
		<description><![CDATA[This is the first real use that I came up with for the EMX board and it would appear that many people have questions regarding the SD card reader capability of the EMX. An SD card would be a quick and easy way to increase the available memory for this primarily embedded system. You might need [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=250&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the first real use that I came up with for the EMX board and it would appear that many people have questions regarding the SD card reader capability of the EMX. An SD card would be a quick and easy way to increase the available memory for this primarily embedded system. You might need to save or read text files or log your application to help debug it, updating your application in the field, or other uses.</p>
<p>Create a new project in Visual Studio 2008. Use the Visual C#-&gt;Micro Framework-&gt;Window Application project template, give the project a meaningful name and click OK. <img class="alignnone size-medium wp-image-251" title="Start" src="http://wesaday.files.wordpress.com/2010/06/start.jpg?w=300&#038;h=212" alt="" width="300" height="212" /> One thing that I do not like about the template is that the Program.cs file contains the Main method and the window definition. I prefer to separate the functionality but if you want to leave it alone feel free. The only thing that you really need in your Main method is:</p>
<p><code>Program myApplication = new Program();// Start the application</code><br />
<code>myApplication.Run(new MainWindow());</code></p>
<p>I delete the rest of the stuff. Now to the MainWindow. I add a new class called MainWindow to the project. The MainWindow must inherit from Window. Add these using statements:</p>
<div><code>using System;<br />
using GHIElectronics.NETMF.IO;<br />
using Microsoft.SPOT.Hardware;<br />
using Microsoft.SPOT.Presentation;<br />
using Microsoft.SPOT.Presentation.Media;<br />
using System.IO;<br />
using Microsoft.SPOT;<br />
using Microsoft.SPOT.IO;</code></div>
<div>We need two private fields; one for the sd card object and one for the SD card insert and removal notification:</div>
<div><code>private PersistentStorage _sdcard;<br />
private InterruptPort _sdDetect = new InterruptPort(GHIElectronics.NETMF.Hardware.EMX.Pin.IO36, true, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeBoth);<br />
</code></div>
<div>The first field sets up a PersistentStorage object for out SD card. The second line sets up a port to provide us an interrupt when the SD card is insert and removed. In this case we are going to use IO36, with a glitch filter, using a pull up resistor on the input and finally we want a notification for high and low transitions. If you look closely at the development board, there is a double row of headers down near the lower left side of the board with one side labeled JP1. The sixth pin down from the top is labeled SD Detect and that line is tied to the switch in the SD card connector. By itself it doesn&#8217;t do anything, you have to tie that line to an input for the processor. I chose IO36 which is conveniently located right next door to the SD Detect line. <a href="http://wesaday.files.wordpress.com/2010/06/emxheader.jpg"><img class="alignnone size-medium wp-image-252" title="OLYMPUS DIGITAL CAMERA" src="http://wesaday.files.wordpress.com/2010/06/emxheader.jpg?w=300&#038;h=225" alt="" width="300" height="225" /></a> You will need to run a jumper wire from SD Detect to whatever IO line you want to use.  Be very careful!</div>
<div>In the MainWindow constructor we will setup the window Height, Width, Background color and the event handler for the interrupt:</div>
<p><code>Width = SystemMetrics.ScreenWidth;<br />
Height = SystemMetrics.ScreenHeight;<br />
Background = new SolidColorBrush(0x000000);</code></p>
<p><code>_sdDetect.OnInterrupt += OnSdInterrupt;</code></p>
<div>The interrupt handler is very simple. However it is somewhat counter-intuitive. Because we are using a pull up resistor on the input, the transition values are backwards from what I would think. 0 means that the card was inserted and 1 means that the card was removed. I did try to use a pull down resistor but that wouldn&#8217;t work. It works so I didn&#8217;t screw with it too much. The handler looks like this:</div>
<p><code>private void OnSdInterrupt(uint data1, uint data2, DateTime time)<br />
{<br />
     if (data2 == 0)<br />
     {<br />
          _sdcard = new PersistentStorage("SD");<br />
          _sdcard.MountFileSystem();<br />
     }<br />
     else<br />
     {<br />
          if (_sdcard != null)<br />
          {<br />
              _sdcard.UnmountFileSystem();<br />
          }<br />
     }<br />
}<br />
</code></p>
<div>The data2 parameter is the state that the input is transitioning to. When the signal goes low then we know that the SD card has been inserted, we instantiate the PersistentStorage object and then mount the file system. The file system is not mounted by default. When the signal goes back high, we know that the SD card has been removed and we unmount the file system. You can compile and run the program now. You won&#8217;t see much of anything though. You can set a break point inside the interrupt handler and see that the input toggles high to low and back to high when you insert and remove an SD card.</div>
<div>The last thing to show is actually using the file system for something. Add the following method to the class:</div>
<p><code>private void GetFiles()<br />
{<br />
     if (!VolumeInfo.GetVolumes()[0].IsFormatted)<br />
     {<br />
           return;<br />
     }</code></p>
<p><code>     string[] files = Directory.GetFiles(VolumeInfo.GetVolumes()[0].RootDirectory);<br />
     foreach (string s in files)<br />
     {<br />
            Debug.Print(s);<br />
     }<br />
}</code></p>
<div>After the call to MountFileSystem add a call to GetFiles(). All we are doing is simply getting a list of files in the root of the SD card and then printing the file names to the output window. Now you can run the program on your development board and see the SD card doing something when you insert it. That is all there is to it.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/250/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/250/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/250/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=250&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2010/06/02/emx-sd-card-reader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/06/start.jpg?w=300" medium="image">
			<media:title type="html">Start</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/06/emxheader.jpg?w=300" medium="image">
			<media:title type="html">OLYMPUS DIGITAL CAMERA</media:title>
		</media:content>
	</item>
		<item>
		<title>EMX &#8211; Hello world</title>
		<link>http://wesaday.wordpress.com/2010/05/23/emx-hello-world/</link>
		<comments>http://wesaday.wordpress.com/2010/05/23/emx-hello-world/#comments</comments>
		<pubDate>Sun, 23 May 2010 22:16:20 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[EMX]]></category>
		<category><![CDATA[GHIElectronics]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=232</guid>
		<description><![CDATA[Today we will explore the ever popular &#8220;Hello world&#8221; using the .NET Micro Framework and see it running in the Emulator. Since the Micro Framework is targeted for embedded systems, there is very limited support for controls. What support there is, is based on WPF but there are some differences. When you install the Micro [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=232&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today we will explore the ever popular &#8220;Hello world&#8221; using the .NET Micro Framework and see it running in the Emulator. Since the Micro Framework is targeted for embedded systems, there is very limited support for controls. What support there is, is based on WPF but there are some differences.</p>
<p>When you install the Micro Framwork SDK it installs some new project templates into Visual Studio. We are going to use these templates to base our program on because creating a project from scratch in the Micro Framework is a bit of a pain. Fire up Visual Studio and create a new project using the Micro Framework Window Application template. In truth, it probably doesn&#8217;t matter if you choose the Console or Window template since we are going to delete everything and build it up step by step. <a href="http://wesaday.files.wordpress.com/2010/05/new.jpg"><img class="alignnone size-medium wp-image-233" title="New" src="http://wesaday.files.wordpress.com/2010/05/new.jpg?w=300&#038;h=201" alt="" width="300" height="201" /></a></p>
<p>Click Ok and let the project get created.   You should wind up with something like this:</p>
<p><a href="http://wesaday.files.wordpress.com/2010/05/template.jpg"><img class="alignnone size-full wp-image-234" title="Template" src="http://wesaday.files.wordpress.com/2010/05/template.jpg?w=278&#038;h=212" alt="" width="278" height="212" /></a> The template files are all well and good but you should know exactly what the template contains and what it does. Select the Resources folder, GPIOButtonInputProvider.cs, Program,cs and Resources.resx file and delete them. That should pretty much wipe out everything, except for the references.  Right click the project in the solution explorer, select Add and then click Class. <a href="http://wesaday.files.wordpress.com/2010/05/add.jpg"><img class="alignnone size-medium wp-image-235" title="Add" src="http://wesaday.files.wordpress.com/2010/05/add.jpg?w=300&#038;h=267" alt="" width="300" height="267" /></a>  Name the class Program and click Ok. This class is going to be the startup class. Add a public static Main method that returns void to the Program class and have Program derive from Application. Then add the following lines to the Main method:</p>
<div><span style="font-size:x-small;"><span style="font-size:x-small;">     Program program = new Program();</span></span></div>
<div><span style="font-size:x-small;"><span style="font-size:x-small;">     MainWindow win = new MainWindow();</span></span></div>
<p><span style="font-size:x-small;"><span style="font-size:x-small;">     program.Run(win);</p>
<p>Nothing to it right? The first line instantiates the Program class. The second line instantiates the MainWindow. The third line tells the program to run using win as the main window. The entire program class looks like this : <a href="http://wesaday.files.wordpress.com/2010/05/main.jpg"><img class="alignnone size-medium wp-image-236" title="Main" src="http://wesaday.files.wordpress.com/2010/05/main.jpg?w=300&#038;h=187" alt="" width="300" height="187" /></a></p>
<p>Now we need to add another class that will be our main window. Add a new class to the solution and call it MainWindow. MainWindow needs to derive from the Window class. Window is contained within the Microsoft.SPOT.Presentation namespace so add that using statement to the top of the file. Add a constructor for MainWindow and add these lines to it: <a href="http://wesaday.files.wordpress.com/2010/05/constructor1.jpg"><img class="alignnone size-medium wp-image-238" title="constructor" src="http://wesaday.files.wordpress.com/2010/05/constructor1.jpg?w=300&#038;h=131" alt="" width="300" height="131" /></a></p>
<p>The first two lines setup the window width and height. The third line sets the background color to blue. Note that the hex values for color are backwards from RGB. The hex values are BGR.</p>
<p>Lines 5 &#8211; 10 are an intializer for the Text class. Text is the equivalent of a Label in Winforms or TextBlock in WPF. I guess if they named it same as in WPF then there wouldn&#8217;t be anything new to learn&#8230;.</p>
<p>The Font for Text is set by getting the font from the resources. TextContent is the Text property. Then the horizontal and vertical alignments are set. In this case we are setting the text to be centered in the screen.</p>
<p>The last line sets the Window child to the Text control. The entire MainWindow class look like this: <a href="http://wesaday.files.wordpress.com/2010/05/mainwindow.jpg"><img class="alignnone size-medium wp-image-239" title="MainWindow" src="http://wesaday.files.wordpress.com/2010/05/mainwindow.jpg?w=300&#038;h=174" alt="" width="300" height="174" /></a></p>
<p>The last thing that we need to do is to add a Resource file to contain the font that we are going to be using. Right click the Project, select Add and then click New Item. <a href="http://wesaday.files.wordpress.com/2010/05/additem.jpg"><img class="alignnone size-medium wp-image-240" title="Additem" src="http://wesaday.files.wordpress.com/2010/05/additem.jpg?w=300&#038;h=292" alt="" width="300" height="292" /></a> Then select the Resources File to add. <a href="http://wesaday.files.wordpress.com/2010/05/resources.jpg"><img class="alignnone size-medium wp-image-241" title="Resources" src="http://wesaday.files.wordpress.com/2010/05/resources.jpg?w=300&#038;h=179" alt="" width="300" height="179" /></a> Once the file is created, click the Add Resource drop down and select Add Existing File. <a href="http://wesaday.files.wordpress.com/2010/05/addresource.jpg"><img class="alignnone size-full wp-image-242" title="AddResource" src="http://wesaday.files.wordpress.com/2010/05/addresource.jpg?w=278&#038;h=212" alt="" width="278" height="212" /></a> Browse to the .NET Micro Framework installation directory, default location is C:\Program Files\Microsoft &gt;NET Micro Framework\v4.0. Open up the Fonts folder and select the small.tinyfnt file and click Ok. The default installation of the Framework only comes with two fonts. You solution should now look like this: <a href="http://wesaday.files.wordpress.com/2010/05/solution.jpg"><img class="alignnone size-full wp-image-243" title="Solution" src="http://wesaday.files.wordpress.com/2010/05/solution.jpg?w=278&#038;h=242" alt="" width="278" height="242" /></a>You should be able to build your solution now.</p>
<p>Almost done. Now you want to see the result of all that work right? Remember this is for embedded systems. So what if you don&#8217;t have an embedded system to run it on? Or you have your system on order but have not go it yet? The Micro Framework comes with an emulator that you can use to run your program in. Click the Project menu item and select Properties. Select the .NET Micro Framework tab. On that page you will see a combo box labeled &#8220;Transport&#8221;. This is where you would select where to run your program. If you have Emulator already selected then you are good to go. Press F5 to start your program. Visual Studio will build and &#8220;deploy&#8221; the program to the emulator. And the final outcome should look like this:<a href="http://wesaday.files.wordpress.com/2010/05/final.jpg"><img class="alignnone size-medium wp-image-244" title="Final" src="http://wesaday.files.wordpress.com/2010/05/final.jpg?w=184&#038;h=300" alt="" width="184" height="300" /></a> </p>
<p><a href="http://wesaday.files.wordpress.com/2010/05/constructor.jpg"></a></p>
<p></span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/232/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=232&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2010/05/23/emx-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/new.jpg?w=300" medium="image">
			<media:title type="html">New</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/template.jpg" medium="image">
			<media:title type="html">Template</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/add.jpg?w=300" medium="image">
			<media:title type="html">Add</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/main.jpg?w=300" medium="image">
			<media:title type="html">Main</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/constructor1.jpg?w=300" medium="image">
			<media:title type="html">constructor</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/mainwindow.jpg?w=300" medium="image">
			<media:title type="html">MainWindow</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/additem.jpg?w=300" medium="image">
			<media:title type="html">Additem</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/resources.jpg?w=300" medium="image">
			<media:title type="html">Resources</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/addresource.jpg" medium="image">
			<media:title type="html">AddResource</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/solution.jpg" medium="image">
			<media:title type="html">Solution</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/final.jpg?w=184" medium="image">
			<media:title type="html">Final</media:title>
		</media:content>
	</item>
		<item>
		<title>EMX &#8211; updating the firmware</title>
		<link>http://wesaday.wordpress.com/2010/05/12/emx-updating-the-firmware/</link>
		<comments>http://wesaday.wordpress.com/2010/05/12/emx-updating-the-firmware/#comments</comments>
		<pubDate>Wed, 12 May 2010 19:55:53 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[EMX]]></category>
		<category><![CDATA[GHIElectronics]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=226</guid>
		<description><![CDATA[Working working with embedded systems may occasionally require you to update the firmware the runs the system. EMX takes advantage of the Midcrosoft Micro Framework .NET and being relatively new, the code tends to change fairly rapidly. When GHI Electronics distributes a new version of their SDK, you will probably want to update your system [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=226&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Working working with embedded systems may occasionally require you to update the firmware the runs the system. EMX takes advantage of the Midcrosoft Micro Framework .NET and being relatively new, the code tends to change fairly rapidly. When GHI Electronics distributes a new version of their SDK, you will probably want to update your system board to take advantage of bug fixes and new features.</p>
<p>Plug the EMX into an available USB port on your computer. The New Hardware Wizard should start if this is the first time that you have plugged the board in. When Windows finally figures out that it doesn&#8217;t know what the drivers would be, direct the wizard to the installation directory for the GHI Electronics SDK, by default C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\USB Drivers\GHI_NETMF_Interface.</p>
<p>Once you have done that, you have to put the EMX into the correct mode to update the firmware. Hold down the Up and Select buttons on the development board and press the Reset button.</p>
<p>Run the MFDeploy too that was installed with the .NET Micro Framework, by default C:\Program Files\Microsoft .NET Micro Framework\v4.0\Tools. <a href="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-start.jpg"><img class="alignnone size-medium wp-image-227" title="MFDelpoy start" src="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-start.jpg?w=300&#038;h=233" alt="" width="300" height="233" /></a></p>
<p>Select USB from the Device combobox</p>
<p><a href="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-usb.jpg"><img class="alignnone size-medium wp-image-228" title="MFDelpoy usb" src="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-usb.jpg?w=300&#038;h=233" alt="" width="300" height="233" /></a></p>
<p>Then click the Browse button and browse to the firmware directory for the development board, by default C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\EMX\Firmware, and select all of the .HEX files.</p>
<p><a href="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-selected.jpg"><img class="alignnone size-medium wp-image-229" title="MFDelpoy selected" src="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-selected.jpg?w=300&#038;h=233" alt="" width="300" height="233" /></a></p>
<p>Click the Deploy button and wait until it has finished doing its thing and you are done!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/226/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/226/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/226/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=226&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2010/05/12/emx-updating-the-firmware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-start.jpg?w=300" medium="image">
			<media:title type="html">MFDelpoy start</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-usb.jpg?w=300" medium="image">
			<media:title type="html">MFDelpoy usb</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2010/05/mfdelpoy-selected.jpg?w=300" medium="image">
			<media:title type="html">MFDelpoy selected</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting started with EMX &#8211; updating the bootloader</title>
		<link>http://wesaday.wordpress.com/2010/05/02/getting-started-with-emx-updating-the-bootloader/</link>
		<comments>http://wesaday.wordpress.com/2010/05/02/getting-started-with-emx-updating-the-bootloader/#comments</comments>
		<pubDate>Sun, 02 May 2010 23:47:55 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[EMX]]></category>
		<category><![CDATA[GHIElectronics]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=224</guid>
		<description><![CDATA[The first thing that you have to do to get started using EMX from GHIElectronics, www.ghielectronics.com, is to go to http://www.microsoft.com/netmf/default.mspx and download the Micro Framework SDK and install it. Then go over to GHI Electronics, http://www.ghielectronics.com/product/129, and download and install the GHI SDK for NETMF. While you are there be sure to download their free ebook, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=224&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The first thing that you have to do to get started using EMX from GHIElectronics, <a href="http://www.ghielectronics.com">www.ghielectronics.com</a>, is to go to <a href="http://www.microsoft.com/netmf/default.mspx">http://www.microsoft.com/netmf/default.mspx</a> and download the Micro Framework SDK and install it. Then go over to GHI Electronics, <a href="http://www.ghielectronics.com/product/129">http://www.ghielectronics.com/product/129</a>, and download and install the GHI SDK for NETMF. While you are there be sure to download their free ebook, &#8220;Beginners guide to NETMF&#8221;. You will of course need Visual Studio. As of this time VS 2008 is supported not VS 2010.</p>
<p>The first thing that you will probably want to do is to update the firmware on the development board. This is accomplished in two steps and involves placing the EMX board into two different operating modes.</p>
<p>Updating the bootloader</p>
<p>Plug the development board into an available USB port on your computer using the supplied USB cable. If the computer asks to install any device drivers, ignore that for now. To access the bootloader update mode, you would hold down the Up, Down and Select buttons on the development board as you power up the board or push the reset button. So patience is called for here. Unless you have teeny tiny fingers, it&#8217;s very difficult to hold all three buttons down at the same time. You know you have it when the screen does not display the boot up messages and is washed out with white.</p>
<p>If this is the first time that you have accessed this mode, the Hardware wizard should start up and want to install device drivers.  The drivers you want to install at this time are located at C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\USB Drivers\GHI_Bootloader_Interface if you used the default location when you installed the GHI SDK. This driver allows you to connect to the board through the USB port using a terminal program. Once the driver is installed you are ready to go.</p>
<p>You need to use a terminal program to upload the new program to the processor. GHI reccommends Terra Term to use to upload the bootloader, you can download the program from their site. Personally, I have not had any success using Terra Term. I had heard that they have had problems with their 1K XModem protocol and I could never get it to work properly. I have used HyperTerminal that comes with Windows successfully. Start up your terminal program and connect to the EMX board. Hopefully you will be able to figure out which comport you need to use. Use 115200 8-N-1 and no flow control as your parameters.</p>
<p>Once you have connected, use the &#8216;E&#8217; command to erase the memory. Note that you have to use upper case characters. Then press &#8216;Y&#8217; to confirm the erase command. Wait until the board memory has been erased. While the erase is going on * characters are printed to the screen. They that stops you are ready to upload the new bootloader.</p>
<p>Press &#8216;X&#8217; to begin the upload procedure. Again, remember upper case! The terminal program will start printing C characters to the screen indicating that the board is waiting for the upload. If you are using HyperTerminal, click the Transfer menu and Send File. Browse to the bootloader program to upload. In this case you want to go to C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\EMX\Firmware\TinyBooter and select the TinyBooter.GHI file. Be sure to select XModem 1K to use for the transfer. The transfer only takes a few seconds. After the transfer is complete, the board will reboot itself in preparation for the next step.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=224&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2010/05/02/getting-started-with-emx-updating-the-bootloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>
	</item>
		<item>
		<title>EMX embedded system</title>
		<link>http://wesaday.wordpress.com/2010/05/01/emx-embedded-system/</link>
		<comments>http://wesaday.wordpress.com/2010/05/01/emx-embedded-system/#comments</comments>
		<pubDate>Sat, 01 May 2010 23:59:18 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[EMX]]></category>
		<category><![CDATA[GHIElectronics]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=222</guid>
		<description><![CDATA[Found this really cool item from GHIElectonics, www.ghielectronics.com. They have a variety of items, I got the EMX. It&#8217;s a development board that utilizes the Microsoft .NET Micro Framework. Basically it&#8217;s .NET embedded on a chip. And since I am more and more working with hardware and embedded systems, I broke open the old piggy [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=222&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Found this really cool item from GHIElectonics, <a href="http://www.ghielectronics.com">www.ghielectronics.com</a>. They have a variety of items, I got the EMX. It&#8217;s a development board that utilizes the Microsoft .NET Micro Framework. Basically it&#8217;s .NET embedded on a chip. And since I am more and more working with hardware and embedded systems, I broke open the old piggy bank and bought one. The board comes with a bunch of connectors that are already wired up so you can pretty much get going right away. It has a ton of features that could be used for a bunch of different applications. The good news is that you can program and debug  the processor using Visual Studio. The bad news is that you have to code everything by hand which isn&#8217;t really bad unless you are doing a user interface using the touch screen as the Micro Framework does not have an overabundance of support for user interface components. What support there is does support WPF elements. XAML is not supported though.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/222/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=222&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2010/05/01/emx-embedded-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF application memory leak</title>
		<link>http://wesaday.wordpress.com/2010/01/18/wpf-application-memory-leak/</link>
		<comments>http://wesaday.wordpress.com/2010/01/18/wpf-application-memory-leak/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 16:19:08 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CMilChannel HwndSource]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=216</guid>
		<description><![CDATA[I have had an issue with a memory leak in one of my WPF (v3.5 SP1) based applications for quite some time. I has been really hard to track down because the appliation runs for 5 days apparently just fine then crashed with an &#8220;Out Of Memory&#8221; exception. So I have been trying to use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=216&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have had an issue with a memory leak in one of my WPF (v3.5 SP1) based applications for quite some time. I has been really hard to track down because the appliation runs for 5 days apparently just fine then crashed with an &#8220;Out Of Memory&#8221; exception. So I have been trying to use profilers and just about any other tool that I could find to try and track down what would be allocating memory on a continual basis and not letting it go. Imagine my surprise when running profilers that the &#8220;before&#8221; and &#8220;after&#8221; snapshots are virtually identical. Very frustrating.</p>
<p>I did find this blog entry here, <a rel="nofollow" href="http://blogs.msdn.com/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx">http://blogs.msdn.com/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx</a>, that disuss many memory leaks and fixes for them but nothing there exactly described my situation, or the meaning was not clear. The demostration application for the leaks has the leak in there but I am not doing what he did (that I know of) and he does not demonstrate how to work around the problem. Then I ran across this question on StackOverflow, <a href="http://stackoverflow.com/questions/801589/track-down-memory-leak-in-wpf">http://stackoverflow.com/questions/801589/track-down-memory-leak-in-wpf</a>, which described exactly what I was seeing. Which also pointed back to the first blog. So, after not thinking about it over the weekend and coming in fresh on Monday I looked again. I found this entry on StackOverflow, <a href="http://stackoverflow.com/questions/1705849/wpf-memory-leak-on-xp-cmilchannel-hwnd">http://stackoverflow.com/questions/1705849/wpf-memory-leak-on-xp-cmilchannel-hwnd</a>, which points out a very simple solution.</p>
<p>Apparently somewhere along the line, the application is getting confused as to who is doing the rendering. So messages are being allocated and sent, but no one is consuming them so they pile up until you run out of memory. The work around is to create a new HwndSource in the application constructor and that reregisters the window class with Windows and does not cause the confusion.</p>
<p><span style="color:#0000ff;">public </span><span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">App</span> : <span style="color:#2b91af;">Application</span></p>
<p>{</p>
<p>public App() <br />
   { <br />
       new HwndSource(new HwndSourceParameters()); <br />
   } </p>
<p>}</p>
<p>This appeared to work for me and hopefully will help someone else.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/216/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=216&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2010/01/18/wpf-application-memory-leak/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>
	</item>
		<item>
		<title>Winforms &#8211; Model-View-Presenter &#8211; A tutorial</title>
		<link>http://wesaday.wordpress.com/2009/05/11/winforms-model-view-presenter-a-tutorial-2/</link>
		<comments>http://wesaday.wordpress.com/2009/05/11/winforms-model-view-presenter-a-tutorial-2/#comments</comments>
		<pubDate>Tue, 12 May 2009 01:41:33 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Model View Presenter]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[Winforms]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=89</guid>
		<description><![CDATA[Introduction Coming from a C/C++ and diving into the .NET, I am constantly surrounded by strange phrases, three letter acronyms and concepts that take a long time to get used to. One of those concepts is the Model-View-Presenter (MVP).  There are plenty of articles about MVP around the Web. Most are pointers to Martin Fowler [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=89&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Introduction</span></h2>
<p><a rel="tag" href="http://www.codeproject.com/script/articles/blogfeedlist.aspx?amid=55831"></a></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Coming from a C/C++ and diving into the .NET, I am constantly surrounded by strange phrases, three letter acronyms and concepts that take a long time to get used to. One of those concepts is the Model-View-Presenter (MVP). <span> </span>There are plenty of articles about MVP around the Web. Most are pointers to Martin Fowler (</span><a href="http://www.martinfowler.com/eaaDev/uiArchs.html"><span style="font-size:small;font-family:Calibri;">http://www.martinfowler.com/eaaDev/uiArchs.html</span></a><span style="font-size:small;font-family:Calibri;">) or the MSDN (</span><a href="http://msdn.microsoft.com/en-us/library/cc304760.aspx"><span style="font-size:small;font-family:Calibri;">http://msdn.microsoft.com/en-us/library/cc304760.aspx</span></a><span style="font-size:small;font-family:Calibri;">). There are also many articles on Code Project (</span><a href="http://www.codeproject.com/"><span style="font-size:small;font-family:Calibri;">www.codeproject.com</span></a><span style="font-size:small;font-family:Calibri;">). The problem that I have had in the reading of these articles is that most use big $.25 words and unfamiliar phrases that mean nothing to the beginner, along with diagrams that are just plain confusing. Nothing I found that was in plain simple English. After a lot of trial and error and study I think I finally have something that I can understand. I do not pretend that this is the “right way” or the only way but it works for me.</span></p>
<p>This is the first part of five. Links to the other parts are:</p>
<p>     <a href="http://wesaday.wordpress.com/2009/01/27/winforms-model-view-presenter-part-ii-the-interface/" target="_self">Part II</a></p>
<p>     <a href="http://wesaday.wordpress.com/2009/01/28/winform-model-view-presenter-tutorial-part-iii/" target="_self">Part III</a></p>
<p>       <a href="http://wesaday.wordpress.com/2009/01/29/winforms-model-view-presenter-part-iv-the-presenter/" target="_self">Part IV</a></p>
<p>       <a href="http://wesaday.wordpress.com/2009/01/30/winform-model-view-presenter-part-v-the-view" target="_self">Part V</a></p>
<p> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">MVP</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The goal of using the MVP design pattern is to separate the responsibilities of the application in such a manner as to make the application code:</span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-.25in;margin:0 0 0 .5in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Calibri;">Testable in an automated manner</span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Calibri;">Make the application more maintainable</span></p>
<p class="MsoListParagraphCxSpLast" style="text-indent:-.25in;margin:0 0 10pt .5in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><span style="font-family:Calibri;">Make the application more extensible.<span>  </span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The first bullet means that there are many tools out there in the world that can be used to test code in an automated manner, called “unit testing”. These tools cannot test code that is in form code-behind modules. So the aim is to take that code out of the form code and place it in a DLL that can be tested.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">I do not know about anyone else, but for me application code is way more maintainable when it is separated out into modules that have a specific purpose. If some unexpected feature does make it through the unit testing, then you will have a pretty good idea where to look just based on knowing what the various classes’ responsibilities are.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The extensibility part comes in when you have this separation of concerns, adding additional functionality is made easier because the code modules are not closely tied together also known as “loose coupling”.</span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">What does it all mean?</span></h2>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The first thing is to understand the meaning of what the terms mean. </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">View: A view is any form or window that is shown to the user of the application.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Presenter: The presenter is an entity that presents the data to the view that is to be shown to the user.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Model: The model is the actual data that the Presenter will request and gets displayed in the View. The Model is responsible for obtaining the data. So the Model is the one that reads files, or connects to a database or if you are really ambitious, gets the data from a data service object.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The pattern is typically drawn like this.</span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"><img class="alignnone size-full wp-image-72" title="uml1" src="http://wesaday.files.wordpress.com/2009/01/uml1.jpg?w=274&#038;h=181" alt="uml1" width="274" height="181" /> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Looks simple doesn’t it? Well what all those other articles, and examples, didn’t tell me was how to turn that simple diagram into a working application.</span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Get on with it already!</span></h2>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The first thing to do is to setup the solution. Open up Visual Studio and create a new Windows Forms Application.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> <img class="alignnone size-medium wp-image-62" title="newproject1" src="http://wesaday.files.wordpress.com/2009/01/newproject1.jpg?w=300&#038;h=213" alt="newproject1" width="300" height="213" /></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Once Visual Studio is through creating your new project, add a class library to the solution to hold all of the various classes. Right click your solution object in the Solution Explorer, select Add then Add new project.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"> <span style="font-size:medium;color:#4f81bd;font-family:Cambria;"><img class="alignnone size-medium wp-image-63" title="addnew1" src="http://wesaday.files.wordpress.com/2009/01/addnew1.jpg?w=240&#038;h=300" alt="addnew1" width="240" height="300" /></span></span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"> </p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"><span style="font-size:small;font-family:Calibri;"><img class="alignnone size-medium wp-image-64" title="classlibrary" src="http://wesaday.files.wordpress.com/2009/01/classlibrary.jpg?w=300&#038;h=191" alt="classlibrary" width="300" height="191" /> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">I named mine Common.Lib.dll you can name yours whatever you want to. I have seen some people that create a class library to contain the business logic and another one to contain the data layer. I think is overkill for this simple example. Go ahead and delete the Class1.cs file that Visual Studio created for you.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">I like to compartmentalize things so I group like classes together. Right click on the class library project; select Add then Select New Folder. Name the new folder, Interfaces. Repeat twice more and name the other two new folders Models and Presenters. Your project should now look like this.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;"><img class="alignnone size-medium wp-image-65" title="solutionex" src="http://wesaday.files.wordpress.com/2009/01/solutionex.jpg?w=290&#038;h=300" alt="solutionex" width="290" height="300" /></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">This is the end of Part 1. After starting the article it quickly grew to 14 pages and I was not done yet so I elected to post a series of pages.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">This is the project skeleton so far. Change the extension from .doc to .zip before you open it. This is a workpress requirement. <a href="http://wesaday.files.wordpress.com/2009/01/projectskeletonzip.doc">projectskeletonzip</a></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=89&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2009/05/11/winforms-model-view-presenter-a-tutorial-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/01/uml1.jpg" medium="image">
			<media:title type="html">uml1</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/01/newproject1.jpg?w=300" medium="image">
			<media:title type="html">newproject1</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/01/addnew1.jpg?w=240" medium="image">
			<media:title type="html">addnew1</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/01/classlibrary.jpg?w=300" medium="image">
			<media:title type="html">classlibrary</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/01/solutionex.jpg?w=290" medium="image">
			<media:title type="html">solutionex</media:title>
		</media:content>
	</item>
		<item>
		<title>Model-View-Presenter and Model-View-ViewModel in Prism</title>
		<link>http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/</link>
		<comments>http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 02:59:02 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CAL]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Composite Application Library]]></category>
		<category><![CDATA[Model View Presenter]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=177</guid>
		<description><![CDATA[ Introduction  One of the most valuable skills a developer can develop is the ability to seperate UI modules, business rules and data access modules so that they are more maintainable. This separation means that the modules can be developed independently of each other without the changes having any impact on other modules. After several years [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=177&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> <span style="font-size:small;font-family:Calibri;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Introduction</span></span></p>
<p> <span style="font-size:small;font-family:Calibri;">One of the most valuable skills a developer can develop is the ability to seperate UI modules, business rules and data access modules so that they are more maintainable. This separation means that the modules can be developed independently of each other without the changes having any impact on other modules. After several years in the business you get kind of tired of making a change and then having to chase down a bug that made its way in your application affecting modules that you never thought your change would touch you will come to appreciate separating out the code into different modules. Prism actually makes this pretty simple.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The first design pattern that will be demonstrated is the Supervising Presenter pattern that most closely resembles the Model-View-Presenter pattern so if you understand the MVP pattern then you should have no problem understanding this. For more information on the Supervising Presenter pattern see the Supervising Presenter topic in the Prism documentation.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">A simple diagram for the MVP pattern looks like this:</span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"> </p>
<p> </p>
<p> </p>
<p> </p>
<div><span style="font-size:small;font-family:Calibri;"></span></div>
<p> </p>
<p><span style="font-size:small;font-family:Calibri;"></p>
<div id="attachment_178" class="wp-caption aligncenter" style="width: 303px"><a rel="attachment wp-att-178" href="http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/mvp/"><img class="size-full wp-image-178" title="mvp" src="http://wesaday.files.wordpress.com/2009/03/mvp.png?w=293&#038;h=186" alt="MVP diagram" width="293" height="186" /></a><p class="wp-caption-text">MVP diagram</p></div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The second design pattern that will be demonstrated is the Presentation Model or Model-View-ViewModel pattern.<span>  </span>For more on the Presentation Model pattern see the Presentation Model topic in the Prism documentation.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">A simple diagram of the Presentation Model pattern looks like this:</span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"> </p>
<p> </p>
<p> </p>
<p> </p>
<div><span style="font-size:small;font-family:Calibri;"></span></div>
<p> </p>
<p><span style="font-size:small;font-family:Calibri;"></p>
<div id="attachment_179" class="wp-caption aligncenter" style="width: 457px"><a rel="attachment wp-att-179" href="http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/mvvm/"><img class="size-full wp-image-179" title="mvvm" src="http://wesaday.files.wordpress.com/2009/03/mvvm.png?w=447&#038;h=73" alt="MVVM diagram" width="447" height="73" /></a><p class="wp-caption-text">MVVM diagram</p></div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The foundation for this demonstration is the final project from the Getting Started article which you can get </span><a href="http://wesaday.wordpress.com/2009/03/17/getting-started-with-prism-2-formerly-known-as-the-composite-application-library/"><span style="font-size:small;font-family:Calibri;">here</span></a><span style="font-size:small;font-family:Calibri;">.</span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">First the MVP pattern</span></h2>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The first thing to do is to decide what kind of data that we are going to display in the view and how we are going to display it. For this simple example we are going to display some strings in a ListBox. So the final ChildOneView will look like this:</span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"> </p>
<p class="MsoNormal" style="text-align:center;"><span style="font-size:small;font-family:Calibri;"><img class="size-full wp-image-180  aligncenter" title="one" src="http://wesaday.files.wordpress.com/2009/03/one.png?w=304&#038;h=304" alt="one" width="304" height="304" /></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The second thing to do is to create some folders within the project to hold the various files that we are going to be creating. This helps to keep the clutter down.<span>  </span>Right click on the ChildOneModule project and add a NewFolder named “Interfaces”. Add two more folders and name them “Presenters” and “Services”. Now we are going to need to create three interfaces, one for the View, one for the Model and one for the Presenter. <span> </span>After that your project will look something like this</span></p>
<p class="MsoNormal" style="text-align:center;"><span style="font-size:small;font-family:Calibri;"><a rel="attachment wp-att-181" href="http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/struct1/"><img class="size-full wp-image-181  aligncenter" title="struct1" src="http://wesaday.files.wordpress.com/2009/03/struct1.png?w=319&#038;h=283" alt="struct1" width="319" height="283" /></a></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The interfaces are very simple. The Model interface will expose a collection strings that the view will bind to.</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">interface</span> <span style="color:#2b91af;">IChildOneService</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">GetStrings</span>();</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The Presenter interface will need to have a reference to the View:</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">interface</span> <span style="color:#2b91af;">IChildOnePresenter</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">IChildOneView</span> <span style="color:#010001;">View</span> { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }<span>   </span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">And finally, the View will need to have a reference to the data that the Model is going to expose:</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">interface</span> <span style="color:#2b91af;">IChildOneView</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">Model</span> { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">That pretty much does it for the interfaces. The next thing to do is to create a class that will serve as the Model. Right click the Services folder and add a new class named “ChildOneService”. The service will need to implement the IChildOneService interface that we created earlier.</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ChildOneService</span> : <span style="color:#2b91af;">IChildOneService</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">GetStrings</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">strings</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; { <span style="color:#a31515;">&#8220;one&#8221;</span>, <span style="color:#a31515;">&#8220;two&#8221;</span>, <span style="color:#a31515;">&#8220;three&#8221;</span>};</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> <span style="color:#010001;">strings</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The GetStrings method will return the string collection and that is what is going to be displayed in the View. It’s important to realize that the data that is displayed could come from anywhere, a file, a database, a web service, etc. </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The Presenter class is also very simple. Create a ChildOnePresenter class in the “Presenters” folder and have it implement the presenter interface. The Presenter will need a reference to the view and the model passed to it in the class constructor.</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ChildOnePresenter</span> : <span style="color:#2b91af;">IChildOnePresenter</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span> </span><span>   </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#2b91af;">IChildOneView</span> <span style="color:#010001;">View</span> { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#010001;">ChildOnePresenter</span>(<span style="color:#2b91af;">IChildOneView</span> <span style="color:#010001;">view</span>, <span style="color:#2b91af;">IChildOneService</span> <span style="color:#010001;">model</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">View</span> = <span style="color:#010001;">view</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">View</span>.<span style="color:#010001;">Model</span> = <span style="color:#010001;">model</span>.<span style="color:#010001;">GetStrings</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Open the view code-behind file. Modify the class definition to implement the IChildOneView interface. The view interface is implemented as a property that is used to data bind to. The data is transferred from the ChildOneService class to the View by the Presenter.</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span style="color:blue;">public</span> <span style="color:blue;">partial</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ChildOneView</span> : <span style="color:#2b91af;">UserControl</span>, <span style="color:#2b91af;">IChildOneView</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#010001;">ChildOneView</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">InitializeComponent</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">Model</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">get</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">return</span> <span style="color:#010001;">DataContext</span> <span style="color:blue;">as</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt;;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">set</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:#010001;">DataContext</span> = <span style="color:blue;">value</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Open the View XAML file and modify the view to include a listbox and bind the listbox item data source to the string collection.</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">StackPanel</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Label</span><span style="font-size:10pt;color:red;font-family:&quot;"> Content</span><span style="font-size:10pt;color:blue;font-family:&quot;">=&#8221;Child one&#8221; /&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ListBox</span><span style="font-size:10pt;color:red;font-family:&quot;"> ItemsSource</span><span style="font-size:10pt;color:blue;font-family:&quot;">=&#8221;{</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Binding</span><span style="font-size:10pt;color:blue;font-family:&quot;">}&#8221; /&gt;</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;color:#a31515;line-height:115%;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;line-height:115%;font-family:&quot;">StackPanel</span><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The last step is to modify the module class. We need to include a reference to the container so that we can notify the container that we have additional classes for it to instantiate. Once that is done, then we register the Model, View and Presenter with the container</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ChildOne</span> : <span style="color:#2b91af;">IModule</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">private</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">IRegionManager</span> <span style="color:#010001;">_regionManager</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">private</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">IUnityContainer</span> <span style="color:#010001;">_container</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#010001;">ChildOne</span>(<span style="color:#2b91af;">IUnityContainer</span> <span style="color:#010001;">container</span>, <span style="color:#2b91af;">IRegionManager</span> <span style="color:#010001;">regionManager</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_regionManager</span> = <span style="color:#010001;">regionManager</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_container</span> = <span style="color:#010001;">container</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> <span style="color:#010001;">Initialize</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_container</span>.<span style="color:#010001;">RegisterType</span>&lt;<span style="color:#2b91af;">IChildOneService</span>, <span style="color:#2b91af;">ChildOneService</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_container</span>.<span style="color:#010001;">RegisterType</span>&lt;<span style="color:#2b91af;">IChildOnePresenter</span>, <span style="color:#2b91af;">ChildOnePresenter</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_container</span>.<span style="color:#010001;">RegisterType</span>&lt;<span style="color:#2b91af;">IChildOneView</span>, <span style="color:#2b91af;">ChildOneView</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">ChildOnePresenter</span> <span style="color:#010001;">presenter</span> = <span style="color:#010001;">_container</span>.<span style="color:#010001;">Resolve</span>&lt;<span style="color:#2b91af;">ChildOnePresenter</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_regionManager</span>.<span style="color:#010001;">Regions</span>[<span style="color:#a31515;">"LeftChild"</span>].<span style="color:#010001;">Add</span>(<span style="color:#010001;">presenter</span>.<span style="color:#010001;">View</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">If you compile and run the application at this point, you should see a window like the picture up top. That is how to implement the MVP pattern in Prism.</span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Model-View-ViewModel</span></h2>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The MVVM pattern is implemented in almost the same way. The only real difference is the way the View displays its data. MVVM relies heavily on data binding and Commands to get things done. This article is not going to cover Commands. That is something for another time. </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">To begin, create folders in the ChildTwoModule project named Interfaces, Services and ViewModels. You should turn out with something that looks like this:</span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"> </p>
<p class="MsoNormal" style="text-align:center;"><span style="font-size:small;font-family:Calibri;"><a rel="attachment wp-att-182" href="http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/struct2/"><img class="aligncenter size-full wp-image-182" title="struct2" src="http://wesaday.files.wordpress.com/2009/03/struct2.png?w=316&#038;h=324" alt="struct2" width="316" height="324" /></a></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">For this example we will need three interfaces, IChildTwoModel, IChildTwoView and IChildTwoViewModel. As in the previous example, the Model will export a list of strings so our interface for the Model will look like this:</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">using</span> <span style="color:#010001;">System</span>.<span style="color:#010001;">Collections</span>.<span style="color:#010001;">ObjectModel</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">interface</span> <span style="color:#2b91af;">IChildTwoModel</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">GetStrings</span>();</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The interface for the ViewModel will need to have a Property that exposes the list of strings to the View. The ViewModel will also need a reference to the View so our interface for the ViewModel will look like this:</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">interface</span> <span style="color:#2b91af;">IChildTwoViewModel</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">ModelStrings</span> { <span style="color:blue;">get</span>; }</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">IChildTwoView</span> <span style="color:#010001;">View</span> { <span style="color:blue;">get</span>; }</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span> </span>The interface for the View will need a way to set the data to display. Since the ViewModel is exposing the data, the View needs a way to data bind the ViewModel to the View:</span></span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">interface</span> <span style="color:#2b91af;">IChildTwoView</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">void</span> <span style="color:#010001;">SetModel</span>(<span style="color:#2b91af;">IChildTwoViewModel</span> <span style="color:#010001;">model</span>);</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now, on to the implementation. The Model class needs to implement the IChildTwoModel interface so create a new class in the Services folder named ChildTwoModel and then implement the interface. Remember that the interface is a method named GetStrings and returns a collection of string objects. So your Model class will look like this:</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">using</span> <span style="color:#010001;">Interfaces</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">using</span> <span style="color:#010001;">System</span>.<span style="color:#010001;">Collections</span>.<span style="color:#010001;">ObjectModel</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ChildTwoModel</span> : <span style="color:#2b91af;">IChildTwoModel</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">GetStrings</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">strings</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; { <span style="color:#a31515;">&#8220;one&#8221;</span>, <span style="color:#a31515;">&#8220;two&#8221;</span>, <span style="color:#a31515;">&#8220;three&#8221;</span> };</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> <span style="color:#010001;">strings</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">For the moment, I am going to skip over the ViewModel class as it is the most involved. Open up the View class and modify it to implement the IChildView interface. That brings in a method SetModel that will setup the data binding:</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">partial</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ChildTwoView</span> : <span style="color:#2b91af;">UserControl</span>, <span style="color:#2b91af;">IChildTwoView</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#010001;">ChildTwoView</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">InitializeComponent</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> <span style="color:#010001;">SetModel</span>(<span style="color:#2b91af;">IChildTwoViewModel</span> <span style="color:#010001;">model</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">DataContext</span> = <span style="color:#010001;">model</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now open up the ChildTwoView.xaml file. Change the Grid layout panel to a StackPanel, and then add a ListBox to the StackPanel. Set the ItemsSource to the bind to the ModelStrings. </span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">StackPanel</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Label</span><span style="font-size:10pt;color:red;font-family:&quot;"> Content</span><span style="font-size:10pt;color:blue;font-family:&quot;">=&#8221;Child two&#8221; /&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#a31515;font-family:&quot;"><span>        </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">ListBox</span><span style="font-size:10pt;color:red;font-family:&quot;"> ItemsSource</span><span style="font-size:10pt;color:blue;font-family:&quot;">=&#8221;{</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">Binding</span><span style="font-size:10pt;color:red;font-family:&quot;"> ModelStrings</span><span style="font-size:10pt;color:blue;font-family:&quot;">}&#8221; /&gt;</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;color:#a31515;line-height:115%;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:#a31515;line-height:115%;font-family:&quot;">StackPanel</span><span style="font-size:10pt;color:blue;line-height:115%;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now we come to the ViewModel class. The ViewModel class in the MVVM pattern takes on a lot of responsibility. The ViewModel not only provides data to the View but it also keeps track of the View state and acting as a go-between to the Model. One thing that is a really nifty feature is that the ViewModel can automatically update the Views data just by raising a property changed event. Okay so our ViewModel class needs to implement the IChildTwoViewModel interface and the INotifyPropertyChanged interface. The class constructor will need a reference to the View and the Model and set the ViewModel in the View:</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>       </span><span> </span><span style="color:blue;">private</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">IChildTwoView</span> <span style="color:#010001;">_view</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">private</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">IChildTwoModel</span> <span style="color:#010001;">_model</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">private</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">_modelStrings</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#010001;">ChildTwoViewModel</span>(<span style="color:#2b91af;">IChildTwoView</span> <span style="color:#010001;">view</span>, <span style="color:#2b91af;">IChildTwoModel</span> <span style="color:#010001;">model</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_view</span> = <span style="color:#010001;">view</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_model</span> = <span style="color:#010001;">model</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_modelStrings</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_modelStrings</span> = <span style="color:#010001;">_model</span>.<span style="color:#010001;">GetStrings</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">View</span>.<span style="color:#010001;">SetModel</span>(<span style="color:blue;">this</span>);</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span> </span>The SetModel method sets the data binding to the ViewModel. Now if you remember the View data binds the ListBox to something called ModelStrings so we need to implement a Property to expose the model strings:</span></span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:#2b91af;">ObservableCollection</span>&lt;<span style="color:blue;">string</span>&gt; <span style="color:#010001;">ModelStrings</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">get</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">return</span> <span style="color:#010001;">_modelStrings</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">set</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:#010001;">_modelStrings</span> = <span style="color:blue;">value</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:#010001;">OnPropertyChanged</span>(<span style="color:#a31515;">&#8220;ModelStrings&#8221;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The OnPropertyChanged event notifies the View that the data has changed (if it does) and to update the data in the View.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;">
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span> </span><span style="color:blue;"><span style="font-size:10pt;font-family:&quot;"><span><span style="color:#000000;">       </span></span><span style="color:blue;">public</span><span style="color:#000000;"> </span><span style="color:blue;">event</span><span style="color:#000000;"> </span><span style="color:#2b91af;">PropertyChangedEventHandler</span><span style="color:#000000;"> </span><span style="color:#010001;">PropertyChanged</span><span style="color:#000000;">;</span></span></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#000000;"> </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span><span style="color:#000000;">        </span></span><span style="color:blue;">private</span><span style="color:#000000;"> </span><span style="color:blue;">void</span><span style="color:#000000;"> </span><span style="color:#010001;">OnPropertyChanged</span><span style="color:#000000;">(</span><span style="color:blue;">string</span><span style="color:#000000;"> </span><span style="color:#010001;">propertyName</span><span style="color:#000000;">)</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#000000;"><span>        </span>{</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span><span style="color:#000000;">            </span></span><span style="color:#2b91af;">PropertyChangedEventHandler</span><span style="color:#000000;"> </span><span style="color:#010001;">handler</span><span style="color:#000000;"> = </span><span style="color:#010001;">PropertyChanged</span><span style="color:#000000;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span><span style="color:#000000;">            </span></span><span style="color:blue;">if</span><span style="color:#000000;"> (</span><span style="color:#010001;">handler</span><span style="color:#000000;"> != </span><span style="color:blue;">null</span><span style="color:#000000;">)</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#000000;"><span>            </span>{</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span><span style="color:#000000;">                </span></span><span style="color:#010001;">handler</span><span style="color:#000000;">(</span><span style="color:blue;">this</span><span style="color:#000000;">, </span><span style="color:blue;">new</span><span style="color:#000000;"> </span><span style="color:#2b91af;">PropertyChangedEventArgs</span><span style="color:#000000;">(</span><span style="color:#010001;">propertyName</span><span style="color:#000000;">));</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#000000;"><span>     </span><span>       </span>}</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span style="color:#000000;"><span>        </span>}</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The final thing is to modify the ChildTwoModule class to register the interfaces and the classes with the container just like we modified the ChildOneModule class.</span></p>
<p> </p>
<p> </p>
<div><span style="font-size:10pt;font-family:&quot;"><span></span></span></div>
<p> </p>
<p><span style="font-size:10pt;font-family:&quot;"><span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> <span style="color:#010001;">Initialize</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_container</span>.<span style="color:#010001;">RegisterType</span>&lt;<span style="color:#2b91af;">IChildTwoModel</span>, <span style="color:#2b91af;">ChildTwoModel</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_container</span>.<span style="color:#010001;">RegisterType</span>&lt;<span style="color:#2b91af;">IChildTwoViewModel</span>, <span style="color:#2b91af;">ChildTwoViewModel</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">_container</span>.<span style="color:#010001;">RegisterType</span>&lt;<span style="color:#2b91af;">IChildTwoView</span>, <span style="color:#2b91af;">ChildTwoView</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">IChildTwoViewModel</span> <span style="color:#010001;">view</span> = <span style="color:#010001;">_container</span>.<span style="color:#010001;">Resolve</span>&lt;<span style="color:#2b91af;">IChildTwoViewModel</span>&gt;();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>          </span><span>  </span><span style="color:#010001;">_regionManager</span>.<span style="color:#010001;">Regions</span>[<span style="color:#a31515;">"RightChild"</span>].<span style="color:#010001;">Add</span>(<span style="color:#010001;">view</span>.<span style="color:#010001;">View</span>);</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Now you should be able to compile and run that application and get a window similar to this:</span></p>
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;" align="center"> </p>
<p class="MsoNormal" style="text-align:center;"><span style="font-size:small;font-family:Calibri;"><a rel="attachment wp-att-183" href="http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/final1/"><img class="aligncenter size-full wp-image-183" title="final1" src="http://wesaday.files.wordpress.com/2009/03/final1.png?w=304&#038;h=304" alt="final1" width="304" height="304" /></a></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">This concludes out whirlwind (and simplistic) tour of the Model-View-Presenter pattern and the Model-View-ViewModel in Prism. Hopefully you have a foundation from which to build and explore more in Prism. The final demonstration project (VS2008) can be found <a rel="attachment wp-att-184" href="http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/mvpandmvvminprism/">here</a>. <strong>Rename the doc to zip before you open the archive. This is a wordpress.com requirment.</strong></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/177/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/177/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=177&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2009/03/23/model-view-presenter-and-model-view-viewmodel-in-prism/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/03/mvp.png" medium="image">
			<media:title type="html">mvp</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/03/mvvm.png" medium="image">
			<media:title type="html">mvvm</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/03/one.png" medium="image">
			<media:title type="html">one</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/03/struct1.png" medium="image">
			<media:title type="html">struct1</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/03/struct2.png" medium="image">
			<media:title type="html">struct2</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/03/final1.png" medium="image">
			<media:title type="html">final1</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting started with Prism 2, formerly known as the Composite Application Library</title>
		<link>http://wesaday.wordpress.com/2009/03/17/getting-started-with-prism-2-formerly-known-as-the-composite-application-library/</link>
		<comments>http://wesaday.wordpress.com/2009/03/17/getting-started-with-prism-2-formerly-known-as-the-composite-application-library/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 00:22:44 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CAL]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Composite Application Library]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/?p=162</guid>
		<description><![CDATA[Introduction Prism is a set of libraries that allow developers to compose applications from separate components into a composite application. Composite meaning that the application functionality is split up into different modules that do not necessarily know about each other and then brought together to create an application.  From the Prism documentation: “Composite applications provide [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=162&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Introduction</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">Prism is a set of libraries that allow developers to compose applications from separate components into a composite application. Composite meaning that the application functionality is split up into different modules that do not necessarily know about each other and then brought together to create an application.</span></p>
<p><span style="font-size:small;"><span style="font-family:Times New Roman;"><span> </span>From the Prism documentation: “Composite applications provide many benefits, including the following:</span></span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">They allow modules to be individually developed, tested, and deployed by different individuals or sub-teams; they also allow them to be modified or extended with new functionality more easily, thereby allowing the application to be more easily extended and maintained. Note that even single-person projects experience benefits in creating more testable and maintainable applications using the composite approach. </span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">They provide a common shell composed of UI components contributed from various modules that interact in a loosely coupled way. This reduces the contention that arises from multiple developers adding new functionality to the UI, and it promotes a common appearance. </span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">They promote re-use and a clean separation of concerns between the application&#8217;s horizontal capabilities, such as logging and authentication, and the vertical capabilities, such as business functionality that is specific to your application. </span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">They help maintain a separation of roles by allowing different individuals or sub-teams to focus on a specific task or piece of functionality according to their focus or expertise. In particular, it provides a cleaner separation between the user interface and the business logic of the application—this means the UI designer can focus on creating a richer user experience. ”</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">The Prism documentation is actually very good with showing you how to accomplish individual tasks. Where the documentation falls short is when you want to bring the differing concepts together. For example, the documentation does lead you through creating an application and showing a view, what it does not show you is how to create a view that possibly contains multiple “child” views</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">The goals for this article are</span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">a.</span><span style="font:7pt &quot;">       </span></span><span style="font-size:small;">Build the Prism library</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">b.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Setup an application shell that shows the main window</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">c.</span><span style="font:7pt &quot;">       </span></span><span style="font-size:small;">Create a module that shows a view in the main window</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">d.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Create a module that shows a view in the first module</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">e.</span><span style="font:7pt &quot;">       </span></span><span style="font-size:small;">Create a module that shows a second view in the first module</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">f.</span><span style="font:7pt &quot;">       </span></span><span style="font-size:small;">Load the modules from a configuration file</span></span></p>
<p><span style="font-size:small;font-family:Times New Roman;">But before we get to that we have to know;</span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">How to get and setup Prism</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">Head on over to the Prism web site, </span><a href="http://www.codeplex.com/Prism"><span style="font-size:small;font-family:Times New Roman;">http://www.codeplex.com/Prism</span></a><span style="font-size:small;font-family:Times New Roman;">, and download the Prism package. The site also serves as the community portal to ask questions of the Prism development team. Unzip the archive to the folder of your choice then open that folder up in explorer to view the files. The folder will contain several batch files that will conveniently open up several different sections of the Prism project. The two batch files that we are interested in at this time are named “Desktop &amp; Silverlight – Open Composite Application Library” and “Desktop only – Open Composite Application Library”. The first batch file will open up a solution that will compile the libraries to use in WPF and Silverlight. If you are not doing any Silverlight application that you can use the second batch file. But you cannot use the libraries interchangeably (I think, I have not verified this as I do not do Silverlight development but otherwise there would be no need for separate projects). So, double click the batch file of your choice and the Prism solution will load up into Visual Studio 2008 (as of this writing). Then build the solution. The output libraries will be placed in &lt;Prism root&gt;CAL-&gt;Desktop</span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Creating the shell</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">I am going to assume that you know how to create an application solution, reference libraries and create class libraries in Visual Studio so I am not going to explain those details in depth. If you do not, you should study those items first. The first thing to do is to fire up Visual Studio 2008. Then create a new WPF application and name it whatever you want. For the purpose of this article I will name my solution “PrismArticle”. This is going to be the “shell” for our application. The shell is just a container to display the primary user interface. The shell can contain one of more views that are displayed to the user. Note that some of the code presented is more or less boilerplate code and copied from the Prism documentation.</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">1.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">In the solution explorer, rename Window1.xaml to Shell.xaml.</span></span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">2.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Then open the code behind file and rename the class name from Window1 to Shell</span></span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">3.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Open Shell.xaml and change the Title attribute to “PrismArticle” or whatever you want.</span></span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">4.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Add the CompositeWPF namespace to the Shell.xaml file, </span></span><span style="font-size:10pt;font-family:&quot;">xmlns:cal=&#8221;http://www.codeplex.com/CompositeWPF&#8221;</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">5.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Remove the Grid tags from the XAML and add a ContentControl named “MainRegion” and set the region name to “MainRegion” for Prism:</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">a.</span><span style="font:7pt &quot;">       </span></span><span><span style="font-size:small;"> </span></span></span><span style="font-size:10pt;font-family:&quot;">&lt;ContentControl Name=&#8221;MainRegion&#8221; cal:RegionManager.RegionName=&#8221;MainRegion&#8221;/&gt;.</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">6.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Add a new class to your project named Bootstrapper.cs.</span></span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">7.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Add references to the Prism libraries:</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">a.</span><span style="font:7pt &quot;">       </span></span><span style="font-size:small;"><span> </span>Microsoft.Practices.Composite </span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">b.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Microsoft.Practices.Composite.UnityExtensions</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">c.</span><span style="font:7pt &quot;">       </span></span><span style="font-size:small;">Microsoft.Practices.Composite.Presentation</span></span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">8.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Add these using statements to the top of the Bootstrapper file.</span></span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-size:10pt;font-family:&quot;"><span>a.<span style="font:7pt &quot;">  </span></span></span><span style="font-size:10pt;font-family:&quot;">using Microsoft.Practices.Composite.Modularity;</span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-size:10pt;font-family:&quot;"><span>b.<span style="font:7pt &quot;">  </span></span></span><span style="font-size:10pt;font-family:&quot;">using Microsoft.Practices.Composite.UnityExtensions;</span></p>
<p style="margin-left:1in;text-indent:-.25in;"><span style="font-size:10pt;font-family:&quot;"><span>c.<span style="font:7pt &quot;">  </span></span></span><span style="font-size:10pt;font-family:&quot;">using System.Windows;</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">9.</span><span style="font:7pt &quot;">      </span></span><span style="font-size:small;">Change the Bootstrapper class to inherit from the UnityBootstrapper class.</span></span></p>
<pre style="margin-left:.5in;"><span style="font-size:x-small;font-family:Courier New;">class Bootstrapper : UnityBootstrapper</span></pre>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">10.</span><span style="font:7pt &quot;">  </span></span><span style="font-size:small;">Override the CreateShell method in the Bootstrapper class.</span></span></p>
<pre><span style="font-size:x-small;"><span style="font-family:Courier New;"><span>        </span>protected override DependencyObject CreateShell()</span></span>
<span style="font-size:x-small;"><span style="font-family:Courier New;"><span>        </span>{</span></span>
<span style="font-size:x-small;"><span style="font-family:Courier New;"><span>               </span>Shell shell = new Shell();</span></span>
<span style="font-size:x-small;"><span style="font-family:Courier New;"><span>               </span>shell.Show();</span></span>
<span style="font-size:x-small;"><span style="font-family:Courier New;"><span>               </span>return shell;</span></span>
<span style="font-size:x-small;"><span style="font-family:Courier New;"><span>        </span>}</span></span></pre>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">11.</span><span style="font:7pt &quot;">  </span></span><span style="font-size:small;">Override the GetModuleCatalog method.</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:#2b91af;">IModuleCatalog</span> <span style="color:#010001;">GetModuleCatalog</span>()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">ModuleCatalog</span> <span style="color:#010001;">catalog</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">ConfigurationModuleCatalog</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> <span style="color:#010001;">catalog</span>;</span></p>
<p style="margin-left:.5in;"><span style="font-size:10pt;font-family:&quot;"><span>  </span>}</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">12.</span><span style="font:7pt &quot;">  </span></span><span style="font-size:small;">Open the App.xaml.cs and override the Startup event.</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> <span style="color:#010001;">OnStartup</span>(<span style="color:#2b91af;">StartupEventArgs</span> <span style="color:#010001;">e</span>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">base</span>.<span style="color:#010001;">OnStartup</span>(<span style="color:#010001;">e</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#2b91af;">Bootstrapper</span> <span style="color:#010001;">bootstrapper</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">Bootstrapper</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:#010001;">bootstrapper</span>.<span style="color:#010001;">Run</span>();</span></p>
<p><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Times New Roman;"><span><span style="font-size:small;">13.</span><span style="font:7pt &quot;">  </span></span><span style="font-size:small;">Open the App.xaml file and remove the StartupUri since we are manually starting up the window in the bootstrapper.</span></span></p>
<p style="text-align:center;" align="center"> </p>
<div></div>
<p><span style="font-size:small;font-family:Times New Roman;"></p>
<div id="attachment_164" class="wp-caption aligncenter" style="width: 331px"><a href="http://wesaday.files.wordpress.com/2009/03/solution.png"><img class="size-full wp-image-164" title="solution" src="http://wesaday.files.wordpress.com/2009/03/solution.png?w=321&#038;h=356" alt="Solution skeleton" width="321" height="356" /></a><p class="wp-caption-text">Solution skeleton</p></div>
<p> </p>
<p> </p>
<p></span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Your final solution should look something like this. If all went well you should be able to build and run the application. But…</span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">What the heck did we just do?</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">Everything up to step 8 should be pretty much self explanatory except for step 5. </span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Step 5 is where we setup a ContentControl in the shell window and named it “MainRegion”. Prism uses a concept called a Region that defines an area where a view is going to be displayed. If we had a module that mapped itself to the MainRegion, then that view would appear in that region. We will be doing just that in the next section. </span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Step 9 is where the application main window is created and shown. </span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Step 10 is where a catalog of the modules that the application uses is created. There are several different ways to accomplish this but for our example we are going to use a ConfigurationModuleCatalog which reads a configuration file and loads the modules defined in that file. </span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Step 11 is where the application starts up and instantiates the Bootstrapper. </span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Creating the first module</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">Before we create our first module we need to do a bit of configuration. Remember that we wanted to load our modules at runtime. To do that we have to have a place for the modules to be. So, in the solution folder create a “bin” folder, and then inside that folder create a “modules” folder. The bin folder is where we will put the executable and the modules folder is where the modules are going to go. Open up the project properties and on the Build tab set the output path to the bin folder that we just created.</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Now for our first module. One thing that I deviate from the Prism documentation is that the Prism docs describe creating the regions to show the views in the shell. What I am going to do is to create a module that is shown in the main window and defines the regions for the application. This way the shell application remains static and the modules define the application. So our first module is the view that is going to be shown in the MainRegion that we defined before. </span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Add a Class Library project to the solution. For the sake of this example, I named my module project “MainWindowModule”. Open the Project properties select the Build tab and then change the output path to the modules folder under the bin folder that we created earlier. </span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Rename the Class1.cs file to MainWindow.cs. This will also rename the class to MainWindow. Add a reference to the Microsoft.Practices.Composite.dll. Then add a using statement to the top of the file:</span></p>
<p style="text-indent:.5in;"><span><span style="font-size:small;font-family:Times New Roman;"> </span></span><span style="font-size:10pt;color:blue;font-family:&quot;">using</span><span style="font-size:small;font-family:Times New Roman;"> </span><span style="font-size:10pt;color:#010001;font-family:&quot;">Microsoft.Practices.Composite.Modularity</span><span style="font-size:small;font-family:Times New Roman;">.</span></p>
<p><span style="font-size:small;"><span style="font-family:Times New Roman;">Add a private variable to the class named _regionManager of type IRegionManager. The RegionManager allows us to access the regions defined in the application. Add a constructor to the class that accepts an IRegionManager parameter. Inside the constructor, make the _regionManager equal to the IRegionManager passed in.</span></span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Edit the class definition so that the class inherits from IModule. IModule is the interface that Prism uses to discover and initialize the modules. The method that we need to implement is the Initialize method. Inside the Initialize method, add the MainWindowView to the MainRegion through the region manager:</span></p>
<p><span><span style="font-size:small;font-family:Times New Roman;">            </span></span><span style="font-size:10pt;color:#010001;font-family:&quot;">_regionManager</span><span style="font-size:10pt;font-family:&quot;">.<span style="color:#010001;">Regions</span>[<span style="color:#a31515;">"MainRegion"</span>].<span style="color:#010001;">Add</span>(<span style="color:blue;">new</span> <span style="color:#010001;">MainWindowView</span>());</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Now we need a MainWindowView to show in the MainRegion. Just to make things a bit tidy, add a new folder to our solution named “Views”. Inside the Views folder, add a new WPF user control named MainWindowView. To make everyone happy, you have to add another using statement to include the Views now.</span></p>
<p style="text-indent:.5in;"><span style="font-size:10pt;color:blue;font-family:&quot;">using</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#010001;">MainWindowModule</span>.<span style="color:#010001;">Views</span>;</span></p>
<p><span style="font-size:small;"><span style="font-family:Times New Roman;"><span> </span><span> </span>Now, after all that what do you think will happen when you build and run the application now? Well, try it and see what happens. Go ahead. I will wait. Ready? What you should have seen is the same window we saw before we created the module and jumped through all those other hoops. If you set a break point in the Initialize method of the module you will find out that the method in not called. So what is up with that? Well before we can see the view in the main window we have to…</span></span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Configure the module</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">To configure the application to load our modules we have to add a configuration file to the executable project. So add a New Item -&gt; Application Configuration File. I named my file App.config. This is the configuration file that the application is going to read to create the ConfigurationModuleCatalog in the Bootstrapper class. Add the following code to the app config file:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>  </span>&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">configSections</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">section</span><span style="font-size:10pt;color:blue;font-family:&quot;"> </span><span style="font-size:10pt;color:red;font-family:&quot;">name</span><span style="font-size:10pt;color:blue;font-family:&quot;">=</span><span style="font-size:10pt;font-family:&quot;">&#8220;<span style="color:blue;">modules</span>&#8220;<span style="color:blue;"> </span><span style="color:red;">type</span><span style="color:blue;">=</span>&#8220;<span style="color:blue;">Microsoft.Practices.Composite.Modularity.ModulesConfigurationSection, Microsoft.Practices.Composite</span>&#8220;<span style="color:blue;"> /&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>  </span>&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">configSections</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>  </span>&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">modules</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><span>    </span>&lt;</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">module</span><span style="font-size:10pt;color:blue;font-family:&quot;"> </span><span style="font-size:10pt;color:red;font-family:&quot;">assemblyFile</span><span style="font-size:10pt;color:blue;font-family:&quot;">=</span><span style="font-size:10pt;font-family:&quot;">&#8220;<span style="color:blue;">Modules/MainWindowModule.dll</span>&#8220;<span style="color:blue;"> </span><span style="color:red;">moduleType</span><span style="color:blue;">=</span>&#8220;<span style="color:blue;">MainWindowModule.MainWindow, MainWindowModule</span>&#8220;<span style="color:blue;"> </span><span style="color:red;">moduleName</span><span style="color:blue;">=</span>&#8220;<span style="color:blue;">MainWindowModule</span>&#8220;<span style="color:blue;"> /&gt;</span></span></p>
<p><span style="font-size:10pt;color:blue;font-family:&quot;"><span>  </span>&lt;/</span><span style="font-size:10pt;color:#a31515;font-family:&quot;">modules</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">The Modules section defines what module to load and where to load it from. The “assemblyFile” attribute defines from where to load the module from. In this case we are loading the module from the Modules folder. The “moduleType” attribute is the name of the class that we want to load. The Prism docs call this a “type” which might be misleading for a beginner. This is the namespace and name of the class that implements the IModule interface. The last attribute simply defines the module name. There are other attributes that I will leave for another time. This is sufficient to get us going.</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Now if you run the application you show at least get a stop at the break point you set earlier. But, chances are that you will see a blank window. Unless you open up the MainWindowView XAML file and put something in the window you won’t see anything. Go ahead and experiment and when you are finished playing around we will go on to the next phase.</span></p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Child views</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">Now that we know how to create and load a module the next thing that we want to do is to create a couple of child windows that we will display in the MainWindowView. We are not going to do anything fancy. Adding child views to the MainWindow is relatively painless. It’s basically the same as what we did for the MainWindowModule expect that the regions that we are going to define are in the MainWindowView. So, open up the MainWindowView XAML file and delete any content that you might have put there to experiment with. If you did do any experimenting you might have noticed that the contents of the MainWindowView were confined to a specific size when you resized the window. This is because of the Width and Height attributes in the view being set to 300. Go ahead and delete those two settings so that the view will fill the parent window.</span></p>
<p><span style="font-size:small;"><span style="font-family:Times New Roman;"><span> </span>Now add a Grid layout control and define two columns. Add a content control to column zero and add another content control to column 1. Being so imaginative I named the region in column 0 “LeftChild” and the region in column 1 “RightChild”. Of course you are free to improve on that design </span><span style="font-family:Wingdings;"><span>J</span></span><span style="font-family:Times New Roman;"> </span></span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Add 2 more class libraries to the solution; name one “ChildOneModule” and the other “ChildTwoModule”. The setup for these modules pretty much mimics the steps we followed to create the MainWindowView. The code for both is about the same except for the region names. </span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Here is what I did. Feel free to experiment. The ChildOneView I simply changed the background color and added a label to identify the view. I did the same to the ChildTwoView except I made the color different.</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">Remember to change the output path for the two modules</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">Remember to add the Prism libraries to the module projects.</span></p>
<p style="margin-left:.5in;text-indent:-.25in;"><span style="font-family:Symbol;"><span><span style="font-size:small;">·</span><span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">Remember to add the module definitions to the app.config file. Note that the order in which the modules are listed matters! If you list the child modules after the MainWindowModule , Prism will throw an exception saying that the RegionManager does not contain the &lt;name of region&gt; region. After running around in circles for about 2 hours, you will discover that the modules appear to be loaded from the bottom up. So the MainWindowView has to get initialized first so the other views have a region to get loaded into. </span></p>
<p><span style="font-size:small;font-family:Times New Roman;">The final application will look like this when it’s all said and done.</span></p>
<div id="attachment_165" class="wp-caption aligncenter" style="width: 470px"><a href="http://wesaday.files.wordpress.com/2009/03/final.png"><img class="size-full wp-image-165" title="final" src="http://wesaday.files.wordpress.com/2009/03/final.png?w=460&#038;h=335" alt="Final result from all this" width="460" height="335" /></a><p class="wp-caption-text">Final result from all this</p></div>
<p> </p>
<h2 style="margin:10pt 0 0;"><span style="font-size:medium;color:#4f81bd;font-family:Cambria;">Conclusion</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">There we have downloaded and complied the Prism Library. Created a project that created a shell window using Prism, added a module to serve as the main window view and then finally added two more modules that served as two child views and loaded into the application dynamically loaded at runtime. This allows the UI views for the application to be developed separately from each other and to be totally independent code. Hopefully this is just the beginning of an exploration of the Prism framework. Depending on my work load and motivation I may continue writing about this. Next I think that I will explore getting our two child views to communication with each without them having to know anything about each other.</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Here are links to the code for this article. Rename the archive from .doc to .zip before opening, this is a wordpress requirement. The code is presented as is with no warranty implied or guaranteed.</span></p>
<p><span style="font-size:small;font-family:Times New Roman;"><a rel="attachment wp-att-169" href="http://wesaday.wordpress.com/2009/03/17/getting-started-with-prism-2-formerly-known-as-the-composite-application-library/prism-article-part-1/">prism-article-part-1</a> This is the code for the initial project</span></p>
<p><span style="font-size:small;font-family:Times New Roman;"><a rel="attachment wp-att-170" href="http://wesaday.wordpress.com/2009/03/17/getting-started-with-prism-2-formerly-known-as-the-composite-application-library/prism-article-part-2/">prism-article-part-2</a> This is the code for the second part of the article</span></p>
<p><span style="font-size:small;font-family:Times New Roman;"><a rel="attachment wp-att-171" href="http://wesaday.wordpress.com/2009/03/17/getting-started-with-prism-2-formerly-known-as-the-composite-application-library/prism-article-part-3/">prism-article-part-3</a> This is the final code solution</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=162&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2009/03/17/getting-started-with-prism-2-formerly-known-as-the-composite-application-library/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/03/solution.png" medium="image">
			<media:title type="html">solution</media:title>
		</media:content>

		<media:content url="http://wesaday.files.wordpress.com/2009/03/final.png" medium="image">
			<media:title type="html">final</media:title>
		</media:content>
	</item>
		<item>
		<title>Mo-XAML power toys</title>
		<link>http://wesaday.wordpress.com/2009/02/22/mo-xaml-power-toys/</link>
		<comments>http://wesaday.wordpress.com/2009/02/22/mo-xaml-power-toys/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 04:45:44 +0000</pubDate>
		<dc:creator>wesaday</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[moxaml]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://wesaday.wordpress.com/2009/02/22/mo-xaml-power-toys/</guid>
		<description><![CDATA[Another one one of the WPF gurus, Pete O&#8217;Hanlon, has released a new version of their WPF helper utilities. Go on over here http://peteohanlon.wordpress.com/moxaml-power-toys/ and get it.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=152&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Another one one of the WPF gurus, Pete O&#8217;Hanlon, has released a new version of their WPF helper utilities. Go on over here <a href="http://peteohanlon.wordpress.com/moxaml-power-toys/" target="_blank">http://peteohanlon.wordpress.com/moxaml-power-toys/</a> and get it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wesaday.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wesaday.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wesaday.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wesaday.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wesaday.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wesaday.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wesaday.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wesaday.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wesaday.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wesaday.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wesaday.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wesaday.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wesaday.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wesaday.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wesaday.wordpress.com&amp;blog=2474097&amp;post=152&amp;subd=wesaday&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wesaday.wordpress.com/2009/02/22/mo-xaml-power-toys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/667812cba11ae02c61b7b22be4412446?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">wesaday</media:title>
		</media:content>
	</item>
	</channel>
</rss>
