<?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>b-rad</title>
	<atom:link href="http://www.bradcurtis.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bradcurtis.com</link>
	<description>adventures in technology</description>
	<lastBuildDate>Thu, 18 Feb 2010 09:27:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Windows Phone 7 Series &#8211; notes from launch</title>
		<link>http://www.bradcurtis.com/2010/02/16/windows-phone-series-7-notes-from-launch/</link>
		<comments>http://www.bradcurtis.com/2010/02/16/windows-phone-series-7-notes-from-launch/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 21:49:22 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://www.bradcurtis.com/?p=12</guid>
		<description><![CDATA[Microsoft announced Windows Phone 7 today. It looks pretty amazing. The only negative point is that it won&#8217;t be out until the fourth quarter of 2010.

Below are my notes from the launch:
Approach

WP7 changed approach, focused on end users, business and otherwise
visual design is called &#8220;metro&#8221; graphical intense, high motion ui
home screen is called the &#8220;start <a href="http://www.bradcurtis.com/2010/02/16/windows-phone-series-7-notes-from-launch/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Microsoft announced Windows Phone 7 today. It looks pretty amazing. The only negative point is that it won&#8217;t be out until the fourth quarter of 2010.</p>
<p><a href="http://www.bradcurtis.com/wp-content/uploads/2010/02/wp7.jpg"><img class="alignnone size-full wp-image-13" title="wp7" src="http://www.bradcurtis.com/wp-content/uploads/2010/02/wp7.jpg" alt="Windows Phone 7 - Prototype Hardware" width="510" height="283" /></a></p>
<p>Below are my notes from the launch:</p>
<h2>Approach</h2>
<ul>
<li>WP7 changed approach, focused on end users, business and otherwise</li>
<li>visual design is called &#8220;metro&#8221; graphical intense, high motion ui</li>
<li>home screen is called the &#8220;start bar&#8221;</li>
<li>focuses on tasks rather than apps &#8211; tasks form a hub</li>
<li>Syncing to social networks seems to be a hands-off experience, sign in and it does the rest</li>
<li>Microsoft want to maintain stricter control of the look &amp; feel of the device while still allowing for third-party innovation</li>
</ul>
<h2>Hardware</h2>
<ul>
<li>three hardware buttons (back, start, search)</li>
<li>require capacitive touch (minimum 4 point touch)</li>
<li>WVGA screen</li>
<li>FM (or digital?) radio</li>
</ul>
<h2>Search</h2>
<ul>
<li>context sensitive &#8211; different results based on where you are in the phone (contacts, email etc.)</li>
<li>automatically uses GPS</li>
<li>search can be of three types, attempts to choose the most appropriate one automatically (local, news, web)</li>
</ul>
<h2>Web Browser</h2>
<ul>
<li>based on PC code for maximum compatibility</li>
<li>pinch zoom</li>
<li>tap to zoom (zoom to column on page)</li>
<li>sub pixel positioning for text)</li>
<li>recognizes phone numbers and addresses and makes them linkable</li>
<li>supports tabs</li>
</ul>
<h2>People Hub</h2>
<ul>
<li>Aggregates all your contacts from social networks (no twitter yet by the looks, I imagine this will change)</li>
<li>Shows people you have communicated with recently</li>
<li>&#8220;What&#8217;s new&#8221; feed: feed from all your social networks</li>
</ul>
<h2>Office Hub</h2>
<ul>
<li>Access to Microsoft Office apps like OneNote, Excel, Word etc.</li>
</ul>
<h2>Games hub</h2>
<ul>
<li>Syncs with Xbox live</li>
<li>Focus on social gamer experience</li>
<li>earn gamer score, achievements</li>
</ul>
<h2>Me tile</h2>
<ul>
<li>Simultaneously update your social networking status to multiple sites</li>
</ul>
<h2>Email</h2>
<ul>
<li>Supports all common providers including gmail, yahoo as well as Exchange (of course)</li>
<li>Never see a loading bar, works against a local cache (very fast experience)</li>
</ul>
<h2>Text</h2>
<ul>
<li>Supports SMS, MMS</li>
<li>Supports portrait/landscape typing modes</li>
</ul>
<h2>Calendar</h2>
<ul>
<li>Automatically merges your personal and work calendars</li>
</ul>
<h2>Pictures</h2>
<ul>
<li>gallery lets you browse all pictures</li>
<li>&#8220;mosaic&#8221; shows recent or favourite pictures</li>
<li>&#8220;What&#8217;s new&#8221; feed shows latest pictures from your social networking sites (Facebook, Windows Live etc)</li>
<li>Album view combines folders from photos synced from Zune software on your PC with albums from Facebook, Windows Live</li>
<li>Social networking comments are displayed when you view a picture</li>
</ul>
<h2>Music and Video</h2>
<ul>
<li>Full Zune HD experience</li>
<li>Supports Zune pass/subscription</li>
</ul>
<h2>Other</h2>
<ul>
<li>toolbar is always available at the bottom to access &#8220;enhanced&#8221; commands</li>
<li>UI is not completely done (especially some of the buttons you see)</li>
<li>one press to correct words you&#8217;ve messed up in keyboard mode</li>
</ul>
<p>More information:</p>
<p><a href="http://channel9.msdn.com/posts/LauraFoy/First-Look-Windows-Phone-7-Series-Hands-on-Demo/" target="_blank">http://channel9.msdn.com/posts/LauraFoy/First-Look-Windows-Phone-7-Series-Hands-on-Demo/</a></p>
<p><a href="http://www.windowsphone7series.com" target="_blank">http://www.windowsphone7series.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradcurtis.com/2010/02/16/windows-phone-series-7-notes-from-launch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows 7 tablets versus the Apple iPad</title>
		<link>http://www.bradcurtis.com/2010/02/07/windows-7-tablets-versus-the-apple-ipad/</link>
		<comments>http://www.bradcurtis.com/2010/02/07/windows-7-tablets-versus-the-apple-ipad/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 07:20:09 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[tablet]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://www.bradcurtis.com/?p=10</guid>
		<description><![CDATA[There&#8217;s plenty of things not to like about the iPad. However the user experience isn&#8217;t one of them. I think the Windows 7 crew have a fair way to go in this respect.
See the videos and make up your own mind.
HP Slate &#8211; Windows 7

Archos 9 &#8211; Windows 7

Apple iPad &#8211; iPhone OS

]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s plenty of things <a href="http://www.crunchgear.com/2010/01/27/apple-has-a-solution-for-the-ipads-missing-sd-card-slot-and-usb-port-adapters/">not</a> <a href="http://gizmodo.com/5458382/8-things-that-suck-about-the-ipad">to</a> <a href="http://www.popsci.com.au/gadgets/article/2010-01/ipad%E2%80%99s-closed-system-sometimes-i-hate-being-right">like</a> about the iPad. However the user experience isn&#8217;t one of them. I think the Windows 7 crew have a fair way to go in this respect.</p>
<p>See the videos and make up your own mind.</p>
<h2>HP Slate &#8211; Windows 7</h2>
<p><object type="application/x-shockwave-flash" style="width:560px; height:340px;" data="http://www.youtube.com/v/En7cdBhlrGU&#038;start=165"><param name="movie" value="http://www.youtube.com/v/En7cdBhlrGU&#038;start=165" /></object></p>
<h2>Archos 9 &#8211; Windows 7</h2>
<p><object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=6493470&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=6493470&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object></p>
<h2>Apple iPad &#8211; iPhone OS</h2>
<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/c4IBN5OAdZc&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;start=20"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/c4IBN5OAdZc&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;start=20" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradcurtis.com/2010/02/07/windows-7-tablets-versus-the-apple-ipad/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Document and report generation using XAML, WPF data binding and XPS</title>
		<link>http://www.bradcurtis.com/2010/02/06/document-and-report-generation-using-xaml-wpf-databinding-and-xps/</link>
		<comments>http://www.bradcurtis.com/2010/02/06/document-and-report-generation-using-xaml-wpf-databinding-and-xps/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 12:18:55 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>
		<category><![CDATA[xps]]></category>

		<guid isPermaLink="false">http://www.bradcurtis.com/?p=3</guid>
		<description><![CDATA[Generating printable documents or reports containing dynamic data is a common requirement of most business systems. In this post I will show you how to create XPS documents dynamically using WPF templates loaded from the file system and populated with data binding. This technique is especially powerful when the output document needs to be either <a href="http://www.bradcurtis.com/2010/02/06/document-and-report-generation-using-xaml-wpf-databinding-and-xps/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Generating printable documents or reports containing dynamic data is a common requirement of most business systems. In this post I will show you how to create XPS documents dynamically using WPF templates loaded from the file system and populated with data binding. This technique is especially powerful when the output document needs to be either highly dynamic or has lots of design elements. The example document we will create looks something like this:</p>
<p><a href="http://www.bradcurtis.com/wp-content/uploads/2010/02/docscreenshot3.png"><img class="size-full wp-image-9 alignnone" title="Document Template" src="http://www.bradcurtis.com/wp-content/uploads/2010/02/docscreenshot3.png" alt="" width="476" height="468" /></a></p>
<h2>The document template</h2>
<p>For a fixed format document the &lt;FixedDocument/&gt; is a logical starting point. The template needed to make our document is as follows:</p>
<pre class="brush: xml">&lt;FixedDocument
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xml:lang="en-au"&gt;
   &lt;FixedDocument.Resources&gt;
      &lt;BooleanToVisibilityConverter x:Key="visConverter"/&gt;
   &lt;/FixedDocument.Resources&gt;
   &lt;PageContent&gt;
      &lt;FixedPage Width="793.76" Height="1122.56"&gt;
         &lt;!-- Page 1 Begins Here --&gt;
         &lt;StackPanel Margin="50"&gt;
            &lt;Border BorderThickness="5" BorderBrush="Gray" CornerRadius="10"
               Padding="20" Width="690"&gt;
               &lt;StackPanel Orientation="Horizontal" Margin="0 0 0 0"&gt;
                  &lt;Image Source="truck.jpg" HorizontalAlignment="Left"/&gt;
                  &lt;TextBlock Margin="30 0 0 0" FontSize="50"
                     Text="{Binding Path=Heading}" VerticalAlignment="Center"/&gt;
               &lt;/StackPanel&gt;
            &lt;/Border&gt;
            &lt;TextBlock Margin="0 30 0 0"
               Text="{Binding Path=CurrentDate, StringFormat='{}{0:d MMMM yyyy}'}"/&gt;
            &lt;TextBlock Margin="0 30 0 0"
               Text="{Binding Path=Name, StringFormat='Dear {0},'}" /&gt;
            &lt;ItemsControl Margin="30 20 0 0" ItemsSource="{Binding Path=DotPoints}"
               HorizontalAlignment="Left"&gt;
               &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                     &lt;StackPanel Margin="0,8,0,0" Orientation="Horizontal" &gt;
                        &lt;TextBlock Text="• " /&gt;
                        &lt;TextBlock Text="{Binding}" TextWrapping="Wrap" Width="400"/&gt;
                     &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
               &lt;/ItemsControl.ItemTemplate&gt;
            &lt;/ItemsControl&gt;
            &lt;TextBlock Margin="0 30 0 0"
               Text="Congratulations, you are entitled to a 50% discount!"
               Visibility="{Binding Path=GiveDiscount,
                                        Converter={StaticResource visConverter}}"/&gt;
         &lt;/StackPanel&gt;
      &lt;/FixedPage&gt;
   &lt;/PageContent&gt;
   &lt;PageContent&gt;
      &lt;FixedPage Width="793.76" Height="1122.56"&gt;
         &lt;!-- Page 2 Begins Here --&gt;
         &lt;TextBlock Margin="50" Text="Nothing to see here."/&gt;
      &lt;/FixedPage&gt;
   &lt;/PageContent&gt;
&lt;/FixedDocument&gt;</pre>
<p>This includes the namespace imports that should be familiar to any WPF developer. One thing of interest in this template is the hard coded width and height of the &lt;FixedPage/&gt;. These values have specified an A4 page in portrait orientation. These have been based on the DPI of WPF (96) and the dimensions of an A4 page.</p>
<p>The XAML template includes standard WPF binding expressions which will be used to populate the document with dynamic data. It also makes use of the BooleanToVisibilityConverter to make easy show/hide functionality through data binding.</p>
<h2>Loading the template from the file system</h2>
<p>System.Windows.Markup.XamlReader provides an easy way of parsing XAML markup into objects:</p>
<pre class="brush: csharp">public static object LoadTemplate(string templatePath)
{
   object template;

   // get the needed template paths
   string absolutePath = Path.GetFullPath(templatePath);
   string directoryPath = Path.GetDirectoryName(absolutePath);

   using (FileStream inputStream = File.OpenRead(absolutePath))
   {
      var pc = new ParserContext
      {
         // It is critical to have the trailing backslash here
         // will not work without it!
         BaseUri = new Uri(directoryPath + "\\")
      };

      template = XamlReader.Load(inputStream, pc);
   }

   return template;
}</pre>
<p>It&#8217;s critical here to setup the ParserContext so that resources can be referenced from the XAML. In our example we reference an image, but you can also reference things like fonts and other XAML files.</p>
<h2>Injecting data into the document with data binding</h2>
<p>For our example we will use basic object data binding. However this technique would work equally well with other WPF binding sources such as XML. The object we will bind to has properties which correspond to the binding expressions in the template:</p>
<pre class="brush: csharp">public class Data
{
   public string Heading { get; set; }
   public DateTime CurrentDate { get; set; }
   public string Name { get; set; }
   public string[] DotPoints { get; set; }
   public bool GiveDiscount { get; set; }
}</pre>
<pre class="brush: csharp">public static void InjectData(FixedDocument document, object dataSource)
{
   document.DataContext = dataSource;

   // we need to give the binding infrastructure a push as we
   // are operating outside of the intended use of WPF
   var dispatcher = Dispatcher.CurrentDispatcher;
   dispatcher.Invoke(
      DispatcherPriority.SystemIdle,
      new DispatcherOperationCallback(delegate { return null; }),
      null);
}</pre>
<p>In this code we set the DataContext for the FixedDocument to be the object containing the data. The strange thing is the dispatcher code. In a normal WPF application the dispatcher is used to marshal calls from worker threads to the UI thread. It seems that data binding outside of the UI context is not triggered unless the dispatcher is woken from its sleepy state. To do this we give it an arbitrary task.</p>
<h2>Save our document to XPS</h2>
<p>The ugliest code is left for last.  Below is what is required to convert a FixedDocument to an XPS format file ready to be viewed and printed by the user:</p>
<pre class="brush: csharp">public static void ConvertToXps(FixedDocument fixedDoc, Stream outputStream)
{
   var package = Package.Open(outputStream, FileMode.Create);
   var xpsDoc = new XpsDocument(package, CompressionOption.Normal);
   XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

   // xps documents are built using fixed document sequences
   var fixedDocSeq = new FixedDocumentSequence();
   var docRef = new DocumentReference();
   docRef.BeginInit();
   docRef.SetDocument(fixedDoc);
   docRef.EndInit();
   ((IAddChild)fixedDocSeq).AddChild(docRef);

   // write out our fixed document to xps
   xpsWriter.Write(fixedDocSeq.DocumentPaginator);

   xpsDoc.Close();
   package.Close();
}</pre>
<p>When working with XPS files you will find that you always have to work within a Package. The other interesting part of this code is the cast to IAddChild which is needed to add the DocumentReference as content within the FixedDocumentSequence.</p>
<h2>Exception: the calling thread must be STA</h2>
<p>WPF controls can only be used in STA threads. This isn&#8217;t usually something you have to consider when you are using WPF in a GUI application. However, if you are attempting to use this XPS code deep within some class library then the apartment state of the calling thread cannot be guaranteed. Instead of putting this requirement onto the consumer of your class you can use code like the following:</p>
<pre class="brush: csharp">if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
{
   var t = new Thread(() =&gt;
      {
         // do work here when calling thread is not STA
      });
   t.SetApartmentState(ApartmentState.STA);
   t.IsBackground = false;
   t.Start();
   t.Join();
}
else
{
   // do work here when calling thread is STA
   // this removes the overhead of creating
   // a new thread when it is not necessary
}</pre>
<h2>Final comments</h2>
<p>This XPS generation technique is extremely flexible. Some key strengths:</p>
<ul>
<li>Allows for the full power of WPF, enabling attractive documents</li>
<li>You can use user controls as well as third party components such as charting libraries</li>
<li>Your own custom ValueConverters in combination with <a title="DataTrigger" href="http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx" target="_self">data triggers</a> can be used for almost any dynamic requirement (this is probably worth another post)</li>
<li>Conversion to PDF is possible with third party libraries</li>
</ul>
<p><strong>Visual Studio 2008 Solution</strong> &#8211; <a href="http://www.bradcurtis.com/wp-content/uploads/2010/02/XpsDocumentGenerator.zip">XpsDocumentGenerator.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bradcurtis.com/2010/02/06/document-and-report-generation-using-xaml-wpf-databinding-and-xps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
