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

<channel>
	<title>Shazaml Design, LLC &#187; Silverlight</title>
	<atom:link href="http://www.shazaml.com/archives/category/development/silverlight/feed" rel="self" type="application/rss+xml" />
	<link>http://www.shazaml.com</link>
	<description>Design and Development for Windows Phone 7</description>
	<lastBuildDate>Thu, 27 Oct 2011 19:33:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>More Complete WP7 Mango Database Update Walkthrough</title>
		<link>http://www.shazaml.com/archives/more-complete-wp7-mango-database-update-walkthrough</link>
		<comments>http://www.shazaml.com/archives/more-complete-wp7-mango-database-update-walkthrough#comments</comments>
		<pubDate>Thu, 15 Sep 2011 16:05:45 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Mango]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=709</guid>
		<description><![CDATA[This walkthrough shows how to handle changes to a WP7 database application over time.]]></description>
			<content:encoded><![CDATA[<p>The MSDN documentation gives a <a href="http://msdn.microsoft.com/en-us/library/hh394022(v=VS.92).aspx">walkthrough</a> of how to update a local database application on the Windows Phone over time. The documentation gives quite a bit of detail but seems to miss a likely scenario. So let’s investigate the process step-by-step.</p>
<p><strong>Initial Version</strong></p>
<p>We are creating the first version of our application and decide that we need a User database table with the following columns: Name (primary key), LastAccessedDate</p>
<p>So we create a User class as follows:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
[Table]
public class User : INotifyPropertyChanged, INotifyPropertyChanging
{
  private string name;
  private DateTime? lastAccessed;

  [Column(IsPrimaryKey = true, CanBeNull = false, AutoSync = AutoSync.OnInsert)]
  public string Name
  {
  get { return name; }
  set
    {
      NotifyPropertyChanging(&quot;Name&quot;);
      name = value;
      NotifyPropertyChanged(&quot;Name&quot;);
    }
  }

  [Column]
  public DateTime? LastAccessed
  {
    get { return lastAccessed; }
    set
    {
      NotifyPropertyChanging(&quot;LastAccessed&quot;);
      lastAccessed = value;
      NotifyPropertyChanged(&quot;LastAccessed&quot;);
    }
  }

  // Version column aids update performance.
  [Column(IsVersion = true)]
  private Binary version;

  // INotifyPropertyChanged Members
  // INotifyPropertyChanging Members
}
</pre>
<p><span id="more-709"></span></p>
<p>In App.xaml.cs, you would use the following code to create your database:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
using (MyDataContext db = new MyDataContext(DBConnectionString))
{
  // Create the database if it does not exist.
  if (db.DatabaseExists() == false)
  {
    // Create the local database.
    db.CreateDatabase();
  }
}
</pre>
<p>That is all the code that is needed for the first version as there are no update scenarios. You deploy your app to the Marketplace and hundreds of customers download it. We will call this group of people that downloaded it: Group A.</p>
<p>It is important to note that when a database is created for the first time (unless specific) it has a DatabaseSchemaVersion of 0.</p>
<p><strong>Version 2</strong></p>
<p>Let’s say that for the next version of your app, you need to change the table schema for User to add a Theme id as now your app lets the user choose which theme to use.</p>
<p>This requires an update to the User class:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
//added in DB_VERSION 2
[Column(CanBeNull = true)]
public int? ThemeId
</pre>
<p>This column must allow nulls so that it can be added to existing rows in User table.</p>
<p>The code is App.xaml.cs will need to change to take into account two scenarios:</p>
<p>· Those in Group A upgrading from the first release to version 2<br />
· Those downloading the app for the first time at version 2 (we will refer to them as Group B)</p>
<p>At the top of App.xaml.cs, add a DB_VERSION field to keep track of the current version of the database changes:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
private static int DB_VERSION = 2;
</pre>
<p>The replace the previous code as follows:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
using (MyDataContext db = new MyDataContext(DBConnectionString))
{
  if (db.DatabaseExists() == false)
  {
    db.CreateDatabase();
    DatabaseSchemaUpdater dbUpdater = db.CreateDatabaseSchemaUpdater();
    dbUpdater.DatabaseSchemaVersion = DB_VERSION;
    dbUpdater.Execute();
  }
  else
  {
    DatabaseSchemaUpdater dbUpdater = db.CreateDatabaseSchemaUpdater();

    if (dbUpdater.DatabaseSchemaVersion &lt; DB_VERSION)
    {
      if (dbUpdater.DatabaseSchemaVersion &lt; 2)
      {
        //added in version 2
        dbUpdater.AddColumn&lt;User&gt;(&quot;ThemeId&quot;);
      }

    dbUpdater.DatabaseSchemaVersion = DB_VERSION;
    dbUpdater.Execute();
    }
  }
}
</pre>
<p>We release this new version of the app to the Marketplace and those in Group A update their application. When they run it for the first time, they will fall into the else statement as the database already exists. The DatabaseSchemaVersion will be 0 which is less than our current version of 2, so it will go into the code that will add the ThemeId column to the existing User table. The DatabaseSchemaVersion will then be updated to 2 so that the update code will no longer run.</p>
<p>Now let’s look at Group B who are downloading the app for the first time when it was at version 2. For them, no database will exist so one will be created. It is important to point out that when the database is created it will include the ThemeId column on User since it is part of the User object. The DatabaseSchemaVersion is now updated so that on the next run of the app when the code hits the else block it will not try to add the column again and throw an exception.</p>
<p><strong>Version 3</strong></p>
<p>Let’s do a third version of the application and add a birthdate column to User:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
//added in DB_VERSION 3
[Column(CanBeNull = true)]
public DateTime? DOB
</pre>
<p>In App.xaml.cs, change the version to 3:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
private static int DB_VERSION = 3;
</pre>
<p>Now add a new if block for the new column:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
using (MyDataContext db = new MyDataContext(DBConnectionString))
{
  if (db.DatabaseExists() == false)
  {
    db.CreateDatabase();
    DatabaseSchemaUpdater dbUpdater = db.CreateDatabaseSchemaUpdater();
    dbUpdater.DatabaseSchemaVersion = DB_VERSION;
    dbUpdater.Execute();
  }
  else
  {
    DatabaseSchemaUpdater dbUpdater = db.CreateDatabaseSchemaUpdater();
    if (dbUpdater.DatabaseSchemaVersion &lt; DB_VERSION)
    {
      if (dbUpdater.DatabaseSchemaVersion &lt; 2)
      {
        //added in version 2
        dbUpdater.AddColumn&lt;User&gt;(&quot;ThemeId&quot;);
      }

      if (dbUpdater.DatabaseSchemaVersion &lt; 3)
      {
        //added in version 3
        dbUpdater.AddColumn&lt;User&gt;(&quot;DOB&quot;);
      }

      dbUpdater.DatabaseSchemaVersion = DB_VERSION;
      dbUpdater.Execute();
    }
  }
}
</pre>
<p>The above code now correctly handles the following scenarios:</p>
<p>· Those installing version 3 of the app as the first version they installed (new database will be created)<br />
· Those with version 2 that are updating to version 3 (upgrade from previous version)<br />
· Those at version 1 that didn’t update to version 2 but are now updating to version 3 (skip intermediate versions)</p>
<p>It should be easy to see how additional versions will require an increment to the DB_VERSION value and the addition of an if block to handle those changes added in a specific version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/more-complete-wp7-mango-database-update-walkthrough/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WP 7.5 Mango ISETool Gotcha</title>
		<link>http://www.shazaml.com/archives/wp-7-5-mango-isetool-gotcha</link>
		<comments>http://www.shazaml.com/archives/wp-7-5-mango-isetool-gotcha#comments</comments>
		<pubDate>Thu, 15 Sep 2011 15:06:09 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[ISETool]]></category>
		<category><![CDATA[IsolatedStorage]]></category>
		<category><![CDATA[Mango]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=707</guid>
		<description><![CDATA[The ISETool has a gotcha when restoring snapshots]]></description>
			<content:encoded><![CDATA[<p>The Isolated Storage Explorer (ISETool.exe) is a command-line tool that comes with the Windows Phone SDK.  It allows you to copy files and directories from isolated storage on the phone (or emulator) to your PC file system.  One use for this is to take snapshots of your database over different versions in order to test upgrade scenarios.</p>
<p>To copy from the emulator’s isolated storage to your computer’s file system use:</p>
<p style="padding-left: 30px;">ISETool.exe ts xd 11111111-2222-3333-4444-555555555555 &#8220;C:\MyApp\DbVersion1&#8243;</p>
<p>Where:</p>
<ul>
<li>ts – take snapshot</li>
<li>xd – emulator</li>
<li>guid – product GUID from WPAppManifest.xml</li>
<li>desktop dir – where to copy the isolated storage files</li>
</ul>
<p>&nbsp;</p>
<p>To later copy those files from my desktop directory back to isolated storage on the emulator, use:</p>
<p style="padding-left: 30px;">ISETool.exe rs xd 11111111-2222-3333-4444-555555555555 &#8220;C:\MyApp\DbVersion1\IsolatedStore&#8221;</p>
<p>&nbsp;</p>
<p>In this case <em>rs</em> means restore snapshot.</p>
<p>But the restoring wasn’t working for me.  I would restore the snapshot, run my code and no database would be found so my code would create a new database.  It took me a few times to notice that what I was doing wrong was reusing the take snapshot command line and changing <em>ts</em> to <em>rs</em>.</p>
<p>But the problem with that is that the directory that you specify with <em>ts</em> is different than the one needed for <em>rs</em>.  Notice that <em>rs</em> adds “\IsolatedStore” to the end.</p>
<p>Hopefully this will save you from pulling  a few hairs out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/wp-7-5-mango-isetool-gotcha/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Free Event: Silverlight Firestarter &#8211; 2 Dec 2010</title>
		<link>http://www.shazaml.com/archives/free-event-silverlight-firestarter-e28093-2-dec-2010</link>
		<comments>http://www.shazaml.com/archives/free-event-silverlight-firestarter-e28093-2-dec-2010#comments</comments>
		<pubDate>Fri, 12 Nov 2010 23:09:20 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[ScottGu]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=678</guid>
		<description><![CDATA[The Future of Silverlight]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.shazaml.com/wp-content/uploads/2010/11/image6.png" alt="Silverlight Firestarter: The Future of Silverlight Starts Now" /></p>
<p>Learn what the future holds for Silverlight at this online event.</p>
<p>Register today: <a title="http://www.silverlight.net/news/events/firestarter/" href="http://www.silverlight.net/news/events/firestarter/">http://www.silverlight.net/news/events/firestarter/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/free-event-silverlight-firestarter-e28093-2-dec-2010/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight Performance Analysis tool &#8211; Coming Soon</title>
		<link>http://www.shazaml.com/archives/silverlight-performance-analysis-tool-coming-soon</link>
		<comments>http://www.shazaml.com/archives/silverlight-performance-analysis-tool-coming-soon#comments</comments>
		<pubDate>Fri, 12 Nov 2010 17:49:58 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[Firestarter]]></category>
		<category><![CDATA[GPU]]></category>
		<category><![CDATA[PDC10]]></category>
		<category><![CDATA[profile]]></category>
		<category><![CDATA[Silverlight Performance Analysis]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=671</guid>
		<description><![CDATA[Introduction to the Silverlight Performance Analysis tool]]></description>
			<content:encoded><![CDATA[<p>At PDC10 as part of the keynote, Scott Guthrie showed off the soon-to-be-released <strong>Silverlight Performance Analysis</strong> tool that would allow developers to profile their Windows Phone 7 applications and identify bottlenecks in frame rate and CPU and relate that back to specific storyboards and even Visual Tree elements.</p>
<p>The below screenshots were taken from the <a href="http://videoaz.microsoftpdc.com/vod/pdc10_pre_event/ShowContent_VOD/PDC_2010_Keynote_PDC_WMV_High_1280x720_2500k.wmv">keynote video</a> and you can see the timings at the bottom if you want to watch the video:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/image5.png"><img style="display: inline; border: 0px;" title="image" src="http://www.shazaml.com/wp-content/uploads/2010/11/image_thumb5.png" border="0" alt="image" width="537" height="59" /></a></p>
<p>In addition to debugging on the device, you can profile the app by selecting <strong>Silverlight Performance Analysis</strong>:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/perf1.jpg"><img style="display: inline; border: 0px;" title="perf1" src="http://www.shazaml.com/wp-content/uploads/2010/11/perf1_thumb.jpg" border="0" alt="perf1" width="240" height="150" /></a></p>
<p>The device will then be prepared for profiling:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/perf2.jpg"><img style="display: inline; border: 0px;" title="perf2" src="http://www.shazaml.com/wp-content/uploads/2010/11/perf2_thumb.jpg" border="0" alt="perf2" width="240" height="150" /></a></p>
<p>After running the application, a graphical summary will be created with execution time on the x-axis.  It shows color-coded frame rates (green is good, red is bad) and relates that to CPU-usage and specific Storyboards:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/perf3.jpg"><img style="display: inline; border: 0px;" title="perf3" src="http://www.shazaml.com/wp-content/uploads/2010/11/perf3_thumb.jpg" border="0" alt="perf3" width="240" height="150" /></a></p>
<p>In the above example, it appears that the first Storyboard might be leading to increased CPU usage and a degraded frame rate.  You can highlight and drill down to see details for a specific time frame (from approx 4.5 to 7.5 seconds into the profiling session):</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/perf4.jpg"><img style="display: inline; border: 0px;" title="perf4" src="http://www.shazaml.com/wp-content/uploads/2010/11/perf4_thumb.jpg" border="0" alt="perf4" width="240" height="150" /></a></p>
<p>The next screen shows CPU and GPU metrics as well as a list of warnings.  The first entry warns about 35 instances of ColorAnimation:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/perf5.jpg"><img style="display: inline; border: 0px;" title="perf5" src="http://www.shazaml.com/wp-content/uploads/2010/11/perf5_thumb.jpg" border="0" alt="perf5" width="240" height="150" /></a></p>
<p>Scrolling down, you will see an Element Summary:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/perf6.jpg"><img style="display: inline; border: 0px;" title="perf6" src="http://www.shazaml.com/wp-content/uploads/2010/11/perf6_thumb.jpg" border="0" alt="perf6" width="240" height="150" /></a></p>
<p>Followed by a Frames section with a CPU usage graph:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/perf7.jpg"><img style="display: inline; border: 0px;" title="perf7" src="http://www.shazaml.com/wp-content/uploads/2010/11/perf7_thumb.jpg" border="0" alt="perf7" width="240" height="150" /></a></p>
<p>And finally the ability to drill down the Visual Tree and see problems highlighted:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/11/perf8.jpg"><img style="display: inline; border: 0px;" title="perf8" src="http://www.shazaml.com/wp-content/uploads/2010/11/perf8_thumb.jpg" border="0" alt="perf8" width="240" height="150" /></a></p>
<p>This tool would be very helpful in analyzing app performance on the device.  ScottGu did not give a specific release date for this or any additional tools that might be coming.</p>
<p>Today I saw that there is a <a href="http://www.silverlight.net/news/events/firestarter/">Silverlight Firestarter event scheduled for December 2, 2010</a> and wonder if the tool will be ready to release then. </p>
<p><a href="http://www.silverlight.net/news/events/firestarter/"><img style="display: inline; border: 0px;" title="image" src="http://www.shazaml.com/wp-content/uploads/2010/11/image6.png" border="0" alt="image" width="365" height="206" /></a></p>
<p>It would make a great time to announce it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/silverlight-performance-analysis-tool-coming-soon/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://videoaz.microsoftpdc.com/vod/pdc10_pre_event/ShowContent_VOD/PDC_2010_Keynote_PDC_WMV_High_1280x720_2500k.wmv" length="2415816193" type="video/asf" />
		</item>
		<item>
		<title>A Caliburn.Micro recipe: filters &#171; Marco Amendola</title>
		<link>http://www.shazaml.com/archives/caliburn-micro-filters</link>
		<comments>http://www.shazaml.com/archives/caliburn-micro-filters#comments</comments>
		<pubDate>Tue, 10 Aug 2010 22:30:35 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Caliburn]]></category>
		<category><![CDATA[Caliburn.Micro]]></category>
		<category><![CDATA[filter]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=632</guid>
		<description><![CDATA[Caliburn.Micro implementation of Filters]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.shazaml.com/wp-content/uploads/2010/08/image6.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.shazaml.com/wp-content/uploads/2010/08/image_thumb5.png" border="0" alt="image" width="640" height="231" /></a></p>
<p>Extension to <a href="http://caliburnmicro.codeplex.com/">Caliburn.Micro</a> to allow implementation of filters similar to what is found in <a href="http://caliburn.codeplex.com/">Caliburn</a>.</p>
<p><a href="http://marcoamendola.wordpress.com/2010/08/10/a-caliburn-micro-recipe-filters/">A Caliburn.Micro recipe: filters « Marco Amendola</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/caliburn-micro-filters/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVVM with Caliburn.Micro</title>
		<link>http://www.shazaml.com/archives/mvvm-with-caliburn-micro</link>
		<comments>http://www.shazaml.com/archives/mvvm-with-caliburn-micro#comments</comments>
		<pubDate>Fri, 30 Jul 2010 21:08:26 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[Caliburn.Micro]]></category>
		<category><![CDATA[MVVM]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/archives/mvvm-with-caliburn-micro</guid>
		<description><![CDATA[Silverlight, WPF, and Windows Phone 7 developers should consider using the Model-View-ViewModel (MVVM) pattern for developing their LOB applications.&#160; One choice for MVVM is Caliburn.Micro developed by Rob Eisenberg. &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Silverlight, WPF, and Windows Phone 7 developers should consider using the Model-View-ViewModel (MVVM) pattern for developing their LOB applications.&#160; One choice for MVVM is <a href="http://caliburnmicro.codeplex.com/">Caliburn.Micro</a> developed by <a href="http://twitter.com/eisenbergeffect">Rob Eisenberg</a>.</p>
<p>&#160;</p>
<p>Here is a link to the documentation topics:</p>
<ul>
<li>Getting Started
<ul>
<li><a href="http://caliburnmicro.codeplex.com/wikipage?title=Introduction&amp;referringTitle=Documentation">Introduction</a></li>
<li><a href="http://caliburnmicro.codeplex.com/wikipage?title=Obtain%20and%20Build%20the%20Code&amp;referringTitle=Documentation">Obtain and Build the Code</a></li>
</ul>
</li>
</ul>
<ul>
<li>Soup to Nuts
<ul>
<li><a href="http://caliburnmicro.codeplex.com/wikipage?title=Basic%20Configuration%2c%20Actions%20and%20Conventions&amp;referringTitle=Documentation">Basic Configuration, Actions and Conventions</a></li>
<li><a href="http://caliburnmicro.codeplex.com/wikipage?title=Customizing%20The%20Bootstrapper&amp;referringTitle=Documentation">Customizing The Bootstrapper</a></li>
<li><a href="http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&amp;referringTitle=Documentation">All About Actions</a></li>
<li>WP7 Basics </li>
<li>Coroutines</li>
</ul>
</li>
</ul>
<ul>
<li>Recipes
<ul>
<li>SimpleContainer</li>
</ul>
</li>
</ul>
<p>&#160;</p>
<p>I know Rob has been working on some WP7 goodness that should be out soon.&#160; Looking forward to the release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/mvvm-with-caliburn-micro/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Infragistics XamWebOutlookBar &amp; Caliburn</title>
		<link>http://www.shazaml.com/archives/infragistics-xamweboutlookbar-caliburn</link>
		<comments>http://www.shazaml.com/archives/infragistics-xamweboutlookbar-caliburn#comments</comments>
		<pubDate>Mon, 14 Jun 2010 21:38:44 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Caliburn]]></category>
		<category><![CDATA[Infragistics]]></category>
		<category><![CDATA[XamWebOutlookBar]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=571</guid>
		<description><![CDATA[Using the Infragistics Silverlight XamWebOutlookBar with Caliburn]]></description>
			<content:encoded><![CDATA[<p>Last week I set out to build a simple Caliburn sample that included the Infragistics Silverlight XamWebOutlookBar.  I made progress and got to a point where Rob Eisenberg was able to help me get the rest of the way.  The approach I was taking was trying to figure out what conventions I should add to get Caliburn to recognize the XamWebOutlookBar.  Rob’s answer was that not everything needs to be a convention.</p>
<p>When you run the application, you will see the XamWebOutlookBar hosted in a sidebar.  Both groups shown in the OutlookBar have corresponding ViewModels that in turn have associated Views:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/06/image.png"><img style="display: inline; border: 0px;" title="image" src="http://www.shazaml.com/wp-content/uploads/2010/06/image_thumb.png" border="0" alt="image" width="261" height="202" /></a></p>
<p>At the end of the article is a link to the project source code.  In order to get the project to compile, you will need to download the Infragistics assemblies and add references to the following:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/06/image1.png"><img style="display: inline; border: 0px;" title="image" src="http://www.shazaml.com/wp-content/uploads/2010/06/image_thumb1.png" border="0" alt="image" width="376" height="83" /></a></p>
<p>A trial of Infragistics can be downloaded from <a href="http://www.infragistics.com/dotnet/netadvantage/silverlight/line-of-businessdownloads.aspx">here</a>.</p>
<p>Here is the final project structure:</p>
<p><a href="http://www.shazaml.com/wp-content/uploads/2010/06/image2.png"><img style="display: inline; border: 0px;" title="image" src="http://www.shazaml.com/wp-content/uploads/2010/06/image_thumb2.png" border="0" alt="image" width="300" height="484" /></a></p>
<h2>Application</h2>
<p>In typical Caliburn style, the App.xaml has been changed to a CaliburnApplication:</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;cal:CaliburnApplication xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
             xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
             xmlns:cal=&quot;clr-namespace:Caliburn.PresentationFramework.ApplicationModel;assembly=Caliburn.PresentationFramework&quot;
             x:Class=&quot;InfragisticsCaliburn.App&quot;&gt;
    &lt;Application.Resources&gt;
    &lt;/Application.Resources&gt;
&lt;/cal:CaliburnApplication&gt;
</pre>
<p>In App.xaml.cs, we setup MEF as the container and the use MEF to find the ShellViewModel:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
protected override IServiceLocator CreateContainer()
{
    return new MEFAdapter(CompositionHost.Initialize(new AssemblyCatalog(Assembly.GetExecutingAssembly())));
}

protected override object CreateRootModel()
{
    var shell = ServiceLocator.Current.GetInstance&lt;IShell&gt;();

    if (IsRunningOutOfBrowser &amp;&amp; HasElevatedPermissions)
        MainWindow.Closing += (s, args) =&gt; { args.Cancel = !ServiceLocator.Current.GetInstance&lt;IShell&gt;().CanShutdown(); };

    return shell;
}
</pre>
<h2>ViewModels</h2>
<p>MEF is able to find ShellViewModel in the container using the IShell type because it implements IShell and Exports itself as IShell:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
[Export(typeof(IShell))]
public class ShellViewModel : ScreenConductor&lt;IScreen&gt;, IShell
{
    private readonly MainViewModel _firstScreen;

    [ImportingConstructor]
    public ShellViewModel(MainViewModel firstScreen)
    {
        _firstScreen = firstScreen;
    }

    protected override void OnInitialize()
    {
        this.OpenScreen(_firstScreen);
    }

}
</pre>
<p>Because of the ImportingConstructor attribute, an instance of MainViewModel is created.  The class is implemented as:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
[Export(typeof(MainViewModel))]
public class MainViewModel : ScreenConductor&lt;ISidebarItem&gt;.WithCollection.OneScreenActive
{
    [ImportingConstructor]
    public MainViewModel([ImportMany] IEnumerable&lt;ISidebarItem&gt; sidebars)
    {
        Screens.AddRange(sidebars);
        this.OpenScreen(Screens.First());
    }
}
</pre>
<p>For the XamWebOutlookBar implementation, the important thing to note is that MainViewModel is setup as a ScreenConductor that manages ISidebarItem instances where only one sidebar screen is active at a time.  The ImportingConstructor attribute then finds all items registered in the MEF container as ISidebarItem.</p>
<p>In this example, both ContentAViewAModel and ContentBViewModel are similar:</p>
<pre class="brush: csharp; gutter: false; title: ; notranslate">
[Export(typeof(ISidebarItem))]
public class ContentAViewModel : Screen, ISidebarItem
{
    string message = &quot;ContentA is working&quot;;

    public ContentAViewModel()
    {
        DisplayName = &quot;Content A Header&quot;;
    }

    public string Message
    {
        get { return message; }
        set
        {
            message = value;
            NotifyOfPropertyChange(() =&gt; Message);
        }
    }

    public string Icon
    {
        get { return @&quot;../../Images/briefcase2.png&quot;; }
    }
}
</pre>
<p>Each of the ViewModels export themselves as ISidebarItem, inherit from Screen, and implement ISidebarItem.</p>
<h2>Views</h2>
<p>In MainView.xaml, the DisplayName and Icon properties are used to render the group’s header and icon:</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;igOB:XamWebOutlookBar x:Name=&quot;sidebarOutlookBar&quot; 
        MinimizedWidth=&quot;35&quot; AllowMinimized=&quot;True&quot; 
        NavigationPaneMinimized=&quot;sidebarOutlookBar_NavigationPaneMinimized&quot;
        NavigationPaneExpanding=&quot;sidebarOutlookBar_NavigationPaneExpanding&quot;
        VerticalAlignment=&quot;Stretch&quot; HorizontalAlignment=&quot;Stretch&quot;
        GroupsSource=&quot;{Binding Screens}&quot;&gt;
    &lt;igOB:XamWebOutlookBar.GroupContentTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;ContentControl cal:View.Model=&quot;{Binding}&quot; /&gt;
        &lt;/DataTemplate&gt;
    &lt;/igOB:XamWebOutlookBar.GroupContentTemplate&gt;
    &lt;igOB:XamWebOutlookBar.GroupHeaderTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;TextBlock Text=&quot;{Binding DisplayName}&quot; /&gt;
        &lt;/DataTemplate&gt;
    &lt;/igOB:XamWebOutlookBar.GroupHeaderTemplate&gt;
    &lt;igOB:XamWebOutlookBar.DefaultLargeIconTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;Image Source=&quot;{Binding Icon, Converter={StaticResource stringToImageSourceConverter}}&quot;/&gt;
        &lt;/DataTemplate&gt;
    &lt;/igOB:XamWebOutlookBar.DefaultLargeIconTemplate&gt;
    &lt;igOB:XamWebOutlookBar.DefaultSmallIconTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;Image Source=&quot;{Binding Icon, Converter={StaticResource stringToImageSourceConverter}}&quot;/&gt;
        &lt;/DataTemplate&gt;
    &lt;/igOB:XamWebOutlookBar.DefaultSmallIconTemplate&gt;
&lt;/igOB:XamWebOutlookBar&gt;
</pre>
<p>Notice the GroupsSource property is bound to the Screens property that the ViewModel inherits from its base class.  The ContentControl for each group is set to the ViewModel representing the group.  The group header is bound to the DisplayName property and the small and large icons are set to the Icon property.</p>
<p>The Message property is bound in the View for the group content:</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;UserControl x:Class=&quot;InfragisticsCaliburn.Views.ContentAView&quot;
    xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
    xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml
    xmlns:d=http://schemas.microsoft.com/expression/blend/2008
    xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
    mc:Ignorable=&quot;d&quot;
    d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;400&quot;&gt;
    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;TextBlock x:Name =&quot;Message&quot;/&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre>
<p>Download the source of the project <a href="http://www.shazaml.com/downloads/InfragisticsCaliburn2.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/infragistics-xamweboutlookbar-caliburn/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Caliburn Book: Chapters 1-3</title>
		<link>http://www.shazaml.com/archives/caliburn-book-chapters-1-3</link>
		<comments>http://www.shazaml.com/archives/caliburn-book-chapters-1-3#comments</comments>
		<pubDate>Mon, 07 Jun 2010 19:37:25 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Caliburn]]></category>
		<category><![CDATA[MVVM]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=545</guid>
		<description><![CDATA[Draft chapters from Caliburn book]]></description>
			<content:encoded><![CDATA[<p>Many months ago I put learning about the Caliburn framework on my “to do” list.  A few weeks ago I started the task and decided to write a book about it.  I don’t think that I am expert enough at the framework to actually publish a book.  Not yet anyway.  But I figured if I could grok it well enough to write about it that I would be well on my way to learning the framework. </p>
<p>You can download the book from <a href="http://www.shazaml.com/downloads/CaliburnBook.zip">here</a>.</p>
<p>The first chapter is a simple introduction to Caliburn.  Chapter 2 walks you through a simple, Hello Caliburn, application.  Chapter 3 is more ambitious and walks you through various aspects of the framework using the Silverlight GameLibrary sample.  It covers the same topics that Rob Eisenberg covered in his MIX10 talk.  There is also an Appendix included that lists some of the conventions found in Caliburn.</p>
<p>If I decide to write additional chapters, then I would include:</p>
<ul>
<li>Adding to Conventions</li>
<li>Overriding Conventions</li>
<li>TDD and Caliburn</li>
<li>Caliburn extensibility points</li>
<li>IResult implementations</li>
<li>Coroutines in more depth</li>
<li>UI patterns besides MVVM</li>
</ul>
<p>There is likely much more to Caliburn that I don’t even know what I don’t know yet.</p>
<p>Please reply with any feedback, corrections, further explanations, or additional chapter ideas.</p>
<p>If a book is ever published about Caliburn, Rob should be the one to do it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/caliburn-book-chapters-1-3/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 Presentation at Desert Code Camp 2010</title>
		<link>http://www.shazaml.com/archives/windows-phone-7-presentation-at-desert-code-camp-2010</link>
		<comments>http://www.shazaml.com/archives/windows-phone-7-presentation-at-desert-code-camp-2010#comments</comments>
		<pubDate>Mon, 17 May 2010 14:00:32 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=536</guid>
		<description><![CDATA[Create a Windows Phone 7 app using Silverlight, the MVVM Light toolkit, and Test-Driven Development]]></description>
			<content:encoded><![CDATA[<p>Last Saturday I presented at my second Desert Code Camp.  The presentation PowerPoint and code for “Windows Phone 7 Silverlight MVVM App the Test-Driven Way” is now available.</p>
<div id="__ss_4124792" style="width: 425px;"><strong style="display: block; margin: 12px 0 4px;"><a title="Windows Phone 7 Silverlight MVVM App the Test-Driven" href="http://www.slideshare.net/marktucker/windows-phone-7-silverlight-mvvm-app-the-testdriven-4124792">Windows Phone 7 Silverlight MVVM App the Test-Driven</a></strong><object id="__sse4124792" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=windows-phone-7-silverlight-mvvm-app-the-testdriven2875&amp;rel=0&amp;stripped_title=windows-phone-7-silverlight-mvvm-app-the-testdriven-4124792" /><param name="name" value="__sse4124792" /><param name="allowfullscreen" value="true" /><embed id="__sse4124792" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=windows-phone-7-silverlight-mvvm-app-the-testdriven2875&amp;rel=0&amp;stripped_title=windows-phone-7-silverlight-mvvm-app-the-testdriven-4124792" allowscriptaccess="always" allowfullscreen="true" name="__sse4124792"></embed></object></div>
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/marktucker">Mark Tucker</a>.</div>
<p>The code consists of two phone projects.  If you run the first, you will get the application UI. Running the second will bring up the test viewer.</p>
<p>Get the code <a href="http://www.shazaml.com/downloads/PhoneTDD2.zip">here</a>.</p>
<p>NOTE:</p>
<p>I told those attending the session that a video of the presentation would be available.  But due to an issue with Camtasia Studio, the video was not recorded.</p>
<p>Thanks again to all those who attended the presentation.  Let me know about the COOL apps you write for WP7.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/windows-phone-7-presentation-at-desert-code-camp-2010/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hidden Object: Episode 14 – Shake it up</title>
		<link>http://www.shazaml.com/archives/hidden-object-episode-14</link>
		<comments>http://www.shazaml.com/archives/hidden-object-episode-14#comments</comments>
		<pubDate>Wed, 25 Nov 2009 13:05:17 +0000</pubDate>
		<dc:creator>Mark Tucker</dc:creator>
				<category><![CDATA[Hidden Object Game]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[ControlStoryboardAction]]></category>
		<category><![CDATA[EventTrigger]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[GlobalCounterMaxReachedTrigger]]></category>
		<category><![CDATA[IncrementGlobalCounterAction]]></category>
		<category><![CDATA[SetGlobalCounterAction]]></category>
		<category><![CDATA[Storyboard]]></category>
		<category><![CDATA[TimerTrigger]]></category>
		<category><![CDATA[Trigger]]></category>

		<guid isPermaLink="false">http://www.shazaml.com/?p=385</guid>
		<description><![CDATA[If the player clicks too many times within a 5 second time frame trying to find an item, play the shake animation.]]></description>
			<content:encoded><![CDATA[<p>So far in the game, we have particles when an item is clicked, a hint to show the location of an unfound item, but what should we do if the player goes berserk and wildly clicks all over the place in hopes of finding a difficult-to-find item? In this episode of <a href="http://www.shazaml.com/archives/creating-a-hidden-object-game-in-silverlight-3">Creating a Hidden Object Game is Silverlight 3</a> we will add an earthquake effect if the player clicks too many times in a 5 second interval.</p>
<p>Let&#8217;s first start with the shake effect.  The magnifierCanvas Canvas contains the background image and all Paths for each clickable item. We will create a new storyboard called ShakeStoryboard that will animate the Left property of the Canvas:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec1.png" alt="" /></p>
<p> </p>
<p>Each of the 4 key frames set the Left property to a different value as shown in the storyboard XAML:</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;Storyboard x:Name=&quot;ShakeStoryboard&quot; RepeatBehavior=&quot;5x&quot; AutoReverse=&quot;False&quot; SpeedRatio=&quot;5&quot;&gt;
    &lt;DoubleAnimationUsingKeyFrames BeginTime=&quot;00:00:00&quot;
        Storyboard.TargetName=&quot;magnifierCanvas&quot;
        Storyboard.TargetProperty=&quot;(Canvas.Left)&quot;&gt;
            &lt;EasingDoubleKeyFrame KeyTime=&quot;00:00:00&quot; Value=&quot;0&quot;/&gt;
            &lt;EasingDoubleKeyFrame KeyTime=&quot;00:00:00.2000000&quot; Value=&quot;-10&quot;/&gt;
            &lt;EasingDoubleKeyFrame KeyTime=&quot;00:00:00.4000000&quot; Value=&quot;10&quot;/&gt;
            &lt;EasingDoubleKeyFrame KeyTime=&quot;00:00:00.6000000&quot; Value=&quot;0&quot;/&gt;
    &lt;/DoubleAnimationUsingKeyFrames&gt;
&lt;/Storyboard&gt;
</pre>
<p> </p>
<p>The Storyboard has the RepeatBehavior property set to repeat 5 times and the SpeedRatio property set to speed up the animation.</p>
<p>If the player clicks on the background image 10 times within a 5 second interval, then the ShakeStoryboard will play. To accomplish this we need three SetGlobalCounterAction instances and one ControlStoryboardAction added to the UserControl:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec2.png" alt="" /></p>
<p>The first SetGlobalCounterAction sets the values for the TooManyClicks counter when the UserControl loads:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec3.png" alt="" /></p>
<p> </p>
<p>The ControlStoryboardAction plays the ShakeStoryboard when the GlobalCounterMaxReachedTrigger is fired for the TooManyClicks key which we set previously to 10.</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec4.png" alt="" /></p>
<p>When the counter reaches 10 we need to set it back to zero which is what the second SetGlobalCounterAction does:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec5.png" alt="" /></p>
<p>The final SetGlobalCounterAction uses the TimerTrigger to reset the counter every 5 seconds:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec6.png" alt="" /></p>
<p> </p>
<p>The only thing left to do is add the IncrementGlobalCounterAction to the background image to increment the counter by 1:</p>
<p><img src="http://www.shazaml.com/wp-content/uploads/2009/11/112509_1805_HiddenObjec7.png" alt="" /></p>
<p> </p>
<p>So with 5 Action instances, 3 Trigger types, 1 Storyboard, and 0 lines of code we were able to quickly add this feature to the game.</p>
<p><a href="http://www.shazaml.com/downloads/ClutteredCubeSource14.zip"><img class="alignnone size-full wp-image-319" title="Zip" src="http://www.shazaml.com/wp-content/uploads/2009/10/Zip.png" alt="Zip" width="93" height="96" /> Source Code</a></p>
<p><a href="http://www.shazaml.com/hidden-object-game-episode-14-demo"><img class="alignnone size-full wp-image-320" title="silverlight" src="http://www.shazaml.com/wp-content/uploads/2009/10/silverlight.png" alt="silverlight" width="93" height="96" /> Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shazaml.com/archives/hidden-object-episode-14/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

