<?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>Colin Eberhardt&#039;s Adventures in .NET &#187; Uncategorized</title>
	<atom:link href="http://www.scottlogic.co.uk/blog/colin/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk/blog/colin</link>
	<description>Colin Eberhardt&#039;s Adventures in .NET</description>
	<lastBuildDate>Thu, 09 Feb 2012 10:21:18 +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>WPUG Talk: Developing cross-platform mobile applications with PhoneGap for Windows Phone 7</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2012/02/wpug-talk-developing-cross-platform-mobile-applications-with-phonegap-for-windows-phone-7/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2012/02/wpug-talk-developing-cross-platform-mobile-applications-with-phonegap-for-windows-phone-7/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 10:21:18 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1971</guid>
		<description><![CDATA[In a couple of weeks I will be giving a talk on using PhoneGap for cross platform mobile application development at the WPUG #NotAtMWC12 event on Tuesday, February 28, in London. Here&#8217;s a brief overview of my talk and a video: Windows Phone 7 and the Silverlight framework are a great pairing; they allow you [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2012%252F02%252Fwpug-talk-developing-cross-platform-mobile-applications-with-phonegap-for-windows-phone-7%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22WPUG%20Talk%3A%20Developing%20cross-platform%20mobile%20applications%20with%20PhoneGap%20for%20Windows%20Phone%207%20%23%22%20%7D);"></div>
<p>In a couple of weeks I will be giving a talk on using PhoneGap for cross platform mobile application development at the <a href="http://www.meetup.com/wpuguk/events/50560792/">WPUG #NotAtMWC12 event</a> on Tuesday, February 28, in London. Here&#8217;s a brief overview of my talk and a video:</p>
<table>
<tr>
<td style="vertical-align:top">
<img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/07/quote.png" alt="" title="quote" width="50" height="50"  />
</td>
<td>
Windows Phone 7 and the Silverlight framework are a great pairing; they allow you to create beautiful Metro applications with ease. The excellent tooling, coupled with the Nokia partnership, should make WP7 a big success.</p>
<p>Will we see a future dominated by WP7? I doubt it, and the analysts at Gartner seem to agree, <a href="http://www.scottlogic.co.uk/blog/colin/2011/04/gartner-predicts-a-promising-future-for-windows-phone-7-developers/">with their 2015 predications</a> indicating that Andoid, WP7 and iOS will all still have a significant market share for a few years to come. If you are developing a smartphone application this means you either make a choice between one of the three, or you have to write the same application three times, once in each of C#, Java and Objective-C.</p>
<p>However, there is another way … all three phones have highly capable browser, in many ways more capable than their desktop counterparts where many people still use quite archaic browsers! All have good HTML5 support, which allows you to create applications that run within the browser. With this technology you can potentially write your mobile application just once using HTML5 (JavaScript / CSS) and reuse it on all three platforms.</p>
<p>This sounds too good to be true doesn’t it?</p>
<p>This talk will focus on the use of PhoneGap for the development of cross platform applications and look at the compromises you make, and the benefits you receive, by using this approach.
</td>
<td style="vertical-align:bottom">
<img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/07/quote2.png" alt="" title="quote" width="50" height="50"  />
</td>
</tr>
</table>
<p>I&#8217;ll be talking quite a bit about <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/property-finder-the-first-html5-based-windows-phone-7-application/">Property Finder</a>, a PhoneGap application I wrote for WP7, which I have now ported to iOS (using PhoneGap build): </p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/rMtdwrEnM0k" frameborder="0" allowfullscreen></iframe></p>
<p>Hopefully see you there!</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2012/02/wpug-talk-developing-cross-platform-mobile-applications-with-phonegap-for-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP7 PhoneGap Backbutton Support Re-visited</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2012/01/wp7-phonegap-backbutton-support-re-visited/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2012/01/wp7-phonegap-backbutton-support-re-visited/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 11:03:11 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1950</guid>
		<description><![CDATA[About a month ago I published an article which demonstrated how to create a WP7 application using static HTML pages and PhoneGap. Whilst PhoneGap makes the packaging of HTML / JavaScript / CSS and images into a breeze, one thing it doesn&#8217;t do is provide correct back-button support. Correct back-button support is a mandatory requirement [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2012%252F01%252Fwp7-phonegap-backbutton-support-re-visited%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22WP7%20PhoneGap%20Backbutton%20Support%20Re-visited%20%23%22%20%7D);"></div>
<p>About a month ago I published an article which demonstrated how to <a href="http://www.scottlogic.co.uk/blog/colin/2011/12/a-simple-multi-page-windows-phone-7-phonegap-example/" title="A Simple Multi-Page Windows Phone 7 PhoneGap Example">create a WP7 application using static HTML pages and PhoneGap</a>. Whilst PhoneGap makes the packaging of HTML / JavaScript / CSS and images into a breeze, one thing it doesn&#8217;t do is provide correct back-button support. Correct back-button support is a mandatory requirement for marketplace certification. Hitting the back button should navigate back through the various screens of an application. Hitting the back-button on the first screen should terminate the application. </p>
<p>The solution I published previously handles the WP7 back keypress in order to keep track of the back-stack depth. When the back-stack depth is just one, a back-button press exits the application. This works fine if backwards navigation is always controlled via the hardware back-button, however if your application has HTML anchor elements that navigate back to a previous page, or you use code such as <code>javascript:history.go(-1)</code>, this back-stack handling code will not detect that a backwards navigation has occurred.</p>
<p><em>As an aside, WP7 applications really should use the hardware back-button for navigation. If you are writing a cross-platform PhoneGap application consider adapting your UI for each platform. This means removing the back-button you woudl have in your iOS version when &#8216;skinning&#8217; for WP7.</em></p>
<p>In order to solve this issue I have updated the code to inspect the URL that the browser control is navigating to in order to detect backwards navigation. The class now maintains a list of URLs, which represent the navigation stack. This allows it to detect a backwards navigation.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Handles the back-button for a PhoneGap application. When the back-button</span>
<span style="color: #008080; font-style: italic;">/// is pressed, the browser history is navigated. If no history is present,</span>
<span style="color: #008080; font-style: italic;">/// the application will exit.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> BackButtonHandler
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> WebBrowser _browser<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> _backStack <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> BackButtonHandler<span style="color: #008000;">&#40;</span>PhoneApplicationPage page, PGView phoneGapView<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// subscribe to the hardware back-button</span>
    page<span style="color: #008000;">.</span><span style="color: #0000FF;">BackKeyPress</span> <span style="color: #008000;">+=</span> Page_BackKeyPress<span style="color: #008000;">;</span>
&nbsp;
    _browser <span style="color: #008000;">=</span> phoneGapView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// handle navigation events</span>
    _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Navigated</span> <span style="color: #008000;">+=</span> Browser_Navigated<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
  <span style="color: #008080; font-style: italic;">/// Handle navigation in order to update our back-stack</span>
  <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Browser_Navigated<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, NavigationEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> url <span style="color: #008000;">=</span> _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Source</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OriginalString</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// ensure all slashes are the same</span>
    <span style="color: #008080; font-style: italic;">// app\www/index.html</span>
    <span style="color: #008080; font-style: italic;">// see: https://issues.apache.org/jira/browse/CB-184</span>
    url <span style="color: #008000;">=</span> url<span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>&quot;</span>, <span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>url<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008080; font-style: italic;">// check whether the URL represents a backwards navigation</span>
      <span style="color: #6666cc; font-weight: bold;">string</span> previousPage <span style="color: #008000;">=</span> _backStack<span style="color: #008000;">&#91;</span>_backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>previousPage <span style="color: #008000;">==</span> url<span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        _backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveAt</span><span style="color: #008000;">&#40;</span>_backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
  <span style="color: #008080; font-style: italic;">/// Handle the hardware back-button</span>
  <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_BackKeyPress<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, CancelEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// if we have items in the back-stack, route this event</span>
    <span style="color: #008080; font-style: italic;">// to the browser</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_backStack<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeScript</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;eval&quot;</span>, <span style="color: #666666;">&quot;history.go(-1)&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      e<span style="color: #008000;">.</span><span style="color: #0000FF;">Cancel</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Note: There use of <code>url.Replace("\\", "/")</code>, this is due to a minor issue with the PhoneGap WP7 native code, which I have raised in the Callback JIRA (<a href="https://issues.apache.org/jira/browse/CB-184">CB-184</a>).</p>
<p>To use this code simply create an instance of the class, passing the PGView (the PhoneGap user control) into teh constructor:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> MainPage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008000;">new</span> BackButtonHandler<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, PGView<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Because back-button handling is a mandatory requirement for WP7 applications, hopefully Nitobi will incorporate this code (or similar) into the <a href="https://build.phonegap.com/apps">PhoneGap Build service</a> (which I tried earlier this week &#8211; it is pretty amazing!)</p>
<p>You can download a working example here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/HTML5SandwichFlow1.zip'>HTML5SandwichFlow.zip</a></p>
<p>(The first three recipe pages have &#8216;back&#8217; anchor elements, two use the URL, one uses JavaScript)</p>
<p>Regards,<br />
Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2012/01/wp7-phonegap-backbutton-support-re-visited/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Proud to be a CodeProject MVP 2012</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2012/01/proud-to-be-a-codeproject-mvp-2012/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2012/01/proud-to-be-a-codeproject-mvp-2012/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 20:48:46 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1919</guid>
		<description><![CDATA[I have just received an email from Chris Maunder, co-founder of CodeProject, informing me that I have been awarded CodeProject MVP status for 2012. I am very pleased to have received this award, which is given to a small handful of individuals each year. What I like about CodeProject is the fantastic quality of the [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2012%252F01%252Fproud-to-be-a-codeproject-mvp-2012%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Proud%20to%20be%20a%20CodeProject%20MVP%202012%20%23%22%20%7D);"></div>
<p>I have just received an email from Chris Maunder, co-founder of CodeProject, informing me that I have been awarded CodeProject MVP status for 2012. I am very pleased to have received this award, which is <a href="http://www.codeproject.com/script/Awards/MVPWinners.aspx">given to a small handful of individuals</a> each year.</p>
<p><a href="http://www.codeproject.com/Members/Colin-Eberhardt"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/04/codeproject.gif" alt="" title="codeproject" width="225" height="72" class="aligncenter size-full wp-image-283" /></a></p>
<p>What I like about CodeProject is the fantastic quality of the articles submitted by the thousands of authors that participate in this site, with the only payment being their own please in the writing.</p>
<p>I have not written that many articles throughout the year, just four of them. However, I have put a lot of effort into each one of them &#8211; and thankfully they have been very well received. It is great that CodeProject favours quality over quantity. My articles for 2011 were:</p>
<ul>
<li><a href="http://www.codeproject.com/KB/codegen/CodeSnippetAutomation.aspx">Declarative Codesnippet Automation with T4 Templates</a></li>
<li><a href="http://www.codeproject.com/KB/windows-phone-7/WindowsPhone7JumpLIst.aspx">Developing a Windows Phone 7 JumpList Control</a></li>
<li><a href="http://www.codeproject.com/KB/scripting/SilverlightToHTML5.aspx">From Silverlight to HTML5</a></li>
<li><a href="http://www.codeproject.com/KB/windows-phone-7/XAMLFinance.aspx">XAMLFinance – A Cross-platform WPF, Silverlight &#038; WP7 Application</a></li>
</ul>
<p>I do also circulate some of my blog posts via the CodeProject Associate program..</p>
<p>On that note, it is almost three months since I last wrote an article &#8230; fortunately I do have an idea for the next article, so I had better get on with writting it &#8230;</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2012/01/proud-to-be-a-codeproject-mvp-2012/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FastClick for WP7 &#8211; Improving Browser Responsiveness for PhoneGap Apps</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2012/01/fastclick-for-wp7-improving-browser-responsiveness-for-phonegap-apps/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2012/01/fastclick-for-wp7-improving-browser-responsiveness-for-phonegap-apps/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 10:23:50 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[phone]]></category>
		<category><![CDATA[WebBrowser]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1907</guid>
		<description><![CDATA[I recently released an update of the HTML5 / PhoneGap application I wrote a few months ago to the marketplace. This update fixed the location detection issue, where the marketplace certification process failed to detect that the application was using geolocation data via the browser (this issue has been fixed in PhoneGap 1.2), plus a [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2012%252F01%252Ffastclick-for-wp7-improving-browser-responsiveness-for-phonegap-apps%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22FastClick%20for%20WP7%20-%20Improving%20Browser%20Responsiveness%20for%20PhoneGap%20Apps%20%23%22%20%7D);"></div>
<p>I recently released an update of the HTML5 / PhoneGap application I wrote a few months ago to the marketplace. This update fixed the location detection issue, where the marketplace certification process failed to detect that the application was using geolocation data via the browser (this issue <a href="https://issues.apache.org/jira/browse/CB-138">has been fixed in PhoneGap 1.2</a>), plus a few cosmetic improvements.</p>
<p>This application still exhibits a few UI quirks that make it fairly obvious that this is not a native application, the first is the <a href="http://stackoverflow.com/questions/6378008/windows-phone-7-browser-turn-off-the-gray-shading-when-links-are-clicked">gray box that appears whenever a link is clicked</a>, the second is the overall responsiveness &#8211; there is a short delay between clicking on links / buttons and the application responding. It is this responsiveness that I would like to tackle in this blog post. This delay unfortunately gives the impression that your application is less responsive than it actually is!</p>
<p><strong><em>So where does this delay come from?</em></strong></p>
<p>Despite the rise in popularity of touch interfaces, much of the web is still designed for interaction with a mouse and keyboard, with the DOM exposing events for mouse-up, mouse-down and click user interactions. The Windows Phone 7 browser control captures touch interactions and translates these into the required mouse events, firing them on the DOM element being interacted with. However, the browser itself also needs to support gestures such as pan, pinch-zoom and double-tap zoom.</p>
<p>If we consider for example the pinch-zoom feature, where the user places two fingers on the screen and moves them apart in order to zoom in. It is highly unlikely they will place both fingers on the screen simultaneously. If, when the first finger was placed, a mouse-down event was fired on the relevant DOM element, there would be no way to &#8216;cancel&#8217; this event when the user&#8217;s second finger made contact with the screen shortly afterwards. For this reason the WP7 mobile browser does not properly support mouse-down / mouse-up events. You will find that mousedown, mouseup then click are always fired immediately in that order regardless of how long you hold your finger on the screen for. Clearly the need to add gesture support to the browser interferes with the way in which native touch events are translated into JavaScript mouse events.</p>
<p>Now consider the double-tap zoom feature, where the user taps twice in quick succession to zoom the web page by some fixed amount. If the DOM click event were fired on the first tap, this would cause a navigation to occur if an anchor element were tapped. This is certainly not the desired behaviour! Again, there is no way to &#8216;cancel&#8217; an event once it is fired, so the only solution to this problem is, when the user first taps the screen, pause for a few hundred milliseconds to see if they tap a second time. Only after this pause is it safe to pass the interaction onto the DOM, firing a click event on the relevant DOM element.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/the_fence.jpg" alt="" title="the_fence" width="300" height="244" class="aligncenter size-full wp-image-1910" /></p>
<p><small>Stock image courtesy of <a href="http://www.sxc.hu/photo/313551">lovetheson</a></small></p>
<p>The need to handle gestures in the native layer causes numerous issues for the browser event handling. Thankfully these issues are relatively minor for most websites, but if your aim is to create a HTML-based application with a native look and feel, these issues become quite major.</p>
<p><strong>Improving responsiveness</strong></p>
<p>The problem I want to tackle in this blog post is that of the click DOM event firing delay to support the double-tap gesture. With HTML5-based applications you will typically want to disable pinch zoom, double-tap zoom and (optionally) scrolling <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control/" title="Suppressing Zoom and Scroll interactions in the Windows Phone 7 WebBrowser Control">as I described in a previous blog post</a>. As a result your application has no need for the double-tap and pinch gestures and we are safe to short-circuit this behaviour, immediately raising DOM click events when the user taps the screen.</p>
<p>My solution follows a similar approach to the utility class I wrote for suppressing pan / zoom, where event handlers are added to the <code>Border </code>that sits within the <code>WebBrowser </code>control visual tree:</p>
<pre>
\-WebBrowser
  \-Border
    \-Border
      \-PanZoomContainer
        \-Grid
          \-Border (*)
            \-ContentPresenter
              \-TileHost
</pre>
<p>In order to forward Tap gestures to the browser, we can add event handlers to the Border element, then use <code>InvokeScript</code> to pass this onto the DOM rendered within the <code>TileHost</code>.</p>
<p>The JavaScript code to achieve this is very simple, the DOM exposes an <code>elementFromPoint</code> function which allows you to hit test the DOM. The IE9 DOM interface also exposes a non-standard <code>click</code> function which invokes any click event handlers, this will cause an anchor element to navigate. Putting it together, if you have an anchor element at <code>(x=100, y=100)</code>, you can cause it to navigate using the following simple code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">elementFromPoint</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Calling this JavaScript from our native C# code in response to Tap events is very easy. I have wrapped it up into a simple utility class:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Captures mouse left button up events, triggering an immediate</span>
<span style="color: #008080; font-style: italic;">/// click event on the clicked DOM element.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> BrowserFastClick
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> WebBrowser _browser<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> Border _border<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> BrowserFastClick<span style="color: #008000;">&#40;</span>WebBrowser browser<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    _browser <span style="color: #008000;">=</span> browser<span style="color: #008000;">;</span>
    browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Loaded</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> RoutedEventHandler<span style="color: #008000;">&#40;</span>Browser_Loaded<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Browser_Loaded<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// locate the element used to capture mouse events</span>
    _border <span style="color: #008000;">=</span> _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">Descendants</span><span style="color: #008000;">&lt;</span>Border<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Last</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Border<span style="color: #008000;">;</span>
    _border<span style="color: #008000;">.</span><span style="color: #0000FF;">Tap</span> <span style="color: #008000;">+=</span> Border_Tap<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Border_Tap<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, GestureEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">//determine the click location</span>
    var pos <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span>_border<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// forward to the browser</span>
    _browser<span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeScript</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;eval&quot;</span>,
      <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;document.elementFromPoint({0},{1}).click()&quot;</span>, pos<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span>, pos<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>      
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>To use it within a PhoneGap application, simply create an instance as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> BrowserFastClick<span style="color: #008000;">&#40;</span>PGView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The net result is that your application becomes more responsive, with the browser immediately navigating links when they are first tapped.</p>
<p>I have updated the HTML5 SandwichFlow application I blogged about a few weeks ago to use this FastClick code. You can download the complete example here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2012/01/HTML5SandwichFlow.zip'>HTML5SandwichFlow.zip</a></p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2012/01/fastclick-for-wp7-improving-browser-responsiveness-for-phonegap-apps/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>A Festive and Fun Windows Phone 7 Maze Game</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2011/12/a-festive-and-fun-windows-phone-7-maze-game/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2011/12/a-festive-and-fun-windows-phone-7-maze-game/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 10:01:19 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1899</guid>
		<description><![CDATA[Last night, with my Christmas presents all wrapped and a lack of any decent programmes (festive or otherwise) on television, I had a few hours to kill, so decided to create a festive-themed WP7 game &#8230; Ever since I first started writing code for Windows Phone 7 I have wanted to do something involving physics [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2011%252F12%252Fa-festive-and-fun-windows-phone-7-maze-game%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22A%20Festive%20and%20Fun%20Windows%20Phone%207%20Maze%20Game%20%23%22%20%7D);"></div>
<p>Last night, with my Christmas presents all wrapped and a lack of any decent programmes (festive or otherwise) on television, I had a few hours to kill, so decided to create a festive-themed WP7 game &#8230;</p>
<p>Ever since I first started writing code for Windows Phone 7 I have wanted to do something involving physics and the accelerometer. I finally found a few hours to spare to give it a go. This blog post doesn’t go into too much detail about <a href="http://farseerphysics.codeplex.com/">Farseer</a>, the Physics Engine that I used, I didn’t really have time to learn it in any great detail. This post is more about how quickly you can put together something really quite cool in quite a short space of time using libraries and code grabbed from the internet.</p>
<p>The simple app I created renders a maze that you ‘roll’ a small ball around by tilting your phone:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/MazeGame.png" alt="" title="MazeGame" width="200" height="363" class="aligncenter size-full wp-image-1900" /></p>
<p>This works well in the new 7.1 emulator where you can tilt the emulator via the extended controls. However, it works best on a real device, where you can control tilt far more easily. See the video below:</p>
<p><iframe width="480" height="360" src="http://www.youtube.com/embed/Xkhh9P-Y45k" frameborder="0" allowfullscreen></iframe></p>
<h2>Farseer Physics Engine</h2>
<p>The game makes use of the popular <a href="http://farseerphysics.codeplex.com/">Farseer Physics Engine</a>. This library allows you to create a world populated with physics bodies, supporting features such as friction, joints, motors and much much more. As I am a Silverlight developer I made use of the <a href="http://physicshelper.codeplex.com/">Physics Helper</a> library which allows you to use the Farseer engine within a Silvelight application with very little effort. With the Physics Helper you simply make the Physics Engine ‘aware’ of the objects you wish it to control and it does the rest, animating them as they are subjected to gravity and other interactions.</p>
<p>The simplest way to use Physics Helper is via behaviours, this allows you to create a fully functioning ‘world’ without writing a single line of C# code. For example, you can create a ball and a surface that it will fall towards, eventually coming to rest, with just a few lines of XAML:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>Canvas x<span style="color: #008000;">:</span>Name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;canvas&quot;</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;!--</span> create our <span style="color: #666666;">'world'</span> <span style="color: #008000;">--&gt;</span>
  <span style="color: #008000;">&lt;</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>pb<span style="color: #008000;">:</span>PhysicsControllerBehavior<span style="color: #008000;">/&gt;</span>
  <span style="color: #008000;">&lt;/</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
&nbsp;
  <span style="color: #008000;">&lt;</span>Ellipse Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;100&quot;</span> Height<span style="color: #008000;">=</span><span style="color: #666666;">&quot;100&quot;</span> Fill<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Red&quot;</span>
            Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Left</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;80&quot;</span> Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;100&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;!--</span> make the engine aware of <span style="color: #0600FF; font-weight: bold;">this</span> element <span style="color: #008000;">--&gt;</span>
    <span style="color: #008000;">&lt;</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
      <span style="color: #008000;">&lt;</span>pb<span style="color: #008000;">:</span>PhysicsObjectBehavior <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;/</span>Ellipse<span style="color: #008000;">&gt;</span>
&nbsp;
&nbsp;
  <span style="color: #008000;">&lt;</span>Rectangle Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;500&quot;</span> Height<span style="color: #008000;">=</span><span style="color: #666666;">&quot;10&quot;</span> Fill<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Blue&quot;</span>
              Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Top</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;500&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;!--</span> make the engine aware of <span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #0600FF; font-weight: bold;">STATIC</span> element <span style="color: #008000;">--&gt;</span>
    <span style="color: #008000;">&lt;</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
      <span style="color: #008000;">&lt;</span>pb<span style="color: #008000;">:</span>PhysicsObjectBehavior IsStatic<span style="color: #008000;">=</span><span style="color: #666666;">&quot;True&quot;</span><span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>i<span style="color: #008000;">:</span>Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">Behaviors</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;/</span>Rectangle<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>Canvas<span style="color: #008000;">&gt;</span></pre></div></div>

<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/SimpleExample.png" alt="" title="SimpleExample" width="600" height="256" class="aligncenter size-full wp-image-1901" /></p>
<p>I find this pretty amazing! </p>
<p>Physics Helper will do much more, it can handle complex paths and geometries, explosions and collisions with minimal effort. For a greater insight into just how much is possible, I would recommend <a href="http://channel9.msdn.com/coding4fun/articles/Creating-a-Pinball-Game-in-Silverlight-Using-the-Physics-Helper-Library--Farseer-Physics">Andy Beaulieu’s Channel 9 article</a>. Andy is the creator of Farseer, so really knows his stuff!</p>
<p>My maze is generated in C# code, so despite the elegance of using Physics Helper via behaviours, I need to add elements to my canvas programmatically. This means that I have to make the physics engine aware of their existence in code also. To achieve this, I add the behaviour in code as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Uses Physics Helper to create a physics body for the given element</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddPhysicsBody<span style="color: #008000;">&#40;</span>FrameworkElement element, <span style="color: #6666cc; font-weight: bold;">bool</span> isStatic<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var behaviorCollection <span style="color: #008000;">=</span> Interaction<span style="color: #008000;">.</span><span style="color: #0000FF;">GetBehaviors</span><span style="color: #008000;">&#40;</span>element<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  behaviorCollection<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> PhysicsObjectBehavior<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    IsStatic <span style="color: #008000;">=</span> isStatic
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  var physicsObject <span style="color: #008000;">=</span> element<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>PhysicsObjectMain<span style="color: #008000;">.</span><span style="color: #0000FF;">PhysicsObjectProperty</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> PhysicsObjectMain<span style="color: #008000;">;</span>
  _physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">AddPhysicsBody</span><span style="color: #008000;">&#40;</span>physicsObject<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Creating a Maze</h2>
<p>I found numerous C# maze algorithms on the internet, most of them based on the same random-walk concept. There is a great description of this approach, with <a href="http://weblog.jamisbuck.org/2011/1/20/maze-generation-wilson-s-algorithm">animated examples on this blog</a>. Unfortunately every C# implementation I came across was tightly coupled to a specific UI framework, often WinForms or XNA (tut-tut remember to separate your concerns!). So, I took a simple maze algorithm <a href="http://www.techpowerup.com/forums/showthread.php?t=109739">from a software forum</a> and ripped-out the WinForms / GDI rendering code. A new maze is constructed simply by creating an instance of the <code>Maze</code> class, passing it the number of rows and columns.</p>
<p>In order to render the maze using Silverlight elements, I simply took the original maze graphics code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> CreateMaze<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// compute the number of rows / cols</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> ratio <span style="color: #008000;">=</span> mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">ActualHeight</span> <span style="color: #008000;">/</span> mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">ActualWidth</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">int</span> cols <span style="color: #008000;">=</span> _mazeSize<span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">int</span> rows <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>cols <span style="color: #008000;">*</span> ratio<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> cellWidth <span style="color: #008000;">=</span> mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">ActualWidth</span> <span style="color: #008000;">/</span> cols<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create the maze</span>
  Maze maze <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Maze<span style="color: #008000;">&#40;</span>rows, cols<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// render the maze</span>
  <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> cols<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> rows<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>j<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      var room <span style="color: #008000;">=</span> maze<span style="color: #008000;">.</span><span style="color: #0000FF;">cells</span><span style="color: #008000;">&#91;</span>i, j<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>room <span style="color: #008000;">&amp;</span> Maze<span style="color: #008000;">.</span><span style="color: #0000FF;">UP</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        DrawLine<span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
                j <span style="color: #008000;">*</span> cellWidth,
                i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
                j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>room <span style="color: #008000;">&amp;</span> Maze<span style="color: #008000;">.</span><span style="color: #0000FF;">DOWN</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        DrawLine<span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>room <span style="color: #008000;">&amp;</span> Maze<span style="color: #008000;">.</span><span style="color: #0000FF;">RIGHT</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        DrawLine<span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>room <span style="color: #008000;">&amp;</span> Maze<span style="color: #008000;">.</span><span style="color: #0000FF;">LEFT</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        DrawLine<span style="color: #008000;">&#40;</span>i <span style="color: #008000;">*</span> cellWidth,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
              i <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>,
              j <span style="color: #008000;">*</span> cellWidth <span style="color: #008000;">+</span> cellWidth <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>And created a method that mimics the behaviour of the <code>System.Drawing.Graphics.DrawLine</code> method which the original maze code depended on:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> DrawLine<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> x1, <span style="color: #6666cc; font-weight: bold;">double</span> y1, <span style="color: #6666cc; font-weight: bold;">double</span> x2, <span style="color: #6666cc; font-weight: bold;">double</span> y2<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> width <span style="color: #008000;">=</span> x2 <span style="color: #008000;">-</span> x1 <span style="color: #008000;">+</span> <span style="color: #FF0000;">2.0</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>width <span style="color: #008000;">==</span> <span style="color: #FF0000;">0.0</span><span style="color: #008000;">&#41;</span> width <span style="color: #008000;">=</span> <span style="color: #FF0000;">2.0</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #6666cc; font-weight: bold;">double</span> height <span style="color: #008000;">=</span>  y2 <span style="color: #008000;">-</span> y1<span style="color: #008000;">+</span> <span style="color: #FF0000;">2.0</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>height <span style="color: #008000;">==</span> <span style="color: #FF0000;">0.0</span><span style="color: #008000;">&#41;</span> height <span style="color: #008000;">=</span> <span style="color: #FF0000;">2.0</span><span style="color: #008000;">;</span>
&nbsp;
  var rec <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Windows</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Shapes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Rectangle</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    Fill <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Red</span><span style="color: #008000;">&#41;</span>,
    Width <span style="color: #008000;">=</span> width,
    Height <span style="color: #008000;">=</span> height
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
  Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetLeft</span><span style="color: #008000;">&#40;</span>rec, x1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetTop</span><span style="color: #008000;">&#40;</span>rec, y1<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>rec<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  AddPhysicsBody<span style="color: #008000;">&#40;</span>rec, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>A bit messy, but gets the job done!</p>
<p>The above code creates a maze comprised of static physics objects, where the<code> _mazeSize</code> field dictates the scale of the maze:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/Mazes.png" alt="" title="Mazes" width="500" height="454" class="aligncenter size-full wp-image-1902" /></p>
<h2>Adding a Rolling Ball</h2>
<p>Adding a ball to the maze is simply a matter of creating an ellipse and adding it at the maze entrance. Note, this physics-body is not static, so will move under the influence of gravity:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Ellipse ball <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Ellipse<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  Width <span style="color: #008000;">=</span> cellWidth <span style="color: #008000;">*</span> <span style="color: #FF0000;">0.7</span>,
  Height <span style="color: #008000;">=</span> cellWidth <span style="color: #008000;">*</span> <span style="color: #FF0000;">0.7</span>,
  Fill <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Resources</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;brush&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Brush
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetLeft</span><span style="color: #008000;">&#40;</span>ball, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>cols <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">0.7</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> cellWidth<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Canvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetTop</span><span style="color: #008000;">&#40;</span>ball, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>ball<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
AddPhysicsBody<span style="color: #008000;">&#40;</span>ball, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>By default, the ‘world’ has gravity with a fixed Y component and no X component. This causes all non-static bodies to fall downwards as you might expect. In order to guide the ball around the maze by tilting the phone, we need to adjust gravity based on accelerometer readings. This is achieved by the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> HandleAccelerometer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  _sensor <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Accelerometer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _sensor<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// 10 times a second, update the gravity</span>
  var gtimer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DispatcherTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  gtimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Interval</span> <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromSeconds</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0.1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  gtimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Tick</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s, e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">Simulator</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">Simulator</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Gravity</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span> <span style="color: #008000;">*</span> <span style="color: #008000;">-</span>_sensor<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentValue</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Acceleration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
      _physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">Simulator</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Gravity</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span> <span style="color: #008000;">*</span> _sensor<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentValue</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Acceleration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
  gtimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Note</strong>: this uses a timer, rather than updating the simulator every time the accelerometer reading changes. I found that without the timer, I was repeatedly seeing the generic “Element is already a child of another element” exception. You will also notice in the code that the maze is built after a pause of a couple of seconds, again in order to avoid this issue. There’s something funny going on inside the Physics Helper!</p>
<p>Finally, we handle collisions in order to play a simple sounds effect a the ball bounces off each wall:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// locate the physics controller</span>
_physicsController <span style="color: #008000;">=</span> mazeContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>PhysicsControllerMain<span style="color: #008000;">.</span><span style="color: #0000FF;">PhysicsControllerProperty</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> PhysicsControllerMain<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// load the WAV file</span>
Stream stream <span style="color: #008000;">=</span> TitleContainer<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenStream</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;boing1.wav&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
_effect <span style="color: #008000;">=</span> SoundEffect<span style="color: #008000;">.</span><span style="color: #0000FF;">FromStream</span><span style="color: #008000;">&#40;</span>stream<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
FrameworkDispatcher<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// play on each collision</span>
_physicsController<span style="color: #008000;">.</span><span style="color: #0000FF;">Collision</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s,e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> _effect<span style="color: #008000;">.</span><span style="color: #0000FF;">Play</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>And there we have it, a simple maze game powered by the Farseer Physics engine. The whole thing only took about an hour to create, with code grabbed from the internet &#8211; a bit rough and ready, but I was impressed with how easy it was to create this game. There is much more that could be done, for example detecting when the ball reaches the end of the maze, advancing to a more difficult level, however, my time has run out on this bit of fun &#8230; Also, if I were to take this idea further, I would probably use XNA rather than Silverlight. The Physics Helper is great for simple XAML-only physics models, but I feel that it wasn’t really built for programmatic creation of bodies.</p>
<p>You can download the code here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/WP7MazeGame.zip'>WP7MazeGame.zip</a></p>
<p>Note, you will have to download and install Physics Helper to run this code.</p>
<p>On another note, Farseer is clearly the result of hundreds of hours of development effort, which makes it easy to create realistic physics-based applications and games. Farseer is free to use under the MS-PL licence. However, I would urge anyone who has used this great library to create a WP7 game to donate via the <a href="http://farseerphysics.codeplex.com/">Farseer codeplex site</a> (scroll to the bottom).</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2011/12/a-festive-and-fun-windows-phone-7-maze-game/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Metro Themed PowerPoint Template</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2011/12/a-metro-themed-powerpoint-template/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2011/12/a-metro-themed-powerpoint-template/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 17:10:57 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[metro]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1889</guid>
		<description><![CDATA[Over the weekend I mentioned on Twitter that I had created a Metro-style PowerPoint template. There were a few requests to share, so hence this blog post. Scroll to the bottom to download the PowerPoint file. So why create a Metro-style PowerPoint presentation? A couple of reasons, firstly, the templates that come with PowerPoint are [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2011%252F12%252Fa-metro-themed-powerpoint-template%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22A%20Metro%20Themed%20PowerPoint%20Template%20%23%22%20%7D);"></div>
<p>Over the weekend I mentioned on Twitter that I had created a Metro-style PowerPoint template. There were a few requests to share, so hence this blog post. Scroll to the bottom to download the PowerPoint file.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/MetroPP.png" alt="" title="MetroPP" width="506" height="378" class="aligncenter size-full wp-image-1890" /></p>
<p>So why create a Metro-style PowerPoint presentation? A couple of reasons, firstly, the templates that come with PowerPoint are absolutely awful!</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/PPTemplates.png" alt="" title="PPTemplates" width="571" height="282" class="aligncenter size-full wp-image-1891" /></p>
<p>They look very dated (to put it politely). Secondly, with the Metro Design Language, which was introduced with Windows Phone 7, Microsoft have come up with something surprisingly stylish. Metro is about clarity, readability, simplicity &#8211; concepts that map very well to presentations. </p>
<p>The &#8216;classic&#8217; Metro look, which I have tried to re-produce with this template, includes highly legible san-serif fonts (from the Segoe family), a lack of chrome (i.e. shadows, gradient) and fluid motions. Many metro applications do include background imagery to add &#8216;warmth&#8217;, as I have done here also.</p>
<p>I have created a template with a master and a number of layouts. Each layout includes a number of sequenced animations, mimicking the &#8216;fast and fluid&#8217; Metro interface:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/Animations.png" alt="" title="Animations" width="600" height="347" class="aligncenter size-full wp-image-1892" /></p>
<p>PowerPoint can be used to create some rather neat sequenced animations, if you ignore the rather garish defaults.</p>
<p>To get a better feel for this template, have a look at it in motion (the quality here is rather poor, I haven&#8217;t managed to find a screen capture tool that works well for subtle colours):</p>
<p><iframe width="480" height="360" src="http://www.youtube.com/embed/Nmtu5vSYrn8" frameborder="0" allowfullscreen></iframe></p>
<p>If you want to use this template, you might want to change the background image. You can do this via the &#8216;slide master view&#8217;. The background I included is one I found on the free stock imagery site stock.xcnhg, by the user <a href="http://www.sxc.hu/photo/1246725">fangol</a>. There are numerous other free images on that site. Please remember to attribute your usage of free stock images.</p>
<p>You might also find that you need to add new layouts based on your content. Again, this is easy to do via the master view.</p>
<p>Anyhow, here is the template, enjoy: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/MetroStyle.pptx'>MetroStyle.pptx</a></p>
<p><b>NOTE:</b> Until I get the mime-types sorted out you might have to right click and select &#8220;save as&#8221; to save the above PowerPoint file.</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2011/12/a-metro-themed-powerpoint-template/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A Simple Multi-Page Windows Phone 7 PhoneGap Example</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2011/12/a-simple-multi-page-windows-phone-7-phonegap-example/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2011/12/a-simple-multi-page-windows-phone-7-phonegap-example/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 15:55:11 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PhoneGap]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1873</guid>
		<description><![CDATA[This blog post shows how you can use PhoneGap to create Windows Phone 7 applications that are comprised of multiple, simple HTML pages, whilst meeting the Marketplace certification requirements. Readers of my blog will know that I have been working on, and writing about, the use of PhoneGap to create HTML5-based Windows Phone 7 applications. [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2011%252F12%252Fa-simple-multi-page-windows-phone-7-phonegap-example%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22A%20Simple%20Multi-Page%20Windows%20Phone%207%20PhoneGap%20Example%20%23%22%20%7D);"></div>
<p><em>This blog post shows how you can use PhoneGap to create Windows Phone 7 applications that are comprised of multiple, simple HTML pages, whilst meeting the Marketplace certification requirements.</em></p>
<p>Readers of my blog will know that I have been working on, and writing about, the use of <a href="http://phonegap.com/">PhoneGap</a> to create HTML5-based Windows Phone 7 applications. Along the way I have solved problems such as <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/handling-the-back-stack-in-windows-phone-7-phonegap-applications/">back-button support</a>, <a href="http://www.scottlogic.co.uk/blog/colin/2011/10/tombstoning-with-phonegap-for-windows-phone-7-and-knockoutjs/">tombstoning</a> and <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control/">suppressing browser pan and zoom</a>. So far the applications I have discussed have all been single-page JavaScript applications, i.e. the <code>WebBrowser </code>control loads a single HTML page which links to the application JavaScript. All subsequent navigation involves updating the DOM dynamically rather than navigating to a new URL. However, I have had numerous questions to my previous blog posts from people who are using PhoneGap to create simple navigation-based applications. In this context PhoneGap is being used as a mechanism for packaging up a collection of relatively static HTML pages.</p>
<p>So why would you want to do this? This is a perfectly valid question! If you have static HTML based content why not simply put it on the web? There are a few reasons, one is to ensure that the content is always available, whether the phone is connected to a network or not. Another is monetization, the app-store model provides an easy way to charge for this content. Regardless of the pros and cons, based on the feedback my previous articles have received, people are very interested in using PhoneGap as a model for packaging static content.</p>
<p>In this blog post I will show how to solve the problems of back-button support and pan / zoom for a simple navigation-based HTML application. As an example, I have chosen a subject which I have a lot of interest in … sandwiches! I have previously blogged about <a href="http://www.scottlogic.co.uk/blog/colin/2011/05/metro-in-motion-5-sandwichflow/">SandwichFlow</a>, an example application which showcased my metro-in-motion series, here I have transformed the sandwich recipe HTML into a collection of static HTML pages.</p>
<h2>Packaging the HTML</h2>
<p>My <a href="http://www.scottlogic.co.uk/blog/colin/2011/09/developing-windows-phone-7-html5-apps-with-phonegap/">first PhoneGap blog post</a> detailed how to get up-and-running with PhoneGap, if you have never used this framework before I would recommend that you read that first. Packaging my sandwich recipe content into an application was simply a matter of copying the files (HTML and CSS) into the ‘www’ directory, running the T4 template that auto-generates the <code>GapSourceDictionary.xml</code>, building and running. The resulting application is as follows:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/SandwichFlowThree.jpg" alt="" title="SandwichFlowThree" width="600" height="346" class="aligncenter size-full wp-image-1883" /></p>
<p>PhoneGap does a great job of making it very easy to package HTML content into an application, loading the files into isolates storage etc … However, there are a few Windows Phone 7 specific concepts that have to be supported in order to ensure certification on submission to the marketplace.</p>
<h2>Back-button Support</h2>
<p><strong>UPDATE:</strong> There are a few issues with the code below. See my <a href="http://www.scottlogic.co.uk/blog/colin/2012/01/wp7-phonegap-backbutton-support-re-visited/" title="WP7 PhoneGap Backbutton support re-visited">more recent blogpost for an improved solution</a>.</p>
<p>Correct back-button support is a mandatory requirement for marketplace certification. Hitting the back button should navigate back through the various screens of an application. Hitting the back-button on the first screen should terminate the application. The standard PhoneGap Visual Studio template does not support the back-button by default, this no-doubt reflects the fact that the other PhoneGap platforms (iPhone, Android, BlackBerry) do not share this same requirement, or lack a back-button altogether.</p>
<p>In my <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/handling-the-back-stack-in-windows-phone-7-phonegap-applications/">previous blog post on back-button support</a> I described how a single-page JavaScript application can manage its own back-stack. This approach does not work for navingation-based HTML applications.</p>
<p>The <code>WebBrowser</code> control which PhoneGap uses to render its contents stores its navigation history in the same way that a desktop browser does. This history can be accessed via the JavaScript ‘history’ object. If the back-button is pressed after navigating to one of the packaged HTML pages, invoking <code>history.go(-1)</code> will cause the WebBrowser control to navigate backwards. All we need to do is to keep track of navigation events to determine whether to route the back-button too our HTML application or not. </p>
<p>The following utility class does just that:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Handles the back-button for a PhoneGap application. When the back-button</span>
<span style="color: #008080; font-style: italic;">/// is pressed, the browser history is navigated. If no history is present,</span>
<span style="color: #008080; font-style: italic;">/// the application will exit.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> BackButtonHandler
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> _browserHistoryLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">private</span> PGView _phoneGapView<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> BackButtonHandler<span style="color: #008000;">&#40;</span>PhoneApplicationPage page, PGView phoneGapView<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// subscribe to the hardware back-button</span>
    page<span style="color: #008000;">.</span><span style="color: #0000FF;">BackKeyPress</span> <span style="color: #008000;">+=</span> Page_BackKeyPress<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// handle navigation events</span>
    phoneGapView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Navigated</span> <span style="color: #008000;">+=</span> Browser_Navigated<span style="color: #008000;">;</span>
&nbsp;
    _phoneGapView <span style="color: #008000;">=</span> phoneGapView<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Browser_Navigated<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, NavigationEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">NavigationMode</span> <span style="color: #008000;">==</span> NavigationMode<span style="color: #008000;">.</span><span style="color: #008000;">New</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _browserHistoryLength<span style="color: #008000;">++;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_BackKeyPress<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, CancelEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_browserHistoryLength <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      _phoneGapView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">.</span><span style="color: #0000FF;">InvokeScript</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;eval&quot;</span>, <span style="color: #666666;">&quot;history.go(-1)&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      _browserHistoryLength <span style="color: #008000;">-=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
      e<span style="color: #008000;">.</span><span style="color: #0000FF;">Cancel</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Note:</strong> I have had a number of requests from readers who do not have any C# / Silverlight experience, so are unsure how to use code snippets like the one above. In this blog post I have included the full sourcecode. Just grab the code and replace the contents of the ‘www’ directory with your own content, and you are good to go!</p>
<p>With the above code in place the application now supports the back-button </p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/BackStack.jpg" alt="" title="BackStack" width="600" height="249" class="aligncenter size-full wp-image-1874" /></p>
<p>With this feature in place you should be able to successfully submit a PhoneGap based application to the Windows Phone 7 marketplace. The other bits of code that follow are all about improving the cosmetics.</p>
<h2>Suppressing Pan and Zoom</h2>
<p>Whilst the viewport metadata settings can be used to prevent scaling, the cosmetics of this feature are not terribly good with Windows Phone 7, the user can still ‘pinch’ your HTML page, however, it snaps back to its original scale when the manipulation ends. I previously published a <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control/">simple class which can intercept manipulation events</a> in order to suppress the pinch zoom behaviour.</p>
<p>This class can also ‘lock’ the browser windows entirely, supressing scroll as well as zoom. However, this is only appropriate for use on pages where you can be sure the content fits entirely within a single page. In order to ‘activate’ this behaviour we need to send a message from the HTML / JavaScript to the C# utility class. The ’about’ page of this application does just that. When it is loaded the following JavaScript is executed:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #006600; font-style: italic;">// ensure that this page does not scroll</span>
  window.<span style="color: #660066;">external</span>.<span style="color: #660066;">Notify</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;noScroll&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The utility class (described in the earlier blog post) is instantiated in code-behind, with the above Notify being used to ‘lock’ the page:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> WebBrowserHelper _browserHelper<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Constructor</span>
<span style="color: #0600FF; font-weight: bold;">public</span> MainPage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008000;">new</span> BackButtonHandler<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, PGView<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _browserHelper <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WebBrowserHelper<span style="color: #008000;">&#40;</span>PGView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  PGView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ScriptNotify</span> <span style="color: #008000;">+=</span> Browser_ScriptNotify<span style="color: #008000;">;</span>
  PGView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Navigated</span> <span style="color: #008000;">+=</span> Browser_Navigated<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Browser_Navigated<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, NavigationEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// when we first navigate to a page, we assume that it can be scrolled</span>
  _browserHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">ScrollDisabled</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Browser_ScriptNotify<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, NotifyEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// if a page notifies that it should not be scrollable, disable</span>
  <span style="color: #008080; font-style: italic;">// scrolling.</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;noScroll&quot;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    _browserHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">ScrollDisabled</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Again, the code above is included in the download at the end of this article. To &#8216;lock&#8217; the scroll on any of your HTML pages, simply add the JavaScript &#8216;Notify&#8217; above. </p>
<h2>Splashscreen</h2>
<p>One final cosmetic issue is the application startup. The application splashcreen is hidden automatically when your application starts up. This is fine for a native application, however a PhoneGap application isn’t quite ready at this point. After the native wrapper starts, the code is loaded into the WebBrwoser control and the HTML / JavaScript application starts. This results in a rather ugly white screen appearing for ~ 0.5 second when the application starts up.</p>
<p>The start screen duration is not configurable, however, there is a simple solution to this problem, when the application first starts, render the splashscreen as the application content, then hide this image when the PhoneGap application starts. </p>
<p>To do this, create an image and position it in front of the PhoneGap browser control:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;Transparent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;my:PGView</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span> </span>
<span style="color: #009900;">                  <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;0,0,0,0&quot;</span>  </span>
<span style="color: #009900;">                  <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;PGView&quot;</span> </span>
<span style="color: #009900;">                  <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Stretch&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">Source</span>=<span style="color: #ff0000;">&quot;/SplashScreenImage.jpg&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;splashImage&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image.Resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Storyboard</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;fadeOut&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">BeginTime</span>=<span style="color: #ff0000;">&quot;0:0:0.5&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">Completed</span>=<span style="color: #ff0000;">&quot;fadeOut_Completed&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DoubleAnimation</span></span>
<span style="color: #009900;">                <span style="color: #000066;">Storyboard.TargetName</span>=<span style="color: #ff0000;">&quot;splashImage&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">Storyboard.TargetProperty</span>=<span style="color: #ff0000;">&quot;Opacity&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">From</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">To</span>=<span style="color: #ff0000;">&quot;0.0&quot;</span> <span style="color: #000066;">Duration</span>=<span style="color: #ff0000;">&quot;0:0:0.3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Storyboard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Image.Resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Image<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This image has a storyboard that fades-out the image. </p>
<p>This animation is triggered when the browser navigates to the first age of the application:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">EventHandler<span style="color: #008000;">&lt;</span>NavigationEventArgs<span style="color: #008000;">&gt;</span> hideSplashScreen <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
hideSplashScreen <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>s, e <span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
  <span style="color: #008000;">&#123;</span>
    fadeOut<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    PGView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Navigated</span> <span style="color: #008000;">-=</span> hideSplashScreen<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
PGView<span style="color: #008000;">.</span><span style="color: #0000FF;">Browser</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Navigated</span> <span style="color: #008000;">+=</span> hideSplashScreen<span style="color: #008000;">;</span></pre></div></div>

<p>Finally, the <code>Completed </code>event handler removes the image altogether when the animation ends:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> fadeOut_Completed<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  splashImage<span style="color: #008000;">.</span><span style="color: #0000FF;">Visibility</span> <span style="color: #008000;">=</span> Visibility<span style="color: #008000;">.</span><span style="color: #0000FF;">Collapsed</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Conclusions</h2>
<p>Hopefully this blog post will help people who are new to WP7 and wish to release PhoneGap applications comprised of multiple HTML pages. </p>
<p>You can download the sourcecode: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/12/HTML5SandwichFlow.zip'>HTML5SandwichFlow.zip</a></p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2011/12/a-simple-multi-page-windows-phone-7-phonegap-example/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Handling the back-stack in Windows Phone 7 PhoneGap applications</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2011/11/handling-the-back-stack-in-windows-phone-7-phonegap-applications/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2011/11/handling-the-back-stack-in-windows-phone-7-phonegap-applications/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 09:01:28 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[knockoutJS]]></category>
		<category><![CDATA[PhoneGap]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1850</guid>
		<description><![CDATA[Recently I have been researching the use of PhoneGap for creating HTML5 Windows Phone 7 applications. I have written an introductory post on the subject and also managed to have a HTML5-based application accepted into the marketplace. The Windows Phone 7 execution model has a few unique features (when compared to Android and iOS) that [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2011%252F11%252Fhandling-the-back-stack-in-windows-phone-7-phonegap-applications%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Handling%20the%20back-stack%20in%20Windows%20Phone%207%20PhoneGap%20applications%20%23%22%20%7D);"></div>
<p>Recently I have been researching the use of PhoneGap for creating HTML5 Windows Phone 7 applications. I have written an <a href="http://www.scottlogic.co.uk/blog/colin/2011/09/developing-windows-phone-7-html5-apps-with-phonegap/" title="Developing Windows Phone 7 HTML5 apps with PhoneGap">introductory post</a> on the subject and also managed to have a <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/property-finder-the-first-html5-based-windows-phone-7-application/" title="Property Finder – the first HTML5-based Windows Phone 7 Application">HTML5-based application accepted into the marketplace</a>.</p>
<p>The Windows Phone 7 execution model has a few unique features (when compared to Android and iOS) that need to be considered when developing HTML5 applications. The first one, <a href="http://www.scottlogic.co.uk/blog/colin/2011/10/tombstoning-with-phonegap-for-windows-phone-7-and-knockoutjs/" title="Tombstoning with PhoneGap for Windows Phone 7 (and KnockoutJS)">tombstoning</a>, is something I dealt with in an earlier blogpost. In this post I want to look at how to handle the back-button and the application back-stack.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/11/BackStack.png" alt="" title="BackStack" width="600" height="279" class="aligncenter size-full wp-image-1853" /></p>
<p>With Windows Phone 7, as the user navigates from one page to the next, the latest page is added to the top of a stack (the back-stack). The back-button is used to navigate back through the pages within your application by pulling them from the top of this stack. When the back stack holds a single page, i.e. the initial entry point into your application, pressing the back-button should exit the application.</p>
<p>So, how do you support this with a HTML5 / PhoneGap application? The PhoneGap APIs expose the <a href="http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html#backbutton">back-button as a JavaScript event</a>. If you subscribe to this event, your JavaScript code is notified each time the user hits the back button. Also, if the JavaScript event is subscribed to, the &#8216;native&#8217; (C#) event is cancelled, which means application back-stack remains unchanged and your PhoneGap application does not exit.</p>
<p>In order to emulate the back-stack functionality in a PhoneGap application you need to subscribe to the PhoneGap backbutton when back-navigation is possible within your application, and unsubscribe when it is not. This means that when the user hits the back-button at the entry-point of your application, the application is terminated as expected.</p>
<h2>A JavaScript Back-Stack</h2>
<p>In order to handle the PhoenGap backbutton event, I felt the easiest approach would be to structure my JavaScript application so that it more closely resembles a Windows Phone 7 application. I have already discussed in my blog post on <a href="http://www.scottlogic.co.uk/blog/colin/2011/10/tombstoning-with-phonegap-for-windows-phone-7-and-knockoutjs/" title="Tombstoning with PhoneGap for Windows Phone 7 (and KnockoutJS)">tombstoning how this task was made easier by using KnockoutJS</a> to structure my code using the Model-View-ViewModel (MVVM) pattern.</p>
<p>In this blog I&#8217;ll add further structure to the code, starting with an <code>ApplicationViewModel</code>. This view model contains a stack of view-models, with the one that is at the top of the stack, exposed via the <code>currentViewModel</code> observable property, being the one which is rendered on screen. The ApplicationViewModel also exposes functions for adding to and removing items from this stack:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> ApplicationViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> that <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">viewModelBackStack</span> <span style="color: #339933;">=</span> ko.<span style="color: #660066;">observableArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">backButtonRequired</span> <span style="color: #339933;">=</span> ko.<span style="color: #660066;">dependentObservable</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>    
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">viewModelBackStack</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentViewModel</span> <span style="color: #339933;">=</span> ko.<span style="color: #660066;">dependentObservable</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">viewModelBackStack</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">viewModelBackStack</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">navigateTo</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>viewModel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">viewModelBackStack</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>viewModel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">back</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">viewModelBackStack</span>.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The <code>currentViewModel</code> is implemented as a <a href="http://knockoutjs.com/documentation/dependentObservables.html">dependent-observable</a>, a really neat KnockoutJS feature where you create a new observable property based on one or more observable properties of a view model. In this case, KnockoutJS does some magic behind the scenes to deduce that<br />
<code>currentViewModel</code> depends upon the <code>viewModelBackStack</code> observable array. Each time the array is modified, bindings that depend on <code>currentViewModel</code> are also updated. That&#8217;s pretty neat!</p>
<p>The UI code needs to be modified so that the view relating to the <code>currentViewModel</code> is rendered and bound to its respective view model. This is simply a matter of subscribing to changes in this observable property in our code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create the view model</span>
application <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ApplicationViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
application.<span style="color: #660066;">currentViewModel</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>viewModel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>viewModel <span style="color: #339933;">!==</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#app&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> viewModel.<span style="color: #660066;">template</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">tmpl</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#app&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ko.<span style="color: #660066;">applyBindings</span><span style="color: #009900;">&#40;</span>viewModel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
application.<span style="color: #660066;">navigateTo</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> TwitterSearchViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For the above code to work, each view model must expose a <code>template</code> property which identified the HTML template which is their corresponding view. The above code creates a view instance and appends it to the <code>#app</code> element.</p>
<p>The templates for the two view-models within this application are shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=text/x-jquery-tmpl&quot; charset=&quot;utf-8&quot; id=&quot;twitterSearchView&quot;&gt;
  &lt;div&gt;
    &lt;form data-bind=&quot;submit: search&quot;&gt;
        &lt;input data-bind=&quot;value: searchTerm, valueUpdate: 'afterkeydown'&quot; /&gt;
        &lt;button type=&quot;submit&quot; data-bind=&quot;enable: searchTerm().length &gt; 0 &amp;&amp; isSearching() == false&quot;&gt;Go&lt;/button&gt;  
    &lt;/form&gt;
    &lt;ul data-bind=&quot;template: {name: 'tweetView', foreach: tweets}&quot;&gt; &lt;/ul&gt;
  &lt;/div&gt;
&lt;/script&gt;
&nbsp;
&lt;script type=&quot;text/x-jquery-tmpl&quot; charset=&quot;utf-8&quot; id=&quot;tweetView&quot;&gt;
  &lt;li class=&quot;tweet&quot;
    data-bind=&quot;click: select&quot;&gt;
    &lt;div class=&quot;thumbnailColumn&quot;&gt;
      &lt;img data-bind=&quot;attr: { src: thumbnail }&quot; class=&quot;thumbnail&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;detailsColumn&quot;&gt;
      &lt;div class=&quot;author&quot; data-bind=&quot;text: author&quot;/&gt; 
      &lt;div class=&quot;text&quot; data-bind=&quot;text: text&quot;/&gt; 
      &lt;div class=&quot;time&quot; data-bind=&quot;text: time&quot;/&gt; 
    &lt;/div&gt;
  &lt;/li&gt;
&lt;/script&gt;
&nbsp;
&lt;script type=&quot;text/x-jquery-tmpl&quot; charset=&quot;utf-8&quot; id=&quot;tweetDetailView&quot;&gt;
  &lt;div class=&quot;tweet&quot;&gt;
    &lt;div class=&quot;thumbnailColumn&quot;&gt;
      &lt;img data-bind=&quot;attr: { src: thumbnail }&quot; class=&quot;thumbnail&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;detailsColumn&quot;&gt;
      &lt;div class=&quot;author&quot; data-bind=&quot;text: author&quot;/&gt; 
      &lt;div class=&quot;text&quot; data-bind=&quot;text: text&quot;/&gt; 
      &lt;div class=&quot;time&quot; data-bind=&quot;text: time&quot;/&gt; 
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/script&gt;
&nbsp;
&lt;h1 id=&quot;welcomeMsg&quot;&gt;Twitter Search&lt;/h1&gt;   
&lt;div id=&quot;app&quot; /&gt;</pre></div></div>

<p>When a tweet is clicked on, the <code>select </code>function is invoked via the Knockout binding. This simply pushes a <code>TweetViewModel</code> instance onto the application stack:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">select</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  application.<span style="color: #660066;">navigateTo</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Handling the Back-Button</h2>
<p>The above code navigates to the given view model, this will cause the <code>currentViewModel</code> dependent observable to notify that a change has occurred and the view that relates to this view model will be rendered. The next step is to wire up the back-button.</p>
<p>The <code>ApplicationViewModel</code> has a boolean <code>backButtonRequired</code> dependent observable that indicates whether the JavaScript code needs to handle the back-button. This is true whenever there is more than one item in the back-stack:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">backButtonRequired</span> <span style="color: #339933;">=</span> ko.<span style="color: #660066;">dependentObservable</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>    
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">viewModelBackStack</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>When the application is initially created, we handle changes to the observable as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">application.<span style="color: #660066;">backButtonRequired</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>backButtonRequired<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>backButtonRequired<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    document.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;backbutton&quot;</span><span style="color: #339933;">,</span> onBackButton<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    document.<span style="color: #660066;">removeEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;backbutton&quot;</span><span style="color: #339933;">,</span> onBackButton<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> onBackButton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  application.<span style="color: #000066;">back</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And that&#8217;s it! When the JavaScript back-stack has more than one item, the PhoneGap <code>backbutton</code> event is handled and the <code>back</code> function invoked on our application, popping the top item from the stack, with the view updating accordingly. When our JavaScript back-stack has a single item, we no longer handle the PhoneGap <code>backbutton</code> event, this results in the Silverlight container handling the back-button. The Silverlight application back-stack always has a single page, so our application will exit.</p>
<p>This technique for handling the back-stack is simple and elegant, this example has just two simple pages, however this same pattern should scale well for more complex HTML5 applications.</p>
<p>You can download the full sourcecode here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/11/PhoneGapBackStack.zip'>PhoneGapBackStack.zip</a></p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2011/11/handling-the-back-stack-in-windows-phone-7-phonegap-applications/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

